Пример #1
0
        void OnDisable()
        {
            if (!IsPrefabAssetInspector())
            {
                RepaintParticleSystem();

                if (Application.isPlaying)
                {
                    if (updateDisposable != null)
                    {
                        updateDisposable.Dispose();
                    }
                }
                else
                {
                    ParticlePlayerEmulator.update -= Emulate;

                    instance.Stop(true, true);

                    if (eventLogDisposable != null)
                    {
                        eventLogDisposable.Dispose();
                    }
                }
            }
        }
        void OnDisable()
        {
            if (Application.isPlaying)
            {
                if (updateDisposable != null)
                {
                    updateDisposable.Dispose();
                }
            }
            else
            {
                ParticlePlayerEmulator.update -= Emulate;

                instance.Stop(true, true);

                if (eventLogDisposable != null)
                {
                    eventLogDisposable.Dispose();
                }
            }

            SetParticleSystemsDirty();
        }
Пример #3
0
        public override void OnInspectorGUI()
        {
            instance = target as ParticlePlayer;

            var activateOnPlay  = Reflection.GetPrivateField <ParticlePlayer, bool>(instance, "activateOnPlay");
            var endActionType   = Reflection.GetPrivateField <ParticlePlayer, EndActionType>(instance, "endActionType");
            var ignoreTimeScale = Reflection.GetPrivateField <ParticlePlayer, bool>(instance, "ignoreTimeScale");
            var lifecycleType   = Reflection.GetPrivateField <ParticlePlayer, LifcycleType>(instance, "lifecycleType");
            var lifeTime        = Reflection.GetPrivateField <ParticlePlayer, float>(instance, "lifeTime");

            EditorGUILayout.Separator();

            if (!Application.isPlaying)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (State.Play == instance.State)
                    {
                        if (GUILayout.Button("Pause"))
                        {
                            instance.Pause = true;
                            Repaint();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Play"))
                        {
                            if (instance.State == State.Pause)
                            {
                                instance.Pause = false;
                            }
                            else
                            {
                                if (emulateDisposable != null)
                                {
                                    emulateDisposable.Dispose();
                                    emulateDisposable = null;
                                }

                                emulateDisposable = instance.Play()
                                                    .Subscribe(_ =>
                                {
                                    instance.Stop(true, true);

                                    if (emulateDisposable != null)
                                    {
                                        emulateDisposable.Dispose();
                                        emulateDisposable = null;
                                    }
                                })
                                                    .AddTo(disposable.Disposable);
                            }

                            Repaint();
                        }
                    }

                    GUI.enabled = State.Play == instance.State || State.Pause == instance.State;

                    if (GUILayout.Button("Stop"))
                    {
                        if (emulateDisposable != null)
                        {
                            emulateDisposable.Dispose();
                            emulateDisposable = null;
                        }

                        instance.Stop(true, true);

                        Repaint();

                        SetParticleSystemsDirty();
                    }

                    GUI.enabled = true;

                    GUILayout.Space(20f);

                    var centeredStyle = GUI.skin.GetStyle("TextArea");
                    centeredStyle.alignment = TextAnchor.MiddleRight;

                    var value = string.Format("{0:f2}", instance.CurrentTime);
                    GUILayout.Label(value, centeredStyle, GUILayout.Width(60f), GUILayout.Height(18f));
                }
            }

            EditorGUILayout.Separator();

            if (EditorLayoutTools.DrawHeader("SortingLayer", "ParticlePlayerInspector-SortingLayer"))
            {
                using (new ContentsScope())
                {
                    var originLabelWidth = EditorLayoutTools.SetLabelWidth(150f);

                    EditorGUI.BeginChangeCheck();

                    var sortingLayerState = (SortingLayer)EditorGUILayout.EnumPopup("SortingLayer", instance.SortingLayer);

                    if (EditorGUI.EndChangeCheck())
                    {
                        UnityEditorUtility.RegisterUndo("ParticlePlayerInspector Undo", instance);
                        instance.SortingLayer = sortingLayerState;
                    }

                    EditorLayoutTools.SetLabelWidth(150f);

                    var sortingOrderState = instance.SortingOrder;

                    // ProjectViewで編集されると子階層への伝搬が正しく出来ないのでHierarchyからのみ編集させる.
                    if (AssetDatabase.IsMainAsset(instance.gameObject))
                    {
                        EditorGUILayout.IntField("SortingOrder", instance.SortingOrder);
                        EditorGUILayout.HelpBox("This parameter can edit in hierarchy.", MessageType.Info);
                    }
                    else
                    {
                        sortingOrderState = EditorGUILayout.IntField("SortingOrder", instance.SortingOrder);
                    }

                    if (instance.SortingOrder != sortingOrderState)
                    {
                        UnityEditorUtility.RegisterUndo("ParticlePlayerInspector Undo", instance);

                        instance.SortingOrder = sortingOrderState;
                    }

                    EditorLayoutTools.SetLabelWidth(originLabelWidth);
                }
            }

            if (EditorLayoutTools.DrawHeader("Option", "ParticlePlayerInspector-Option"))
            {
                using (new ContentsScope())
                {
                    EditorGUI.BeginChangeCheck();

                    var originLabelWidth = EditorLayoutTools.SetLabelWidth(150f);

                    activateOnPlay = EditorGUILayout.Toggle("AutoPlay", activateOnPlay);

                    ignoreTimeScale = EditorGUILayout.Toggle("Ignore TimeScale", ignoreTimeScale);

                    endActionType = (EndActionType)EditorGUILayout.EnumPopup("End Action", endActionType);

                    lifecycleType = (LifcycleType)EditorGUILayout.EnumPopup("Lifcycle Type", lifecycleType);

                    if (lifecycleType == LifcycleType.Manual)
                    {
                        lifeTime = EditorGUILayout.FloatField("Life Time", lifeTime);
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        UnityEditorUtility.RegisterUndo("ParticlePlayerInspector Undo", instance);

                        Reflection.SetPrivateField(instance, "activateOnPlay", activateOnPlay);
                        Reflection.SetPrivateField(instance, "endActionType", endActionType);
                        Reflection.SetPrivateField(instance, "ignoreTimeScale", ignoreTimeScale);
                        Reflection.SetPrivateField(instance, "lifecycleType", lifecycleType);
                        Reflection.SetPrivateField(instance, "lifeTime", lifeTime);
                        Reflection.SetPrivateField(instance, "activateOnPlay", activateOnPlay);
                    }

                    EditorLayoutTools.SetLabelWidth(originLabelWidth);
                }
            }

            EditorGUILayout.Separator();
        }
