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;
|
inspectButton.ButtonText.text = animatorPlayer.animator.name;
|
||||||
IgnoreMasterToggle.isOn = animatorPlayer.shouldIgnoreMasterToggle;
|
IgnoreMasterToggle.isOn = animatorPlayer.shouldIgnoreMasterToggle;
|
||||||
AnimatorToggle.isOn = animatorPlayer.animator.speed != 0;
|
AnimatorToggle.isOn = animatorPlayer.animator.speed != 0;
|
||||||
MeshToggle.isOn = animatorPlayer.skinnedMesh.enabled;
|
|
||||||
|
|
||||||
UpdateDropdownOptions();
|
UpdateDropdownOptions();
|
||||||
}
|
}
|
||||||
@ -195,7 +194,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void EnableMesh(bool value){
|
internal void EnableMesh(bool value){
|
||||||
animatorPlayer.skinnedMesh.enabled = value;
|
animatorPlayer.SetMeshesEnabled(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,8 @@ namespace UnityExplorer.UI.Panels
|
|||||||
|
|
||||||
BonesManager bonesManager;
|
BonesManager bonesManager;
|
||||||
private List<Transform> bones = new List<Transform>();
|
private List<Transform> bones = new List<Transform>();
|
||||||
public SkinnedMeshRenderer skinnedMesh;
|
private List<SkinnedMeshRenderer> skinnedMeshes = new();
|
||||||
|
private List<MeshRenderer> extraMeshes = new();
|
||||||
|
|
||||||
public IAnimationClip overridingAnimation;
|
public IAnimationClip overridingAnimation;
|
||||||
private IAnimationClip lastCurrentAnimation;
|
private IAnimationClip lastCurrentAnimation;
|
||||||
@ -46,7 +47,9 @@ namespace UnityExplorer.UI.Panels
|
|||||||
this.overridingAnimation = lastCurrentAnimation != null ? lastCurrentAnimation : (animations.Count > 0 ? animations[0] : null);
|
this.overridingAnimation = lastCurrentAnimation != null ? lastCurrentAnimation : (animations.Count > 0 ? animations[0] : null);
|
||||||
|
|
||||||
this.favAnimations = new List<IAnimationClip>();
|
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
|
// 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(){
|
public void OpenBonesPanel(){
|
||||||
if (skinnedMesh == null) return;
|
if (skinnedMeshes.Count == 0 && extraMeshes.Count == 0) return;
|
||||||
if (bonesManager == null){
|
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);
|
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
|
public class IAnimator
|
||||||
|
@ -11,12 +11,12 @@ namespace UnityExplorer.UI.Panels
|
|||||||
public Transform bone;
|
public Transform bone;
|
||||||
public TransformControls transformControls;
|
public TransformControls transformControls;
|
||||||
|
|
||||||
Text boneName;
|
|
||||||
ComponentControl positionControl;
|
ComponentControl positionControl;
|
||||||
ComponentControl rotationControl;
|
ComponentControl rotationControl;
|
||||||
ComponentControl scaleControl;
|
ComponentControl scaleControl;
|
||||||
public AxisComponentControl CurrentSlidingAxisControl { get; set; }
|
public AxisComponentControl CurrentSlidingAxisControl { get; set; }
|
||||||
public BonesManager Owner;
|
public BonesManager Owner;
|
||||||
|
private ButtonRef inspectButton;
|
||||||
|
|
||||||
// ICell
|
// ICell
|
||||||
public float DefaultHeight => 25f;
|
public float DefaultHeight => 25f;
|
||||||
@ -29,7 +29,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
|
|
||||||
public void SetBone(Transform bone, BonesManager bonesManager){
|
public void SetBone(Transform bone, BonesManager bonesManager){
|
||||||
this.bone = bone;
|
this.bone = bone;
|
||||||
boneName.text = bone.name;
|
inspectButton.ButtonText.text = bone.name;
|
||||||
Owner = bonesManager;
|
Owner = bonesManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +44,13 @@ namespace UnityExplorer.UI.Panels
|
|||||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(header, false, false, true, true, 4, childAlignment: TextAnchor.MiddleLeft);
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(header, false, false, true, true, 4, childAlignment: TextAnchor.MiddleLeft);
|
||||||
UIFactory.SetLayoutElement(header, minHeight: 25, flexibleWidth: 9999, flexibleHeight: 800);
|
UIFactory.SetLayoutElement(header, minHeight: 25, flexibleWidth: 9999, flexibleHeight: 800);
|
||||||
|
|
||||||
boneName = UIFactory.CreateLabel(header, "BoneLabel", "");
|
GameObject MeshToggleObj = UIFactory.CreateToggle(header, "MeshToggle", out Toggle MeshToggle, out Text MeshToggleText);
|
||||||
UIFactory.SetLayoutElement(boneName.gameObject, minWidth: 100, minHeight: 25);
|
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);
|
GameObject headerButtons = UIFactory.CreateUIObject("BoneHeader", header);
|
||||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(headerButtons, false, false, true, true, 4, childAlignment: TextAnchor.MiddleRight);
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(headerButtons, false, false, true, true, 4, childAlignment: TextAnchor.MiddleRight);
|
||||||
@ -66,6 +71,10 @@ namespace UnityExplorer.UI.Panels
|
|||||||
Owner.RestoreBoneState(bone.name);
|
Owner.RestoreBoneState(bone.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetBoneEnabled(bool value){
|
||||||
|
bone.gameObject.SetActive(value);
|
||||||
|
}
|
||||||
|
|
||||||
// TransformControls-like functions
|
// TransformControls-like functions
|
||||||
public void UpdateTransformControlValues(bool force){
|
public void UpdateTransformControlValues(bool force){
|
||||||
positionControl.Update(force);
|
positionControl.Update(force);
|
||||||
|
@ -112,7 +112,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
|
|
||||||
foreach (AnimatorPlayer animatorPlayer in animators){
|
foreach (AnimatorPlayer animatorPlayer in animators){
|
||||||
if (!animatorPlayer.shouldIgnoreMasterToggle){
|
if (!animatorPlayer.shouldIgnoreMasterToggle){
|
||||||
animatorPlayer.skinnedMesh.enabled = enable;
|
animatorPlayer.SetMeshesEnabled(enable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,18 @@ namespace UnityExplorer.UI.Panels
|
|||||||
|
|
||||||
private void OnTurnOffAnimatorToggle(bool value)
|
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();
|
bonesOriginalState.Clear();
|
||||||
foreach (Transform bone in bones){
|
foreach (Transform bone in bones){
|
||||||
bonesOriginalState[bone.name] = new CachedBonesTransform(bone.localPosition, bone.localEulerAngles, bone.localScale);
|
bonesOriginalState[bone.name] = new CachedBonesTransform(bone.localPosition, bone.localEulerAngles, bone.localScale);
|
||||||
|
Reference in New Issue
Block a user