74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking.Types;
|
|
|
|
[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(SerializableBone bone)
|
|
{
|
|
this.Name = bone.Name;
|
|
this.Tags = bone.Tags.ToList();
|
|
this.Transform = new SerializableTransform(bone.Transform);
|
|
}
|
|
|
|
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<Osage>() != 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;
|
|
}
|
|
|
|
//feel free to add more. do not change order!
|
|
public enum BoneTags
|
|
{
|
|
Left,
|
|
Right,
|
|
Dynamic,
|
|
Humanoid,
|
|
Finger,
|
|
Face,
|
|
Untagged,
|
|
IK,
|
|
Root,
|
|
}
|
|
|
|
#region JSON
|
|
public bool ShouldSerializeTags() { return Tags.Count > 0; }
|
|
#endregion
|
|
}
|