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 bool IsActiveGame; //玩家位置 public Vector2 PlayerPosition { private set; get; } //全局特殊单例 public static MapContent Instance; private void Awake () { //全局特殊单例 Instance = this; var componentInChildren = this.transform.GetComponentInChildren (); 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.ScenePart.InitPart (); // this.Pathfinder.data.SetData (this.ScenePart.mapCacheData.bytes); // this.Pathfinder.FlushGraphUpdates (); this.Pathfinder.Scan (); CameraManager.Instance.SetBoxCollider (this.ScenePart.cameraCollider); } public void ResetGame () { this.ScenePart.RefreshInit (); 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); } } }