using FL.Battle; using FL.Battle.Components; using Spine.Unity; using UnityEngine; using XGame.Framework.Map; using XGame.Framework.ObjectCollection; namespace FL.Map { public class MonsterEntityView : BattleEntityView, ISkillContext, ISpineContext, IVfxContext, IStatesContext { public override Transform UIPoint => VM.UIPoint; protected override EEntityType DefaultTargetType => EEntityType.Player; //public void FindTarget(int skillId) //{ // Selector.FindAsync(this, EEntityType.Player, (target) => // { // SelectTarget(target, skillId); // }); //} public IAnimator Animator => GetComponent(); #region ISkillContext Transform ISkillContext.ActionRoot => VM.ActionRoot; void ISkillContext.OnSkillStart(int skillId) { if (States.IsState(EEntityState.MoveAI)) { Move.Pause(); } } void ISkillContext.OnSkillStop(int skillId) { //TOTO 临时代码 if ((Entity as MonsterEntity).IsBoss) return; //TOTO 临时代码 if (States.IsState(EEntityState.MoveAI)) { Move.Resume(); } else { var target = (Entity as MonsterEntity).BirthPosition; target.y -= 8; target.x += Random.Range(-2.5f, 2.5f); target.y += Random.Range(-4f, 4f); var moveArgs = new MoveArgs() { target = VM.Tr.parent.TransformPoint(target), speed = Entity.Attr.MoveSpeed * 0.5f, timeScale = Entity.Attr.MoveSpeedScale, }; moveArgs.onComplete += () => { States.RemoveState(EEntityState.MoveAI); }; States.AddState(EEntityState.MoveAI); Move.MoveTo(moveArgs); } } #endregion #region ISpineContext SkeletonAnimation ISpineContext.Skeleton => VM.Skeleton; #endregion #region IVfxContext Transform IVfxContext.WorldTr => null; Transform IVfxContext.CenterTr => VM.Tr; Transform IVfxContext.CastTr => VM.Tr; #endregion public override EpigraphicsComponent Epigraphics => null; } public class MonsterEntityVM : EntityViewModel { public Transform ActionRoot { get; private set; } public Transform UIPoint { get; private set; } public SkeletonAnimation Skeleton { get; private set; } protected override void OnInit(IObjectCollector collector) { ActionRoot = collector.GetGameObject("ActionRoot").transform; UIPoint = collector.GetGameObject("UIPoint").transform; Skeleton = collector.GetComponent("Skeleton"); } } }