summaryrefslogtreecommitdiff
path: root/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs
blob: 556f411f8b78ec834cb228e6f0c454afb146898f (plain)
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
70
71
72
using Rigging.BodyPart;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Rigging.Data
{
    //Player <StepHandler> 更新脚步切换状态,返回哪个脚在前,哪个在后,配合AnimationObject使用
    public class StepHandler : RiggingDataBase
    {

        public float staticCounter;

        public AnimationParam<Step> steps;

        public bool isLeft;//左脚还是右脚在前面

        public float counter;

        public Transform leftLeg;

        public Transform rightLeg;

        public Transform hip;

        protected override void OnStart()
        {
            if (staticCounter == 0f)
            {
                leftLeg = player.body.legLeft.transform;
                rightLeg = player.body.legRight.transform;
                hip = player.body.hip.transform;
            }
            steps.SetPlayer(player);
        }

        protected override void OnUpdate()
        {
            counter += Time.deltaTime;
            if (staticCounter != 0f)
            {
                if (counter > staticCounter)
                {
                    Switch();
                }
            }
            else if ( counter > steps.current.minTime
            && player.status.animation.animationState > 0 // 非standing
            && (steps.current.minAngle == 0f || steps.current.minAngle < Vector3.Angle(leftLeg.forward, rightLeg.forward))
            && isLeft == hip.InverseTransformPoint(leftLeg.position + leftLeg.forward).z > hip.InverseTransformPoint(rightLeg.position + rightLeg.forward).z//
            )
            {
                Switch();
            }
        }

        private void Switch()
        {
            //Debug.Log(counter);
            isLeft = !isLeft;
            counter = 0f;
        }

        public void OnGUI()
        {
            GUILayout.Label(isLeft.ToString());
        }

    }
     
}