using Thousandto.Code.Center; using Thousandto.Code.Logic.WarningField; using Thousandto.Core.Asset; using Thousandto.Core.Base; using Thousandto.Plugins.Common.UniScene; using System.Collections.Generic; using UnityEngine; namespace Thousandto.Code.Logic { public class WarningFiledInst { #region//私有变量 private Entity _host = null; private static uint _idCounter = 1; private uint _id = 0; private GameObject _ownerGo = null; private Transform _ownerTrans = null; private NewWarningFiled _filedScript = null; private float _maxLifeTime = 0f; private float _lifeTimer = 0f; private bool _syncPos = false; private bool _syncDir = false; //技能参数 private SkillTargetArea _areaType = SkillTargetArea.Rectangle; private float _skillParam1 = 0f; private float _skillParam2 = 0f; #endregion #region//属性 public bool IsFinish { get { return _maxLifeTime > 0 ? _lifeTimer >= _maxLifeTime : false; } } public uint ID { get { return _id; } } public Entity Host { get { return _host; } } public Vector2 Position2D { get { return new Vector2(_ownerTrans.position.x, _ownerTrans.position.z); } } public Vector2 Forward2D { get { return new Vector2(_ownerTrans.forward.x, _ownerTrans.forward.z); } } public SkillTargetArea AreaType { get { return _areaType; } } public float SkillParam1 { get { return _skillParam1; } } public float SkillParam2 { get { return _skillParam2; } } public float LifeTimer { get { return _lifeTimer; } } #endregion #region//构造函数 public WarningFiledInst(Entity host, bool syncPos, bool syncDir, SkillTargetArea areaType, float param1, float param2, float startDis, float aniTime) { _host = host; _ownerGo = new GameObject(string.Format("{0}_{1}", host.GetType().Name, _host.ID)); _ownerTrans = _ownerGo.transform; _ownerTrans.parent = WarningFiledManager.Root; _ownerTrans.position = host.Position; _ownerTrans.forward = host.Skin.GetForward(); _syncPos = syncPos; _syncDir = syncDir; _maxLifeTime = aniTime + 0.5f; _lifeTimer = 0f; _id = ++_idCounter; _areaType = areaType; _skillParam1 = param1; _skillParam2 = param2; switch (areaType) { case SkillTargetArea.Rectangle: _filedScript = NewWarningFiled.AddRectWarningField(_ownerGo, param1, param2, startDis, aniTime, GetHeightFunc); break; case SkillTargetArea.FanShaped: _filedScript = NewWarningFiled.AddFanShapedWarningField(_ownerGo, param1, param2, startDis, aniTime, GetHeightFunc); break; case SkillTargetArea.Round: _filedScript = NewWarningFiled.AddRoundWarningField(_ownerGo, param1, aniTime, startDis, GetHeightFunc); break; } } public WarningFiledInst(Entity host, Vector3 pos, SkillTargetArea areaType, float param1, float param2, float startDis, float aniTime) { _host = host; _ownerGo = new GameObject(string.Format("{0}_{1}", host.GetType().Name, _host.ID)); _ownerTrans = _ownerGo.transform; _ownerTrans.parent = WarningFiledManager.Root; _ownerTrans.position = pos; _ownerTrans.forward = host.Skin.GetForward(); _syncPos = false; _syncDir = false; _maxLifeTime = aniTime + 0.5f; _lifeTimer = 0f; _id = ++_idCounter; _areaType = areaType; _skillParam1 = param1; _skillParam2 = param2; switch (areaType) { case SkillTargetArea.Rectangle: _filedScript = NewWarningFiled.AddRectWarningField(_ownerGo, param1, param2, startDis, aniTime, GetHeightFunc); break; case SkillTargetArea.FanShaped: _filedScript = NewWarningFiled.AddFanShapedWarningField(_ownerGo, param1, param2, startDis, aniTime, GetHeightFunc); break; case SkillTargetArea.Round: _filedScript = NewWarningFiled.AddRoundWarningField(_ownerGo, param1, startDis, aniTime, GetHeightFunc); break; } } private Vector3 GetHeightFunc(Vector3 pos) { float height = 0; _host.Scene.GetHeightOnTerrain(pos.x, pos.z, out height); height += 0.15f; return new Vector3(pos.x, height, pos.z); } #endregion #region//公有函数 public void Destroy() { if (_filedScript != null) { _filedScript.DestoryField(); } GameObject.Destroy(_ownerGo); } public void Update() { if (_maxLifeTime > 0 && _lifeTimer < _maxLifeTime) { _lifeTimer += Time.deltaTime; } if (_syncPos) { _ownerTrans.position = _host.Position; } if (_syncDir) { _ownerTrans.forward = _host.Skin.GetForward(); } } #endregion } }