f928a802d7
Pose serialization, deserialization (no face) UI handle system
67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class SerializableBone
|
|
{
|
|
public string Name = "";
|
|
public string ParentName = "";
|
|
public List<BoneTags> Tags = new List<BoneTags>();
|
|
public SerializableTransform Transform = new SerializableTransform();
|
|
|
|
/// <summary> Reference to original bone for runtime. Not saved to file. </summary>
|
|
[NonSerialized] public Transform Bone;
|
|
|
|
public SerializableBone(){}
|
|
|
|
public SerializableBone(Transform t, bool generateTags = true, List<BoneTags> tags = null)
|
|
{
|
|
if(tags == null) tags = new List<BoneTags>();
|
|
|
|
if (generateTags)
|
|
{
|
|
if (t.name.EndsWith("_L"))
|
|
{
|
|
Tags.Add(BoneTags.Left);
|
|
}
|
|
else if (t.name.EndsWith("_R"))
|
|
{
|
|
Tags.Add(BoneTags.Right);
|
|
}
|
|
|
|
if(t.GetComponentInParent<DynamicBone>() != null)
|
|
{
|
|
Tags.Add(BoneTags.Dynamic);
|
|
}
|
|
}
|
|
|
|
Name = t.name;
|
|
Tags = tags;
|
|
Transform = new SerializableTransform(t, Space.Self);
|
|
ParentName = t.parent == null ? "root" : t.parent.name;
|
|
|
|
Bone = t;
|
|
}
|
|
|
|
public void ApplyTo(SerializableBone target)
|
|
{
|
|
if(target.Bone == null)
|
|
{
|
|
Debug.LogError($"Target bone {target.Name} does not reference a bone in the scene.");
|
|
return;
|
|
}
|
|
|
|
Transform.ApplyTo(target.Bone);
|
|
}
|
|
|
|
//feel free to add more
|
|
public enum BoneTags
|
|
{
|
|
Left,
|
|
Right,
|
|
Dynamic,
|
|
Humanoid,
|
|
}
|
|
}
|