-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGimzo.cs
133 lines (118 loc) · 3.77 KB
/
Gimzo.cs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace BuilderMenu
{
public class Gizmo : MonoBehaviour
{
LineRenderer lr;
CapsuleCollider col;
public static float Lenght= 2;
public static float Witdh = 0.2f;
public static float Offset = 0.3f;
public static Transform parent;
public static Texture2D posImg;
public static Texture2D scaImg;
public static Texture2D rotImg;
public static Color selectColor;
private static bool isInitialized = false;
public GizmoTypes GizmoType;
public enum GizmoTypes
{
PositionX,
PositionY,
PositionZ,
RotationX,
RotationY,
RotationZ,
ScaleX,
ScaleY,
ScaleZ,
None
}
private Color color;
void Start()
{
if (!isInitialized)
{
parent = transform.parent;
posImg = ModAPI.Resources.GetTexture("Pos.PNG");
scaImg = ModAPI.Resources.GetTexture("Sca.PNG");
rotImg = ModAPI.Resources.GetTexture("Rot.PNG");
selectColor = Color.white;
}
Material mat = new Material(EditorVariables.GizmoMaterial);
if (GizmoType == GizmoTypes.PositionX)
{
mat.color = Color.red;
mat.mainTexture = posImg;
}
else if (GizmoType == GizmoTypes.PositionY)
{
mat.color = Color.green;
mat.mainTexture = posImg;
}
else if (GizmoType == GizmoTypes.PositionZ)
{
mat.color = Color.blue;
mat.mainTexture = posImg;
}
else if (GizmoType == GizmoTypes.ScaleX)
{
mat.color = Color.red;
mat.mainTexture = scaImg;
}
else if (GizmoType == GizmoTypes.ScaleY)
{
mat.color = Color.green;
mat.mainTexture = scaImg;
}
else if (GizmoType == GizmoTypes.ScaleZ)
{
mat.color = Color.blue;
mat.mainTexture = scaImg;
}
else if (GizmoType == GizmoTypes.RotationX)
{
mat.color = Color.red;
mat.mainTexture = rotImg;
}
else if (GizmoType == GizmoTypes.RotationY)
{
mat.color = Color.green;
mat.mainTexture = rotImg;
}
else if (GizmoType == GizmoTypes.RotationZ)
{
mat.color = Color.blue;
mat.mainTexture = rotImg;
}
color = mat.color;
lr = gameObject.AddComponent<LineRenderer>();
lr.material = mat;
col = gameObject.AddComponent<CapsuleCollider>();
col.direction = 2;
col.radius = 0.4f;
col.height = 2;
col.center = Vector3.zero;
col.isTrigger = false;
}
void Update()
{
lr.positionCount = 2;
lr.SetPosition(1, transform.position - transform.forward * Lenght / 2);
lr.SetPosition(0, transform.position + transform.forward * Lenght / 2);
transform.LookAt(parent);
}
public void SetEnabled()
{
lr.material.color = selectColor;
}
public void SetDisabled()
{
lr.material.color = color;
}
}
}