diff --git a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfAssetEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfAssetEditor.cs index fb86143..a69fe90 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfAssetEditor.cs @@ -96,9 +96,7 @@ namespace FlashTools.Internal { void DrawGUISettingsControls() { var prop = SwfEditorUtils.GetPropertyByName(serializedObject, "Overridden"); if ( prop.isExpanded ) { - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - { + SwfEditorUtils.DoRightHorizontalGUI(() => { var default_settings = GetDefaultSettings().Settings; SwfEditorUtils.DoWithEnabledGUI( _assets.Any(p => !p.Overridden.CheckEquals(default_settings)), () => { @@ -115,8 +113,7 @@ namespace FlashTools.Internal { ApplyAllOverriddenSettings(); } }); - } - GUILayout.EndHorizontal(); + }); } } diff --git a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipAssetEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipAssetEditor.cs index 7e2a11e..60378e6 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipAssetEditor.cs @@ -120,16 +120,14 @@ namespace FlashTools.Internal { } void DrawGUIControls() { - GUILayout.BeginHorizontal(); - { + SwfEditorUtils.DoHorizontalGUI(() => { if ( GUILayout.Button("Create prefab") ) { CreateAllClipsPrefabs(); } if ( GUILayout.Button("Instance to scene") ) { CreateAllClipsOnScene(); } - } - GUILayout.EndHorizontal(); + }); } // --------------------------------------------------------------------- diff --git a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipControllerEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipControllerEditor.cs index 05530cf..8d7abb3 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipControllerEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipControllerEditor.cs @@ -16,17 +16,14 @@ namespace FlashTools.Internal { } void DrawClipControls() { - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - { + SwfEditorUtils.DoRightHorizontalGUI(() => { if ( GUILayout.Button("Stop") ) { AllControllersForeach(ctrl => ctrl.Stop(ctrl.isStopped)); } if ( GUILayout.Button("Play") ) { AllControllersForeach(ctrl => ctrl.Play(ctrl.isPlaying)); } - } - GUILayout.EndHorizontal(); + }); } // --------------------------------------------------------------------- diff --git a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipEditor.cs index 71bdb47..ca482ac 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfClipEditor.cs @@ -109,9 +109,7 @@ namespace FlashTools.Internal { void DrawClipControls() { EditorGUILayout.Space(); - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - { + SwfEditorUtils.DoCenterHorizontalGUI(() => { if ( GUILayout.Button(new GUIContent("<<", "to begin frame")) ) { AllClipsForeachWithUndo(p => p.ToBeginFrame()); } @@ -127,9 +125,7 @@ namespace FlashTools.Internal { if ( GUILayout.Button(new GUIContent(">>", "to end frame")) ) { AllClipsForeachWithUndo(p => p.ToEndFrame()); } - } - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); + }); } void HideMaterials() { diff --git a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfManagerEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfManagerEditor.cs index 06f6c07..e765de2 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfManagerEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfManagerEditor.cs @@ -1,10 +1,14 @@ using UnityEngine; using UnityEditor; +using System.Collections.Generic; + namespace FlashTools.Internal { [CustomEditor(typeof(SwfManager))] public class SwfManagerEditor : Editor { - SwfManager _manager = null; + SwfManager _manager = null; + SwfList _controllers = new SwfList(); + bool _groupsFoldout = true; void DrawCounts() { SwfEditorUtils.DoWithEnabledGUI(false, () => { @@ -18,17 +22,53 @@ namespace FlashTools.Internal { } void DrawControls() { - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - { + SwfEditorUtils.DoRightHorizontalGUI(() => { if ( _manager.isPaused && GUILayout.Button("Resume") ) { _manager.Resume(); } if ( _manager.isPlaying && GUILayout.Button("Pause") ) { _manager.Pause(); } + }); + } + + void DrawGroupControls() { + var group_names = GetAllGroupNames(); + if ( group_names.Count > 0 ) { + _groupsFoldout = EditorGUILayout.Foldout(_groupsFoldout, "Groups"); + if ( _groupsFoldout ) { + foreach ( var group_name in group_names ) { + SwfEditorUtils.DoWithEnabledGUI(false, () => { + EditorGUILayout.TextField("Name", group_name); + }); + EditorGUI.BeginChangeCheck(); + var new_rate_scale = EditorGUILayout.FloatField( + "Rate Scale", _manager.GetGroupRateScale(group_name)); + if ( EditorGUI.EndChangeCheck() ) { + _manager.SetGroupRateScale(group_name, new_rate_scale); + } + SwfEditorUtils.DoRightHorizontalGUI(() => { + if ( _manager.IsGroupPaused(group_name) && GUILayout.Button("Resume") ) { + _manager.ResumeGroup(group_name); + } + if ( _manager.IsGroupPlaying(group_name) && GUILayout.Button("Pause") ) { + _manager.PauseGroup(group_name); + } + }); + } + } } - GUILayout.EndHorizontal(); + } + + HashSet GetAllGroupNames() { + var result = new HashSet(); + for ( int i = 0, e = _controllers.Count; i < e; ++i ) { + var ctrl = _controllers[i]; + if ( !string.IsNullOrEmpty(ctrl.groupName) ) { + result.Add(ctrl.groupName); + } + } + return result; } // --------------------------------------------------------------------- @@ -39,6 +79,7 @@ namespace FlashTools.Internal { void OnEnable() { _manager = target as SwfManager; + _manager.GetAllControllers(_controllers); } public override void OnInspectorGUI() { @@ -47,6 +88,7 @@ namespace FlashTools.Internal { DrawCounts(); if ( Application.isPlaying ) { DrawControls(); + DrawGroupControls(); } if ( GUI.changed ) { serializedObject.ApplyModifiedProperties(); diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs index 8bcfbac..2f261fd 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorUtils.cs @@ -37,6 +37,36 @@ namespace FlashTools.Internal { } } + public static void DoHorizontalGUI(System.Action act) { + GUILayout.BeginHorizontal(); + try { + act(); + } finally { + GUILayout.EndHorizontal(); + } + } + + public static void DoRightHorizontalGUI(System.Action act) { + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + try { + act(); + } finally { + GUILayout.EndHorizontal(); + } + } + + public static void DoCenterHorizontalGUI(System.Action act) { + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + try { + act(); + } finally { + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + } + public static SerializedProperty GetPropertyByName(SerializedObject obj, string name) { var prop = obj.FindProperty(name); if ( prop == null ) { diff --git a/Assets/FlashTools/Scripts/SwfClipController.cs b/Assets/FlashTools/Scripts/SwfClipController.cs index 8cea8a8..f2456f8 100644 --- a/Assets/FlashTools/Scripts/SwfClipController.cs +++ b/Assets/FlashTools/Scripts/SwfClipController.cs @@ -51,6 +51,13 @@ namespace FlashTools { set { _rateScale = Mathf.Clamp(value, 0.0f, float.MaxValue); } } + [SerializeField] + string _groupName = string.Empty; + public string groupName { + get { return _groupName; } + set { _groupName = value; } + } + [SerializeField] PlayModes _playMode = PlayModes.Forward; public PlayModes playMode { diff --git a/Assets/FlashTools/Scripts/SwfManager.cs b/Assets/FlashTools/Scripts/SwfManager.cs index 8b18084..0240bce 100644 --- a/Assets/FlashTools/Scripts/SwfManager.cs +++ b/Assets/FlashTools/Scripts/SwfManager.cs @@ -1,15 +1,18 @@ using UnityEngine; using FlashTools.Internal; +using System.Collections.Generic; namespace FlashTools { [ExecuteInEditMode, DisallowMultipleComponent] public class SwfManager : MonoBehaviour { + SwfAssocList _clips = new SwfAssocList(); + SwfAssocList _controllers = new SwfAssocList(); + SwfList _safeUpdates = new SwfList(); - SwfAssocList _clips = new SwfAssocList(); - SwfAssocList _controllers = new SwfAssocList(); - - bool _isPaused = false; - SwfList _safeUpdates = new SwfList(); + bool _isPaused = false; + float _rateScale = 1.0f; + HashSet _groupPauses = new HashSet(); + Dictionary _groupRateScales = new Dictionary(); // --------------------------------------------------------------------- // @@ -35,14 +38,6 @@ namespace FlashTools { // // --------------------------------------------------------------------- - [SerializeField] - [SwfFloatRange(0.0f, float.MaxValue)] - float _rateScale = 1.0f; - public float rateScale { - get { return _rateScale; } - set { _rateScale = Mathf.Clamp(value, 0.0f, float.MaxValue); } - } - public int clipCount { get { return _clips.Count; } } @@ -59,6 +54,11 @@ namespace FlashTools { get { return !isPaused; } } + public float rateScale { + get { return _rateScale; } + set { _rateScale = Mathf.Clamp(value, 0.0f, float.MaxValue); } + } + // --------------------------------------------------------------------- // // Functions @@ -73,6 +73,39 @@ namespace FlashTools { _isPaused = false; } + public void PauseGroup(string group_name) { + if ( !string.IsNullOrEmpty(group_name) ) { + _groupPauses.Add(group_name); + } + } + + public void ResumeGroup(string group_name) { + if ( !string.IsNullOrEmpty(group_name) ) { + _groupPauses.Remove(group_name); + } + } + + public bool IsGroupPaused(string group_name) { + return _groupPauses.Contains(group_name); + } + + public bool IsGroupPlaying(string group_name) { + return !IsGroupPaused(group_name); + } + + public void SetGroupRateScale(string group_name, float rate_scale) { + if ( !string.IsNullOrEmpty(group_name) ) { + _groupRateScales[group_name] = Mathf.Clamp(rate_scale, 0.0f, float.MaxValue); + } + } + + public float GetGroupRateScale(string group_name) { + float rate_scale; + return _groupRateScales.TryGetValue(group_name, out rate_scale) + ? rate_scale + : 1.0f; + } + // --------------------------------------------------------------------- // // Internal @@ -87,6 +120,10 @@ namespace FlashTools { _clips.Remove(clip); } + public void GetAllClips(SwfList clips) { + _clips.AssignTo(clips); + } + public void AddController(SwfClipController controller) { _controllers.Add(controller); } @@ -95,10 +132,14 @@ namespace FlashTools { _controllers.Remove(controller); } + public void GetAllControllers(SwfList controllers) { + _controllers.AssignTo(controllers); + } + void GrabEnabledClips() { - var all_clips = FindObjectsOfType(); - for ( int i = 0, e = all_clips.Length; i < e; ++i ) { - var clip = all_clips[i]; + var clips = FindObjectsOfType(); + for ( int i = 0, e = clips.Length; i < e; ++i ) { + var clip = clips[i]; if ( clip.enabled ) { _clips.Add(clip); } @@ -106,9 +147,9 @@ namespace FlashTools { } void GrabEnabledControllers() { - var all_controllers = FindObjectsOfType(); - for ( int i = 0, e = all_controllers.Length; i < e; ++i ) { - var controller = all_controllers[i]; + var controllers = FindObjectsOfType(); + for ( int i = 0, e = controllers.Length; i < e; ++i ) { + var controller = controllers[i]; if ( controller.enabled ) { _controllers.Add(controller); } @@ -128,7 +169,13 @@ namespace FlashTools { for ( int i = 0, e = _safeUpdates.Count; i < e; ++i ) { var ctrl = _safeUpdates[i]; if ( ctrl ) { - ctrl.InternalUpdate(dt); + var group_name = ctrl.groupName; + if ( string.IsNullOrEmpty(group_name) ) { + ctrl.InternalUpdate(dt); + } else if ( !IsGroupPaused(group_name) ) { + var group_rate_scale = GetGroupRateScale(group_name); + ctrl.InternalUpdate(group_rate_scale * dt); + } } } _safeUpdates.Clear();