using Framework; using Gameplay.Effect; using Gameplay.Unit; using PhxhSDK; using UnityEngine; using Constants = Framework.Constants; namespace Gameplay.Level { public class SelecterView : Singlenton, IInitable { // 选中圆圈特效 private EffectPlayingData _selectedGFX; // 选中的节点 private Node _selectedNode; private GameObject _selectedGroundGFX; // 目标特效 private Node _targetGFX; // 目标信息 private TargetInfo _targetInfo; public class TargetInfo { public Vector3 pos; } public void SetSelectAndTarget(Node node, TargetInfo targetInfo) { _selectedNode = node; _targetInfo = targetInfo; if (_selectedGFX == null) { _selectedGFX = EffectManager.instance.PlayEffectById(Constants.EID_CHARACTER_SELECT); } if (_targetGFX == null) { Node n = new Node(); AssetManager.Instance.LoadAssetAsync(Constants.CHARACTER_TARGET_GFX, delegate(GameObject o) { var instObj = Object.Instantiate(o, n.GameObject.transform); instObj.transform.ResetLocals(); }); _targetGFX = n; } BindGfx(); UpdateSelectedGround(null); } public void UnSelect(Node node) { if (_selectedNode == node) { if (_selectedGFX != null) { _selectedGFX.transform.SetParent(null); _selectedGFX.SetActive(false); } if (_targetInfo != null) { if (_targetGFX != null) { _targetGFX.IsActive = false; } _targetInfo = null; } if (_selectedGroundGFX != null) { _selectedGroundGFX.SetActive(false); } _selectedNode = null; } } public void Update(float deltaTime) { if (_selectedNode != null) { var nodePos = _selectedNode.GetPosition(); nodePos.y = 0.1f; _selectedGFX.transform.position = nodePos; } } private void BindGfx() { if (_selectedNode != null) { _selectedGFX.SetActive(true); } else { _selectedGFX.SetActive(false); } if (_targetInfo != null) { _targetGFX.transform.position = _targetInfo.pos; _targetGFX.transform.localRotation = Quaternion.identity; _targetGFX.transform.localScale = Vector3.one; _targetGFX.IsActive = true; } else { _targetGFX.IsActive = false; } } public void Init() { EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, OnCharacterArriveBlock); } public void Release() { EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, OnCharacterArriveBlock); if (_selectedGFX != null) { _selectedGFX.Destroy(); _selectedGFX = null; } if (_targetGFX != null) { _targetGFX.Dispose(); _targetGFX = null; } if (_selectedGroundGFX != null) { PhxhSDK.Utils.Destroy(_selectedGroundGFX); _selectedGroundGFX = null; } _selectedNode = null; _targetInfo = null; } private void OnCharacterArriveBlock(GameUnit gameUnit) { UpdateSelectedGround(gameUnit); } private void UpdateSelectedGround(GameUnit gameUnit) { if (_selectedNode == null) { return; } if (gameUnit != null && gameUnit.Node != null && gameUnit.Node != _selectedNode) { return; } var map = LevelManager.Instance.CurrentLevel?.Map?.TerrainGridSystem; if (map == null) { return; } var cell = gameUnit != null ? map.cells[gameUnit.transData.cellIndex] : map.CellGetAtPosition(_selectedNode.GetPosition(), true); var pos = map.CellGetPosition(cell); if (_selectedGroundGFX == null) { var sampleObj = AssetManager.Instance.GetPreLoadResult(Constants.CHARACTER_SELECT_GROUND_GFX); _selectedGroundGFX = GameObject.Instantiate(sampleObj); _selectedGroundGFX.transform.position = pos; } else { _selectedGroundGFX.SetActive(true); _selectedGroundGFX.transform.position = pos; } } } }