You've already forked taptap2024_GJ_chidouren
74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
using System;
|
|
using Framework.Timer;
|
|
using UnityEngine;
|
|
|
|
namespace Game.Component
|
|
{
|
|
public class MapContent : MonoBehaviour
|
|
{
|
|
public PlayerEntity PlayerEntity;
|
|
[HideInInspector] public ScenePart ScenePart;
|
|
public AstarPath Pathfinder;
|
|
|
|
//玩家位置
|
|
public Vector2 PlayerPosition { private set; get; }
|
|
|
|
//全局特殊单例
|
|
public static MapContent Instance;
|
|
|
|
private void Awake ()
|
|
{
|
|
//全局特殊单例
|
|
Instance = this;
|
|
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;
|
|
this.Pathfinder.data.SetData (this.ScenePart.mapCacheData.bytes);
|
|
CameraManager.Instance.SetBoxCollider (this.ScenePart.cameraCollider);
|
|
ResetPlayer ();
|
|
CameraManager.Instance.SetCameraState (CameraManager.CameraState.Player_Near);
|
|
}
|
|
|
|
public void ResetPlayer ()
|
|
{
|
|
this.PlayerEntity.transform.position = this.ScenePart.createPos.position;
|
|
this.PlayerEntity.gameObject.SetActive (true);
|
|
this.PlayerEntity.RefreshInit ();
|
|
//播放特效
|
|
}
|
|
|
|
public void OverlyCoin (int messageOverlyCoin)
|
|
{
|
|
// ReSharper disable once Unity.NoNullPropagation
|
|
this.ScenePart?.AddConditionNumber (messageOverlyCoin);
|
|
}
|
|
}
|
|
} |