1using NaughtyAttributes;
2using System.Collections;
3using System.Collections.Generic;
14 private GameObject canvasGo;
15 private Canvas canvas;
16 private Canvas canvasOffsetEditor;
18 private GameObject handPrefab, leftHandPrefab;
19 private GameObject handInstance;
20 private GameObject objectToGrab;
21 private Transform attachPoint;
22 private bool editingLeft =
false;
27 pb_GUIUtility.AddVerticalLayoutGroup(gameObject);
29 var horizontalParent =
new GameObject(
"HorizontalParent");
30 var hlg = horizontalParent.AddComponent<HorizontalLayoutGroup>();
31 var lec = horizontalParent.AddComponent<LayoutElement>();
33 horizontalParent.transform.SetParent(transform);
36 var buttonGO =
new GameObject(
"ClickButton");
37 var image = buttonGO.AddComponent<
Image>();
38 var button = buttonGO.AddComponent<
Button>();
39 var textGO =
new GameObject(
"LabelGO");
40 var text = textGO.AddComponent<Text>();
41 textGO.GetComponent<RectTransform>().sizeDelta =
new Vector2(65, 14);
42 text.font = Font.CreateDynamicFontFromOSFont(
"Arial", 24);
43 text.alignment = TextAnchor.MiddleCenter;
44 text.text =
Macro.
T(
"Edit Left offset");
45 text.color =
Color.white;
46 text.resizeTextForBestFit =
true;
47 text.resizeTextMaxSize = 16;
48 textGO.transform.SetParent(buttonGO.transform);
49 image.sprite = GameObject.Find(
"SaveButton").GetComponent<
Image>().sprite;
50 image.type =
Image.Type.Sliced;
51 image.color =
new Color(255, 255, 255, 40 / 255.0f);
52 buttonGO.transform.SetParent(horizontalParent.transform);
53 button.onClick.AddListener(EnterLeftOffsetEditor);
56 var buttonGO =
new GameObject(
"ClickButton");
57 var image = buttonGO.AddComponent<
Image>();
58 var button = buttonGO.AddComponent<
Button>();
59 var textGO =
new GameObject(
"LabelGO");
60 var text = textGO.AddComponent<Text>();
61 textGO.GetComponent<RectTransform>().sizeDelta =
new Vector2(65, 14);
62 text.font = Font.CreateDynamicFontFromOSFont(
"Arial", 24);
63 text.alignment = TextAnchor.MiddleCenter;
64 text.text =
Macro.
T(
"Edit Right offset");
65 text.color =
Color.white;
66 text.resizeTextForBestFit =
true;
67 text.resizeTextMaxSize = 16;
68 textGO.transform.SetParent(buttonGO.transform);
69 image.sprite = GameObject.Find(
"SaveButton").GetComponent<
Image>().sprite;
70 image.type =
Image.Type.Sliced;
71 image.color =
new Color(255,255,255, 40/255.0f);
72 buttonGO.transform.SetParent(horizontalParent.transform);
73 button.onClick.AddListener(EnterOffsetEditor);
77 handPrefab = Resources.Load(
"OffsetEditorHand_new") as GameObject;
78 leftHandPrefab = Resources.Load(
"OffsetEditorLeftHand_new") as GameObject;
80 handPrefab = Resources.Load(
"OffsetEditorHand_WebGL") as GameObject;
81 leftHandPrefab = Resources.Load(
"OffsetEditorLeftHand_WebGL") as GameObject;
85 void EnterOffsetEditor()
87 if (handPrefab ==
null){
88 Debug.LogError(
"couldn't find glove, offset editor cannot be entered");
93 if(objectToGrab ==
null){
94 Debug.LogError(
"no selected object, offset editor cannot be entered");
98 Vector3 scale = objectToGrab.transform.localScale;
99 if(scale.x == 0f || scale.y == 0f || scale.z == 0f) {
100 Debug.LogError(
"object has at least one scale component set to 0, offset editor cannot be entered");
104 offsetHolder = objectToGrab.GetComponent<
OffsetHolder>();
105 StartCoroutine(SpawnHand());
108 void EnterLeftOffsetEditor()
110 if (leftHandPrefab ==
null){
111 Debug.LogError(
"couldn't find glove, offset editor cannot be entered");
115 objectToGrab = pb_Selection.activeGameObject;
116 if(objectToGrab ==
null){
117 Debug.LogError(
"no selected object, offset editor cannot be entered");
121 Vector3 scale = objectToGrab.transform.localScale;
122 if(scale.x == 0f || scale.y == 0f || scale.z == 0f) {
123 Debug.LogError(
"object has at least one scale component set to 0, offset editor cannot be entered");
127 offsetHolder = objectToGrab.GetComponent<
OffsetHolder>();
128 StartCoroutine(SpawnHand(
true));
133 canvasGo = GameObject.Find(
"Canvas");
134 canvas = canvasGo.GetComponent<Canvas>();
135 canvas.enabled =
false;
137 GameObject canvasOffsetGo = GameObject.Find(
"Canvas_OffsetEditor");
138 canvasOffsetEditor = canvasOffsetGo.GetComponent<Canvas>();
139 canvasOffsetEditor.enabled =
true;
141 saveBtn = canvasOffsetGo.GetComponentInChildren<
Button>();
144 Debug.Log(
"save btn not found");
147 saveBtn.onClick.AddListener(ExitOffsetEditor);
148 pb_Selection.Clear();
149 pb_Selection.SetSelection(attachPoint.gameObject);
150 pb_Selection.AddOnRemovedFromSelectionListener(OnRemovedFromSelection);
153 IEnumerator SpawnHand(
bool left =
false)
157 handInstance = Instantiate(left ? leftHandPrefab : handPrefab,
Vector3.zero,
new Quaternion(),
null);
160 attachPoint = handInstance.transform.Find(
"AttachPoint");
161 attachPoint.transform.SetParent(
null,
true);
164 handInstance.transform.SetParent(attachPoint,
true);
167 attachPoint.transform.SetParent(objectToGrab.transform,
true);
170 attachPoint.transform.localPosition = left ? offsetHolder.
LeftOffset : offsetHolder.
Offset;
174 var scale = attachPoint.transform.localScale;
176 if (scale.x != scale.y || scale.x != scale.z)
178 attachPoint.transform.SetParent(
null,
true);
181 attachPoint.transform.localScale =
Vector3.one;
183 attachPoint.transform.localScale =
Vector3.one * 0.09f;
192 private void slowspawn1()
194 objectToGrab = pb_Selection.activeGameObject;
195 offsetHolder = objectToGrab.GetComponent<
OffsetHolder>();
199 private void slowspawn2()
201 attachPoint = handInstance.transform.Find(
"AttachPoint");
202 attachPoint.transform.SetParent(
null,
true);
205 private void slowspawn3()
207 handInstance.transform.SetParent(attachPoint,
true);
210 private void slowspawn4()
212 attachPoint.transform.SetParent(objectToGrab.transform,
true);
215 private void slowspawn5()
217 attachPoint.transform.localPosition = offsetHolder.
Offset;
221 void ExitOffsetEditor()
223 saveBtn.onClick.RemoveListener(ExitOffsetEditor);
224 pb_Selection.instance.OnRemovedFromSelection -= OnRemovedFromSelection;
226 MiscLogicManager.
instance.OffsetEditorHelper(attachPoint, objectToGrab, offsetHolder, canvas, canvasOffsetEditor, editingLeft);
247 IEnumerator ActualExitSave()
249 attachPoint.SetParent(objectToGrab.transform,
true);
254 offsetHolder.
LeftOffset = attachPoint.localPosition;
255 offsetHolder.
LeftRotation = attachPoint.localRotation.eulerAngles;
259 offsetHolder.
Offset = attachPoint.localPosition;
260 offsetHolder.
Rotation = attachPoint.localRotation.eulerAngles;
263 if (attachPoint.gameObject !=
null) Destroy(attachPoint.gameObject);
265 pb_Selection.Clear();
267 canvas.enabled =
true;
268 canvasOffsetEditor.enabled =
false;
271 void OnRemovedFromSelection(IEnumerable<GameObject> selection)
UnityEngine.UI.Button Button
System.Drawing.Image Image
Component target
The UnityEngine.Component being edited.
override void InitializeGUI()
static GameObject activeGameObject
static string T(string key)