public void OnGUI(float width, bool fixedWidth) { bool isRepaintEvent = Event.current.type == EventType.Repaint; // Name of current emitter string selectedEmitterName = null; if (m_ParticleSystems.Length > 1) { selectedEmitterName = "Multiple Particle Systems"; } else if (m_ParticleSystems.Length > 0) { selectedEmitterName = m_ParticleSystems[0].gameObject.name; } if (fixedWidth) { EditorGUIUtility.labelWidth = width * 0.4f; EditorGUILayout.BeginVertical(GUILayout.Width(width)); } else { // First make sure labelWidth is at default width, then subtract EditorGUIUtility.labelWidth = 0; EditorGUIUtility.labelWidth = EditorGUIUtility.labelWidth - 4; EditorGUILayout.BeginVertical(); } { InitialModuleUI initial = (InitialModuleUI)m_Modules[0]; for (int i = 0; i < m_Modules.Length; ++i) { ModuleUI module = m_Modules[i]; if (module == null) { continue; } bool initialModule = (module == m_Modules[0]); // Skip if not visible (except initial module which should always be visible) if (!module.visibleUI && !initialModule) { continue; } // Module header size GUIContent headerLabel = new GUIContent(); Rect moduleHeaderRect; if (initialModule) { moduleHeaderRect = GUILayoutUtility.GetRect(width, 25); } else { moduleHeaderRect = GUILayoutUtility.GetRect(width, 15); } // Module content here to render it below the the header if (module.foldout) { using (new EditorGUI.DisabledScope(!module.enabled)) { Rect moduleSize = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding); { moduleSize.y -= 4; // pull background 'up' behind title to fill rounded corners. moduleSize.height += 4; GUI.Label(moduleSize, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle); module.OnInspectorGUI(initial); } EditorGUILayout.EndVertical(); } } // TODO: Get Texture instead of static preview. Render Icon (below titlebar due to rounded corners) if (initialModule) { // Get preview of material or mesh ParticleSystemRenderer renderer = m_ParticleSystems[0].GetComponent <ParticleSystemRenderer>(); float iconSize = 21; Rect iconRect = new Rect(moduleHeaderRect.x + 4, moduleHeaderRect.y + 2, iconSize, iconSize); if (isRepaintEvent && renderer != null) { bool iconRendered = false; int instanceID = 0; if (!multiEdit) { if (renderer.renderMode == ParticleSystemRenderMode.Mesh) { if (renderer.mesh != null) { instanceID = renderer.mesh.GetInstanceID(); } } else if (renderer.sharedMaterial != null) { instanceID = renderer.sharedMaterial.GetInstanceID(); } // If the asset is dirty we ensure to get a updated one by clearing cache of temporary previews if (EditorUtility.IsDirty(instanceID)) { AssetPreview.ClearTemporaryAssetPreviews(); } if (instanceID != 0) { Texture2D icon = AssetPreview.GetAssetPreview(instanceID); if (icon != null) { GUI.DrawTexture(iconRect, icon, ScaleMode.StretchToFill, true); iconRendered = true; } } } // Fill so we do not see the background when we have no icon (eg multi-edit) if (!iconRendered) { GUI.Label(iconRect, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle); } } // Select gameObject when clicking on icon if (!multiEdit && EditorGUI.DropdownButton(iconRect, GUIContent.none, FocusType.Passive, GUIStyle.none)) { // Toggle selected particle system from selection if (EditorGUI.actionKey) { List <int> newSelection = new List <int>(); int instanceID = m_ParticleSystems[0].gameObject.GetInstanceID(); newSelection.AddRange(Selection.instanceIDs); if (!newSelection.Contains(instanceID) || newSelection.Count != 1) { if (newSelection.Contains(instanceID)) { newSelection.Remove(instanceID); } else { newSelection.Add(instanceID); } } Selection.instanceIDs = newSelection.ToArray(); } else { Selection.instanceIDs = new int[0]; Selection.activeInstanceID = m_ParticleSystems[0].gameObject.GetInstanceID(); } } } // Button logic for enabledness (see below for UI) Rect checkMarkRect = new Rect(moduleHeaderRect.x + 2, moduleHeaderRect.y + 1, 13, 13); if (!initialModule && GUI.Button(checkMarkRect, GUIContent.none, GUIStyle.none)) { module.enabled = !module.enabled; } // Button logic for plus/minus (see below for UI) Rect plusRect = new Rect(moduleHeaderRect.x + moduleHeaderRect.width - 10, moduleHeaderRect.y + moduleHeaderRect.height - 10, 10, 10); Rect plusRectInteract = new Rect(plusRect.x - 4, plusRect.y - 4, plusRect.width + 4, plusRect.height + 4); Rect infoRect = new Rect(plusRect.x - 23, plusRect.y - 8, 20, 20); if (initialModule && EditorGUI.DropdownButton(plusRectInteract, s_Texts.addModules, FocusType.Passive, GUIStyle.none)) { ShowAddModuleMenu(); } // Module header (last to become top most renderered) if (!string.IsNullOrEmpty(selectedEmitterName)) { headerLabel.text = initialModule ? selectedEmitterName : module.displayName; } else { headerLabel.text = module.displayName; } headerLabel.tooltip = module.toolTip; bool newToggleState = module.DrawHeader(moduleHeaderRect, headerLabel); if (newToggleState != module.foldout) { switch (Event.current.button) { case 0: bool newFoldoutState = !module.foldout; if (Event.current.control) { foreach (var moduleUi in m_Modules) { if (moduleUi != null && moduleUi.visibleUI) { moduleUi.foldout = newFoldoutState; } } } else { module.foldout = newFoldoutState; } break; case 1: if (initialModule) { ShowEmitterMenu(); } else { ShowModuleMenu(i); } break; } } // Render checkmark on top (logic: see above) if (!initialModule) { EditorGUI.showMixedValue = module.enabledHasMultipleDifferentValues; GUIStyle style = EditorGUI.showMixedValue ? ParticleSystemStyles.Get().checkmarkMixed : ParticleSystemStyles.Get().checkmark; GUI.Toggle(checkMarkRect, module.enabled, GUIContent.none, style); EditorGUI.showMixedValue = false; } // Render plus/minus on top if (isRepaintEvent && initialModule) { GUI.Label(plusRect, GUIContent.none, ParticleSystemStyles.Get().plus); } if (initialModule && !string.IsNullOrEmpty(m_SupportsCullingTextLabel)) { var supportsCullingText = new GUIContent("", ParticleSystemStyles.Get().warningIcon, m_SupportsCullingTextLabel); GUI.Label(infoRect, supportsCullingText); } GUILayout.Space(1); // dist to next module } // foreach module GUILayout.Space(-1); } EditorGUILayout.EndVertical(); // end fixed moduleWidth // Apply the property, handle undo ApplyProperties(); }
public void OnGUI(float width, bool fixedWidth) { bool flag = Event.current.type == EventType.Repaint; string text = null; if (this.m_ParticleSystems.Length > 1) { text = "Multiple Particle Systems"; } else if (this.m_ParticleSystems.Length > 0) { text = this.m_ParticleSystems[0].gameObject.name; } if (fixedWidth) { EditorGUIUtility.labelWidth = width * 0.4f; EditorGUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(width) }); } else { EditorGUIUtility.labelWidth = 0f; EditorGUIUtility.labelWidth -= 4f; EditorGUILayout.BeginVertical(new GUILayoutOption[0]); } InitialModuleUI initial = (InitialModuleUI)this.m_Modules[0]; for (int i = 0; i < this.m_Modules.Length; i++) { ModuleUI moduleUI = this.m_Modules[i]; if (moduleUI != null) { bool flag2 = moduleUI == this.m_Modules[0]; if (moduleUI.visibleUI || flag2) { GUIContent gUIContent = new GUIContent(); Rect rect; if (flag2) { rect = GUILayoutUtility.GetRect(width, 25f); } else { rect = GUILayoutUtility.GetRect(width, 15f); } if (moduleUI.foldout) { using (new EditorGUI.DisabledScope(!moduleUI.enabled)) { Rect position = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding, new GUILayoutOption[0]); position.y -= 4f; position.height += 4f; GUI.Label(position, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle); moduleUI.OnInspectorGUI(initial); EditorGUILayout.EndVertical(); } } if (flag2) { ParticleSystemRenderer component = this.m_ParticleSystems[0].GetComponent <ParticleSystemRenderer>(); float num = 21f; Rect position2 = new Rect(rect.x + 4f, rect.y + 2f, num, num); if (flag && component != null) { bool flag3 = false; int num2 = 0; if (!this.multiEdit) { if (component.renderMode == ParticleSystemRenderMode.Mesh) { if (component.mesh != null) { num2 = component.mesh.GetInstanceID(); } } else if (component.sharedMaterial != null) { num2 = component.sharedMaterial.GetInstanceID(); } if (EditorUtility.IsDirty(num2)) { AssetPreview.ClearTemporaryAssetPreviews(); } if (num2 != 0) { Texture2D assetPreview = AssetPreview.GetAssetPreview(num2); if (assetPreview != null) { GUI.DrawTexture(position2, assetPreview, ScaleMode.StretchToFill, true); flag3 = true; } } } if (!flag3) { GUI.Label(position2, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle); } } if (!this.multiEdit && EditorGUI.DropdownButton(position2, GUIContent.none, FocusType.Passive, GUIStyle.none)) { if (EditorGUI.actionKey) { List <int> list = new List <int>(); int instanceID = this.m_ParticleSystems[0].gameObject.GetInstanceID(); list.AddRange(Selection.instanceIDs); if (!list.Contains(instanceID) || list.Count != 1) { if (list.Contains(instanceID)) { list.Remove(instanceID); } else { list.Add(instanceID); } } Selection.instanceIDs = list.ToArray(); } else { Selection.instanceIDs = new int[0]; Selection.activeInstanceID = this.m_ParticleSystems[0].gameObject.GetInstanceID(); } } } Rect position3 = new Rect(rect.x + 2f, rect.y + 1f, 13f, 13f); if (!flag2 && GUI.Button(position3, GUIContent.none, GUIStyle.none)) { moduleUI.enabled = !moduleUI.enabled; } Rect position4 = new Rect(rect.x + rect.width - 10f, rect.y + rect.height - 10f, 10f, 10f); Rect position5 = new Rect(position4.x - 4f, position4.y - 4f, position4.width + 4f, position4.height + 4f); Rect position6 = new Rect(position4.x - 23f, position4.y - 8f, 20f, 20f); if (flag2 && EditorGUI.DropdownButton(position5, ParticleSystemUI.s_Texts.addModules, FocusType.Passive, GUIStyle.none)) { this.ShowAddModuleMenu(); } if (!string.IsNullOrEmpty(text)) { gUIContent.text = ((!flag2) ? moduleUI.displayName : text); } else { gUIContent.text = moduleUI.displayName; } gUIContent.tooltip = moduleUI.toolTip; bool flag4 = moduleUI.DrawHeader(rect, gUIContent); if (flag4 != moduleUI.foldout) { int button = Event.current.button; if (button != 0) { if (button == 1) { if (flag2) { this.ShowEmitterMenu(); } else { this.ShowModuleMenu(i); } } } else { bool foldout = !moduleUI.foldout; if (Event.current.control) { ModuleUI[] modules = this.m_Modules; for (int j = 0; j < modules.Length; j++) { ModuleUI moduleUI2 = modules[j]; if (moduleUI2 != null && moduleUI2.visibleUI) { moduleUI2.foldout = foldout; } } } else { moduleUI.foldout = foldout; } } } if (!flag2) { EditorGUI.showMixedValue = moduleUI.enabledHasMultipleDifferentValues; GUIStyle style = (!EditorGUI.showMixedValue) ? ParticleSystemStyles.Get().checkmark : ParticleSystemStyles.Get().checkmarkMixed; GUI.Toggle(position3, moduleUI.enabled, GUIContent.none, style); EditorGUI.showMixedValue = false; } if (flag && flag2) { GUI.Label(position4, GUIContent.none, ParticleSystemStyles.Get().plus); } if (flag2 && !string.IsNullOrEmpty(this.m_SupportsCullingTextLabel)) { GUIContent content = new GUIContent("", ParticleSystemStyles.Get().warningIcon, this.m_SupportsCullingTextLabel); GUI.Label(position6, content); } GUILayout.Space(1f); } } } GUILayout.Space(-1f); EditorGUILayout.EndVertical(); this.ApplyProperties(); }