using UnityEngine; using System.Collections.Generic; using System; #if UNITY_EDITOR public class TestAction : RecordAction { protected int targetIndex; protected int selfIndex; protected int distance = 100; protected float duration = 2f; public TestAction(BattleField _battleField, int _targetIndex, int _selfIndex, int _distance, float _duration) : base(RecordActionType.Death, _battleField, null) { targetIndex = _targetIndex; selfIndex = _selfIndex; distance = _distance; duration = _duration; } public override bool IsFinished() { return isFinish; } public override void Run() { base.Run(); if (!isRunOnce) { isRunOnce = true; RectTransform target = battleField.GetTeamNode(BattleCamp.Blue, targetIndex); MoveToTarget(target, new Vector2(distance, 0), duration, () => { BattleDebug.LogError(" reach to the target "); isFinish = true; }); return; } } protected void MoveToTarget(RectTransform target, Vector2 offset, float duration, Action onComplete = null) { try { BattleObject caster = battleField.battleObjMgr.GetBattleObjectByIndex(BattleCamp.Red, selfIndex); BattleDebug.LogError("Move to target , target is " + target.name); caster.motionBase.PlayAnimation(MotionName.run, true); var tweener = BattleUtility.MoveToTarget(caster.heroRectTrans, target, offset, () => { caster.motionBase.PlayAnimation(MotionName.idle, true); onComplete?.Invoke(); }); battleField.battleTweenMgr.OnPlayTween(tweener); } catch (Exception e) { BattleDebug.LogError("Error in MoveToTarget: " + e.Message); isFinish = true; } } } #endif