Пример #1
0
    static void OnSceneGUIInternal(CharacterAnimation character_animation)
    {
        if (character_animation.Animation == null || EditorApplication.isPlaying && UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().path.StartsWith("Assets/AniTest") == false)
        {
            return;
        }

        int  width = 240, height = 210;
        Rect r = new Rect(Screen.width - width, Screen.height - height - 40, width, height);

        Vector2 mouse = Event.current.mousePosition;

        Rect r2 = r;

        r2.yMin -= 30;
        r2.xMin -= 10;
        r2.xMax += 10;
        r2.yMax += 10;

        if (r2.Contains(mouse) && Event.current.type == EventType.Layout)
        {
            int controlID = GUIUtility.GetControlID(1024, FocusType.Passive);
            HandleUtility.AddControl(controlID, 0F);
        }

        Handles.BeginGUI();
        GUILayout.BeginArea(r, character_animation.gameObject.name, "Window");
        bool reset_playback = false;

        EditorGUILayout.BeginHorizontal();
        if (character_animation.IsPlaying == true)
        {
            if (character_animation.IsPause == false)
            {
                if (GUILayout.Button("Pause"))
                {
                    character_animation.IsPause = true;
                }
            }
            else
            {
                if (GUILayout.Button("Resume"))
                {
                    character_animation.IsPause = false;
                }
            }
        }
        else
        {
            if (GUILayout.Button("Play"))
            {
                character_animation.Play(false);
            }
        }
        if (GUILayout.Button("Reset"))
        {
            reset_playback = true;
            character_animation.Reset();
            foreach (var particle in m_Particles)
            {
                HFX_ParticleSystemInspector.GetSeed(particle);
            }
        }
        if (GUILayout.Button("Stop"))
        {
            character_animation.Stop();
            foreach (var particle in m_Particles)
            {
                particle.Stop();
            }
        }
        EditorGUILayout.EndHorizontal();

        EditorGUIUtility.labelWidth = 50f;
        OnInspectorPlayback("", character_animation, reset_playback);

        EditorGUIUtility.labelWidth = 0f;

        EditorGUILayout.BeginHorizontal();
        bool linked         = EditorPrefs.GetBool("CharacterInspectorLinkEffect", true);
        int  particle_count = character_animation.transform.GetComponentsInChildren <HFX_ParticleSystem>().Sum(p => p.ParticleCount);

        IsApplyEffect = EditorGUILayout.ToggleLeft(string.Format("Effect - {0}", particle_count), IsApplyEffect, GUILayout.Width(100f));
        GUILayout.FlexibleSpace();

        if (linked == true && HFX_ParticleSystemInspector.SceneGUIInspector == null)
        {
            HFX_ParticleSystemInspector.SceneGUIInspector = OnSceneGUIInspector;
            HFX_ParticleSystemInspector.OnPlaybackChanged = OnEffectPlaybackChanged;
            HFX_EmitterInspector.SceneGUIInspector        = OnSceneGUIInspector;
            HFX_EmitterInspector.OnPlaybackChanged        = OnEffectPlaybackChanged;
        }
        if (HFX_ParticleSystemInspector.SceneGUIInspector != null)
        {
            if (GUILayout.Button("Unlink"))
            {
                EditorPrefs.SetBool("CharacterInspectorLinkEffect", false);
                HFX_ParticleSystemInspector.SceneGUIInspector = null;
                HFX_ParticleSystemInspector.OnPlaybackChanged = null;
                HFX_EmitterInspector.SceneGUIInspector        = null;
                HFX_EmitterInspector.OnPlaybackChanged        = null;
            }
        }
        else
        {
            if (GUILayout.Button("Link"))
            {
                EditorPrefs.SetBool("CharacterInspectorLinkEffect", true);
                HFX_ParticleSystemInspector.SceneGUIInspector = OnSceneGUIInspector;
                HFX_ParticleSystemInspector.OnPlaybackChanged = OnEffectPlaybackChanged;
                HFX_EmitterInspector.SceneGUIInspector        = OnSceneGUIInspector;
                HFX_EmitterInspector.OnPlaybackChanged        = OnEffectPlaybackChanged;
            }
        }
        EditorGUILayout.EndHorizontal();

        if (EditorApplication.isPlaying == false && character_animation.IsPlaying)
        {
            EditorUtility.SetDirty((MonoBehaviour)character_animation);
        }

        GUILayout.EndArea();

        Handles.EndGUI();
    }
Пример #2
0
    public bool OnInspectorPlay(CharacterAnimation character_animation)
    {
        GUI.changed = false;

        //        Color backup_color = GUI.color;
        bool reset_playback = false;

        if (!EditorUtility.IsPersistent(character_animation))
        {
            EditorGUILayout.BeginHorizontal();
            if (character_animation.IsPlaying == true)
            {
                if (character_animation.IsPause == false)
                {
                    if (GUILayout.Button("Pause"))
                    {
                        character_animation.IsPause = true;
                    }
                }
                else
                {
                    if (GUILayout.Button("Resume"))
                    {
                        character_animation.IsPause = false;
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Play"))
                {
                    character_animation.Play(false);
                }
            }
            if (GUILayout.Button("Reset"))
            {
                reset_playback = true;
                character_animation.Reset();
                foreach (var particle in m_Particles)
                {
                    HFX_ParticleSystemInspector.GetSeed(particle);
                }
            }
            if (GUILayout.Button("Stop"))
            {
                character_animation.Stop();
                foreach (var particle in m_Particles)
                {
                    particle.Stop();
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        OnInspectorPlayback("Playback ", character_animation, reset_playback);

        if (GUI.changed == true)
        {
            EditorUtility.SetDirty((MonoBehaviour)character_animation);
        }

        if (EditorApplication.isPlaying == false && character_animation.IsPlaying)
        {
            EditorUtility.SetDirty((MonoBehaviour)character_animation);
        }

        return(true);
    }