Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions Assets/Plugins/StatefulUI/Runtime/Core/StatefulComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,7 @@ private GameObject GetObject(int role)
return null;
}

private Image GetImage(int role)
{
for (var i = 0; i < Images.Count; i++)
{
if (Images[i].Role == role)
{
return Images[i].Image;
}
}

var go = gameObject;
var roleName = RoleUtils.GetName(RoleUtils.ImageRoleType, role);
Debug.LogError($"View {name} does not contain image with role {roleName}, scene path: {go.GetScenePath()}", go);

return null;
}

private ImageReference GetImageReference(int role)
private ImageReference GetImage(int role)
{
for (var i = 0; i < Images.Count; i++)
{
Expand Down Expand Up @@ -290,41 +273,41 @@ private AnimatorReference GetAnimator(int role)
return null;
}

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

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

return false;
}

private ContainerView GetContainer(int role)
private ContainerReference GetContainer(int role)
{
if (!TryGetContainer(role, out var view))
if (!TryGetContainer(role, out var containerRef))
{
var go = gameObject;
var roleName = RoleUtils.GetName(RoleUtils.ContainerRoleType, role);
Debug.LogError($"View {name} does not contain container with role {roleName}, scene path: {go.GetScenePath()}", go);
}

return view;
return containerRef;
}

private Slider GetSlider(int role)
private SliderReference GetSlider(int role)
{
for (var i = 0; i < Sliders.Count; i++)
{
if (Sliders[i].Role == role)
{
return Sliders[i].Slider;
return Sliders[i];
}
}

Expand All @@ -335,13 +318,13 @@ private Slider GetSlider(int role)
return null;
}

private Toggle GetToggle(int role)
private ToggleReference GetToggle(int role)
{
for (var i = 0; i < Toggles.Count; i++)
{
if (Toggles[i].Role == role)
{
return Toggles[i].Toggle;
return Toggles[i];
}
}

Expand Down Expand Up @@ -457,12 +440,12 @@ public T GetItem<T>(int roleValue) where T : class
{
var type = typeof(T);
var manager = StatefulUiManager.Instance;

if (type == manager.AnimatorReferenceType) return GetAnimator(roleValue) as T;
if (type == manager.ButtonReferenceType) return GetButton(roleValue) as T;
if (type == manager.ContainerReferenceType) return GetContainer(roleValue) as T;
if (type == manager.DropdownReferenceType) return GetDropdown(roleValue) as T;
if (type == manager.ImageReferenceType) return GetImageReference(roleValue) as T;
if (type == manager.ImageReferenceType) return GetImage(roleValue) as T;
if (type == manager.InnerComponentReferenceType) return GetInnerComponent(roleValue) as T;
if (type == manager.ObjectReferenceType) return GetObject(roleValue) as T;
if (type == manager.SliderReferenceType) return GetSlider(roleValue) as T;
Expand All @@ -471,6 +454,7 @@ public T GetItem<T>(int roleValue) where T : class
if (type == manager.ToggleReferenceType) return GetToggle(roleValue) as T;
if (type == manager.VideoPlayerReferenceType) return GetVideoPlayer(roleValue) as T;


throw new Exception($"Type {type} is not supported");
}

Expand Down