UIEffectEditor.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.Linq;
  4. using System;
  5. using System.Reflection;
  6. using Object = UnityEngine.Object;
  7. namespace Coffee.UIEffects.Editors
  8. {
  9. /// <summary>
  10. /// UIEffect editor.
  11. /// </summary>
  12. [CustomEditor(typeof(UIEffect), true)]
  13. [CanEditMultipleObjects]
  14. public class UIEffect2Editor : Editor
  15. {
  16. private static readonly PropertyInfo s_PiGradient = typeof(SerializedProperty)
  17. .GetProperty("gradientValue", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
  18. private static readonly Func<SerializedProperty, Gradient> s_GetGradient =
  19. (Func<SerializedProperty, Gradient>)Delegate.CreateDelegate(typeof(Func<SerializedProperty, Gradient>),
  20. s_PiGradient.GetMethod);
  21. private static readonly Action<SerializedProperty, Gradient> s_SetGradient =
  22. (Action<SerializedProperty, Gradient>)Delegate.CreateDelegate(typeof(Action<SerializedProperty, Gradient>),
  23. s_PiGradient.SetMethod);
  24. private SerializedProperty _toneFilter;
  25. private SerializedProperty _toneIntensity;
  26. private SerializedProperty _colorFilter;
  27. private SerializedProperty _color;
  28. private SerializedProperty _colorIntensity;
  29. private SerializedProperty _colorGlow;
  30. private SerializedProperty _samplingFilter;
  31. private SerializedProperty _samplingIntensity;
  32. private SerializedProperty _samplingWidth;
  33. private SerializedProperty _samplingScale;
  34. private SerializedProperty _transitionFilter;
  35. private SerializedProperty _transitionRate;
  36. private SerializedProperty _transitionTex;
  37. private SerializedProperty _transitionTexScale;
  38. private SerializedProperty _transitionTexOffset;
  39. private SerializedProperty _transitionReverse;
  40. private SerializedProperty _transitionRotation;
  41. private SerializedProperty _transitionKeepAspectRatio;
  42. private SerializedProperty _transitionWidth;
  43. private SerializedProperty _transitionSoftness;
  44. private SerializedProperty _transitionRange;
  45. private SerializedProperty _transitionColorFilter;
  46. private SerializedProperty _transitionColor;
  47. private SerializedProperty _transitionColorGlow;
  48. private SerializedProperty _transitionPatternReverse;
  49. private SerializedProperty _transitionAutoPlaySpeed;
  50. private SerializedProperty _targetMode;
  51. private SerializedProperty _targetColor;
  52. private SerializedProperty _targetRange;
  53. private SerializedProperty _targetSoftness;
  54. private SerializedProperty _blendType;
  55. private SerializedProperty _srcBlendMode;
  56. private SerializedProperty _dstBlendMode;
  57. private SerializedProperty _shadowMode;
  58. private SerializedProperty _shadowDistance;
  59. private SerializedProperty _shadowDistanceX;
  60. private SerializedProperty _shadowDistanceY;
  61. private SerializedProperty _shadowIteration;
  62. private SerializedProperty _shadowFade;
  63. private SerializedProperty _shadowMirrorScale;
  64. private SerializedProperty _shadowBlurIntensity;
  65. private SerializedProperty _shadowColorFilter;
  66. private SerializedProperty _shadowColor;
  67. private SerializedProperty _shadowColorGlow;
  68. private SerializedProperty _gradationMode;
  69. private SerializedProperty _gradationColor1;
  70. private SerializedProperty _gradationColor2;
  71. private SerializedProperty _gradationColor3;
  72. private SerializedProperty _gradationColor4;
  73. private SerializedProperty _gradationGradient;
  74. private SerializedProperty _gradationOffset;
  75. private SerializedProperty _gradationScale;
  76. private SerializedProperty _gradationRotation;
  77. private SerializedProperty _edgeMode;
  78. private SerializedProperty _edgeWidth;
  79. private SerializedProperty _edgeColorFilter;
  80. private SerializedProperty _edgeColor;
  81. private SerializedProperty _edgeShinyRate;
  82. private SerializedProperty _edgeShinyWidth;
  83. private SerializedProperty _edgeShinyAutoPlaySpeed;
  84. private SerializedProperty _patternArea;
  85. private bool _expandOthers = true;
  86. private SerializedProperty _allowToModifyMeshShape;
  87. private void OnEnable()
  88. {
  89. if (target == null) return;
  90. _toneFilter = serializedObject.FindProperty("m_ToneFilter");
  91. _toneIntensity = serializedObject.FindProperty("m_ToneIntensity");
  92. _colorFilter = serializedObject.FindProperty("m_ColorFilter");
  93. _color = serializedObject.FindProperty("m_Color");
  94. _colorIntensity = serializedObject.FindProperty("m_ColorIntensity");
  95. _colorGlow = serializedObject.FindProperty("m_ColorGlow");
  96. _samplingFilter = serializedObject.FindProperty("m_SamplingFilter");
  97. _samplingIntensity = serializedObject.FindProperty("m_SamplingIntensity");
  98. _samplingWidth = serializedObject.FindProperty("m_SamplingWidth");
  99. _samplingScale = serializedObject.FindProperty("m_SamplingScale");
  100. _transitionFilter = serializedObject.FindProperty("m_TransitionFilter");
  101. _transitionRate = serializedObject.FindProperty("m_TransitionRate");
  102. _transitionTex = serializedObject.FindProperty("m_TransitionTex");
  103. _transitionTexScale = serializedObject.FindProperty("m_TransitionTexScale");
  104. _transitionTexOffset = serializedObject.FindProperty("m_TransitionTexOffset");
  105. _transitionReverse = serializedObject.FindProperty("m_TransitionReverse");
  106. _transitionRotation = serializedObject.FindProperty("m_TransitionRotation");
  107. _transitionKeepAspectRatio = serializedObject.FindProperty("m_TransitionKeepAspectRatio");
  108. _transitionWidth = serializedObject.FindProperty("m_TransitionWidth");
  109. _transitionSoftness = serializedObject.FindProperty("m_TransitionSoftness");
  110. _transitionRange = serializedObject.FindProperty("m_TransitionRange");
  111. _transitionColorFilter = serializedObject.FindProperty("m_TransitionColorFilter");
  112. _transitionColor = serializedObject.FindProperty("m_TransitionColor");
  113. _transitionColorGlow = serializedObject.FindProperty("m_TransitionColorGlow");
  114. _transitionPatternReverse = serializedObject.FindProperty("m_TransitionPatternReverse");
  115. _transitionAutoPlaySpeed = serializedObject.FindProperty("m_TransitionAutoPlaySpeed");
  116. _targetMode = serializedObject.FindProperty("m_TargetMode");
  117. _targetColor = serializedObject.FindProperty("m_TargetColor");
  118. _targetRange = serializedObject.FindProperty("m_TargetRange");
  119. _targetSoftness = serializedObject.FindProperty("m_TargetSoftness");
  120. _blendType = serializedObject.FindProperty("m_BlendType");
  121. _srcBlendMode = serializedObject.FindProperty("m_SrcBlendMode");
  122. _dstBlendMode = serializedObject.FindProperty("m_DstBlendMode");
  123. _shadowMode = serializedObject.FindProperty("m_ShadowMode");
  124. _shadowDistance = serializedObject.FindProperty("m_ShadowDistance");
  125. _shadowDistanceX = _shadowDistance.FindPropertyRelative("x");
  126. _shadowDistanceY = _shadowDistance.FindPropertyRelative("y");
  127. _shadowIteration = serializedObject.FindProperty("m_ShadowIteration");
  128. _shadowFade = serializedObject.FindProperty("m_ShadowFade");
  129. _shadowMirrorScale = serializedObject.FindProperty("m_ShadowMirrorScale");
  130. _shadowBlurIntensity = serializedObject.FindProperty("m_ShadowBlurIntensity");
  131. _shadowColorFilter = serializedObject.FindProperty("m_ShadowColorFilter");
  132. _shadowColor = serializedObject.FindProperty("m_ShadowColor");
  133. _shadowColorGlow = serializedObject.FindProperty("m_ShadowColorGlow");
  134. _edgeMode = serializedObject.FindProperty("m_EdgeMode");
  135. _edgeWidth = serializedObject.FindProperty("m_EdgeWidth");
  136. _edgeColorFilter = serializedObject.FindProperty("m_EdgeColorFilter");
  137. _edgeColor = serializedObject.FindProperty("m_EdgeColor");
  138. _edgeShinyRate = serializedObject.FindProperty("m_EdgeShinyRate");
  139. _edgeShinyWidth = serializedObject.FindProperty("m_EdgeShinyWidth");
  140. _edgeShinyAutoPlaySpeed = serializedObject.FindProperty("m_EdgeShinyAutoPlaySpeed");
  141. _patternArea = serializedObject.FindProperty("m_PatternArea");
  142. _gradationMode = serializedObject.FindProperty("m_GradationMode");
  143. _gradationColor1 = serializedObject.FindProperty("m_GradationColor1");
  144. _gradationColor2 = serializedObject.FindProperty("m_GradationColor2");
  145. _gradationColor3 = serializedObject.FindProperty("m_GradationColor3");
  146. _gradationColor4 = serializedObject.FindProperty("m_GradationColor4");
  147. _gradationGradient = serializedObject.FindProperty("m_GradationGradient");
  148. _gradationOffset = serializedObject.FindProperty("m_GradationOffset");
  149. _gradationScale = serializedObject.FindProperty("m_GradationScale");
  150. _gradationRotation = serializedObject.FindProperty("m_GradationRotation");
  151. _allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
  152. }
  153. public override void OnInspectorGUI()
  154. {
  155. serializedObject.Update();
  156. DrawPresetMenu(targets);
  157. DrawSeparator();
  158. DrawProperties();
  159. serializedObject.ApplyModifiedProperties();
  160. }
  161. public void DrawProperties()
  162. {
  163. serializedObject.Update();
  164. // Tone filter
  165. if (DrawHeaderPopup(_toneFilter))
  166. {
  167. EditorGUI.indentLevel++;
  168. EditorGUILayout.PropertyField(_toneIntensity);
  169. EditorGUI.indentLevel--;
  170. }
  171. // Color filter
  172. DrawSeparator();
  173. var prevColorFilter = (ColorFilter)_colorFilter.intValue;
  174. if (DrawHeaderPopup(_colorFilter))
  175. {
  176. EditorGUI.indentLevel++;
  177. EditorGUILayout.PropertyField(_colorIntensity);
  178. DrawColor(_color, (ColorFilter)_colorFilter.intValue, prevColorFilter, false);
  179. EditorGUILayout.PropertyField(_colorGlow);
  180. EditorGUI.indentLevel--;
  181. }
  182. EditorGUI.EndChangeCheck();
  183. // Sampling filter
  184. DrawSeparator();
  185. if (DrawHeaderPopup(_samplingFilter))
  186. {
  187. EditorGUI.indentLevel++;
  188. EditorGUILayout.PropertyField(_samplingIntensity);
  189. if (_samplingFilter.intValue == (int)SamplingFilter.EdgeAlpha
  190. || _samplingFilter.intValue == (int)SamplingFilter.EdgeLuminance)
  191. {
  192. EditorGUILayout.PropertyField(_samplingWidth);
  193. }
  194. EditorGUI.indentLevel--;
  195. }
  196. // Transition filter
  197. DrawSeparator();
  198. if (DrawHeaderPopup(_transitionFilter))
  199. {
  200. EditorGUI.indentLevel++;
  201. EditorGUILayout.PropertyField(_transitionRate);
  202. EditorGUILayout.PropertyField(_transitionTex);
  203. EditorGUI.indentLevel++;
  204. EditorGUILayout.PropertyField(_transitionTexScale, EditorGUIUtility.TrTempContent("Scale"));
  205. EditorGUILayout.PropertyField(_transitionTexOffset, EditorGUIUtility.TrTempContent("Offset"));
  206. EditorGUILayout.PropertyField(_transitionRotation, EditorGUIUtility.TrTempContent("Rotation"));
  207. EditorGUILayout.PropertyField(_transitionKeepAspectRatio,
  208. EditorGUIUtility.TrTempContent("Keep Aspect Ratio"));
  209. EditorGUILayout.PropertyField(_transitionReverse, EditorGUIUtility.TrTempContent("Reverse"));
  210. EditorGUI.indentLevel--;
  211. if (_transitionFilter.intValue == (int)TransitionFilter.Pattern)
  212. {
  213. EditorGUILayout.PropertyField(_transitionWidth, EditorGUIUtility.TrTempContent("Pattern Size"));
  214. EditorGUILayout.PropertyField(_transitionRange, EditorGUIUtility.TrTempContent("Pattern Range"));
  215. EditorGUILayout.PropertyField(_transitionPatternReverse,
  216. EditorGUIUtility.TrTempContent("Pattern Reverse"));
  217. DrawColor(_transitionColorFilter, _transitionColor, null);
  218. }
  219. else if (2 < _transitionFilter.intValue)
  220. {
  221. EditorGUILayout.PropertyField(_transitionWidth);
  222. EditorGUILayout.PropertyField(_transitionSoftness);
  223. DrawColor(_transitionColorFilter, _transitionColor, _transitionColorGlow);
  224. }
  225. EditorGUILayout.PropertyField(_transitionAutoPlaySpeed);
  226. if (0 < _transitionFilter.intValue && !Mathf.Approximately(0, _transitionAutoPlaySpeed.floatValue))
  227. {
  228. EditorApplication.QueuePlayerLoopUpdate();
  229. }
  230. EditorGUI.indentLevel--;
  231. }
  232. // Target
  233. DrawSeparator();
  234. if (DrawHeaderPopup(_targetMode))
  235. {
  236. EditorGUI.indentLevel++;
  237. EditorGUILayout.PropertyField(_targetColor);
  238. EditorGUILayout.PropertyField(_targetRange);
  239. EditorGUILayout.PropertyField(_targetSoftness);
  240. EditorGUI.indentLevel--;
  241. }
  242. // Blending
  243. DrawSeparator();
  244. if (!DrawHeaderPopup(_blendType))
  245. {
  246. EditorGUI.indentLevel++;
  247. EditorGUILayout.PropertyField(_srcBlendMode);
  248. EditorGUILayout.PropertyField(_dstBlendMode);
  249. EditorGUI.indentLevel--;
  250. }
  251. // Shadow
  252. DrawSeparator();
  253. var prevShadowMode = (ShadowMode)_shadowMode.intValue;
  254. if (DrawHeaderPopup(_shadowMode))
  255. {
  256. EditorGUI.indentLevel++;
  257. if ((ShadowMode)_shadowMode.intValue == ShadowMode.Mirror)
  258. {
  259. if (prevShadowMode != ShadowMode.Mirror)
  260. {
  261. _shadowDistanceX.floatValue = 0.5f;
  262. _shadowDistanceY.floatValue = 0f;
  263. }
  264. EditorGUILayout.Slider(_shadowDistanceX, 0, 1, "Reflection");
  265. EditorGUILayout.PropertyField(_shadowDistanceY, EditorGUIUtility.TrTempContent("Offset"));
  266. EditorGUILayout.PropertyField(_shadowMirrorScale);
  267. EditorGUILayout.PropertyField(_shadowFade);
  268. }
  269. else
  270. {
  271. if (prevShadowMode == ShadowMode.Mirror)
  272. {
  273. _shadowDistanceX.floatValue = 1f;
  274. _shadowDistanceY.floatValue = -1f;
  275. }
  276. EditorGUILayout.PropertyField(_shadowDistance);
  277. EditorGUILayout.PropertyField(_shadowIteration);
  278. DrawColor(_shadowColorFilter, _shadowColor, _shadowColorGlow, false);
  279. EditorGUILayout.PropertyField(_shadowFade);
  280. }
  281. // Shadow blur intensity
  282. switch ((SamplingFilter)_samplingFilter.intValue)
  283. {
  284. case SamplingFilter.BlurFast:
  285. case SamplingFilter.BlurMedium:
  286. case SamplingFilter.BlurDetail:
  287. EditorGUILayout.PropertyField(_shadowBlurIntensity);
  288. break;
  289. }
  290. EditorGUI.indentLevel--;
  291. }
  292. // Gradient
  293. DrawSeparator();
  294. if (DrawHeaderPopup(_gradationMode))
  295. {
  296. EditorGUI.indentLevel++;
  297. switch ((GradationMode)_gradationMode.intValue)
  298. {
  299. case GradationMode.HorizontalGradient:
  300. case GradationMode.VerticalGradient:
  301. case GradationMode.AngleGradient:
  302. DrawGradientField(_gradationGradient);
  303. break;
  304. case GradationMode.Diagonal:
  305. DrawColorPickerField("Top", _gradationColor1, _gradationColor2);
  306. DrawColorPickerField("Bottom", _gradationColor3, _gradationColor4);
  307. break;
  308. default:
  309. DrawColorPickerField(EditorGUILayout.GetControlRect(), _gradationColor1, true);
  310. var r = EditorGUILayout.GetControlRect();
  311. r.width -= 24;
  312. DrawColorPickerField(r, _gradationColor2, true);
  313. r.x += r.width + 4;
  314. r.width = 20;
  315. SwapColorsButton(r, _gradationColor1, _gradationColor2);
  316. break;
  317. }
  318. EditorGUILayout.PropertyField(_gradationOffset);
  319. EditorGUILayout.PropertyField(_gradationScale);
  320. if ((GradationMode)_gradationMode.intValue == GradationMode.Angle
  321. || (GradationMode)_gradationMode.intValue == GradationMode.AngleGradient)
  322. {
  323. EditorGUILayout.PropertyField(_gradationRotation);
  324. }
  325. EditorGUI.indentLevel--;
  326. }
  327. // Edge Mode
  328. DrawSeparator();
  329. if (DrawHeaderPopup(_edgeMode))
  330. {
  331. EditorGUILayout.PropertyField(_edgeWidth);
  332. DrawColor(_edgeColorFilter, _edgeColor, null);
  333. if ((EdgeMode)_edgeMode.intValue == EdgeMode.Shiny)
  334. {
  335. EditorGUILayout.PropertyField(_edgeShinyRate);
  336. EditorGUILayout.PropertyField(_edgeShinyWidth);
  337. EditorGUILayout.PropertyField(_edgeShinyAutoPlaySpeed);
  338. if (!Mathf.Approximately(0, _edgeShinyAutoPlaySpeed.floatValue))
  339. {
  340. EditorApplication.QueuePlayerLoopUpdate();
  341. }
  342. }
  343. if (_transitionFilter.intValue == (int)TransitionFilter.Pattern)
  344. {
  345. EditorGUILayout.PropertyField(_patternArea);
  346. }
  347. }
  348. DrawSeparator();
  349. _expandOthers = EditorGUILayout.BeginFoldoutHeaderGroup(_expandOthers, "Others");
  350. if (_expandOthers)
  351. {
  352. EditorGUILayout.PropertyField(_samplingScale);
  353. EditorGUILayout.PropertyField(_allowToModifyMeshShape);
  354. }
  355. }
  356. private static void DrawColorPickerField(string label, SerializedProperty color1, SerializedProperty color2)
  357. {
  358. var labelWidth = EditorGUIUtility.labelWidth;
  359. var r = EditorGUILayout.GetControlRect();
  360. r.width -= 24;
  361. EditorGUI.PrefixLabel(new Rect(r.x, r.y, labelWidth, r.height), EditorGUIUtility.TrTempContent(label));
  362. var indentLevel = EditorGUI.indentLevel;
  363. EditorGUI.indentLevel = 0;
  364. var rPos = new Rect(r.x + labelWidth, r.y, (r.width - labelWidth) / 2, r.height);
  365. DrawColorPickerField(rPos, GUIContent.none, color1, true);
  366. rPos.x += rPos.width;
  367. DrawColorPickerField(rPos, GUIContent.none, color2, true);
  368. // Swap colors button
  369. SwapColorsButton(new Rect(r.x + r.width + 4, r.y, 20, 20), color1, color2);
  370. EditorGUI.indentLevel = indentLevel;
  371. }
  372. private static void DrawColorPickerField(Rect rect, SerializedProperty color, bool showAlpha)
  373. {
  374. var label = EditorGUIUtility.TrTempContent(color.displayName);
  375. label.tooltip = color.tooltip;
  376. DrawColorPickerField(rect, label, color, showAlpha);
  377. }
  378. private static void DrawColorPickerField(Rect rect, GUIContent label, SerializedProperty color, bool showAlpha)
  379. {
  380. var hdr = UIEffectProjectSettings.useHdrColorPicker;
  381. EditorGUI.showMixedValue = color.hasMultipleDifferentValues;
  382. EditorGUI.BeginChangeCheck();
  383. var colorValue = EditorGUI.ColorField(rect, label, color.colorValue, true, showAlpha, hdr);
  384. if (EditorGUI.EndChangeCheck())
  385. {
  386. color.colorValue = colorValue;
  387. }
  388. }
  389. private static void DrawGradientField(SerializedProperty gradient)
  390. {
  391. var r = EditorGUILayout.GetControlRect();
  392. var label = EditorGUIUtility.TrTempContent(gradient.displayName);
  393. label.tooltip = gradient.tooltip;
  394. var hdr = UIEffectProjectSettings.useHdrColorPicker;
  395. EditorGUI.showMixedValue = gradient.hasMultipleDifferentValues;
  396. EditorGUI.BeginChangeCheck();
  397. var gradientValue = EditorGUI.GradientField(r, label, s_GetGradient(gradient), hdr);
  398. if (EditorGUI.EndChangeCheck())
  399. {
  400. s_SetGradient(gradient, gradientValue);
  401. }
  402. }
  403. private static void DrawColor(SerializedProperty color, ColorFilter filter, ColorFilter prevFilter,
  404. bool showAlpha = true)
  405. {
  406. if (filter == ColorFilter.None) return;
  407. if (filter == ColorFilter.HsvModifier)
  408. {
  409. if (prevFilter != ColorFilter.HsvModifier)
  410. {
  411. color.colorValue = Color.black;
  412. }
  413. EditorGUILayout.Slider(color.FindPropertyRelative("r"), -0.5f, 0.5f, "Hue");
  414. EditorGUILayout.Slider(color.FindPropertyRelative("g"), -1f, 1f, "Saturation");
  415. EditorGUILayout.Slider(color.FindPropertyRelative("b"), -1f, 1f, "Value");
  416. EditorGUILayout.Slider(color.FindPropertyRelative("a"), 0, 1, "Alpha");
  417. }
  418. else if (filter == ColorFilter.Contrast)
  419. {
  420. if (prevFilter != ColorFilter.Contrast)
  421. {
  422. color.colorValue = Color.black;
  423. }
  424. EditorGUILayout.Slider(color.FindPropertyRelative("r"), -1f, 1f, "Contrast");
  425. EditorGUILayout.Slider(color.FindPropertyRelative("g"), -1f, 1f, "Brightness");
  426. EditorGUILayout.Slider(color.FindPropertyRelative("a"), 0, 1, "Alpha");
  427. }
  428. else
  429. {
  430. if (prevFilter == ColorFilter.HsvModifier || prevFilter == ColorFilter.Contrast)
  431. {
  432. color.colorValue = Color.white;
  433. }
  434. DrawColorPickerField(EditorGUILayout.GetControlRect(), color, showAlpha);
  435. }
  436. }
  437. private static void DrawColor(SerializedProperty filter, SerializedProperty color, SerializedProperty glow,
  438. bool showAlpha = true)
  439. {
  440. var prevFilter = (ColorFilter)filter.intValue;
  441. EditorGUILayout.PropertyField(filter);
  442. if (filter.intValue == (int)ColorFilter.None) return;
  443. EditorGUI.indentLevel++;
  444. DrawColor(color, (ColorFilter)filter.intValue, prevFilter, showAlpha);
  445. if (glow != null)
  446. {
  447. EditorGUILayout.PropertyField(glow);
  448. }
  449. EditorGUI.indentLevel--;
  450. }
  451. private static void SwapColorsButton(Rect rect, SerializedProperty color1, SerializedProperty color2)
  452. {
  453. if (GUI.Button(rect, EditorGUIUtility.IconContent("preaudioloopoff"), "iconbutton"))
  454. {
  455. (color1.colorValue, color2.colorValue) = (color2.colorValue, color1.colorValue);
  456. }
  457. }
  458. private static bool DrawHeaderPopup(SerializedProperty sp)
  459. {
  460. var r = EditorGUILayout.GetControlRect();
  461. var pos = EditorGUI.PrefixLabel(r, EditorGUIUtility.TrTempContent(sp.displayName), EditorStyles.boldLabel);
  462. EditorGUI.PropertyField(pos, sp, GUIContent.none);
  463. return 0 < sp.intValue;
  464. }
  465. private static void DrawSeparator()
  466. {
  467. EditorGUILayout.Space(4);
  468. GUILayout.Label(GUIContent.none, "sv_iconselector_sep", GUILayout.ExpandWidth(true));
  469. }
  470. private static void DrawPresetMenu(Object[] targets)
  471. {
  472. var r = EditorGUILayout.GetControlRect();
  473. r.width /= 2;
  474. if (GUI.Button(r, EditorGUIUtility.TrTempContent("Load"), "MiniPopup"))
  475. {
  476. var menu = new GenericMenu();
  477. foreach (var preset in UIEffectProjectSettings.LoadEditorPresets())
  478. {
  479. var path = UIEffectProjectSettings.GetPresetPath(preset);
  480. menu.AddItem(new GUIContent(path), false, () =>
  481. {
  482. Array.ForEach(targets.OfType<UIEffect>().ToArray(), t =>
  483. {
  484. t.LoadPreset(preset);
  485. });
  486. });
  487. }
  488. menu.DropDown(r);
  489. }
  490. r.x += r.width;
  491. if (GUI.Button(r, EditorGUIUtility.TrTempContent("Save As New"), "MiniButton"))
  492. {
  493. EditorApplication.delayCall += () =>
  494. {
  495. UIEffectProjectSettings.SaveAsNewPreset(targets.OfType<UIEffect>().FirstOrDefault());
  496. };
  497. }
  498. }
  499. }
  500. }