FSettings.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. namespace FluxEditor
  5. {
  6. public class FSettings : ScriptableObject {
  7. [MenuItem("Window/Flux/Create Flux Settings",false, 101)]
  8. public static void CreateColorSettings()
  9. {
  10. string settingsPath = FluxEditor.FUtility.GetFluxEditorPath()+"FluxSettings.asset";
  11. if( AssetDatabase.LoadMainAssetAtPath( settingsPath ) != null )
  12. {
  13. if( !EditorUtility.DisplayDialog("Warning", "Flux Settings already exist, are you sure you want to replace them?", "Replace", "Cancel" ) )
  14. return;
  15. }
  16. FSettings settings = CreateInstance<FSettings>();
  17. AssetDatabase.CreateAsset( settings, settingsPath );
  18. }
  19. [SerializeField]
  20. private List<FColorSetting> _eventColors = new List<FColorSetting>();
  21. public List<FColorSetting> EventColors { get { return _eventColors; } }
  22. private Dictionary<string, FColorSetting> _eventColorsHash = null;
  23. [SerializeField]
  24. private List<FColorSetting> _defaultContainers = new List<FColorSetting>();
  25. public List<FColorSetting> DefaultContainers { get { return _defaultContainers; } }
  26. public void Init()
  27. {
  28. if( _eventColorsHash == null )
  29. _eventColorsHash = new Dictionary<string, FColorSetting>();
  30. else
  31. _eventColorsHash.Clear();
  32. foreach( FColorSetting colorSetting in _eventColors )
  33. {
  34. if( string.IsNullOrEmpty( colorSetting._str ) )
  35. return;
  36. if( _eventColorsHash.ContainsKey( colorSetting._str ) )
  37. return; // can't add duplicates!
  38. _eventColorsHash.Add( colorSetting._str, colorSetting );
  39. }
  40. }
  41. public Color GetEventColor( string str )
  42. {
  43. if( _eventColorsHash == null )
  44. Init();
  45. // Debug.Log ( eventTypeStr );
  46. FColorSetting c;
  47. if( !_eventColorsHash.TryGetValue( str, out c ) )
  48. return FGUI.GetEventColor();
  49. return c._color;
  50. }
  51. }
  52. [System.Serializable]
  53. public class FColorSetting
  54. {
  55. public string _str;
  56. public Color _color;
  57. public FColorSetting( string str, Color color )
  58. {
  59. _str = str;
  60. _color = color;
  61. }
  62. }
  63. }