yyl
3 天以前 cec8b67d82c2c2c1662d55c818c4a46bcc0487db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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, duration, () =>
            {
                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