Files
taptap2024_GJ_chidouren/Assets/Scripts/Game/Component/MapContent.cs

79 lines
2.2 KiB
C#
Raw Normal View History

2024-10-16 00:03:41 +08:00
using System;
2024-10-21 16:20:37 +08:00
using Framework.Timer;
2024-10-16 00:03:41 +08:00
using UnityEngine;
namespace Game.Component
{
public class MapContent : MonoBehaviour
{
2024-10-21 16:20:37 +08:00
public PlayerEntity PlayerEntity;
[HideInInspector] public ScenePart ScenePart;
public AstarPath Pathfinder;
2024-10-21 17:02:25 +08:00
public bool IsActiveGame;
2024-10-16 00:03:41 +08:00
//玩家位置
public Vector2 PlayerPosition { private set; get; }
//全局特殊单例
public static MapContent Instance;
private void Awake ()
{
//全局特殊单例
Instance = this;
2024-10-21 16:20:37 +08:00
var componentInChildren = this.transform.GetComponentInChildren<ScenePart> ();
if (componentInChildren != null)
{
SetPart (componentInChildren);
}
}
private void OnEnable ()
{
GameUpdateMgr.Instance.AddUpdater (DoUpdate);
}
private void OnDisable ()
{
GameUpdateMgr.Instance.RemoveUpdater (DoUpdate);
}
private void DoUpdate ()
{
this.PlayerPosition = this.PlayerEntity.transform.position;
}
public void SetPart (ScenePart scenePart)
{
if (this.ScenePart != null)
{
GameObject.Destroy (this.ScenePart.gameObject);
}
this.ScenePart = scenePart;
2024-10-21 17:02:25 +08:00
this.ScenePart.InitPart ();
2024-10-21 16:32:14 +08:00
// this.Pathfinder.data.SetData (this.ScenePart.mapCacheData.bytes);
// this.Pathfinder.FlushGraphUpdates ();
this.Pathfinder.Scan ();
2024-10-21 16:20:37 +08:00
CameraManager.Instance.SetBoxCollider (this.ScenePart.cameraCollider);
}
2024-10-21 17:02:25 +08:00
public void ResetGame ()
2024-10-21 16:20:37 +08:00
{
2024-10-21 17:02:25 +08:00
this.ScenePart.RefreshInit ();
2024-10-21 16:20:37 +08:00
this.PlayerEntity.transform.position = this.ScenePart.createPos.position;
this.PlayerEntity.gameObject.SetActive (true);
this.PlayerEntity.RefreshInit ();
//播放特效
2024-10-16 00:03:41 +08:00
}
2024-10-21 16:20:37 +08:00
public void OverlyCoin (int messageOverlyCoin)
2024-10-16 00:03:41 +08:00
{
2024-10-21 16:20:37 +08:00
// ReSharper disable once Unity.NoNullPropagation
this.ScenePart?.AddConditionNumber (messageOverlyCoin);
2024-10-16 00:03:41 +08:00
}
}
}