mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2025-07-19 01:57:56 +08:00
Added buttons to restore individual bones in the BonesManager.
This commit is contained in:
@ -40,9 +40,21 @@ namespace UnityExplorer.UI.Panels
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(UIRoot, false, false, true, true, 3);
|
||||
UIFactory.SetLayoutElement(UIRoot, minHeight: 25, minWidth: 50, flexibleWidth: 9999);
|
||||
|
||||
boneName = UIFactory.CreateLabel(UIRoot, $"BoneLabel", "");
|
||||
GameObject header = UIFactory.CreateUIObject("BoneHeader", UIRoot);
|
||||
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 headerButtons = UIFactory.CreateUIObject("BoneHeader", header);
|
||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(headerButtons, false, false, true, true, 4, childAlignment: TextAnchor.MiddleRight);
|
||||
UIFactory.SetLayoutElement(headerButtons, minHeight: 25, flexibleWidth: 9999, flexibleHeight: 800);
|
||||
|
||||
ButtonRef restoreBoneStateButton = UIFactory.CreateButton(headerButtons, "RestoreBoneState", "Restore State");
|
||||
UIFactory.SetLayoutElement(restoreBoneStateButton.GameObject, minWidth: 125, minHeight: 25);
|
||||
restoreBoneStateButton.OnClick += RestoreBoneState;
|
||||
|
||||
positionControl = ComponentControl.Create(this, UIRoot, "Local Position", TransformType.LocalPosition, 0.01f);
|
||||
rotationControl = ComponentControl.Create(this, UIRoot, "Rotation", TransformType.Rotation, 10f);
|
||||
scaleControl = ComponentControl.Create(this, UIRoot, "Scale", TransformType.Scale, 0.1f);
|
||||
@ -50,6 +62,10 @@ namespace UnityExplorer.UI.Panels
|
||||
return UIRoot;
|
||||
}
|
||||
|
||||
private void RestoreBoneState(){
|
||||
Owner.RestoreBoneState(bone.name);
|
||||
}
|
||||
|
||||
// TransformControls-like functions
|
||||
public void UpdateTransformControlValues(bool force){
|
||||
positionControl.Update(force);
|
||||
|
@ -16,6 +16,7 @@ namespace UnityExplorer.UI.Panels
|
||||
private IAnimator animator;
|
||||
private Text skeletonName;
|
||||
private List<Transform> bones = new List<Transform>();
|
||||
private Dictionary<string, CachedBonesTransform> bonesOriginalState = new();
|
||||
|
||||
private ScrollPool<BonesCell> boneScrollPool;
|
||||
public int ItemCount => bones.Count;
|
||||
@ -48,7 +49,7 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
GameObject turnOffAnimatorToggleObj = UIFactory.CreateToggle(ContentRoot, "Animator toggle", out turnOffAnimatorToggle, out Text turnOffAnimatorToggleText);
|
||||
UIFactory.SetLayoutElement(turnOffAnimatorToggleObj, minHeight: 25, flexibleWidth: 9999);
|
||||
turnOffAnimatorToggle.onValueChanged.AddListener(value => { animator.enabled = value; });
|
||||
turnOffAnimatorToggle.onValueChanged.AddListener(OnTurnOffAnimatorToggle);
|
||||
turnOffAnimatorToggleText.text = "Toggle animator (needs to be off to move bones)";
|
||||
|
||||
boneScrollPool = UIFactory.CreateScrollPool<BonesCell>(ContentRoot, "BonesList", out GameObject scrollObj,
|
||||
@ -56,6 +57,30 @@ namespace UnityExplorer.UI.Panels
|
||||
UIFactory.SetLayoutElement(scrollObj, flexibleWidth: 9999, flexibleHeight: 9999);
|
||||
}
|
||||
|
||||
private void OnTurnOffAnimatorToggle(bool value)
|
||||
{
|
||||
if (!value){
|
||||
bonesOriginalState.Clear();
|
||||
foreach (Transform bone in bones){
|
||||
bonesOriginalState[bone.name] = new CachedBonesTransform(bone.localPosition, bone.localEulerAngles, bone.localScale);
|
||||
}
|
||||
}
|
||||
animator.enabled = value;
|
||||
}
|
||||
|
||||
public void RestoreBoneState(string boneName)
|
||||
{
|
||||
foreach (Transform bone in bones){
|
||||
if (bone.name == boneName){
|
||||
CachedBonesTransform CachedBonesTransform = bonesOriginalState[boneName];
|
||||
bone.localPosition = CachedBonesTransform.position;
|
||||
bone.localEulerAngles = CachedBonesTransform.angles;
|
||||
bone.localScale = CachedBonesTransform.scale;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCell(BonesCell cell, int index)
|
||||
{
|
||||
if (index >= bones.Count)
|
||||
@ -82,4 +107,18 @@ namespace UnityExplorer.UI.Panels
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CachedBonesTransform
|
||||
{
|
||||
public CachedBonesTransform(Vector3 position, Vector3 angles, Vector3 scale)
|
||||
{
|
||||
this.position = position;
|
||||
this.angles = angles;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public readonly Vector3 position;
|
||||
public readonly Vector3 angles;
|
||||
public readonly Vector3 scale;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user