VFXParameterEditor.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEditor;
  6. using UnityEditor.Experimental;
  7. using UnityEditor.SceneManagement;
  8. using UnityEngine;
  9. using UnityEngine.VFX;
  10. using UnityEditor.VFX;
  11. using UnityEditor.VFX.UI;
  12. using Object = UnityEngine.Object;
  13. using UnityEditorInternal;
  14. using System.Reflection;
  15. [CustomEditor(typeof(VFXParameter), true)]
  16. [CanEditMultipleObjects]
  17. class VFXParameterEditor : VFXSlotContainerEditor
  18. {
  19. VFXViewController controller;
  20. protected new void OnEnable()
  21. {
  22. base.OnEnable();
  23. VFXViewWindow current = VFXViewWindow.currentWindow;
  24. if (current != null)
  25. {
  26. controller = current.graphView.controller;
  27. if (controller != null)
  28. controller.useCount++;
  29. }
  30. }
  31. protected new void OnDisable()
  32. {
  33. if (controller != null)
  34. {
  35. controller.useCount--;
  36. controller = null;
  37. }
  38. base.OnDisable();
  39. }
  40. public override SerializedProperty DoInspectorGUI()
  41. {
  42. var saveEnabled = GUI.enabled;
  43. var referenceModel = serializedObject.targetObject as VFXModel;
  44. var resource = referenceModel.GetResource();
  45. if (resource != null && !resource.IsAssetEditable())
  46. {
  47. GUI.enabled = false;
  48. saveEnabled = false;
  49. }
  50. if (serializedObject.isEditingMultipleObjects)
  51. {
  52. GUI.enabled = false; // no sense to change the name in multiple selection because the name must be unique
  53. EditorGUI.showMixedValue = true;
  54. EditorGUILayout.TextField("Exposed Name", "-");
  55. EditorGUI.showMixedValue = false;
  56. GUI.enabled = saveEnabled;
  57. }
  58. else
  59. {
  60. VFXParameter parameter = (VFXParameter)target;
  61. GUI.enabled = controller != null && saveEnabled;
  62. string newName = EditorGUILayout.DelayedTextField("Exposed Name", parameter.exposedName);
  63. GUI.enabled = saveEnabled;
  64. if (GUI.changed)
  65. {
  66. VFXParameterController parameterController = controller.GetParameterController(parameter);
  67. if (parameterController != null)
  68. {
  69. parameterController.exposedName = newName;
  70. }
  71. }
  72. }
  73. return base.DoInspectorGUI();
  74. }
  75. }