1
0
mirror of https://github.com/originalnicodr/CinematicUnityExplorer.git synced 2025-07-19 01:57:56 +08:00

Added mesh toggle to the animator panel, and reworked the panel UI.

This commit is contained in:
originalnicodr
2024-06-20 00:01:29 -03:00
parent a02460be33
commit ca726e0ae7
4 changed files with 67 additions and 34 deletions

View File

@ -21,6 +21,7 @@ namespace UnityExplorer.UI.Panels
public Toggle IgnoreMasterToggle;
public Toggle AnimatorToggle;
public Toggle MeshToggle;
public ButtonRef inspectButton;
public Dropdown animatorDropdown;
ButtonRef favAnimation;
@ -42,6 +43,7 @@ namespace UnityExplorer.UI.Panels
inspectButton.ButtonText.text = animatorPlayer.animator.name;
IgnoreMasterToggle.isOn = animatorPlayer.shouldIgnoreMasterToggle;
AnimatorToggle.isOn = animatorPlayer.animator.speed != 0;
MeshToggle.isOn = animatorPlayer.skinnedMesh.enabled;
UpdateDropdownOptions();
}
@ -74,13 +76,13 @@ namespace UnityExplorer.UI.Panels
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);
@ -94,11 +96,16 @@ namespace UnityExplorer.UI.Panels
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);
@ -114,7 +121,7 @@ namespace UnityExplorer.UI.Panels
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;
@ -166,8 +173,8 @@ namespace UnityExplorer.UI.Panels
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(); };
@ -186,5 +193,9 @@ namespace UnityExplorer.UI.Panels
if (animatorPlayer.animator.wrappedObject != null)
animatorPlayer.animator.speed = value ? 1 : 0;
}
internal void EnableMesh(bool value){
animatorPlayer.skinnedMesh.enabled = value;
}
}
}

View File

@ -22,6 +22,7 @@ namespace UnityExplorer.UI.Panels
BonesManager bonesManager;
private List<Transform> bones = new List<Transform>();
public SkinnedMeshRenderer skinnedMesh;
public IAnimationClip overridingAnimation;
private IAnimationClip lastCurrentAnimation;
@ -45,6 +46,7 @@ namespace UnityExplorer.UI.Panels
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
@ -120,16 +122,10 @@ namespace UnityExplorer.UI.Panels
}
}
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);
}

View File

@ -44,7 +44,7 @@ namespace UnityExplorer.UI.Panels
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);
@ -254,7 +254,7 @@ namespace UnityExplorer.UI.Panels
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);

View File

@ -23,14 +23,15 @@ namespace UnityExplorer.UI.Panels
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>();
@ -105,6 +106,19 @@ namespace UnityExplorer.UI.Panels
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;
}
}
animatorScrollPool.Refresh(true, false);
}
public void HotkeyToggleAnimators(){
masterAnimatorToggle.isOn = !masterAnimatorToggle.isOn;
}
@ -116,25 +130,37 @@ namespace UnityExplorer.UI.Panels
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));