Пример #4
0
        public override void OnInspectorGUI()
        {
            instance = target as ParticlePlayer;

            var activateOnPlay  = Reflection.GetPrivateField <ParticlePlayer, bool>(instance, "activateOnPlay");
            var endActionType   = Reflection.GetPrivateField <ParticlePlayer, EndActionType>(instance, "endActionType");
            var ignoreTimeScale = Reflection.GetPrivateField <ParticlePlayer, bool>(instance, "ignoreTimeScale");
            var lifecycleType   = Reflection.GetPrivateField <ParticlePlayer, LifecycleControl>(instance, "lifecycleControl");
            var lifeTime        = Reflection.GetPrivateField <ParticlePlayer, float>(instance, "lifeTime");
            var events          = Reflection.GetPrivateField <ParticlePlayer, ParticlePlayer.EventInfo[]>(instance, "eventInfos");

            EditorGUILayout.Separator();

            if (!Application.isPlaying)
            {
                if (!IsPrefabAssetInspector())
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        if (State.Play == instance.State)
                        {
                            if (GUILayout.Button("Pause"))
                            {
                                instance.Pause = true;
                                Repaint();
                            }
                        }
                        else
                        {
                            if (GUILayout.Button("Play"))
                            {
                                if (instance.State == State.Pause)
                                {
                                    instance.Pause = false;
                                }
                                else
                                {
                                    if (emulateDisposable != null)
                                    {
                                        emulateDisposable.Dispose();
                                        emulateDisposable = null;
                                    }

                                    Reflection.InvokePrivateMethod(instance, "RunCollectContents");

                                    emulateDisposable = instance.Play()
                                                        .Subscribe(_ =>
                                    {
                                        instance.Stop(true, true);

                                        if (emulateDisposable != null)
                                        {
                                            emulateDisposable.Dispose();
                                            emulateDisposable = null;
                                        }
                                    })
                                                        .AddTo(disposable.Disposable);
                                }

                                Repaint();
                            }
                        }

                        GUI.enabled = State.Play == instance.State || State.Pause == instance.State;

                        if (GUILayout.Button("Stop"))
                        {
                            if (emulateDisposable != null)
                            {
                                emulateDisposable.Dispose();
                                emulateDisposable = null;
                            }

                            RepaintParticleSystem();

                            instance.Stop(true, true);

                            Repaint();
                        }

                        GUI.enabled = true;

                        GUILayout.Space(20f);

                        var centeredStyle = GUI.skin.GetStyle("TextArea");
                        centeredStyle.alignment = TextAnchor.MiddleRight;

                        var value = string.Format("{0:f2}", instance.CurrentTime);
                        GUILayout.Label(value, centeredStyle, GUILayout.Width(60f), GUILayout.Height(18f));
                    }
                }
            }

            EditorGUILayout.Separator();

            if (EditorLayoutTools.Header("SortingLayer", "ParticlePlayerInspector-SortingLayer"))
            {
                using (new ContentsScope())
                {
                    var originLabelWidth = EditorLayoutTools.SetLabelWidth(150f);

                    EditorGUI.BeginChangeCheck();

                    var sortingLayerState = (SortingLayer)EditorGUILayout.EnumPopup("SortingLayer", instance.SortingLayer);

                    if (EditorGUI.EndChangeCheck())
                    {
                        UnityEditorUtility.RegisterUndo("ParticlePlayerInspector Undo", instance);

                        Reflection.InvokePrivateMethod(instance, "RunCollectContents");
                        instance.SortingLayer = sortingLayerState;
                    }

                    EditorLayoutTools.SetLabelWidth(150f);

                    var sortingOrderState = instance.SortingOrder;

                    // ProjectViewで編集されると子階層への伝搬が正しく出来ないのでHierarchyからのみ編集させる.
                    if (AssetDatabase.IsMainAsset(instance.gameObject))
                    {
                        EditorGUILayout.IntField("SortingOrder", instance.SortingOrder);
                        EditorGUILayout.HelpBox("This parameter can edit in hierarchy.", MessageType.Info);
                    }
                    else
                    {
                        sortingOrderState = EditorGUILayout.IntField("SortingOrder", instance.SortingOrder);
                    }

                    if (instance.SortingOrder != sortingOrderState)
                    {
                        UnityEditorUtility.RegisterUndo("ParticlePlayerInspector Undo", instance);

                        Reflection.InvokePrivateMethod(instance, "RunCollectContents");
                        instance.SortingOrder = sortingOrderState;
                    }

                    EditorLayoutTools.SetLabelWidth(originLabelWidth);
                }
            }

            if (EditorLayoutTools.Header("Option", "ParticlePlayerInspector-Option"))
            {
                using (new ContentsScope())
                {
                    EditorGUI.BeginChangeCheck();

                    var originLabelWidth = EditorLayoutTools.SetLabelWidth(150f);

                    activateOnPlay = EditorGUILayout.Toggle("AutoPlay", activateOnPlay);

                    ignoreTimeScale = EditorGUILayout.Toggle("Ignore TimeScale", ignoreTimeScale);

                    endActionType = (EndActionType)EditorGUILayout.EnumPopup("End Action", endActionType);

                    lifecycleType = (LifecycleControl)EditorGUILayout.EnumPopup("Lifcycle Type", lifecycleType);

                    if (lifecycleType == LifecycleControl.Manual)
                    {
                        lifeTime = EditorGUILayout.FloatField("Life Time", lifeTime);
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        UnityEditorUtility.RegisterUndo("ParticlePlayerInspector Undo", instance);

                        Reflection.SetPrivateField(instance, "activateOnPlay", activateOnPlay);
                        Reflection.SetPrivateField(instance, "endActionType", endActionType);
                        Reflection.SetPrivateField(instance, "ignoreTimeScale", ignoreTimeScale);
                        Reflection.SetPrivateField(instance, "lifecycleControl", lifecycleType);
                        Reflection.SetPrivateField(instance, "lifeTime", lifeTime);
                        Reflection.SetPrivateField(instance, "activateOnPlay", activateOnPlay);
                    }

                    EditorLayoutTools.SetLabelWidth(originLabelWidth);
                }
            }

            if (EditorLayoutTools.Header("Event", "ParticlePlayerInspector-Event"))
            {
                var updated   = false;
                var eventList = events != null?events.ToList() : new List <ParticlePlayer.EventInfo>();

                using (new ContentsScope())
                {
                    if (eventList.IsEmpty())
                    {
                        EditorGUILayout.HelpBox("Press the + button if add event", MessageType.Info);
                    }
                    else
                    {
                        GUILayout.Space(3f);

                        DrawEventHeaderGUI(eventList.Count);

                        var deleteTargets = new List <ParticlePlayer.EventInfo>();

                        Action drawContents = () =>
                        {
                            foreach (var eventInfo in eventList)
                            {
                                EditorGUI.BeginChangeCheck();

                                var delete = DrawEventInfoGUI(eventInfo);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    updated = true;
                                }

                                if (delete)
                                {
                                    deleteTargets.Add(eventInfo);
                                    updated = true;
                                }

                                GUILayout.Space(2f);
                            }
                        };

                        if (eventList.Count <= 5)
                        {
                            drawContents();
                        }
                        else
                        {
                            using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition, GUILayout.Height(100f)))
                            {
                                drawContents();

                                scrollPosition = scrollViewScope.scrollPosition;
                            }
                        }

                        foreach (var deleteTarget in deleteTargets)
                        {
                            eventList.Remove(deleteTarget);
                        }
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(60f)))
                        {
                            var eventInfo = new ParticlePlayer.EventInfo()
                            {
                                trigger = ParticlePlayer.EventInfo.EventTrigger.Time,
                                target  = null,
                                time    = 0f,
                                message = string.Empty,
                            };

                            eventList.Add(eventInfo);

                            updated = true;
                        }
                    }

                    if (updated)
                    {
                        Reflection.SetPrivateField(instance, "eventInfos", eventList.ToArray());
                    }
                }
            }

            EditorGUILayout.Separator();
        }