public static Vector3 GetObjOffsetPos(SetObjectType type) { var offsetPos = new Vector3(0, 0, 0); if (type != null) { var offsetPosExtra = type.GetExtra("OffsetPosition"); if (offsetPosExtra == null) { offsetPos.X = GetFloatExtra("OffsetPositionX", "Offset_Position_X"); offsetPos.Y = GetFloatExtra("OffsetPositionY", "Offset_Position_Y"); offsetPos.Z = GetFloatExtra("OffsetPositionZ", "Offset_Position_Z"); } else if (!string.IsNullOrEmpty(offsetPosExtra.Value)) { offsetPos = (Vector3)Helpers.ChangeType( offsetPosExtra.Value, typeof(Vector3)); } // Sub-Methods float GetFloatExtra(string name, string altName) { var extra = type.GetExtra(name); if (extra == null) { extra = type.GetExtra(altName); } float.TryParse((string.IsNullOrEmpty(extra?.Value)) ? "0" : extra.Value, out float f); return(f); } } return(offsetPos); }
public static Vector3 GetObjScale(SetObjectType type, SetObject obj) { if (type == null) { return(new Vector3(1, 1, 1)); } var scaleExtra = type.GetExtra("scale"); if (scaleExtra != null && !string.IsNullOrEmpty(scaleExtra.Value)) { if (float.TryParse(scaleExtra.Value, out float s)) { return(new Vector3(s, s, s)); } // TODO: Maybe try to parse it as a Vector3 as well? else { int scaleParamIndex = type.GetParameterIndex(scaleExtra.Value); if (scaleParamIndex != -1) { var param = obj.Parameters[scaleParamIndex]; if (param != null) { if (param.DataType == typeof(Vector3)) { return((Vector3)param.Data); } else if (param.DataType == typeof(float)) { float f = (float)param.Data; return(new Vector3(f, f, f)); } } } } } return(new Vector3(1, 1, 1)); }