Skip to content

Commit

Permalink
Added mesh toggle to the animator panel, and reworked the panel UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
originalnicodr committed Jun 20, 2024
1 parent a02460b commit ca726e0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 34 deletions.
31 changes: 21 additions & 10 deletions src/Cinematic/Cells/AnimatorCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AnimatorCell : ICell

public Toggle IgnoreMasterToggle;
public Toggle AnimatorToggle;
public Toggle MeshToggle;
public ButtonRef inspectButton;
public Dropdown animatorDropdown;
ButtonRef favAnimation;
Expand All @@ -42,6 +43,7 @@ public void SetAnimatorPlayer(AnimatorPlayer animatorPlayer){
inspectButton.ButtonText.text = animatorPlayer.animator.name;
IgnoreMasterToggle.isOn = animatorPlayer.shouldIgnoreMasterToggle;
AnimatorToggle.isOn = animatorPlayer.animator.speed != 0;
MeshToggle.isOn = animatorPlayer.skinnedMesh.enabled;

Check failure on line 46 in src/Cinematic/Cells/AnimatorCell.cs

View workflow job for this annotation

GitHub Actions / build_dotnet

'SkinnedMeshRenderer' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'SkinnedMeshRenderer' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 46 in src/Cinematic/Cells/AnimatorCell.cs

View workflow job for this annotation

GitHub Actions / build_dotnet

'SkinnedMeshRenderer' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'SkinnedMeshRenderer' could be found (are you missing a using directive or an assembly reference?)

UpdateDropdownOptions();
}
Expand Down Expand Up @@ -74,13 +76,13 @@ private void PlayButton_OnClick(){

public virtual GameObject CreateContent(GameObject parent)
{
GameObject AnimatorToggleObj = UIFactory.CreateToggle(parent, $"AnimatorToggle", out AnimatorToggle, out Text animatorToggleText);
UIFactory.SetLayoutElement(AnimatorToggleObj, minHeight: 30);
AnimatorToggle.isOn = animatorPlayer != null && animatorPlayer.animator.speed == 1;
AnimatorToggle.onValueChanged.AddListener(EnableAnimation);
UIRoot = UIFactory.CreateUIObject("AnimatorCell", parent);
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(UIRoot, false, false, true, true, 4, childAlignment: TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(UIRoot, minHeight: 25, flexibleWidth: 9999);

UIRoot = AnimatorToggleObj;
UIRoot.SetActive(false);
GameObject MeshToggleObj = UIFactory.CreateToggle(UIRoot, "MeshToggle", out MeshToggle, out Text MeshToggleText);
UIFactory.SetLayoutElement(MeshToggleObj, minHeight: 30);
MeshToggle.onValueChanged.AddListener(EnableMesh);

Rect = UIRoot.GetComponent<RectTransform>();
Rect.anchorMin = new Vector2(0, 1);
Expand All @@ -94,11 +96,16 @@ public virtual GameObject CreateContent(GameObject parent)
UIFactory.SetLayoutElement(inspectButton.GameObject, minWidth: 200, minHeight: 25);
inspectButton.OnClick += () => InspectorManager.Inspect(animatorPlayer.animator.gameObject);

GameObject AnimatorToggleObj = UIFactory.CreateToggle(UIRoot, "AnimatorToggle", out AnimatorToggle, out Text animatorToggleText);
UIFactory.SetLayoutElement(AnimatorToggleObj, minHeight: 30);
AnimatorToggle.isOn = animatorPlayer != null && animatorPlayer.animator.speed == 1;
AnimatorToggle.onValueChanged.AddListener(EnableAnimation);

ButtonRef resetAnimation = UIFactory.CreateButton(UIRoot, "Reset Animation", "Reset");
UIFactory.SetLayoutElement(resetAnimation.GameObject, minWidth: 50, minHeight: 25);
resetAnimation.OnClick += ResetAnimation;

GameObject ignoresMasterTogglerObj = UIFactory.CreateToggle(UIRoot, $"AnimatorIgnoreMasterToggle", out IgnoreMasterToggle, out Text ignoreMasterToggleText);
GameObject ignoresMasterTogglerObj = UIFactory.CreateToggle(UIRoot, "AnimatorIgnoreMasterToggle", out IgnoreMasterToggle, out Text ignoreMasterToggleText);
UIFactory.SetLayoutElement(ignoresMasterTogglerObj, minHeight: 25, minWidth: 155);
IgnoreMasterToggle.isOn = false;
IgnoreMasterToggle.onValueChanged.AddListener(IgnoreMasterToggle_Clicked);
Expand All @@ -114,7 +121,7 @@ public virtual GameObject CreateContent(GameObject parent)
favAnimation.ButtonText.text = animatorPlayer.IsAnimationFaved(animatorPlayer.overridingAnimation) ? "★" : "☆";
};

GameObject overridingAnimationObj = UIFactory.CreateDropdown(UIRoot, $"Animations_Dropdown", out animatorDropdown, null, 14, (idx) => {
GameObject overridingAnimationObj = UIFactory.CreateDropdown(UIRoot, "Animations_Dropdown", out animatorDropdown, null, 14, (idx) => {
if (animatorPlayer.animator.wrappedObject == null)
return;
animatorPlayer.overridingAnimation = idx < animatorDropdown.options.Count ? animatorPlayer.animations.Find(a => a.name == animatorDropdown.options[idx].text) : animatorPlayer.overridingAnimation;
Expand Down Expand Up @@ -166,8 +173,8 @@ public virtual GameObject CreateContent(GameObject parent)
UIFactory.SetLayoutElement(playButton.Component.gameObject, minHeight: 25, minWidth: 90);
playButton.OnClick += PlayButton_OnClick;

openBonesPanelButton = UIFactory.CreateButton(UIRoot, "OpenBonesPanelButton", "Open bones panel");
UIFactory.SetLayoutElement(openBonesPanelButton.Component.gameObject, minWidth: 125, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0);
openBonesPanelButton = UIFactory.CreateButton(UIRoot, "OpenBonesPanelButton", "Open Bones Panel");
UIFactory.SetLayoutElement(openBonesPanelButton.Component.gameObject, minWidth: 150, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0);

openBonesPanelButton.OnClick += () => { animatorPlayer.OpenBonesPanel(); };

Expand All @@ -186,5 +193,9 @@ internal void EnableAnimation(bool value){
if (animatorPlayer.animator.wrappedObject != null)
animatorPlayer.animator.speed = value ? 1 : 0;
}

internal void EnableMesh(bool value){
animatorPlayer.skinnedMesh.enabled = value;

Check failure on line 198 in src/Cinematic/Cells/AnimatorCell.cs

View workflow job for this annotation

GitHub Actions / build_dotnet

'SkinnedMeshRenderer' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'SkinnedMeshRenderer' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 198 in src/Cinematic/Cells/AnimatorCell.cs

View workflow job for this annotation

GitHub Actions / build_dotnet

'SkinnedMeshRenderer' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'SkinnedMeshRenderer' could be found (are you missing a using directive or an assembly reference?)
}
}
}
12 changes: 4 additions & 8 deletions src/Cinematic/Cells/AnimatorPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AnimatorPlayer {

BonesManager bonesManager;
private List<Transform> bones = new List<Transform>();
public SkinnedMeshRenderer skinnedMesh;

public IAnimationClip overridingAnimation;
private IAnimationClip lastCurrentAnimation;
Expand All @@ -45,6 +46,7 @@ public AnimatorPlayer(Behaviour animator){
this.overridingAnimation = lastCurrentAnimation != null ? lastCurrentAnimation : (animations.Count > 0 ? animations[0] : null);

this.favAnimations = new List<IAnimationClip>();
this.skinnedMesh = this.animator.wrappedObject.gameObject.GetComponentInChildren<SkinnedMeshRenderer>();
}

// Include the animations being played in other layers
Expand Down Expand Up @@ -120,16 +122,10 @@ public bool enabled
}
}

private void FindBones(){
GameObject parentObj = animator.wrappedObject.gameObject;
SkinnedMeshRenderer skeleton = parentObj.GetComponentInChildren<SkinnedMeshRenderer>();
bones = new List<Transform>(skeleton.bones);
}

public void OpenBonesPanel(){
if (!bones.Any()) FindBones();
if (skinnedMesh == null) return;
if (bonesManager == null){
bonesManager = new BonesManager(UIManager.GetPanel<UnityExplorer.UI.Panels.AnimatorPanel>(UIManager.Panels.AnimatorPanel).Owner, bones, animator);
bonesManager = new BonesManager(UIManager.GetPanel<UnityExplorer.UI.Panels.AnimatorPanel>(UIManager.Panels.AnimatorPanel).Owner, new List<Transform>(skinnedMesh.bones), animator);
}
bonesManager.SetActive(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cinematic/Cells/BonesCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public virtual GameObject CreateContent(GameObject parent)
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(header, false, false, true, true, 4, childAlignment: TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(header, minHeight: 25, flexibleWidth: 9999, flexibleHeight: 800);

boneName = UIFactory.CreateLabel(header, $"BoneLabel", "");
boneName = UIFactory.CreateLabel(header, "BoneLabel", "");
UIFactory.SetLayoutElement(boneName.gameObject, minWidth: 100, minHeight: 25);

GameObject headerButtons = UIFactory.CreateUIObject("BoneHeader", header);
Expand Down Expand Up @@ -254,7 +254,7 @@ public static ComponentControl Create(BonesCell cell, GameObject transformGroup,
control.IncrementInput.Component.GetOnEndEdit().AddListener(control.IncrementInput_OnEndEdit);

if (type == TransformType.Scale){
GameObject extraRowObj = UIFactory.CreateUIObject($"Row_UniformScale", transformGroup);
GameObject extraRowObj = UIFactory.CreateUIObject("Row_UniformScale", transformGroup);
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(extraRowObj, false, false, true, true, 5, 0, 0, 0, 0, default);
UIFactory.SetLayoutElement(extraRowObj, minHeight: 25, flexibleWidth: 9999);

Expand Down
54 changes: 40 additions & 14 deletions src/UI/Panels/AnimatorPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ public AnimatorPanel(UIBase owner) : base(owner)

public override string Name => "Animator";
public override UIManager.Panels PanelType => UIManager.Panels.AnimatorPanel;
public override int MinWidth => 1250;
public override int MinWidth => 1300;
public override int MinHeight => 200;
public override Vector2 DefaultAnchorMin => new(0.4f, 0.4f);
public override Vector2 DefaultAnchorMax => new(0.6f, 0.6f);
public override bool NavButtonWanted => true;
public override bool ShouldSaveActiveState => true;

Toggle masterAnimatorToggle = new Toggle();
Toggle masterAnimatorToggle;
Toggle masterMeshToggle;

private static ScrollPool<AnimatorCell> animatorScrollPool;
internal List<AnimatorPlayer> animators = new List<AnimatorPlayer>();
Expand Down Expand Up @@ -105,6 +106,19 @@ public void MasterToggleAnimators(bool enable){
animatorScrollPool.Refresh(true, false);
}

public void MasterToggleMeshes(bool enable){
// Load animators for the first time if there are not any
if (animators.Count == 0) FindAllAnimators();

foreach (AnimatorPlayer animatorPlayer in animators){
if (!animatorPlayer.shouldIgnoreMasterToggle){
animatorPlayer.skinnedMesh.enabled = enable;

Check failure on line 115 in src/UI/Panels/AnimatorPanel.cs

View workflow job for this annotation

GitHub Actions / build_dotnet

'SkinnedMeshRenderer' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'SkinnedMeshRenderer' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 115 in src/UI/Panels/AnimatorPanel.cs

View workflow job for this annotation

GitHub Actions / build_dotnet

'SkinnedMeshRenderer' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'SkinnedMeshRenderer' could be found (are you missing a using directive or an assembly reference?)
}
}

animatorScrollPool.Refresh(true, false);
}

public void HotkeyToggleAnimators(){
masterAnimatorToggle.isOn = !masterAnimatorToggle.isOn;
}
Expand All @@ -116,25 +130,37 @@ protected override void ConstructPanelContent()
GameObject firstGroup = UIFactory.CreateHorizontalGroup(ContentRoot, "MainOptions", false, false, true, true, 3,
default, new Color(1, 1, 1, 0), TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(firstGroup, minHeight: 25, flexibleWidth: 9999);
//UIElements.Add(horiGroup);

ButtonRef updateAnimators = UIFactory.CreateButton(firstGroup, "RefreshAnimators", "Refresh Animators");
UIFactory.SetLayoutElement(updateAnimators.GameObject, minWidth: 150, minHeight: 25);
updateAnimators.OnClick += FindAllAnimators;
GameObject headerSpace1 = UIFactory.CreateUIObject("HeaderSpace1", firstGroup);
UIFactory.SetLayoutElement(headerSpace1, minWidth: 0, flexibleWidth: 0);

GameObject meshObj = UIFactory.CreateToggle(firstGroup, "Master Mesh Toggle", out masterMeshToggle, out Text masterMeshText);
UIFactory.SetLayoutElement(meshObj, minHeight: 25, minWidth: 230);
masterMeshToggle.onValueChanged.AddListener(value => MasterToggleMeshes(value));
masterMeshText.text = "Master Mesh Toggler";

GameObject animatorObj = UIFactory.CreateToggle(firstGroup, "Master Animation Toggle", out masterAnimatorToggle, out Text masterAnimatorText);
UIFactory.SetLayoutElement(animatorObj, minHeight: 25);
masterAnimatorToggle.onValueChanged.AddListener(value => MasterToggleAnimators(value));
masterAnimatorText.text = "Master Animator Toggler";

GameObject headerSpace2 = UIFactory.CreateUIObject("HeaderSpace2", firstGroup);
UIFactory.SetLayoutElement(headerSpace2, minWidth: 10, flexibleWidth: 0);

ButtonRef resetAnimators = UIFactory.CreateButton(firstGroup, "ResetAnimators", "Reset Animators");
UIFactory.SetLayoutElement(resetAnimators.GameObject, minWidth: 150, minHeight: 25);
resetAnimators.OnClick += ResetAllAnimators;

GameObject animatorObj = UIFactory.CreateToggle(firstGroup, $"Master Animation Toggle", out masterAnimatorToggle, out Text masterAnimatorText);
UIFactory.SetLayoutElement(animatorObj, minHeight: 25);
masterAnimatorToggle.isOn = true;
masterAnimatorToggle.onValueChanged.AddListener(value => MasterToggleAnimators(value));
masterAnimatorText.text = "Master Toggler";
GameObject secondGroup = UIFactory.CreateHorizontalGroup(firstGroup, "HeaderRight", false, false, true, true, 3,
default, new Color(1, 1, 1, 0), TextAnchor.MiddleRight);
UIFactory.SetLayoutElement(secondGroup, minHeight: 25, flexibleWidth: 9999);

GameObject secondGroup = UIFactory.CreateHorizontalGroup(ContentRoot, "MainOptions", false, false, true, true, 3,
default, new Color(1, 1, 1, 0), TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(firstGroup, minHeight: 25, flexibleWidth: 9999);
ButtonRef updateAnimators = UIFactory.CreateButton(secondGroup, "RefreshAnimators", "Refresh Animators");
UIFactory.SetLayoutElement(updateAnimators.GameObject, minWidth: 150, minHeight: 25);
updateAnimators.OnClick += FindAllAnimators;

GameObject headerSpaceRight = UIFactory.CreateUIObject("HeaderSpaceRight", firstGroup);
UIFactory.SetLayoutElement(headerSpaceRight, minWidth: 25, flexibleWidth: 0);

animatorScrollPool = UIFactory.CreateScrollPool<AnimatorCell>(ContentRoot, "AnimatorsList", out GameObject scrollObj,
out GameObject scrollContent, new Color(0.03f, 0.03f, 0.03f));
Expand Down

0 comments on commit ca726e0

Please sign in to comment.