RiverVFXInspectorBase.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // River Modeler
  2. // Staggart Creations (http://staggart.xyz)
  3. // Copyright protected under Unity Asset Store EULA
  4. // Copying or referencing source code for the production of new asset store content is strictly prohibited.
  5. using sc.modeling.river.runtime;
  6. using sc.modeling.water.common.editor;
  7. using UnityEditor;
  8. namespace sc.modeling.river.editor
  9. {
  10. [CustomEditor(typeof(RiverVFX))]
  11. public class RiverVFXInspectorBase : Editor
  12. {
  13. public SerializedProperty river;
  14. private SerializedProperty confines;
  15. private SerializedProperty boundsSize;
  16. private SerializedProperty targetEffect;
  17. private bool isValidEffect;
  18. private void OnEnable()
  19. {
  20. Enable();
  21. }
  22. public virtual void Enable()
  23. {
  24. river = serializedObject.FindProperty("river");
  25. confines = serializedObject.FindProperty("confines");
  26. boundsSize = serializedObject.FindProperty("boundsSize");
  27. targetEffect = serializedObject.FindProperty("targetEffect");
  28. #if VFX_GRAPH && MATHEMATICS
  29. if (targetEffect.objectReferenceValue)
  30. {
  31. isValidEffect = ((RiverVFX)target).IsValidEffect();
  32. }
  33. #endif
  34. }
  35. public override void OnInspectorGUI()
  36. {
  37. UI.DrawHeader(Asset.NAME, Asset.VERSION);
  38. #if !URP
  39. EditorGUILayout.HelpBox("This VFX Graph was constructed for the Universal Render Pipeline", MessageType.Error);
  40. #endif
  41. #if !VFX_GRAPH
  42. EditorGUILayout.HelpBox("This component requires the VFX Graph package!", MessageType.Error);
  43. return;
  44. #endif
  45. serializedObject.Update();
  46. EditorGUI.BeginChangeCheck();
  47. EditorGUILayout.PropertyField(river);
  48. if (!river.objectReferenceValue)
  49. {
  50. EditorGUILayout.HelpBox("A target river component must be assigned!", MessageType.Error);
  51. }
  52. EditorGUI.BeginChangeCheck();
  53. EditorGUILayout.PropertyField(targetEffect);
  54. if (EditorGUI.EndChangeCheck())
  55. {
  56. if (targetEffect.objectReferenceValue) isValidEffect = ((RiverVFX)target).IsValidEffect();
  57. }
  58. #if URP
  59. if (targetEffect.objectReferenceValue && isValidEffect == false)
  60. {
  61. EditorGUILayout.HelpBox("This Visual Effect uses a graph that is missing the \"Emitter Positions\" property.\n\n"+
  62. "Re-import is from the asset store, or open it and recompile it, if this appears to be in error.", MessageType.Warning);
  63. }
  64. #endif
  65. EditorGUILayout.Space();
  66. EditorGUILayout.PropertyField(confines);
  67. if (confines.intValue == (int)(RiverVFX.Confines.Bounds))
  68. {
  69. EditorGUI.indentLevel++;
  70. EditorGUILayout.PropertyField(boundsSize);
  71. EditorGUILayout.HelpBox("The Transform's position defines the bounds center", MessageType.None);
  72. EditorGUI.indentLevel--;
  73. }
  74. EditorGUILayout.Space();
  75. if (EditorGUI.EndChangeCheck())
  76. {
  77. serializedObject.ApplyModifiedProperties();
  78. EditorApplication.delayCall += () =>
  79. {
  80. foreach (var m_target in targets)
  81. ((RiverVFX)m_target).GenerateEmitters();
  82. };
  83. }
  84. }
  85. }
  86. }