ParticleSystemCurveEditor.Init C# (CSharp) Method

Init() public method

public Init ( ) : void
return void
    public void Init()
    {
        if (this.m_AddedCurves == null)
        {
            this.m_AddedCurves = new List<CurveData>();
            this.m_Colors = new Color[] { new Color(1f, 0.6196079f, 0.1294118f), new Color(0.8745098f, 0.2117647f, 0.5803922f), new Color(0f, 0.6862745f, 1f), new Color(1f, 0.9215686f, 0f), new Color(0.1960784f, 1f, 0.2666667f), new Color(0.9803922f, 0f, 0f) };
            this.m_AvailableColors = new List<Color>(this.m_Colors);
            m_CurveEditorSettings.useFocusColors = true;
            m_CurveEditorSettings.showAxisLabels = false;
            m_CurveEditorSettings.hRangeMin = 0f;
            m_CurveEditorSettings.vRangeMin = 0f;
            m_CurveEditorSettings.vRangeMax = 1f;
            m_CurveEditorSettings.hRangeMax = 1f;
            m_CurveEditorSettings.vSlider = false;
            m_CurveEditorSettings.hSlider = false;
            m_CurveEditorSettings.showWrapperPopups = true;
            m_CurveEditorSettings.rectangleToolFlags = CurveEditorSettings.RectangleToolFlags.MiniRectangleTool;
            m_CurveEditorSettings.hTickLabelOffset = 5f;
            m_CurveEditorSettings.allowDraggingCurvesAndRegions = true;
            m_CurveEditorSettings.allowDeleteLastKeyInCurve = false;
            TickStyle style = new TickStyle {
                tickColor = { color = new Color(0f, 0f, 0f, 0.2f) },
                distLabel = 30,
                stubs = false,
                centerLabel = true
            };
            m_CurveEditorSettings.hTickStyle = style;
            TickStyle style2 = new TickStyle {
                tickColor = { color = new Color(0f, 0f, 0f, 0.2f) },
                distLabel = 20,
                stubs = false,
                centerLabel = true
            };
            m_CurveEditorSettings.vTickStyle = style2;
            this.m_CurveEditor = new CurveEditor(new Rect(0f, 0f, 1000f, 100f), this.CreateCurveWrapperArray(), false);
            this.m_CurveEditor.settings = m_CurveEditorSettings;
            this.m_CurveEditor.leftmargin = 40f;
            float num = 25f;
            this.m_CurveEditor.bottommargin = num;
            this.m_CurveEditor.topmargin = num;
            this.m_CurveEditor.rightmargin = num;
            this.m_CurveEditor.SetShownHRangeInsideMargins(m_CurveEditorSettings.hRangeMin, m_CurveEditorSettings.hRangeMax);
            this.m_CurveEditor.SetShownVRangeInsideMargins(m_CurveEditorSettings.vRangeMin, m_CurveEditorSettings.hRangeMax);
            this.m_CurveEditor.ignoreScrollWheelUntilClicked = false;
            Undo.undoRedoPerformed = (Undo.UndoRedoCallback) Delegate.Combine(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(this.UndoRedoPerformed));
        }
    }

Usage Example

