// ---------------------------------------------------------------- // Initialize // ---------------------------------------------------------------- public void Initialize(TravelMindData data) { PosA = data.posA; PosB = data.posB; Speed = data.speed; LocOffset = data.locOffset; oscLoc = LocOffset; // start with my desired offset! // Set refs. myTravelable = GetComponent <ITravelable>(); Prop myProp = GetComponent <Prop>(); if (myProp != null) { myRoomPos = myProp.MyRoom.PosGlobal; oscLoc += myProp.MyRoom.RoomTime * Speed; // also start us at the right spot, based on the Room's age (in case we're made DURING being in the Room [i.e. in editor]). } ApplyPos(); // Move this component just under my Script, for easiness. #if UNITY_EDITOR UnityEditorInternal.ComponentUtility.MoveComponentUp(this); UnityEditorInternal.ComponentUtility.MoveComponentUp(this); UnityEditorInternal.ComponentUtility.MoveComponentUp(this); UnityEditorInternal.ComponentUtility.MoveComponentUp(this); UnityEditorInternal.ComponentUtility.MoveComponentUp(this); UnityEditorInternal.ComponentUtility.MoveComponentUp(this); UnityEditorInternal.ComponentUtility.MoveComponentDown(this); #endif }
public void AddTravelMind(TravelMindData data) { if (travelMind != null) { return; } // Safety check. travelMind = gameObject.AddComponent <PropTravelMind>(); travelMind.Initialize(data); DisableSnappingScript(); }
public void AddDefaultTravelMind() { TravelMindData tmd = new TravelMindData { posA = pos, posB = pos, speed = 2f, locOffset = 0 }; AddTravelMind(tmd); }
static public TravelMindData FromString(string str) { str = str.Substring(1, str.Length - 2); // cut the parenthesis. string[] values = str.Split(','); TravelMindData data = new TravelMindData { posA = new Vector2(TextUtils.ParseFloat(values[0]), TextUtils.ParseFloat(values[1])), posB = new Vector2(TextUtils.ParseFloat(values[2]), TextUtils.ParseFloat(values[3])), speed = TextUtils.ParseFloat(values[4]), locOffset = TextUtils.ParseFloat(values[5]) }; return(data); }
static private void SetPropDataFieldValue(PropData propData, string fieldName, string fieldValueString) { // What extension of PropData is this? Type propDataType = propData.GetType(); // Get the FieldInfo of the requested name from this propData's class. FieldInfo fieldInfo = propDataType.GetField(fieldName); // Get the VALUE of this field from the string! if (fieldInfo == null) { Debug.LogError("We've been provided an unidentified prop field type. " + debug_roomDataLoadingRoomKey + ". PropData: " + propData + ", fieldName: " + fieldName); } else if (fieldInfo.FieldType == typeof(bool)) { fieldInfo.SetValue(propData, bool.Parse(fieldValueString)); } else if (fieldInfo.FieldType == typeof(float)) { fieldInfo.SetValue(propData, TextUtils.ParseFloat(fieldValueString)); } else if (fieldInfo.FieldType == typeof(int)) { fieldInfo.SetValue(propData, TextUtils.ParseInt(fieldValueString)); } else if (fieldInfo.FieldType == typeof(string)) { fieldInfo.SetValue(propData, fieldValueString); } else if (fieldInfo.FieldType == typeof(Rect)) { fieldInfo.SetValue(propData, TextUtils.GetRectFromString(fieldValueString)); } else if (fieldInfo.FieldType == typeof(Vector2)) { fieldInfo.SetValue(propData, TextUtils.GetVector2FromString(fieldValueString)); } else if (fieldInfo.FieldType == typeof(OnOfferData)) { fieldInfo.SetValue(propData, OnOfferData.FromString(fieldValueString)); } else if (fieldInfo.FieldType == typeof(TravelMindData)) { fieldInfo.SetValue(propData, TravelMindData.FromString(fieldValueString)); } else { Debug.LogWarning("Unrecognized field type in Room file: " + debug_roomDataLoadingRoomKey + ". PropData: " + propData + ", fieldName: " + fieldName); } }