mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2025-07-18 17:38:01 +08:00
Added mesh togglers for each bone, added non-bone meshes to the BoneManager, captured multiple skinnedMeshRenderers, and restored the mesh scale when enabling the animator again.
This commit is contained in:
@ -43,7 +43,6 @@ 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();
|
||||
}
|
||||
@ -195,7 +194,7 @@ namespace UnityExplorer.UI.Panels
|
||||
}
|
||||
|
||||
internal void EnableMesh(bool value){
|
||||
animatorPlayer.skinnedMesh.enabled = value;
|
||||
animatorPlayer.SetMeshesEnabled(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
BonesManager bonesManager;
|
||||
private List<Transform> bones = new List<Transform>();
|
||||
public SkinnedMeshRenderer skinnedMesh;
|
||||
private List<SkinnedMeshRenderer> skinnedMeshes = new();
|
||||
private List<MeshRenderer> extraMeshes = new();
|
||||
|
||||
public IAnimationClip overridingAnimation;
|
||||
private IAnimationClip lastCurrentAnimation;
|
||||
@ -46,7 +47,9 @@ 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>();
|
||||
|
||||
this.skinnedMeshes.AddRange(this.animator.wrappedObject.gameObject.GetComponentsInChildren<SkinnedMeshRenderer>(false));
|
||||
this.extraMeshes.AddRange(this.animator.wrappedObject.gameObject.GetComponentsInChildren<MeshRenderer>(false));
|
||||
}
|
||||
|
||||
// Include the animations being played in other layers
|
||||
@ -122,13 +125,35 @@ namespace UnityExplorer.UI.Panels
|
||||
}
|
||||
}
|
||||
|
||||
private List<Transform> GetMeshes(){
|
||||
List<Transform> meshes = new List<Transform>();
|
||||
|
||||
foreach (SkinnedMeshRenderer skinnedMesh in skinnedMeshes) {
|
||||
meshes.AddRange(skinnedMesh.bones);
|
||||
}
|
||||
meshes.AddRange(extraMeshes.Select(m => m.transform));
|
||||
|
||||
return meshes.GroupBy(b => b.name).Select(b => b.First()).ToList().OrderBy(b => b.name).ToList();
|
||||
}
|
||||
|
||||
public void OpenBonesPanel(){
|
||||
if (skinnedMesh == null) return;
|
||||
if (skinnedMeshes.Count == 0 && extraMeshes.Count == 0) return;
|
||||
if (bonesManager == null){
|
||||
bonesManager = new BonesManager(UIManager.GetPanel<UnityExplorer.UI.Panels.AnimatorPanel>(UIManager.Panels.AnimatorPanel).Owner, new List<Transform>(skinnedMesh.bones), animator);
|
||||
bonesManager = new BonesManager(UIManager.GetPanel<UnityExplorer.UI.Panels.AnimatorPanel>(UIManager.Panels.AnimatorPanel).Owner, GetMeshes(), animator);
|
||||
}
|
||||
bonesManager.SetActive(true);
|
||||
}
|
||||
|
||||
public void SetMeshesEnabled(bool value){
|
||||
PropertyInfo enabledProperty = typeof(SkinnedMeshRenderer).GetProperty("enabled");
|
||||
foreach (SkinnedMeshRenderer skinnedMesh in skinnedMeshes) {
|
||||
enabledProperty.SetValue(skinnedMesh, value, null);
|
||||
}
|
||||
|
||||
foreach (MeshRenderer meshRenderer in extraMeshes) {
|
||||
meshRenderer.enabled = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IAnimator
|
||||
|
@ -11,12 +11,12 @@ namespace UnityExplorer.UI.Panels
|
||||
public Transform bone;
|
||||
public TransformControls transformControls;
|
||||
|
||||
Text boneName;
|
||||
ComponentControl positionControl;
|
||||
ComponentControl rotationControl;
|
||||
ComponentControl scaleControl;
|
||||
public AxisComponentControl CurrentSlidingAxisControl { get; set; }
|
||||
public BonesManager Owner;
|
||||
private ButtonRef inspectButton;
|
||||
|
||||
// ICell
|
||||
public float DefaultHeight => 25f;
|
||||
@ -29,7 +29,7 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
public void SetBone(Transform bone, BonesManager bonesManager){
|
||||
this.bone = bone;
|
||||
boneName.text = bone.name;
|
||||
inspectButton.ButtonText.text = bone.name;
|
||||
Owner = bonesManager;
|
||||
}
|
||||
|
||||
@ -44,8 +44,13 @@ 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", "");
|
||||
UIFactory.SetLayoutElement(boneName.gameObject, minWidth: 100, minHeight: 25);
|
||||
GameObject MeshToggleObj = UIFactory.CreateToggle(header, "MeshToggle", out Toggle MeshToggle, out Text MeshToggleText);
|
||||
UIFactory.SetLayoutElement(MeshToggleObj, minHeight: 30);
|
||||
MeshToggle.onValueChanged.AddListener(SetBoneEnabled);
|
||||
|
||||
inspectButton = UIFactory.CreateButton(header, "InspectButton", "");
|
||||
UIFactory.SetLayoutElement(inspectButton.GameObject, minWidth: 150, minHeight: 25);
|
||||
inspectButton.OnClick += () => InspectorManager.Inspect(bone.gameObject);
|
||||
|
||||
GameObject headerButtons = UIFactory.CreateUIObject("BoneHeader", header);
|
||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(headerButtons, false, false, true, true, 4, childAlignment: TextAnchor.MiddleRight);
|
||||
@ -66,6 +71,10 @@ namespace UnityExplorer.UI.Panels
|
||||
Owner.RestoreBoneState(bone.name);
|
||||
}
|
||||
|
||||
private void SetBoneEnabled(bool value){
|
||||
bone.gameObject.SetActive(value);
|
||||
}
|
||||
|
||||
// TransformControls-like functions
|
||||
public void UpdateTransformControlValues(bool force){
|
||||
positionControl.Update(force);
|
||||
|
@ -112,7 +112,7 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
foreach (AnimatorPlayer animatorPlayer in animators){
|
||||
if (!animatorPlayer.shouldIgnoreMasterToggle){
|
||||
animatorPlayer.skinnedMesh.enabled = enable;
|
||||
animatorPlayer.SetMeshesEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,18 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
private void OnTurnOffAnimatorToggle(bool value)
|
||||
{
|
||||
if (!value){
|
||||
if (value){
|
||||
// Restore meshes manually in case some are not part of a skeleton and won't get restored automatically.
|
||||
// Besides, this restores the scale, which the animator doesn't.
|
||||
foreach (Transform bone in bones){
|
||||
CachedBonesTransform CachedBonesTransform = bonesOriginalState[bone.name];
|
||||
bone.localPosition = CachedBonesTransform.position;
|
||||
bone.localEulerAngles = CachedBonesTransform.angles;
|
||||
bone.localScale = CachedBonesTransform.scale;
|
||||
// We assume these were on before. If not we should save its state beforehand.
|
||||
bone.gameObject.SetEnabled(true);
|
||||
}
|
||||
} else {
|
||||
bonesOriginalState.Clear();
|
||||
foreach (Transform bone in bones){
|
||||
bonesOriginalState[bone.name] = new CachedBonesTransform(bone.localPosition, bone.localEulerAngles, bone.localScale);
|
||||
|
Reference in New Issue
Block a user