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 Tags = new List(); public SerializableTransform Transform = new SerializableTransform(); /// Reference to original bone for runtime. Not saved to file. [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 tags = null) { if(tags == null) tags = new List(); if (generateTags) { if (t.name.EndsWith("_l")) { tags.Add(BoneTags.Left); } else if (t.name.EndsWith("_r")) { tags.Add(BoneTags.Right); } //if(t.GetComponentInParent() != 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 }