summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/ActionToolGizmos.cs
blob: eda72b1c1646039d8307638c697309cf1b0f1a45 (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
73
74
75
76
77
78
79
80
81
82
83
84
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ActionTool
{

    public class ActionToolGizmos : MonoBehaviour
    {
        AnimationData m_AnimationData;

        float m_CurAnimFrame;

        public void SetAnimationData(AnimationData data)
        {
            m_AnimationData = data;
        }

        public void SetCurAnimFrame(float frame)
        {
            m_CurAnimFrame = frame;
        }

        void OnDrawGizmos()
        {
            DrawRoot();
            DrawAxis();
            DrawColliders();
        }

        void DrawRoot()
        {
            Gizmos.color = Color.yellow;
            Gizmos.DrawCube(transform.position, new Vector3(0.1f, 0.1f, 0.1f));
        }

        void DrawAxis()
        {
            Gizmos.color = Color.red;
            Gizmos.DrawLine(Vector3.zero, Vector3.right * 1000);
            Gizmos.color = Color.green;
            Gizmos.DrawLine(Vector3.zero, Vector3.up * 1000);
            Gizmos.color = Color.blue;
            Gizmos.DrawLine(-Vector3.forward * 1000, Vector3.forward * 1000);
        }

        void DrawColliders()
        {
            if (m_AnimationData == null)
                return;
            DrawBoxes(m_AnimationData.hurtBoxes, Color.green);
            DrawBoxes(m_AnimationData.hitBoxes, Color.red);
        }

        void DrawBoxes(List<ColliderData> boxes, Color color)
        {
            if (boxes != null && boxes.Count > 0)
            {
                for (int i = 0; i < boxes.Count; ++i)
                {
                    var box = boxes[i];
                    if (box != null)
                    {
                        var info = box.GetColliderInfo(m_CurAnimFrame);
                        if (!info.active)
                            continue;
                        Vector3 pos = info.position;
                        switch (box.pivot)
                        {
                            case ColliderBox.Pivot.MiddleBottom:
                                pos.y += info.size.y / 2;
                                break;
                        }
                        pos += transform.position;
                        Gizmos.color = color * 0.5f;
                        Gizmos.DrawCube(pos, info.size);
                    }
                }
            }

        }

    }
}