FSettingsInspector.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. namespace FluxEditor
  5. {
  6. [CustomEditor(typeof(FSettings))]
  7. public class FSettingsInspector : Editor {
  8. private FSettings _fluxSettings = null;
  9. private Texture2D _plusTexture = null;
  10. private Texture2D _minusTexture = null;
  11. private const string EVENT_COLOR_MSG = "The name you associate with the color needs to be the full "
  12. + "path of the event type, i.e. Namespace.EventType, e.g. Flux.FPlayAnimationEvent";
  13. private const string CONTAINER_COLOR_MSG = "Default containers can be added by right clicking the add "
  14. + "container button in the Flux editor window.";
  15. void OnEnable()
  16. {
  17. _fluxSettings = (FSettings)target;
  18. _plusTexture = FUtility.GetFluxTexture( "Plus.png" );
  19. _minusTexture = FUtility.GetFluxTexture( "Minus.png" );
  20. }
  21. public override void OnInspectorGUI ()
  22. {
  23. GUIStyle centeredLabel = new GUIStyle( EditorStyles.largeLabel );
  24. centeredLabel.alignment = TextAnchor.MiddleCenter;
  25. GUILayout.Label( "Flux Color Settings", centeredLabel );
  26. EditorGUI.BeginChangeCheck();
  27. RenderColorList( "Event Colors", _fluxSettings.EventColors, "<Flux.EventType>", FGUI.GetEventColor(), EVENT_COLOR_MSG );
  28. GUILayout.Space(10);
  29. RenderColorList( "Default Containers", _fluxSettings.DefaultContainers, "<Container Name>", Flux.FContainer.DEFAULT_COLOR, CONTAINER_COLOR_MSG );
  30. if( EditorGUI.EndChangeCheck() )
  31. {
  32. RebuildSettingsCache();
  33. }
  34. }
  35. private void RenderColorList( string title, List<FColorSetting> colors, string defaultName, Color defaultColor, string helpStr )
  36. {
  37. EditorGUI.BeginChangeCheck();
  38. EditorGUILayout.BeginVertical("box");
  39. EditorGUILayout.BeginHorizontal();
  40. GUIContent label = new GUIContent( title, helpStr );
  41. GUILayout.Label( label );
  42. if( GUILayout.Button( _plusTexture, GUILayout.Width(40), GUILayout.Height(16) ) )
  43. colors.Add( new FColorSetting(defaultName, defaultColor) );
  44. EditorGUILayout.EndHorizontal();
  45. for( int i = 0; i != colors.Count; ++i )
  46. {
  47. EditorGUILayout.BeginHorizontal();
  48. colors[i]._str = EditorGUILayout.TextField( colors[i]._str );
  49. colors[i]._color = EditorGUILayout.ColorField( colors[i]._color );
  50. if( GUILayout.Button( _minusTexture, GUILayout.Width(40), GUILayout.Height(16) ) )
  51. {
  52. colors.RemoveAt( i );
  53. RebuildSettingsCache();
  54. EditorGUIUtility.ExitGUI();
  55. }
  56. EditorGUILayout.EndHorizontal();
  57. }
  58. // EditorGUILayout.HelpBox( helpStr, MessageType.Info );
  59. EditorGUILayout.EndVertical();
  60. if( EditorGUI.EndChangeCheck() )
  61. EditorUtility.SetDirty( _fluxSettings );
  62. }
  63. private void RebuildSettingsCache()
  64. {
  65. _fluxSettings.Init();
  66. if( FSequenceEditorWindow.instance != null )
  67. FSequenceEditorWindow.instance.Repaint();
  68. }
  69. }
  70. }