using UnityEditor; using UnityEngine; using System.Collections.Generic; using ParticlePlayground; using ParticlePlaygroundLanguage; using PlaygroundSplines; [CustomEditor (typeof(PlaygroundC))] public class PlaygroundInspectorC : Editor { ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Playground variables ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static PlaygroundC playgroundScriptReference; public static SerializedObject playground; public static SerializedProperty calculate; public static SerializedProperty pixelFilterMode; public static SerializedProperty globalTimeScale; public static SerializedProperty autoGroup; public static SerializedProperty buildZeroAlphaPixels; public static SerializedProperty drawGizmos; public static SerializedProperty drawSourcePositions; public static SerializedProperty drawWireframe; public static SerializedProperty drawSplinePreview; public static SerializedProperty paintToolbox; public static SerializedProperty showShuriken; public static SerializedProperty showSnapshots; public static SerializedProperty threadPool; public static SerializedProperty threads; public static SerializedProperty threadsTurbulence; public static SerializedProperty threadsSkinned; public static SerializedProperty maxThreads; public static SerializedProperty particleSystems; public static SerializedProperty manipulators; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Internal variables ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static Vector3 manipulatorHandlePosition; public static GUIStyle boxStyle; public static bool showSnapshotsSettings; public static PlaygroundSettingsC playgroundSettings; public static PlaygroundLanguageC playgroundLanguage; public void OnEnable () { Initialize(target as PlaygroundC); } public static void Initialize (PlaygroundC targetRef) { playgroundScriptReference = targetRef; PlaygroundC.reference = targetRef; if (playgroundScriptReference==null) return; playground = new SerializedObject(playgroundScriptReference); particleSystems = playground.FindProperty("particleSystems"); manipulators = playground.FindProperty("manipulators"); calculate = playground.FindProperty("calculate"); pixelFilterMode = playground.FindProperty("pixelFilterMode"); globalTimeScale = playground.FindProperty("globalTimeScale"); autoGroup = playground.FindProperty("autoGroup"); buildZeroAlphaPixels = playground.FindProperty("buildZeroAlphaPixels"); drawGizmos = playground.FindProperty("drawGizmos"); drawSourcePositions = playground.FindProperty("drawSourcePositions"); drawWireframe = playground.FindProperty("drawWireframe"); drawSplinePreview = playground.FindProperty("drawSplinePreview"); paintToolbox = playground.FindProperty("paintToolbox"); showShuriken = playground.FindProperty("showShuriken"); showSnapshots = playground.FindProperty("showSnapshotsInHierarchy"); threadPool = playground.FindProperty("threadPoolMethod"); threads = playground.FindProperty("threadMethod"); threadsTurbulence = playground.FindProperty("turbulenceThreadMethod"); threadsSkinned = playground.FindProperty("skinnedMeshThreadMethod"); maxThreads = playground.FindProperty("maxThreads"); playgroundSettings = PlaygroundSettingsC.GetReference(); playgroundLanguage = PlaygroundSettingsC.GetLanguage(); } public override void OnInspectorGUI () { if (PlaygroundC.reference==null) return; if (boxStyle==null) boxStyle = GUI.skin.FindStyle("box"); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(playgroundLanguage.playgroundName+" "+PlaygroundC.version+PlaygroundC.specialVersion, EditorStyles.largeLabel, GUILayout.Height(20)); EditorGUILayout.Separator(); if(GUILayout.Button(playgroundLanguage.openPlaygroundWizard, EditorStyles.toolbarButton, GUILayout.Width(130))) { PlaygroundParticleWindowC.ShowWindow(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); RenderPlaygroundSettings(); if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") { foreach (PlaygroundParticlesC p in playgroundScriptReference.particleSystems) { p.Boot(); } } } void OnSceneGUI () { if (playgroundScriptReference!=null && playgroundScriptReference.drawGizmos && playgroundSettings.globalManipulatorsFoldout) for (int i = 0; i0) Handles.Label(thisManipulator.transform.transform.position+new Vector3(thisManipulator.size+1f,1f,0f), playgroundLanguage.size+" "+thisManipulator.size.ToString("f2")); // Box Bounds } else if (thisManipulator.shape==MANIPULATORSHAPEC.Box) { DrawManipulatorBox(thisManipulator); } // Strength manipulatorHandlePosition = thisManipulator.transform.transform.position+new Vector3(0f,thisManipulator.strength,0f); // Event particles if (thisManipulator.trackParticles) { Handles.Label(thisManipulator.transform.transform.position+new Vector3(0f,-(thisManipulator.size+1f),0f), thisManipulator.particles.Count+" "+playgroundLanguage.particles); } Handles.DrawLine(thisManipulator.transform.transform.position, manipulatorHandlePosition); thisManipulator.strength = Handles.ScaleValueHandle(thisManipulator.strength, manipulatorHandlePosition, Quaternion.identity, HandleUtility.GetHandleSize(manipulatorHandlePosition), Handles.SphereCap, 1); if (thisManipulator.enabled && GUIUtility.hotControl>0) Handles.Label(manipulatorHandlePosition+new Vector3(1f,1f,0f), playgroundLanguage.strength+" "+thisManipulator.strength.ToString("f2")); Handles.color = new Color(.4f,.6f,1f,.025f); Handles.DrawSolidDisc(thisManipulator.transform.transform.position, Camera.current.transform.forward, thisManipulator.strength); Handles.color = new Color(.4f,.6f,1f,.5f); Handles.DrawSolidDisc(thisManipulator.transform.transform.position, Camera.current.transform.forward, HandleUtility.GetHandleSize(thisManipulator.transform.transform.position)*.05f); } } // Draws a Manipulator bounding box with handles in scene view public static void DrawManipulatorBox (ManipulatorObjectC manipulator) { Vector3 boxFrontTopLeft; Vector3 boxFrontTopRight; Vector3 boxFrontBottomLeft; Vector3 boxFrontBottomRight; Vector3 boxBackTopLeft; Vector3 boxBackTopRight; Vector3 boxBackBottomLeft; Vector3 boxBackBottomRight; Vector3 boxFrontDot; Vector3 boxLeftDot; Vector3 boxUpDot; // Always set positive values of bounds manipulator.bounds.extents = new Vector3(Mathf.Abs(manipulator.bounds.extents.x), Mathf.Abs(manipulator.bounds.extents.y), Mathf.Abs(manipulator.bounds.extents.z)); // Set positions from bounds boxFrontTopLeft = new Vector3(manipulator.bounds.center.x - manipulator.bounds.extents.x, manipulator.bounds.center.y + manipulator.bounds.extents.y, manipulator.bounds.center.z - manipulator.bounds.extents.z); boxFrontTopRight = new Vector3(manipulator.bounds.center.x + manipulator.bounds.extents.x, manipulator.bounds.center.y + manipulator.bounds.extents.y, manipulator.bounds.center.z - manipulator.bounds.extents.z); boxFrontBottomLeft = new Vector3(manipulator.bounds.center.x - manipulator.bounds.extents.x, manipulator.bounds.center.y - manipulator.bounds.extents.y, manipulator.bounds.center.z - manipulator.bounds.extents.z); boxFrontBottomRight = new Vector3(manipulator.bounds.center.x + manipulator.bounds.extents.x, manipulator.bounds.center.y - manipulator.bounds.extents.y, manipulator.bounds.center.z - manipulator.bounds.extents.z); boxBackTopLeft = new Vector3(manipulator.bounds.center.x - manipulator.bounds.extents.x, manipulator.bounds.center.y + manipulator.bounds.extents.y, manipulator.bounds.center.z + manipulator.bounds.extents.z); boxBackTopRight = new Vector3(manipulator.bounds.center.x + manipulator.bounds.extents.x, manipulator.bounds.center.y + manipulator.bounds.extents.y, manipulator.bounds.center.z + manipulator.bounds.extents.z); boxBackBottomLeft = new Vector3(manipulator.bounds.center.x - manipulator.bounds.extents.x, manipulator.bounds.center.y - manipulator.bounds.extents.y, manipulator.bounds.center.z + manipulator.bounds.extents.z); boxBackBottomRight = new Vector3(manipulator.bounds.center.x + manipulator.bounds.extents.x, manipulator.bounds.center.y - manipulator.bounds.extents.y, manipulator.bounds.center.z + manipulator.bounds.extents.z); boxFrontDot = new Vector3(manipulator.bounds.center.x + manipulator.bounds.extents.x, manipulator.bounds.center.y, manipulator.bounds.center.z); boxUpDot = new Vector3(manipulator.bounds.center.x, manipulator.bounds.center.y + manipulator.bounds.extents.y, manipulator.bounds.center.z); boxLeftDot = new Vector3(manipulator.bounds.center.x, manipulator.bounds.center.y, manipulator.bounds.center.z + manipulator.bounds.extents.z); // Apply transform positioning boxFrontTopLeft = manipulator.transform.transform.TransformPoint(boxFrontTopLeft); boxFrontTopRight = manipulator.transform.transform.TransformPoint(boxFrontTopRight); boxFrontBottomLeft = manipulator.transform.transform.TransformPoint(boxFrontBottomLeft); boxFrontBottomRight = manipulator.transform.transform.TransformPoint(boxFrontBottomRight); boxBackTopLeft = manipulator.transform.transform.TransformPoint(boxBackTopLeft); boxBackTopRight = manipulator.transform.transform.TransformPoint(boxBackTopRight); boxBackBottomLeft = manipulator.transform.transform.TransformPoint(boxBackBottomLeft); boxBackBottomRight = manipulator.transform.transform.TransformPoint(boxBackBottomRight); boxFrontDot = manipulator.transform.transform.TransformPoint(boxFrontDot); boxLeftDot = manipulator.transform.transform.TransformPoint(boxLeftDot); boxUpDot = manipulator.transform.transform.TransformPoint(boxUpDot); // Draw front lines Handles.DrawLine(boxFrontTopLeft, boxFrontTopRight); Handles.DrawLine(boxFrontTopRight, boxFrontBottomRight); Handles.DrawLine(boxFrontBottomLeft, boxFrontTopLeft); Handles.DrawLine(boxFrontBottomRight, boxFrontBottomLeft); // Draw back lines Handles.DrawLine(boxBackTopLeft, boxBackTopRight); Handles.DrawLine(boxBackTopRight, boxBackBottomRight); Handles.DrawLine(boxBackBottomLeft, boxBackTopLeft); Handles.DrawLine(boxBackBottomRight, boxBackBottomLeft); // Draw front to back lines Handles.DrawLine(boxFrontTopLeft, boxBackTopLeft); Handles.DrawLine(boxFrontTopRight, boxBackTopRight); Handles.DrawLine(boxFrontBottomLeft, boxBackBottomLeft); Handles.DrawLine(boxFrontBottomRight, boxBackBottomRight); // Draw extents handles boxFrontDot = Handles.Slider(boxFrontDot, manipulator.transform.right, HandleUtility.GetHandleSize(boxFrontDot)*.03f, Handles.DotCap, 0f); boxUpDot = Handles.Slider(boxUpDot, manipulator.transform.up, HandleUtility.GetHandleSize(boxUpDot)*.03f, Handles.DotCap, 0f); boxLeftDot = Handles.Slider(boxLeftDot, manipulator.transform.forward, HandleUtility.GetHandleSize(boxLeftDot)*.03f, Handles.DotCap, 0f); manipulator.bounds.extents = new Vector3( manipulator.transform.transform.InverseTransformPoint(boxFrontDot).x-manipulator.bounds.center.x, manipulator.transform.transform.InverseTransformPoint(boxUpDot).y-manipulator.bounds.center.y, manipulator.transform.transform.InverseTransformPoint(boxLeftDot).z-manipulator.bounds.center.z ); } public static void RenderPlaygroundSettings () { if (boxStyle==null) boxStyle = GUI.skin.FindStyle("box"); EditorGUILayout.BeginVertical(boxStyle); if (playgroundSettings==null) { playgroundSettings = PlaygroundSettingsC.GetReference(); playgroundLanguage = PlaygroundSettingsC.GetLanguage(); } playgroundSettings.playgroundManagerFoldout = GUILayout.Toggle(playgroundSettings.playgroundManagerFoldout, playgroundLanguage.playgroundManager, EditorStyles.foldout); if (playgroundSettings.playgroundManagerFoldout) { EditorGUILayout.BeginVertical(boxStyle); if (playgroundScriptReference==null) { playgroundScriptReference = GameObject.FindObjectOfType(); if (playgroundScriptReference) Initialize(playgroundScriptReference); } if (playgroundSettings.playgroundFoldout && playgroundScriptReference!=null) { playground.Update(); // Particle System List if (GUILayout.Button(playgroundLanguage.particleSystems+" ("+playgroundScriptReference.particleSystems.Count+")", EditorStyles.toolbarDropDown)) playgroundSettings.particleSystemsFoldout=!playgroundSettings.particleSystemsFoldout; if (playgroundSettings.particleSystemsFoldout) { EditorGUILayout.Separator(); if (playgroundScriptReference.particleSystems.Count>0) { for (int ps = 0; ps1); if(GUILayout.Button(playgroundLanguage.upSymbol, EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(18), GUILayout.Height(16)})){ particleSystems.MoveArrayElement(ps, ps==0?playgroundScriptReference.particleSystems.Count-1:ps-1); } if(GUILayout.Button(playgroundLanguage.downSymbol, EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(18), GUILayout.Height(16)})){ particleSystems.MoveArrayElement(ps, ps(); // Add this to Manager if (PlaygroundC.reference!=null) { PlaygroundC.particlesQuantity++; ppsDuplicate.particleSystemId = PlaygroundC.particlesQuantity; if (PlaygroundC.reference.autoGroup && ppsDuplicate.particleSystemTransform.parent==null) ppsDuplicate.particleSystemTransform.parent = PlaygroundC.referenceTransform; } } if(GUILayout.Button("-", EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(18), GUILayout.Height(16)})){ if (EditorUtility.DisplayDialog( playgroundLanguage.remove+" "+playgroundScriptReference.particleSystems[ps].particleSystemGameObject.name+"?", playgroundLanguage.removeParticlePlaygroundSystem, playgroundLanguage.yes, playgroundLanguage.no)) { if (Selection.activeGameObject==playgroundScriptReference.particleSystems[ps].particleSystemGameObject) Selection.activeGameObject = PlaygroundC.referenceTransform.gameObject; PlaygroundC.Destroy(playgroundScriptReference.particleSystems[ps]); playground.ApplyModifiedProperties(); return; } } if (playgroundScriptReference.particleSystems[ps].particleSystemGameObject == Selection.activeGameObject) GUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } } else { EditorGUILayout.HelpBox(playgroundLanguage.noParticleSystems, MessageType.Info); } if(GUILayout.Button(playgroundLanguage.create, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))){ PlaygroundParticlesC createdParticles = PlaygroundC.Particle(); Selection.activeGameObject = createdParticles.particleSystemGameObject; } EditorGUILayout.Separator(); } // Manipulators if (GUILayout.Button(playgroundLanguage.globalManipulators+" ("+playgroundScriptReference.manipulators.Count+")", EditorStyles.toolbarDropDown)) playgroundSettings.globalManipulatorsFoldout=!playgroundSettings.globalManipulatorsFoldout; if (playgroundSettings.globalManipulatorsFoldout) { EditorGUILayout.Separator(); if (manipulators.arraySize>0) { for (int i = 0; i24) mName = mName.Substring(0, 24)+"..."; } else { GUI.color = Color.red; mName = "("+playgroundLanguage.missingTransform+")"; } EditorGUILayout.BeginVertical(boxStyle); EditorGUILayout.BeginHorizontal(); GUILayout.Label(i.ToString(), EditorStyles.miniLabel, GUILayout.Width(18)); playgroundScriptReference.manipulators[i].unfolded = GUILayout.Toggle(playgroundScriptReference.manipulators[i].unfolded, ManipulatorTypeName(playgroundScriptReference.manipulators[i].type), EditorStyles.foldout, GUILayout.Width(Screen.width/4)); if (playgroundScriptReference.manipulators[i].transform.available) { if (GUILayout.Button(" ("+mName+")", EditorStyles.label)) { Selection.activeGameObject = playgroundScriptReference.manipulators[i].transform.transform.gameObject; } } else { GUILayout.Button(ManipulatorTypeName(playgroundScriptReference.manipulators[i].type)+" ("+playgroundLanguage.missingTransform+")", EditorStyles.label); } GUI.contentColor = Color.white; EditorGUILayout.Separator(); GUI.enabled = (playgroundScriptReference.manipulators.Count>1); if(GUILayout.Button(playgroundLanguage.upSymbol, EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(18), GUILayout.Height(16)})){ manipulators.MoveArrayElement(i, i==0?playgroundScriptReference.manipulators.Count-1:i-1); } if(GUILayout.Button(playgroundLanguage.downSymbol, EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(18), GUILayout.Height(16)})){ manipulators.MoveArrayElement(i, i0 && Selection.activeGameObject.transform && Selection.activeTransform!=null) { Transform mTrans = new GameObject().transform; mTrans.parent = PlaygroundC.referenceTransform; mTrans.position = Selection.activeGameObject.transform.position+Vector3.up; if (manipulators.arraySize>0) mTrans.name = "Global Manipulator "+(manipulators.arraySize+1); else mTrans.name = "Global Manipulator"; PlaygroundC.ManipulatorObject(mTrans); } else manipulators.InsertArrayElementAtIndex(manipulators.arraySize); SceneView.RepaintAll(); } EditorGUILayout.Separator(); } // Advanced Settings if (GUILayout.Button(playgroundLanguage.advanced, EditorStyles.toolbarDropDown)) playgroundSettings.advancedSettingsFoldout=!playgroundSettings.advancedSettingsFoldout; if (playgroundSettings.advancedSettingsFoldout) { showSnapshotsSettings = PlaygroundC.reference.showSnapshotsInHierarchy; EditorGUILayout.Separator(); EditorGUILayout.PropertyField(calculate, new GUIContent(playgroundLanguage.calculateParticles, playgroundLanguage.calculateParticlesDescription)); EditorGUILayout.PropertyField(autoGroup, new GUIContent(playgroundLanguage.groupAutomatically, playgroundLanguage.groupAutomaticallyDescription)); EditorGUILayout.PropertyField(buildZeroAlphaPixels, new GUIContent(playgroundLanguage.buildZeroAlphaPixels, playgroundLanguage.buildZeroAlphaPixelsDescription)); EditorGUILayout.PropertyField(drawGizmos, new GUIContent(playgroundLanguage.sceneGizmos, playgroundLanguage.sceneGizmosDescription)); GUI.enabled = drawGizmos.boolValue; EditorGUILayout.PropertyField(drawSourcePositions, new GUIContent(playgroundLanguage.sourcePositions, playgroundLanguage.sourcePositionsDescription)); EditorGUILayout.PropertyField(drawSplinePreview, new GUIContent(playgroundLanguage.drawSplinePreview, playgroundLanguage.drawSplinePreviewDescription)); PlaygroundSpline.drawSplinePreviews = drawSplinePreview.boolValue; GUI.enabled = true; EditorGUILayout.PropertyField(drawWireframe, new GUIContent(playgroundLanguage.wireframes, playgroundLanguage.wireframesDescription)); EditorGUILayout.PropertyField(paintToolbox, new GUIContent(playgroundLanguage.paintToolbox, playgroundLanguage.paintToolboxDescription)); EditorGUILayout.PropertyField(showShuriken, new GUIContent(playgroundLanguage.showShuriken, playgroundLanguage.showShurikenDescription)); EditorGUILayout.PropertyField(showSnapshots, new GUIContent(playgroundLanguage.advancedSnapshots, playgroundLanguage.advancedSnapshotsDescription)); EditorGUILayout.PropertyField(pixelFilterMode, new GUIContent(playgroundLanguage.pixelFilterMode, playgroundLanguage.pixelFilterModeDescription)); EditorGUILayout.PropertyField(globalTimeScale, new GUIContent(playgroundLanguage.globalTimeScale, playgroundLanguage.globalTimeScaleDescription)); EditorGUILayout.Separator(); GUILayout.BeginVertical(boxStyle); EditorGUILayout.LabelField(playgroundLanguage.multithreading+" ("+PlaygroundC.ActiveThreads().ToString()+" "+playgroundLanguage.activeThreads+", "+PlaygroundC.ProcessorCount()+" "+playgroundLanguage.processors+")", EditorStyles.miniLabel); EditorGUILayout.PropertyField(threadPool, new GUIContent(playgroundLanguage.threadPoolMethod, playgroundLanguage.threadPoolMethodDescription)); EditorGUILayout.PropertyField(threads, new GUIContent(playgroundLanguage.particleThreadMethod, playgroundLanguage.threadMethodDescription)); EditorGUILayout.PropertyField(threadsTurbulence, new GUIContent(playgroundLanguage.turbulenceThreadMethod, playgroundLanguage.threadMethodDescription)); EditorGUILayout.PropertyField(threadsSkinned, new GUIContent(playgroundLanguage.skinnedMeshThreadMethod, playgroundLanguage.threadMethodDescription)); GUI.enabled = playgroundScriptReference.threadMethod==ThreadMethod.Automatic; EditorGUILayout.PropertyField(maxThreads, new GUIContent(playgroundLanguage.maxThreads, playgroundLanguage.maxThreadsDescription)); GUI.enabled = true; switch (playgroundScriptReference.threadMethod) { case ThreadMethod.NoThreads:EditorGUILayout.HelpBox(playgroundLanguage.threadInfo01, MessageType.Info);break; case ThreadMethod.OnePerSystem:EditorGUILayout.HelpBox(playgroundLanguage.threadInfo02, MessageType.Info);break; case ThreadMethod.OneForAll:EditorGUILayout.HelpBox(playgroundLanguage.threadInfo03, MessageType.Info);break; case ThreadMethod.Automatic:EditorGUILayout.HelpBox(playgroundLanguage.threadInfo04, MessageType.Info);break; } GUILayout.EndHorizontal(); EditorGUILayout.Separator(); // Update snapshot visibility if (showSnapshots.boolValue != showSnapshotsSettings) { UpdateSnapshots(); } // Time reset GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(playgroundLanguage.timeSimulation); if(GUILayout.Button(playgroundLanguage.reset, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))){ PlaygroundC.TimeReset(); for (int p = 0; p0) { SerializedProperty serializedManipulatorProperties = serializedManipulator.FindPropertyRelative("properties"); int prevPropertyCount = thisManipulator.properties.Count; for (int i = 0; i1); if(GUILayout.Button(playgroundLanguage.upSymbol, EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(18), GUILayout.Height(16)})){ serializedManipulatorProperties.MoveArrayElement(i, i==0?thisManipulator.properties.Count-1:i-1); } if(GUILayout.Button(playgroundLanguage.downSymbol, EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(18), GUILayout.Height(16)})){ serializedManipulatorProperties.MoveArrayElement(i, i0) { for (int t = 0; t