Skip to content

Commit

Permalink
Merge pull request #1 from dmitry-ivashenko/main
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
turanheydarli authored Jul 20, 2024
2 parents 2bea37b + 34c376a commit ed2e03c
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 28 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
2 changes: 1 addition & 1 deletion Assets/Plugins/StatefulUI/Editor/Core/TypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void AddEndBracket()
_result.AppendLine("}");
}

public override String ToString()
public override string ToString()
{
return _result.ToString();
}
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
10 changes: 5 additions & 5 deletions Assets/Plugins/StatefulUI/Runtime/Core/StatefulComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,23 @@ private AnimatorReference GetAnimator(int role)
return null;
}

public bool TryGetContainer(int role, out ContainerView view)
public bool TryGetContainer(int role, out ContainerReference view)
{
view = null;

for (var i = 0; i < Containers.Count; i++)
{
if (Containers[i].Role == role)
{
view = Containers[i].Container;
view = Containers[i];
return true;
}
}

return false;
}

private ContainerView GetContainer(int role)
private ContainerReference GetContainer(int role)
{
if (!TryGetContainer(role, out var view))
{
Expand Down Expand Up @@ -352,13 +352,13 @@ private Toggle GetToggle(int role)
return null;
}

private StatefulComponent GetInnerComponent(int role)
private InnerComponentReference GetInnerComponent(int role)
{
for (var i = 0; i < InnerComponents.Count; i++)
{
if (InnerComponents[i].Role == role)
{
return InnerComponents[i].InnerComponent;
return InnerComponents[i];
}
}

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
12 changes: 12 additions & 0 deletions Assets/Plugins/StatefulUI/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "dmitry-ivashenko.statefului",
"displayName": "StatefulUI",
"version": "1.0.5",
"unity": "2021.3",
"description": "Stateful UI - A library for structured state-based UI development in Unity",
"keywords": ["UI"],
"license": "MIT",
"documentationUrl": "https://github.com/dmitry-ivashenko/StatefulUI/blob/main/README.md",
"changelogUrl": "https://github.com/dmitry-ivashenko/StatefulUI/releases",
"licensesUrl": "https://github.com/dmitry-ivashenko/StatefulUI/blob/main/LICENSE"
}
7 changes: 7 additions & 0 deletions Assets/Plugins/StatefulUI/package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ public void ShowResults(IEnumerable<IReward> rewards)
}
```

## Installation

### Install via UPM (using Git URL)

1. Open UPM from Window -> Package Manager.
2. Click "+" then click "Add package from git URL"
3. Enter the URL "https://github.com/dmitry-ivashenko/StatefulUI.git?path=Assets/Plugins/StatefulUI" and click add.
3. UPM should now install the package.

### Install manually (using .unitypackage)

1. Download the .unitypackage from [releases](https://github.com/dmitry-ivashenko/StatefulUI/releases) page.
2. Open .unitypackage file.

## Roadmap

- Enhancing State capabilities, including new UI changes such as animations and sound effects.
Expand Down

0 comments on commit ed2e03c

Please sign in to comment.