mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2026-03-22 12:55:32 +07:00
clip groups
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<SwfClipController> _controllers = new SwfList<SwfClipController>();
|
||||
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<string> GetAllGroupNames() {
|
||||
var result = new HashSet<string>();
|
||||
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();
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
using UnityEngine;
|
||||
using FlashTools.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlashTools {
|
||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||
public class SwfManager : MonoBehaviour {
|
||||
SwfAssocList<SwfClip> _clips = new SwfAssocList<SwfClip>();
|
||||
SwfAssocList<SwfClipController> _controllers = new SwfAssocList<SwfClipController>();
|
||||
SwfList<SwfClipController> _safeUpdates = new SwfList<SwfClipController>();
|
||||
|
||||
SwfAssocList<SwfClip> _clips = new SwfAssocList<SwfClip>();
|
||||
SwfAssocList<SwfClipController> _controllers = new SwfAssocList<SwfClipController>();
|
||||
|
||||
bool _isPaused = false;
|
||||
SwfList<SwfClipController> _safeUpdates = new SwfList<SwfClipController>();
|
||||
bool _isPaused = false;
|
||||
float _rateScale = 1.0f;
|
||||
HashSet<string> _groupPauses = new HashSet<string>();
|
||||
Dictionary<string, float> _groupRateScales = new Dictionary<string, float>();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
@@ -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<SwfClip> 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<SwfClipController> controllers) {
|
||||
_controllers.AssignTo(controllers);
|
||||
}
|
||||
|
||||
void GrabEnabledClips() {
|
||||
var all_clips = FindObjectsOfType<SwfClip>();
|
||||
for ( int i = 0, e = all_clips.Length; i < e; ++i ) {
|
||||
var clip = all_clips[i];
|
||||
var clips = FindObjectsOfType<SwfClip>();
|
||||
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<SwfClipController>();
|
||||
for ( int i = 0, e = all_controllers.Length; i < e; ++i ) {
|
||||
var controller = all_controllers[i];
|
||||
var controllers = FindObjectsOfType<SwfClipController>();
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user