1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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<MonsterEntityVM>, 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<SpineComponent>();
- #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<SkeletonAnimation>("Skeleton");
- }
- }
- }
|