UnityEditor.ParticleSystemUI.OnGUI C# (CSharp) Method

OnGUI() public method

public OnGUI ( ParticleSystem root, float width, bool fixedWidth ) : void
root UnityEngine.ParticleSystem
width float
fixedWidth bool
return void
        public void OnGUI(ParticleSystem root, float width, bool fixedWidth)
        {
            if (s_Texts == null)
            {
                s_Texts = new Texts();
            }
            bool flag = Event.current.type == EventType.Repaint;
            string str = (this.m_ParticleSystem == null) ? null : this.m_ParticleSystem.gameObject.name;
            if (fixedWidth)
            {
                EditorGUIUtility.labelWidth = width * 0.4f;
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(width) };
                EditorGUILayout.BeginVertical(options);
            }
            else
            {
                EditorGUIUtility.labelWidth = 0f;
                EditorGUIUtility.labelWidth -= 4f;
                EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            }
            for (int i = 0; i < this.m_Modules.Length; i++)
            {
                GUIStyle emitterHeaderStyle;
                Rect rect;
                bool flag5;
                ModuleUI eui = this.m_Modules[i];
                if (eui == null)
                {
                    continue;
                }
                bool flag2 = eui == this.m_Modules[0];
                if (!eui.visibleUI && !flag2)
                {
                    continue;
                }
                GUIContent content = new GUIContent();
                if (flag2)
                {
                    rect = GUILayoutUtility.GetRect(width, 25f);
                    emitterHeaderStyle = ParticleSystemStyles.Get().emitterHeaderStyle;
                }
                else
                {
                    rect = GUILayoutUtility.GetRect(width, 15f);
                    emitterHeaderStyle = ParticleSystemStyles.Get().moduleHeaderStyle;
                }
                if (eui.foldout)
                {
                    using (new EditorGUI.DisabledScope(!eui.enabled))
                    {
                        Rect rect2 = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding, new GUILayoutOption[0]);
                        rect2.y -= 4f;
                        rect2.height += 4f;
                        GUI.Label(rect2, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                        eui.OnInspectorGUI(this.m_ParticleSystem);
                        EditorGUILayout.EndVertical();
                    }
                }
                if (flag2)
                {
                    ParticleSystemRenderer particleSystemRenderer = this.GetParticleSystemRenderer();
                    float num2 = 21f;
                    Rect rect3 = new Rect(rect.x + 4f, rect.y + 2f, num2, num2);
                    if (flag && (particleSystemRenderer != null))
                    {
                        bool flag3 = false;
                        int instanceID = 0;
                        RendererModuleUI eui2 = this.m_Modules[this.m_Modules.Length - 1] as RendererModuleUI;
                        if (eui2 != null)
                        {
                            if (eui2.IsMeshEmitter())
                            {
                                if (particleSystemRenderer.mesh != null)
                                {
                                    instanceID = particleSystemRenderer.mesh.GetInstanceID();
                                }
                            }
                            else if (particleSystemRenderer.sharedMaterial != null)
                            {
                                instanceID = particleSystemRenderer.sharedMaterial.GetInstanceID();
                            }
                            if (EditorUtility.IsDirty(instanceID))
                            {
                                AssetPreview.ClearTemporaryAssetPreviews();
                            }
                        }
                        if (instanceID != 0)
                        {
                            Texture2D assetPreview = AssetPreview.GetAssetPreview(instanceID);
                            if (assetPreview != null)
                            {
                                GUI.DrawTexture(rect3, assetPreview, ScaleMode.StretchToFill, true);
                                flag3 = true;
                            }
                        }
                        if (!flag3)
                        {
                            GUI.Label(rect3, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                        }
                    }
                    if (EditorGUI.ButtonMouseDown(rect3, GUIContent.none, FocusType.Passive, GUIStyle.none))
                    {
                        if (EditorGUI.actionKey)
                        {
                            List<int> list = new List<int>();
                            int item = this.m_ParticleSystem.gameObject.GetInstanceID();
                            list.AddRange(Selection.instanceIDs);
                            if (!list.Contains(item) || (list.Count != 1))
                            {
                                if (list.Contains(item))
                                {
                                    list.Remove(item);
                                }
                                else
                                {
                                    list.Add(item);
                                }
                            }
                            Selection.instanceIDs = list.ToArray();
                        }
                        else
                        {
                            Selection.instanceIDs = new int[0];
                            Selection.activeInstanceID = this.m_ParticleSystem.gameObject.GetInstanceID();
                        }
                    }
                }
                Rect position = new Rect(rect.x + 2f, rect.y + 1f, 13f, 13f);
                if (!flag2 && GUI.Button(position, GUIContent.none, GUIStyle.none))
                {
                    eui.enabled = !eui.enabled;
                }
                Rect rect5 = new Rect((rect.x + rect.width) - 10f, (rect.y + rect.height) - 10f, 10f, 10f);
                Rect rect6 = new Rect(rect5.x - 4f, rect5.y - 4f, rect5.width + 4f, rect5.height + 4f);
                Rect rect7 = new Rect(rect5.x - 23f, rect5.y - 3f, 16f, 16f);
                if (flag2 && EditorGUI.ButtonMouseDown(rect6, s_Texts.addModules, FocusType.Passive, GUIStyle.none))
                {
                    this.ShowAddModuleMenu();
                }
                if (!string.IsNullOrEmpty(str))
                {
                    content.text = !flag2 ? eui.displayName : str;
                }
                else
                {
                    content.text = eui.displayName;
                }
                content.tooltip = eui.toolTip;
                if (GUI.Toggle(rect, eui.foldout, content, emitterHeaderStyle) != eui.foldout)
                {
                    switch (Event.current.button)
                    {
                        case 0:
                            flag5 = !eui.foldout;
                            if (!Event.current.control)
                            {
                                goto Label_05BB;
                            }
                            foreach (ModuleUI eui3 in this.m_Modules)
                            {
                                if ((eui3 != null) && eui3.visibleUI)
                                {
                                    eui3.foldout = flag5;
                                }
                            }
                            break;

                        case 1:
                            if (flag2)
                            {
                                this.ShowEmitterMenu();
                            }
                            else
                            {
                                this.ShowModuleMenu(i);
                            }
                            break;
                    }
                }
                goto Label_05E9;
            Label_05BB:
                eui.foldout = flag5;
            Label_05E9:
                if (!flag2)
                {
                    GUI.Toggle(position, eui.enabled, GUIContent.none, ParticleSystemStyles.Get().checkmark);
                }
                if (flag && flag2)
                {
                    GUI.Label(rect5, GUIContent.none, ParticleSystemStyles.Get().plus);
                }
                s_Texts.supportsCullingText.tooltip = this.m_SupportsCullingText;
                if (flag2 && (s_Texts.supportsCullingText.tooltip != null))
                {
                    GUI.Label(rect7, s_Texts.supportsCullingText);
                }
                GUILayout.Space(1f);
            }
            GUILayout.Space(-1f);
            EditorGUILayout.EndVertical();
            this.ApplyProperties();
        }

Usage Example

コード例 #1
0
        private void InspectorParticleSystemGUI()
        {
            GUILayout.BeginVertical(ParticleSystemStyles.Get().effectBgStyle);
            {
                ParticleSystem selectedSystem = (m_SelectedParticleSystems.Count > 0) ? m_SelectedParticleSystems[0] : null;
                if (selectedSystem != null)
                {
                    ParticleSystemUI psUI = m_Emitters.FirstOrDefault(o => o.m_ParticleSystems[0] == selectedSystem);
                    if (psUI != null)
                    {
                        float width = GUIClip.visibleRect.width - 18; // -10 is effect_bg padding, -8 is inspector padding
                        psUI.OnGUI(width, false);
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();

            HandleKeyboardShortcuts();
        }
All Usage Examples Of UnityEditor.ParticleSystemUI::OnGUI