Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-789] Small fix and minor improvements #215

Merged
merged 8 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion Runtime/AvatarCreator/Prefabs/Buttons/ButtonElement.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 313019198674256498}
- component: {fileID: 313019198674256496}
- component: {fileID: 313019198674256497}
- component: {fileID: 1414305276025593266}
m_Layer: 5
m_Name: RawImage
m_TagString: Untagged
Expand All @@ -35,7 +36,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -10, y: -10}
m_SizeDelta: {x: 0, y: -10}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &313019198674256496
CanvasRenderer:
Expand Down Expand Up @@ -72,6 +73,20 @@ MonoBehaviour:
y: 0
width: 1
height: 1
--- !u!114 &1414305276025593266
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 313019198674256499}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 86710e43de46f6f4bac7c8e50813a599, type: 3}
m_Name:
m_EditorClassIdentifier:
m_AspectMode: 2
m_AspectRatio: 1
--- !u!1 &313019200304032553
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -208,3 +223,4 @@ MonoBehaviour:
m_EditorClassIdentifier:
button: {fileID: 313019200304032559}
rawImage: {fileID: 313019198674256497}
aspectRatioFitter: {fileID: 1414305276025593266}
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ MonoBehaviour:
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 1
m_ChildAlignment: 0
m_StartCorner: 0
m_StartAxis: 0
m_CellSize: {x: 180, y: 180}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ MonoBehaviour:
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 1
m_ChildAlignment: 0
m_StartCorner: 0
m_StartAxis: 0
m_CellSize: {x: 180, y: 180}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ MonoBehaviour:
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 1
m_ChildAlignment: 0
m_StartCorner: 0
m_StartAxis: 0
m_CellSize: {x: 180, y: 180}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ReadyPlayerMe.AvatarCreator
{
public static class RawImageExtensions
{
public static Vector2 SizeToParent(this RawImage image, float padding = 0)
public static void SizeToParent(this RawImage image, float padding = 0)
{
var width = 0f;
var height = 0f;
Expand All @@ -16,8 +16,7 @@ public static Vector2 SizeToParent(this RawImage image, float padding = 0)
{
if (!parent)
{
//if we don't have a parent, just return our current width
return imageTransform.sizeDelta;
return;
}

padding = 1 - padding;
Expand All @@ -43,7 +42,6 @@ public static Vector2 SizeToParent(this RawImage image, float padding = 0)
}
imageTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
imageTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
return imageTransform.sizeDelta;
}
}
}
10 changes: 5 additions & 5 deletions Runtime/AvatarCreator/Scripts/UI/Buttons/SelectionButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SelectionButton : MonoBehaviour
{
[SerializeField] private Button button;
[SerializeField] private RawImage rawImage;

[SerializeField] private AspectRatioFitter aspectRatioFitter;
private RectTransform rawImageRectTransform;

/// <summary>
Expand All @@ -28,17 +28,17 @@ public void AddListener(Action action)
/// Sets the icon on the rawImage component
/// </summary>
/// <param name="texture">The texture to be assigned to the RawImage component</param>
/// <param name="sizeToParent">If true the icon will resize itself to fit inside the parent RectTransform</param>
public void SetIcon(Texture texture)
{
if (rawImageRectTransform == null)
{
rawImageRectTransform = rawImage.GetComponent<RectTransform>();
}

var previousSize = rawImageRectTransform.sizeDelta;
rawImage.texture = texture;
rawImageRectTransform.sizeDelta = previousSize;
if (aspectRatioFitter != null)
{
aspectRatioFitter.aspectRatio = (float) texture.width / texture.height;
}
}

public void SetColor(string hexColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public abstract class SelectionElement : MonoBehaviour
[SerializeField] private GameObject selectedIconPrefab;
[SerializeField] private Transform buttonContainer;
private GameObject selectedIcon;

[Space(5)]
public UnityEvent<IAssetData> onAssetSelected;
private readonly Dictionary<string, SelectionButton> buttonElementById = new Dictionary<string, SelectionButton>();

protected Transform ButtonContainer => buttonContainer;

private void Start()
{
selectedIcon = Instantiate(selectedIconPrefab, transform);
selectedIcon = Instantiate(selectedIconPrefab, buttonContainer);
selectedIcon.SetActive(false);
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public void ClearButtons()

private void ResetSelectIcon()
{
selectedIcon.transform.SetParent(transform);
selectedIcon.transform.SetParent(buttonContainer);
selectedIcon.SetActive(false);
}

Expand Down