UIElementEditor.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEditor;
  6. using UnityEditor.AnimatedValues;
  7. [CanEditMultipleObjects()]
  8. [CustomEditor(typeof(UIElement))]
  9. public class UIElementEditor : Editor
  10. {
  11. #region Settings Properties
  12. private SerializedProperty menuDependant;
  13. private SerializedProperty visible;
  14. private SerializedProperty controlledBy;
  15. private SerializedProperty prewarm;
  16. private SerializedProperty deactivateWhileInvisible;
  17. private SerializedProperty showAfter;
  18. private SerializedProperty hideAfter;
  19. private SerializedProperty showingDuration;
  20. private SerializedProperty hidingDuration;
  21. private SerializedProperty durationLink;
  22. #endregion
  23. #region Movement Properties
  24. private SerializedProperty movementSection;
  25. private SerializedProperty hidingPosition;
  26. private SerializedProperty edgeGap;
  27. private bool recordingPosition;
  28. private bool lastRecordingState;
  29. AnimBool showMovementProps;
  30. private static bool movementFoldout = true;
  31. #endregion
  32. #region Rotation Properties
  33. private SerializedProperty rotationSection;
  34. private SerializedProperty showingDirection;
  35. private SerializedProperty hidingDirection;
  36. AnimBool showRotationProps;
  37. private static bool rotationFoldout;
  38. #endregion
  39. #region Scale Properties
  40. private SerializedProperty scaleSection;
  41. AnimBool showScaleProps;
  42. private static bool scaleFoldout;
  43. #endregion
  44. #region Opacity Properties
  45. private SerializedProperty opacitySection;
  46. private SerializedProperty targetFader;
  47. AnimBool showOpacityProps;
  48. private static bool opacityFoldout;
  49. #endregion
  50. #region Slice Properties
  51. private SerializedProperty sliceSection;
  52. AnimBool showSliceProps;
  53. private static bool sliceFoldout;
  54. #endregion
  55. #region Activation Properties
  56. private SerializedProperty useSimpleActivation;
  57. #endregion
  58. #region Sounds Properties
  59. private SerializedProperty showingClip;
  60. private SerializedProperty hidingClip;
  61. #endregion
  62. #region Events Properties
  63. private SerializedProperty onShow;
  64. private SerializedProperty onHide;
  65. private SerializedProperty ignoreEventsOnInitialization;
  66. #endregion
  67. #region Editor Variables
  68. private static int selectedAnimTab = 0;
  69. private Texture linkIcon;
  70. private int lastAnimSection;
  71. private bool lastDurationLink;
  72. #endregion
  73. void OnEnable()
  74. {
  75. #region Settings Properties
  76. menuDependant = serializedObject.FindProperty("MenuDependent");
  77. visible = serializedObject.FindProperty("Visible");
  78. controlledBy = serializedObject.FindProperty("ControlledBy");
  79. prewarm = serializedObject.FindProperty("Prewarm");
  80. deactivateWhileInvisible = serializedObject.FindProperty("DeactivateWhileInvisible");
  81. showAfter = serializedObject.FindProperty("ShowAfter");
  82. hideAfter = serializedObject.FindProperty("HideAfter");
  83. showingDuration = serializedObject.FindProperty("ShowingDuration");
  84. hidingDuration = serializedObject.FindProperty("HidingDuration");
  85. durationLink = serializedObject.FindProperty("durationLink");
  86. #endregion
  87. #region Movement Properties
  88. movementSection = serializedObject.FindProperty("MovementSection");
  89. hidingPosition = serializedObject.FindProperty("HidingPosition");
  90. edgeGap = serializedObject.FindProperty("EdgeGap");
  91. bool showMovementPropsBool = true;
  92. for (int i = 0; i < targets.Length; i++)
  93. {
  94. if (!movementSection.FindPropertyRelative("UseSection").boolValue)
  95. showMovementPropsBool = false;
  96. }
  97. showMovementProps = new AnimBool(showMovementPropsBool);
  98. showMovementProps.valueChanged.AddListener(Repaint);
  99. #endregion
  100. #region Rotation Properties
  101. rotationSection = serializedObject.FindProperty("RotationSection");
  102. showingDirection = serializedObject.FindProperty("ShowingDirection");
  103. hidingDirection = serializedObject.FindProperty("HidingDirection");
  104. bool showRotationPropsBool = true;
  105. for (int i = 0; i < targets.Length; i++)
  106. {
  107. if (!rotationSection.FindPropertyRelative("UseSection").boolValue)
  108. showRotationPropsBool = false;
  109. }
  110. showRotationProps = new AnimBool(showRotationPropsBool);
  111. showRotationProps.valueChanged.AddListener(Repaint);
  112. #endregion
  113. #region Scale Properties
  114. scaleSection = serializedObject.FindProperty("ScaleSection");
  115. bool showScalePropsBool = true;
  116. for (int i = 0; i < targets.Length; i++)
  117. {
  118. if (!scaleSection.FindPropertyRelative("UseSection").boolValue)
  119. showScalePropsBool = false;
  120. }
  121. showScaleProps = new AnimBool(showScalePropsBool);
  122. showScaleProps.valueChanged.AddListener(Repaint);
  123. #endregion
  124. #region Opacity Properties
  125. opacitySection = serializedObject.FindProperty("OpacitySection");
  126. targetFader = serializedObject.FindProperty("TargetFader");
  127. bool showOpacityPropsBool = true;
  128. for (int i = 0; i < targets.Length; i++)
  129. {
  130. if (!opacitySection.FindPropertyRelative("UseSection").boolValue)
  131. showOpacityPropsBool = false;
  132. }
  133. showOpacityProps = new AnimBool(showOpacityPropsBool);
  134. showOpacityProps.valueChanged.AddListener(Repaint);
  135. #endregion
  136. #region Slice Properties
  137. sliceSection = serializedObject.FindProperty("SliceSection");
  138. bool showSlicePropsBool = true;
  139. for (int i = 0; i < targets.Length; i++)
  140. {
  141. if (!sliceSection.FindPropertyRelative("UseSection").boolValue)
  142. showSlicePropsBool = false;
  143. }
  144. showSliceProps = new AnimBool(showSlicePropsBool);
  145. showSliceProps.valueChanged.AddListener(Repaint);
  146. #endregion
  147. #region Activation Properties
  148. useSimpleActivation = serializedObject.FindProperty("UseSimpleActivation");
  149. #endregion
  150. #region Souds
  151. showingClip = serializedObject.FindProperty("ShowingClip");
  152. hidingClip = serializedObject.FindProperty("HidingClip");
  153. #endregion
  154. #region Events
  155. onShow = serializedObject.FindProperty("OnShow");
  156. onHide = serializedObject.FindProperty("OnHide");
  157. ignoreEventsOnInitialization = serializedObject.FindProperty("IgnoreEventsOnInitialization");
  158. #endregion
  159. #region Get Icons
  160. linkIcon = (Texture)EditorGUIUtility.Load("ZUI/LinkIcon.png");
  161. #endregion
  162. #region Editor Variables
  163. lastAnimSection = selectedAnimTab;
  164. movementFoldout = EditorPrefs.GetBool("movementFoldout", true);
  165. rotationFoldout = EditorPrefs.GetBool("rotationFoldout");
  166. scaleFoldout = EditorPrefs.GetBool("scaleFoldout");
  167. opacityFoldout = EditorPrefs.GetBool("opacityFoldout");
  168. lastDurationLink = durationLink.boolValue;
  169. #endregion
  170. }
  171. public override void OnInspectorGUI()
  172. {
  173. serializedObject.Update();
  174. bool usedActivationControl = false;
  175. for (int i = 0; i < targets.Length; i++)
  176. {
  177. UIElement element = targets[i] as UIElement;
  178. if (element.UseSimpleActivation)
  179. usedActivationControl = true;
  180. }
  181. EditorGUILayout.Space();
  182. #region Settings
  183. EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
  184. EditorGUILayout.BeginHorizontal();
  185. bool someoneControlled = false;
  186. for (int i = 0; i < targets.Length; i++)
  187. {
  188. UIElement e = (UIElement)targets[i];
  189. if (e.ControlledBy != null)
  190. someoneControlled = true;
  191. }
  192. string controllerName = "NONE";
  193. //if we are only selecting one object and there's someone controlled in the selection array, then it is this object.
  194. if (targets.Length == 1 && someoneControlled)
  195. controllerName = controlledBy.objectReferenceValue.name;
  196. else if (targets.Length > 1 && someoneControlled)
  197. controllerName = "-";
  198. #region Controlled By
  199. EditorGUILayout.LabelField("Controlled By: ", controllerName);
  200. if (someoneControlled && GUILayout.Button("Remove Control"))
  201. {
  202. for (int i = 0; i < targets.Length; i++)
  203. {
  204. UIElement e = (UIElement)targets[i];
  205. Undo.RecordObject(e, "Remove Control");
  206. Menu m = e.ControlledBy as Menu;
  207. if (m != null)
  208. {
  209. Undo.RecordObject(m, "Remove Control");
  210. m.AnimatedElements.Remove((UIElement)targets[i]);
  211. }
  212. else
  213. {
  214. UIElementsGroup eg = e.ControlledBy as UIElementsGroup;
  215. if (eg != null)
  216. {
  217. Undo.RecordObject(eg, "Remove Control");
  218. eg.AnimatedElements.Remove((UIElement)targets[i]);
  219. }
  220. else
  221. {
  222. SideMenu sm = e.ControlledBy as SideMenu;
  223. if (sm != null)
  224. {
  225. Undo.RecordObject(sm, "Remove Control");
  226. sm.AnimatedElements.Remove((UIElement)targets[i]);
  227. }
  228. else
  229. {
  230. Popup p = e.ControlledBy as Popup;
  231. if (p != null)
  232. {
  233. Undo.RecordObject(p, "Remove Control");
  234. p.AnimatedElements.Remove((UIElement)targets[i]);
  235. }
  236. }
  237. }
  238. }
  239. e.ControlledBy = null;
  240. }
  241. }
  242. #endregion
  243. EditorGUILayout.EndHorizontal();
  244. EditorGUILayout.LabelField("Is Visible?", visible.boolValue.ToString());
  245. EditorGUILayout.PropertyField(menuDependant);
  246. if (!menuDependant.boolValue)
  247. {
  248. EditorGUILayout.PropertyField(visible);
  249. EditorGUILayout.PropertyField(prewarm);
  250. }
  251. EditorGUILayout.PropertyField(deactivateWhileInvisible);
  252. #endregion
  253. if (!usedActivationControl)
  254. {
  255. EditorGUILayout.Space();
  256. EditorGUILayout.LabelField("Animations", EditorStyles.boldLabel);
  257. selectedAnimTab = GUILayout.Toolbar(selectedAnimTab, new string[] { "Hiding", "Showing" });
  258. if (selectedAnimTab != lastAnimSection)
  259. {
  260. GUI.FocusControl("");
  261. lastAnimSection = selectedAnimTab;
  262. }
  263. bool hidingTab = selectedAnimTab == 0;
  264. #region Animation Sections
  265. if (hidingTab)
  266. {
  267. EditorGUILayout.PropertyField(hideAfter);
  268. EditorGUILayout.PropertyField(hidingDuration);
  269. }
  270. else
  271. {
  272. EditorGUILayout.PropertyField(showAfter);
  273. #region Showing Duration
  274. EditorGUILayout.BeginHorizontal();
  275. EditorGUI.BeginDisabledGroup(durationLink.boolValue);
  276. if (durationLink.boolValue)
  277. showingDuration.floatValue = hidingDuration.floatValue;
  278. EditorGUILayout.PropertyField(showingDuration);
  279. EditorGUI.EndDisabledGroup();
  280. durationLink.boolValue = GUILayout.Toggle(durationLink.boolValue, new GUIContent(linkIcon, "Toggle hiding duration link."), EditorStyles.miniButton, GUILayout.Width(25));
  281. if (lastDurationLink != durationLink.boolValue)
  282. {
  283. GUI.FocusControl("");
  284. lastDurationLink = durationLink.boolValue;
  285. }
  286. EditorGUILayout.EndHorizontal();
  287. #endregion
  288. }
  289. EditorGUILayout.Space();
  290. //Movement
  291. DrawAnimationSection(movementSection, hidingTab, ref movementFoldout, ref showMovementProps);
  292. EditorGUILayout.Space();
  293. //Rotation
  294. DrawAnimationSection(rotationSection, hidingTab, ref rotationFoldout, ref showRotationProps);
  295. EditorGUILayout.Space();
  296. //Scale
  297. DrawAnimationSection(scaleSection, hidingTab, ref scaleFoldout, ref showScaleProps);
  298. EditorGUILayout.Space();
  299. //Opacity
  300. DrawAnimationSection(opacitySection, hidingTab, ref opacityFoldout, ref showOpacityProps);
  301. EditorGUILayout.Space();
  302. //Slice
  303. DrawAnimationSection(sliceSection, hidingTab, ref sliceFoldout, ref showSliceProps);
  304. #endregion
  305. GUILayout.Space(10);
  306. EditorGUILayout.LabelField("* Shared settings between both tabs.", EditorStyles.miniLabel);
  307. #region Separator
  308. EditorGUILayout.BeginHorizontal();
  309. GUILayout.FlexibleSpace();
  310. GUILayout.Label("__________________");
  311. GUILayout.FlexibleSpace();
  312. EditorGUILayout.EndHorizontal();
  313. GUILayout.Space(20);
  314. #endregion
  315. }
  316. else
  317. {
  318. EditorGUILayout.Space();
  319. EditorGUILayout.HelpBox("No animation controls available. This GameObject is being controlled by \"Simple Activate/Deactivate\" option.", MessageType.Info);
  320. }
  321. #region Activation
  322. EditorGUILayout.LabelField("Simple Activate/Deactivate", EditorStyles.boldLabel);
  323. EditorGUILayout.PropertyField(useSimpleActivation, new GUIContent("Use Activation Control"));
  324. #endregion
  325. EditorGUILayout.Space();
  326. #region Sounds
  327. EditorGUILayout.LabelField("Sounds", EditorStyles.boldLabel);
  328. EditorGUILayout.PropertyField(showingClip, new GUIContent("Showing Clip"));
  329. EditorGUILayout.PropertyField(hidingClip, new GUIContent("Hiding Clip"));
  330. #endregion
  331. EditorGUILayout.Space();
  332. #region Events
  333. EditorGUILayout.LabelField("Events", EditorStyles.boldLabel);
  334. EditorGUILayout.PropertyField(onShow, new GUIContent("On Show"));
  335. EditorGUILayout.PropertyField(onHide, new GUIContent("On Hide"));
  336. EditorGUILayout.PropertyField(ignoreEventsOnInitialization, new GUIContent("Ignore On Initialization"));
  337. #endregion
  338. EditorGUILayout.Space();
  339. EditorPrefs.SetBool("movementFoldout", movementFoldout);
  340. EditorPrefs.SetBool("rotationFoldout", rotationFoldout);
  341. EditorPrefs.SetBool("scaleFoldout", scaleFoldout);
  342. EditorPrefs.SetBool("opacityFoldout", opacityFoldout);
  343. serializedObject.ApplyModifiedProperties();
  344. }
  345. void DrawAnimationSection(SerializedProperty section, bool hiding, ref bool foldout, ref AnimBool animBool)
  346. {
  347. #region Properties Initialization
  348. SerializedProperty useSection = section.FindPropertyRelative("UseSection");
  349. SerializedProperty type = section.FindPropertyRelative((hiding ? "Hide" : "Show") + "Type");
  350. SerializedProperty hideType = section.FindPropertyRelative("HideType"); //We still need a reference of the hide type to assign it's value to show type if there's a link.
  351. SerializedProperty typeLink = section.FindPropertyRelative("TypeLink");
  352. SerializedProperty wantedVectorValue = section.FindPropertyRelative("WantedVectorValue");
  353. SerializedProperty wantedFloatValue = section.FindPropertyRelative("WantedFloatValue");
  354. SerializedProperty startAfter = section.FindPropertyRelative((hiding ? "Hide" : "Show") + "After");
  355. SerializedProperty duration = section.FindPropertyRelative((hiding ? "Hiding" : "Showing") + "Duration");
  356. SerializedProperty easingParams = section.FindPropertyRelative((hiding ? "hiding" : "showing") + "EasingParams");
  357. #endregion
  358. string sectionName = section.displayName.Substring(0, section.displayName.Length - 8);
  359. #region Header
  360. EditorStyles.foldout.fontStyle = FontStyle.Bold;
  361. string chosenType = useSection.boolValue ? type.enumDisplayNames[type.enumValueIndex] : "None";
  362. foldout = EditorGUILayout.Foldout(foldout, sectionName + " (" + chosenType + ")", true);
  363. EditorStyles.foldout.fontStyle = FontStyle.Normal;
  364. #endregion
  365. if (foldout)
  366. {
  367. if (sectionName == "Opacity")
  368. EditorGUILayout.PropertyField(targetFader);
  369. EditorGUILayout.PropertyField(useSection, new GUIContent("Use " + sectionName + "*"));
  370. #region Group Checks
  371. bool showPropsBool = true;
  372. bool allStartAfterShow = true;
  373. bool allDurationShow = true;
  374. bool allHidingPositionsCustom = true;
  375. for (int i = 0; i < targets.Length; i++)
  376. {
  377. UIElement element = targets[i] as UIElement;
  378. System.Reflection.PropertyInfo sectionProp = element.GetType().GetProperty("_" + section.name);
  379. UIElement.AnimationSection s = sectionProp.GetValue(element, null) as UIElement.AnimationSection;
  380. if (hiding && s.HideAfter < 0)
  381. allStartAfterShow = false;
  382. else if (!hiding && s.ShowAfter < 0)
  383. allStartAfterShow = false;
  384. if (hiding && s.HidingDuration < 0)
  385. allDurationShow = false;
  386. else if (!hiding && s.ShowingDuration < 0)
  387. allDurationShow = false;
  388. if (!s.UseSection)
  389. showPropsBool = false;
  390. if (element.HidingPosition != UIElement.ScreenSides.Custom)
  391. allHidingPositionsCustom = false;
  392. }
  393. #endregion
  394. animBool.target = showPropsBool;
  395. if (!showPropsBool && useSection.boolValue && animBool.faded < 0.1f)
  396. EditorGUILayout.PropertyField(type);
  397. if (EditorGUILayout.BeginFadeGroup(animBool.faded))
  398. {
  399. if (hiding)
  400. EditorGUILayout.PropertyField(type);
  401. else
  402. {
  403. #region Showing Type
  404. EditorGUILayout.BeginHorizontal();
  405. EditorGUI.BeginDisabledGroup(typeLink.boolValue);
  406. if (typeLink.boolValue)
  407. type.enumValueIndex = hideType.enumValueIndex;
  408. EditorGUILayout.PropertyField(type);
  409. EditorGUI.EndDisabledGroup();
  410. typeLink.boolValue = GUILayout.Toggle(typeLink.boolValue, new GUIContent(linkIcon, "Toggle hiding type link."), EditorStyles.miniButton, GUILayout.Width(25));
  411. EditorGUILayout.EndHorizontal();
  412. #endregion
  413. }
  414. #region Wanted Values
  415. if (sectionName == "Movement" && hiding)
  416. {
  417. EditorGUILayout.PropertyField(hidingPosition, new GUIContent("Hiding Position"));
  418. if (allHidingPositionsCustom)
  419. {
  420. #region Discard Button
  421. if (recordingPosition)
  422. {
  423. EditorGUILayout.BeginHorizontal();
  424. GUILayout.FlexibleSpace();
  425. if (GUILayout.Button("X", GUILayout.Width(50), GUILayout.Height(15)))
  426. DiscardRecording();
  427. EditorGUILayout.EndHorizontal();
  428. }
  429. #endregion
  430. #region Record Button
  431. EditorGUILayout.BeginHorizontal();
  432. GUILayout.FlexibleSpace();
  433. if (recordingPosition)
  434. GUI.color = Color.red;
  435. recordingPosition = GUILayout.Toggle(recordingPosition, !recordingPosition ? "Record Position" : "Finish Recording", EditorStyles.miniButton);
  436. GUI.color = Color.white;
  437. EditorGUILayout.EndHorizontal();
  438. if (lastRecordingState != recordingPosition)
  439. {
  440. //If recording start
  441. if (recordingPosition)
  442. {
  443. for (int i = 0; i < targets.Length; i++)
  444. {
  445. UIElement element = targets[i] as UIElement;
  446. RectTransform elementRT = element.GetComponent<RectTransform>();
  447. RectTransform parentCanvas = element.GetComponentInParent<Canvas>().GetComponent<RectTransform>();
  448. float canvasWidth = parentCanvas.lossyScale.x * parentCanvas.rect.width;
  449. float canvasHeight = parentCanvas.lossyScale.y * parentCanvas.rect.height;
  450. if (element.MovementSection.WantedVectorValue == new Vector3(9999, 9999))
  451. {
  452. float canvasStartX = parentCanvas.position.x - canvasWidth / 2;
  453. float canvasStartY = parentCanvas.position.y - canvasHeight / 2;
  454. Undo.RecordObject(element, "Position");
  455. element.MovementSection.WantedVectorValue = new Vector3((elementRT.position.x - canvasStartX) / canvasWidth,
  456. (elementRT.position.y - canvasStartY) / canvasHeight, elementRT.position.z);
  457. }
  458. element.MovementSection.startVectorValue = elementRT.position;
  459. elementRT.position = new Vector3(
  460. parentCanvas.position.x + (element.MovementSection.WantedVectorValue.x - 0.5f) * canvasWidth,
  461. parentCanvas.position.y + (element.MovementSection.WantedVectorValue.y - 0.5f) * canvasHeight, elementRT.position.z);
  462. }
  463. }
  464. //If recording end
  465. if (!recordingPosition)
  466. {
  467. EndRecording();
  468. }
  469. }
  470. lastRecordingState = recordingPosition;
  471. #endregion
  472. Vector2 customVec = wantedVectorValue.vector3Value;
  473. wantedVectorValue.vector3Value = EditorGUILayout.Vector2Field(new GUIContent("Hiding Position", "Custom hiding position as percentage of the screen."), customVec);
  474. }
  475. else
  476. {
  477. EditorGUILayout.PropertyField(edgeGap);
  478. }
  479. }
  480. if (sectionName == "Rotation")
  481. {
  482. if (hiding)
  483. {
  484. EditorGUILayout.PropertyField(wantedVectorValue, new GUIContent("Hiding Rotation", "The rotation this element should change to when it's invisible."));
  485. EditorGUILayout.PropertyField(hidingDirection);
  486. }
  487. else
  488. EditorGUILayout.PropertyField(showingDirection);
  489. }
  490. if (sectionName == "Scale" && hiding)
  491. EditorGUILayout.PropertyField(wantedVectorValue, new GUIContent("Hiding Scale", "The scale this element should change to when it's invisible."));
  492. if (sectionName == "Opacity" && hiding)
  493. EditorGUILayout.Slider(wantedFloatValue, 0, 1, new GUIContent("Hiding Opacity", "The opacity this element should fade to when it's invisible."));
  494. if (sectionName == "Slice" && hiding)
  495. EditorGUILayout.Slider(wantedFloatValue, 0, 1, new GUIContent("Hiding Fill Amount", "The fill amount this element's image should change to when it's invisible."));
  496. #endregion
  497. //Ease Function Parameters Drawing
  498. if (hiding || !typeLink.boolValue)
  499. DrawEasingParams(type.enumNames[type.enumValueIndex], easingParams);
  500. #region Custom Properties
  501. #region Custom Properties Drawing
  502. if (allStartAfterShow)
  503. {
  504. EditorGUILayout.BeginHorizontal();
  505. EditorGUILayout.PropertyField(startAfter);
  506. if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
  507. {
  508. Undo.RecordObjects(targets, "Delete Custom " + startAfter.displayName);
  509. for (int i = 0; i < targets.Length; i++)
  510. {
  511. UIElement element = targets[i] as UIElement;
  512. System.Reflection.PropertyInfo sectionProp = element.GetType().GetProperty("_" + section.name);
  513. UIElement.AnimationSection s = sectionProp.GetValue(element, null) as UIElement.AnimationSection;
  514. if (hiding)
  515. s.HideAfter = -1;
  516. else
  517. s.ShowAfter = -1;
  518. }
  519. }
  520. EditorGUILayout.EndHorizontal();
  521. }
  522. if (allDurationShow)
  523. {
  524. EditorGUILayout.BeginHorizontal();
  525. EditorGUILayout.PropertyField(duration);
  526. if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
  527. {
  528. Undo.RecordObjects(targets, "Delete Custom Duration");
  529. for (int i = 0; i < targets.Length; i++)
  530. {
  531. UIElement element = targets[i] as UIElement;
  532. System.Reflection.PropertyInfo sectionProp = element.GetType().GetProperty("_" + section.name);
  533. UIElement.AnimationSection s = sectionProp.GetValue(element, null) as UIElement.AnimationSection;
  534. if (hiding)
  535. s.HidingDuration = -1;
  536. else
  537. s.ShowingDuration = -1;
  538. }
  539. }
  540. EditorGUILayout.EndHorizontal();
  541. }
  542. #endregion
  543. //Seperate in case there an option to add custom property
  544. if (!allStartAfterShow || !allDurationShow)
  545. EditorGUILayout.Space();
  546. #region Custom Properties Adding
  547. if (!allStartAfterShow)
  548. {
  549. string txt = targets.Length == 1 ? "Add custom \"" + startAfter.displayName + "\"" : "Add custom \"" + startAfter.displayName + "\" to all";
  550. string tooltip = "Add a custom \"" + startAfter.displayName + "\" for this animation section, meaning this section will ignore general \"" + startAfter.displayName + "\".";
  551. EditorGUILayout.BeginHorizontal();
  552. GUILayout.FlexibleSpace();
  553. if (GUILayout.Button(new GUIContent(txt, tooltip), EditorStyles.miniButtonRight, GUILayout.Width(EditorGUIUtility.currentViewWidth / 2)))
  554. {
  555. Undo.RecordObjects(targets, "Add Custom " + startAfter.displayName);
  556. for (int i = 0; i < targets.Length; i++)
  557. {
  558. UIElement element = targets[i] as UIElement;
  559. System.Reflection.PropertyInfo sectionProp = element.GetType().GetProperty("_" + section.name);
  560. UIElement.AnimationSection s = sectionProp.GetValue(element, null) as UIElement.AnimationSection;
  561. if (hiding && s.HideAfter < 0)
  562. s.HideAfter = element.HideAfter;
  563. else if (!hiding && s.ShowAfter < 0)
  564. s.ShowAfter = element.ShowAfter;
  565. }
  566. }
  567. EditorGUILayout.EndHorizontal();
  568. }
  569. if (!allDurationShow)
  570. {
  571. string txt = targets.Length == 1 ? "Add custom \"" + duration.displayName + "\"" : "Add custom \"" + duration.displayName + "\" to all";
  572. string tooltip = "Add a custom \"" + duration.displayName + "\" for this animation section, meaning this section will ignore general \"" + duration.displayName + "\".";
  573. EditorGUILayout.BeginHorizontal();
  574. GUILayout.FlexibleSpace();
  575. if (GUILayout.Button(new GUIContent(txt, tooltip), EditorStyles.miniButtonRight, GUILayout.Width(EditorGUIUtility.currentViewWidth/2)))
  576. {
  577. Undo.RecordObjects(targets, "Add Custom Duration");
  578. for (int i = 0; i < targets.Length; i++)
  579. {
  580. UIElement element = targets[i] as UIElement;
  581. System.Reflection.PropertyInfo sectionProp = element.GetType().GetProperty("_" + section.name);
  582. UIElement.AnimationSection s = sectionProp.GetValue(element, null) as UIElement.AnimationSection;
  583. if (hiding && s.HidingDuration < 0)
  584. s.HidingDuration = element.HidingDuration;
  585. else if (!hiding && s.ShowingDuration < 0)
  586. s.ShowingDuration = element.ShowingDuration;
  587. }
  588. }
  589. EditorGUILayout.EndHorizontal();
  590. }
  591. #endregion
  592. #endregion
  593. EditorGUILayout.EndFadeGroup();
  594. }
  595. }
  596. }
  597. void DrawEasingParams(string equationName, SerializedProperty easingParams)
  598. {
  599. SerializedProperty property = easingParams.FindPropertyRelative(equationName);
  600. if (property != null)
  601. {
  602. SerializedProperty endProp = property.Copy();
  603. endProp.Next(false);
  604. SerializedProperty c = property.Copy();
  605. c.Next(true);
  606. while(true)
  607. {
  608. EditorGUILayout.PropertyField(c, new GUIContent(c.displayName), true);
  609. c.Next(true);
  610. if (SerializedProperty.EqualContents(c, endProp))
  611. break;
  612. }
  613. }
  614. }
  615. void EndRecording()
  616. {
  617. for (int i = 0; i < targets.Length; i++)
  618. {
  619. UIElement element = targets[i] as UIElement;
  620. RectTransform elementRT = element.GetComponent<RectTransform>();
  621. RectTransform parentCanvas = element.GetComponentInParent<Canvas>().GetComponent<RectTransform>();
  622. Undo.RecordObject(element, "Record Hiding Position");
  623. float canvasWidth = parentCanvas.lossyScale.x * parentCanvas.rect.width;
  624. float canvasHeight = parentCanvas.lossyScale.y * parentCanvas.rect.height;
  625. float canvasStartX = parentCanvas.position.x - canvasWidth / 2;
  626. float canvasStartY = parentCanvas.position.y - canvasHeight / 2;
  627. element.MovementSection.WantedVectorValue = new Vector2((elementRT.position.x - canvasStartX) / canvasWidth,
  628. (elementRT.position.y - canvasStartY) / canvasHeight);
  629. elementRT.position = element.MovementSection.startVectorValue;
  630. }
  631. }
  632. void DiscardRecording()
  633. {
  634. for (int i = 0; i < targets.Length; i++)
  635. {
  636. UIElement element = targets[i] as UIElement;
  637. RectTransform elementRT = element.GetComponent<RectTransform>();
  638. elementRT.position = element.MovementSection.startVectorValue;
  639. }
  640. lastRecordingState = recordingPosition = false;
  641. }
  642. void OnDisable()
  643. {
  644. if (recordingPosition)
  645. {
  646. if (EditorUtility.DisplayDialog("Recording", "You are recording a position, would you like to apply it?", "Apply", "No"))
  647. EndRecording();
  648. else
  649. DiscardRecording();
  650. }
  651. }
  652. }