Skip to content

Commit

Permalink
add editor animation update loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ivashenko committed Jun 26, 2024
1 parent 792e3e1 commit 2c12706
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Assets/Plugins/StatefulUI/Editor/Core/EditCommentWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void Button(SerializedObject serializedObject, SerializedProperty
}
}

public void Init(Vector2 mousePos, SerializedProperty property, SerializedObject serializedObject, string name)
private void Init(Vector2 mousePos, SerializedProperty property, SerializedObject serializedObject, string name)
{
_name = name;
_serializedObject = serializedObject;
Expand Down
15 changes: 13 additions & 2 deletions Assets/Plugins/StatefulUI/Editor/Selector/ItemsSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,20 @@ private void OnGUI()
{
GUILayout.Space(10);
GUI.SetNextControlName("NameFilter");
_filter = GUILayout.TextField(_filter ?? "", GUI.skin.FindStyle("ToolbarSearchTextField"));
var style = GUI.skin.FindStyle("ToolbarSearchTextField");
if (style == null)
{
style = new GUIStyle(GUI.skin.FindStyle("SearchTextField"));
}
_filter = GUILayout.TextField(_filter ?? "", style);

var cancelStyle = GUI.skin.FindStyle("ToolbarSearchCancelButton");
if (cancelStyle == null)
{
cancelStyle = new GUIStyle(GUI.skin.FindStyle("SearchCancelButton"));
}

if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSearchCancelButton")))
if (GUILayout.Button("", cancelStyle))
{
// Remove focus if cleared
_filter = "";
Expand Down
41 changes: 38 additions & 3 deletions Assets/Plugins/StatefulUI/Runtime/Core/StatefulUiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Globalization;
using System.Linq;
using System.Text;
using StatefulUI.Runtime.Localization;
using UnityEngine;
using UnityEngine.UI;

Expand Down Expand Up @@ -311,7 +310,7 @@ public static string CamelCase(this string format)
return result;
}


public static T GetComponentAlways<T>(this GameObject gameObject) where T : Component
{
return gameObject.TryGetComponent<T>(out var component) ? component : gameObject.AddComponent<T>();
Expand Down Expand Up @@ -350,7 +349,7 @@ public static T FindImplementation<T>(params Type[] excludes)

return default;
}

public static bool IsImplementationExists<T>(params Type[] excludes)
{
var baseType = typeof(T);
Expand All @@ -369,5 +368,41 @@ public static bool IsImplementationExists<T>(params Type[] excludes)

return false;
}

private static float _updateFinishTime;

public static void StartEditorUpdateLoop(float duration)
{
#if UNITY_EDITOR
if (Application.isPlaying || duration <= 0f) return;

if (_updateFinishTime > Time.realtimeSinceStartup)
{
_updateFinishTime = Mathf.Max(_updateFinishTime, Time.realtimeSinceStartup + duration);
return;
}

_updateFinishTime = Time.realtimeSinceStartup + duration;

UnityEditor.EditorApplication.CallbackFunction callback = null;
callback = () =>
{
if (Time.realtimeSinceStartup > _updateFinishTime)
{
UnityEditor.EditorApplication.update -= callback;
Debug.Log("Editor update loop finished");
return;
}

UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
UnityEditor.SceneView.RepaintAll();
};

UnityEditor.EditorApplication.update += callback;

UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
UnityEditor.SceneView.RepaintAll();
#endif
}
}
}
16 changes: 1 addition & 15 deletions Assets/Plugins/StatefulUI/Runtime/States/NodeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,9 @@
namespace StatefulUI.Runtime.States
{
[Serializable]
public class NodeData : ISerializationCallbackReceiver
public class NodeData
{
public Vector2 Position;
public int ParentRole;
public bool HasParent;
public List<int> ParentRoles = new List<int>();

public void OnBeforeSerialize()
{
}

public void OnAfterDeserialize()
{
if (HasParent && !ParentRoles.Contains(ParentRole))
{
ParentRoles.Add(ParentRole);
}
}
}
}
3 changes: 2 additions & 1 deletion Assets/Plugins/StatefulUI/Runtime/States/StateProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ private float ApplyAnimation(StateReference state, StateDescription desc)
duration = clip.length;
}

StatefulUiUtils.StartEditorUpdateLoop(clip.isLooping ? 100 * clip.length : clip.length);

stateAnimationInfo.OnUpdate();
break;
}
Expand All @@ -165,7 +167,6 @@ private float ApplyAnimation(StateReference state, StateDescription desc)
}

return duration;

}

private static void ApplyButton(StateDescription desc)
Expand Down

0 comments on commit 2c12706

Please sign in to comment.