using System.Reflection; using UnityEngine; namespace RimWorldAnimationStudio { public class BodyTypeOffset { public string Male; public string Female; public string Thin; public string Hulk; public string Fat; public bool AllOffsetsEmpty() { return string.IsNullOrEmpty(Male) && string.IsNullOrEmpty(Female) && string.IsNullOrEmpty(Thin) && string.IsNullOrEmpty(Hulk) && string.IsNullOrEmpty(Fat); } public void SetOffset(string bodyType, Vector2 bodyOffset) { FieldInfo bodyTypeOffsetInfo = typeof(BodyTypeOffset).GetField(bodyType); if (bodyTypeOffsetInfo == null) { return; } string _bodyOffset = "(" + bodyOffset.x + ", " + bodyOffset.y + ")"; bodyTypeOffsetInfo.SetValue(this, _bodyOffset); } public Vector3 GetOffset(string bodyType) { FieldInfo bodyTypeOffsetInfo = typeof(BodyTypeOffset).GetField(bodyType); if (bodyTypeOffsetInfo == null) { return new Vector2(); } string bodyTypeOffsetString = (string)bodyTypeOffsetInfo.GetValue(this); if (bodyTypeOffsetString == null || bodyTypeOffsetString == "") { return new Vector2(); } bodyTypeOffsetString = bodyTypeOffsetString.Trim(); bodyTypeOffsetString = bodyTypeOffsetString.Replace("(", ""); bodyTypeOffsetString = bodyTypeOffsetString.Replace(")", ""); var bodyTypeOffsetStrings = bodyTypeOffsetString.Split(','); return new Vector3(float.Parse(bodyTypeOffsetStrings[0]), 0f, float.Parse(bodyTypeOffsetStrings[1])); } } }