rimworld-animation-studio/Assets/Scripts/AnimationComponents/PawnRaceOffset.cs
AbstractConcept 757badf4f6 Code refactor
2022-10-27 00:56:04 -05:00

49 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
namespace RimWorldAnimationStudio
{
[Serializable]
public class PawnRaceOffset
{
// Local data
public string defName = "Human";
public string offset = "(0, 0)";
// SHoulda serialize
public bool ShouldSerializedefName() { return OffsetIsZero() == false; }
public bool ShouldSerializeoffset() { return OffsetIsZero() == false; }
// Constructors
public PawnRaceOffset() { }
public PawnRaceOffset(string defName)
{
this.defName = defName;
}
// Methods
public void SetOffset(Vector2 raceOffset)
{
offset = "(" + raceOffset.x + ", " + raceOffset.y + ")";
}
public Vector3 GetOffset()
{
string raceOffset = offset;
raceOffset = raceOffset.Trim();
raceOffset = raceOffset.Replace("(", "");
raceOffset = raceOffset.Replace(")", "");
var raceOffsets = raceOffset.Split(',');
return new Vector3(float.Parse(raceOffsets[0]), 0f, float.Parse(raceOffsets[1]));
}
public bool OffsetIsZero()
{
Vector3 vec = GetOffset();
return Mathf.Approximately(vec.x, 0f) && Mathf.Approximately(vec.y, 0f) && Mathf.Approximately(vec.x, 0f);
}
}
}