pause, resume and rate scale for manger

This commit is contained in:
2016-09-16 03:03:33 +07:00
parent 3d688d1ac2
commit 7a0940b6a1
5 changed files with 88 additions and 29 deletions

View File

@@ -6,14 +6,31 @@ namespace FlashTools.Internal {
public class SwfManagerEditor : Editor {
SwfManager _manager = null;
void DrawAnimationCount() {
void DrawCounts() {
SwfEditorUtils.DoWithEnabledGUI(false, () => {
EditorGUILayout.IntField(
"Clip count",
_manager.AllClipCount);
_manager.clipCount);
EditorGUILayout.IntField(
"Controller count",
_manager.controllerCount);
});
}
void DrawControls() {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
if ( _manager.isPaused && GUILayout.Button("Resume") ) {
_manager.Resume();
}
if ( _manager.isPlaying && GUILayout.Button("Pause") ) {
_manager.Pause();
}
}
GUILayout.EndHorizontal();
}
// ---------------------------------------------------------------------
//
// Messages
@@ -25,8 +42,15 @@ namespace FlashTools.Internal {
}
public override void OnInspectorGUI() {
serializedObject.Update();
DrawDefaultInspector();
DrawAnimationCount();
DrawCounts();
if ( Application.isPlaying ) {
DrawControls();
}
if ( GUI.changed ) {
serializedObject.ApplyModifiedProperties();
}
}
}
}

View File

@@ -73,7 +73,7 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
//
// Private
// Internal
//
// ---------------------------------------------------------------------

View File

@@ -254,14 +254,14 @@ namespace FlashTools {
void OnEnable() {
var swf_manager = SwfManager.GetInstance(true);
if ( swf_manager ) {
swf_manager.AddSwfClip(this);
swf_manager.AddClip(this);
}
}
void OnDisable() {
var swf_manager = SwfManager.GetInstance(false);
if ( swf_manager ) {
swf_manager.RemoveSwfClip(this);
swf_manager.RemoveClip(this);
}
}

View File

@@ -74,7 +74,7 @@ namespace FlashTools {
}
public bool isStopped {
get { return !_isPlaying; }
get { return !isPlaying; }
}
// ---------------------------------------------------------------------
@@ -258,14 +258,14 @@ namespace FlashTools {
void OnEnable() {
var swf_manager = SwfManager.GetInstance(true);
if ( swf_manager ) {
swf_manager.AddSwfClipController(this);
swf_manager.AddController(this);
}
}
void OnDisable() {
var swf_manager = SwfManager.GetInstance(false);
if ( swf_manager ) {
swf_manager.RemoveSwfClipController(this);
swf_manager.RemoveController(this);
}
}
}

View File

@@ -7,6 +7,8 @@ namespace FlashTools {
SwfAssocList<SwfClip> _clips = new SwfAssocList<SwfClip>();
SwfAssocList<SwfClipController> _controllers = new SwfAssocList<SwfClipController>();
bool _isPaused = false;
SwfList<SwfClipController> _safeUpdates = new SwfList<SwfClipController>();
// ---------------------------------------------------------------------
@@ -27,42 +29,72 @@ namespace FlashTools {
return _instance;
}
// ---------------------------------------------------------------------
//
// Properties
//
// ---------------------------------------------------------------------
[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; }
}
public int controllerCount {
get { return _controllers.Count; }
}
public bool isPaused {
get { return _isPaused; }
}
public bool isPlaying {
get { return !isPaused; }
}
// ---------------------------------------------------------------------
//
// Functions
//
// ---------------------------------------------------------------------
public void Pause() {
_isPaused = true;
}
public void Resume() {
_isPaused = false;
}
// ---------------------------------------------------------------------
//
// Internal
//
// ---------------------------------------------------------------------
public int AllClipCount {
get { return _clips.Count; }
}
public void AddSwfClip(SwfClip clip) {
public void AddClip(SwfClip clip) {
_clips.Add(clip);
}
public void RemoveSwfClip(SwfClip clip) {
public void RemoveClip(SwfClip clip) {
_clips.Remove(clip);
}
public int AllClipControllerCount {
get { return _controllers.Count; }
}
public void AddSwfClipController(SwfClipController controller) {
public void AddController(SwfClipController controller) {
_controllers.Add(controller);
}
public void RemoveSwfClipController(SwfClipController controller) {
public void RemoveController(SwfClipController controller) {
_controllers.Remove(controller);
}
// ---------------------------------------------------------------------
//
// Private
//
// ---------------------------------------------------------------------
void GrabEnabledClips() {
var all_clips = FindObjectsOfType<SwfClip>();
for ( int i = 0, e = all_clips.Length; i < e; ++i ) {
@@ -99,6 +131,7 @@ namespace FlashTools {
ctrl.InternalUpdate(dt);
}
}
_safeUpdates.Clear();
}
void LateUpdateClips() {
@@ -127,8 +160,10 @@ namespace FlashTools {
}
void Update() {
var dt = Time.deltaTime;
UpdateControllers(dt);
if ( isPlaying ) {
var dt = Time.deltaTime;
UpdateControllers(rateScale * dt);
}
}
void LateUpdate() {