示例#1
0
        // Should be called often to ensure we catch if selected Particle System is dragged in/out of root hierarchy
        public bool InitializeIfNeeded(IEnumerable <ParticleSystem> systems)
        {
            bool anyAdded = false;

            ParticleSystem[] allSystems     = systems.ToArray();
            bool             usingMultiEdit = (allSystems.Count() > 1);

            bool           initializeRequired = false;
            ParticleSystem mainSystem         = null;

            foreach (ParticleSystem shuriken in allSystems)
            {
                ParticleSystem[] shurikens;
                if (!usingMultiEdit)
                {
                    ParticleSystem root = ParticleSystemEditorUtils.GetRoot(shuriken);
                    if (root == null)
                    {
                        continue;
                    }

                    shurikens  = GetParticleSystems(root);
                    mainSystem = root;

                    // Check if we need to re-initialize?
                    if (m_SelectedParticleSystems != null && m_SelectedParticleSystems.Count > 0)
                    {
                        if (root == ParticleSystemEditorUtils.GetRoot(m_SelectedParticleSystems[0]))
                        {
                            if (m_ParticleSystemCurveEditor != null && m_Emitters != null && shurikens.Length == m_Emitters.Length && shuriken.gameObject.activeInHierarchy == m_EmittersActiveInHierarchy)
                            {
                                m_SelectedParticleSystems = new List <ParticleSystem>();
                                m_SelectedParticleSystems.Add(shuriken);

                                if (IsShowOnlySelectedMode())
                                {
                                    RefreshShowOnlySelected(); // always refresh
                                }
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    // in multi-edit mode, we explicitly choose the systems to edit, so don't automatically add child systems or search for the root
                    shurikens  = new ParticleSystem[] { shuriken };
                    mainSystem = shuriken;
                }

                // Cleanup before initializing
                if (m_ParticleSystemCurveEditor != null)
                {
                    Clear();
                }

                // Now initialize
                initializeRequired = true;
                if (!anyAdded)
                {
                    m_SelectedParticleSystems = new List <ParticleSystem>();
                    anyAdded = true;
                }
                m_SelectedParticleSystems.Add(shuriken);

                // Single edit emitter setup
                if (!usingMultiEdit)
                {
                    // Init CurveEditor before modules (they may add curves during construction)
                    m_ParticleSystemCurveEditor = new ParticleSystemCurveEditor();
                    m_ParticleSystemCurveEditor.Init();

                    int numEmitters = shurikens.Length;
                    if (numEmitters > 0)
                    {
                        m_Emitters = new ParticleSystemUI[numEmitters];

                        for (int i = 0; i < numEmitters; ++i)
                        {
                            m_Emitters[i] = new ParticleSystemUI();
                            m_Emitters[i].Init(this, new ParticleSystem[] { shurikens[i] });
                        }

                        m_EmittersActiveInHierarchy = shuriken.gameObject.activeInHierarchy;
                    }
                }
            }

            if (initializeRequired)
            {
                // Multi-edit emitter setup
                if (usingMultiEdit)
                {
                    // Init CurveEditor before modules (they may add curves during construction)
                    m_ParticleSystemCurveEditor = new ParticleSystemCurveEditor();
                    m_ParticleSystemCurveEditor.Init();

                    int numEmitters = m_SelectedParticleSystems.Count;
                    if (numEmitters > 0)
                    {
                        m_Emitters    = new ParticleSystemUI[1];
                        m_Emitters[0] = new ParticleSystemUI();
                        m_Emitters[0].Init(this, m_SelectedParticleSystems.ToArray());
                        m_EmittersActiveInHierarchy = m_SelectedParticleSystems[0].gameObject.activeInHierarchy;
                    }
                }

                // Allow modules to validate their state (the user can have moved emitters around in the hierarchy)
                foreach (ParticleSystemUI e in m_Emitters)
                {
                    foreach (ModuleUI m in e.m_Modules)
                    {
                        if (m != null)
                        {
                            m.Validate();
                        }
                    }
                }

                // Sync to state
                if (GetAllModulesVisible())
                {
                    SetAllModulesVisible(true);
                }

                m_EmitterAreaWidth      = EditorPrefs.GetFloat("ParticleSystemEmitterAreaWidth", k_MinEmitterAreaSize.x);
                m_CurveEditorAreaHeight = EditorPrefs.GetFloat("ParticleSystemCurveEditorAreaHeight", k_MinCurveAreaSize.y);

                // For now only allow ShowOnlySelectedMode for ParticleSystemWindow
                SetShowOnlySelectedMode((m_Owner is ParticleSystemWindow) ? SessionState.GetBool(k_ShowSelectedId + mainSystem.GetInstanceID(), false) : false);

                m_EmitterAreaScrollPos.x = SessionState.GetFloat("CurrentEmitterAreaScroll", 0.0f);

                if (ShouldManagePlaybackState(mainSystem))
                {
                    // Restore lastPlayBackTime if available in session cache
                    Vector3 simulationState = SessionState.GetVector3(k_SimulationStateId + mainSystem.GetInstanceID(), Vector3.zero);
                    if (mainSystem.GetInstanceID() == (int)simulationState.x)
                    {
                        float lastPlayBackTime = simulationState.z;
                        if (lastPlayBackTime > 0f)
                        {
                            ParticleSystemEditorUtils.playbackTime = lastPlayBackTime;
                            ParticleSystemEditorUtils.PerformCompleteResimulation();
                        }
                    }

                    // Play when selecting a new particle effect
                    if (m_MainPlaybackSystem != mainSystem)
                    {
                        Play();
                    }
                }
            }

            m_MainPlaybackSystem = mainSystem;

            return(initializeRequired);
        }