public void LoadWithName(string fileName, float duration = 0, string tweenStyle = null) { if (!fileName.EndsWith(".pst")) { fileName += ".pst"; } if (debug) { Debug.Log("Loading " + fileName + " preset for " + id + " with " + (tweenStyle == null ? " no tween " : tweenStyle)); } StreamReader file; try { file = new StreamReader(targetDirectory + fileName); ControllableData cData = JsonUtility.FromJson <ControllableData>(file.ReadLine()); loadData(cData, duration, tweenStyle); file.Close(); } catch (Exception e) { Debug.LogError("Error while loading preset : " + e.Message + e.StackTrace); return; } currentPreset = fileName; }
public object getData() { ControllableData data = new ControllableData(); data.dataID = id; foreach (FieldInfo p in Properties.Values) { OSCProperty attribute = Attribute.GetCustomAttribute(p, typeof(OSCProperty)) as OSCProperty; if (attribute.IncludeInPresets) { Debug.Log("Attribute : " + p.Name + " of type " + p.FieldType + " is saved."); data.nameList.Add(p.Name); //Because a simple "toString" doesn't give the full value if (p.FieldType.ToString() == "UnityEngine.Vector3") { data.valueList.Add(((Vector3)p.GetValue(this)).ToString("F8")); } else if (p.FieldType.ToString() == "System.Single") { data.valueList.Add(((float)p.GetValue(this)).ToString("F8")); } else { data.valueList.Add(p.GetValue(this).ToString()); } } } return(data); }
public void loadData(ControllableData data) { int index = 0; foreach (string dn in data.nameList) { List <object> values = new List <object>(); FieldInfo info; if (Properties.TryGetValue(dn, out info)) { values.Add(getObjectForValue(Properties[dn].FieldType.ToString(), data.valueList[index])); setFieldProp(Properties[dn], dn, values); } index++; } }
public void LoadPreset() { //if (debug) Debug.Log("Loading " + currentPreset + " preset for " + id); var file = new StreamReader(targetDirectory + currentPreset); ControllableData cData = JsonUtility.FromJson <ControllableData>(file.ReadLine()); loadData(cData); DataLoaded(); LastUsedPreset = currentPreset; file.Close(); if (debug) { Debug.Log("Done."); } }
public object getData() { ControllableData data = new ControllableData(); data.dataID = id; foreach (MemberInfo p in Properties.Values) { OSCProperty attribute = Attribute.GetCustomAttribute(p, typeof(OSCProperty)) as OSCProperty; if (attribute.IncludeInPresets) { string typeString = getInfoTypeString(p); if (debug) { Debug.Log("Attribute : " + p.Name + " of type " + typeString + " is saved."); } data.nameList.Add(p.Name); //Because a simple "toString" doesn't give the full value object val = getInfoValue(p); if (typeString == "UnityEngine.Vector3") { data.valueList.Add(((Vector3)val).ToString("F8")); } else if (typeString == "System.Single") { data.valueList.Add(((float)val).ToString("F8")); } else { data.valueList.Add(val.ToString()); } } } return(data); }
public void loadData(ControllableData data, float duration = 0, string tweenStyle = null) { if (tweenStyle != null) { tweenStyle = tweenStyle.ToLower(); if (tweenStyle != "easeout" && tweenStyle != "easein" && tweenStyle != "easeinout" && tweenStyle != "linear") { Debug.LogWarning("Unknow tween style !"); tweenStyle = null; } } int index = 0; foreach (string dn in data.nameList) { FieldInfo info; if (Fields.TryGetValue(dn, out info)) { if (tweenStyle != null) { var curve = new AnimationCurve(); if (tweenStyle == "easeinout") { curve = TweenCurves.Instance.EaseInOutCurve; } else if (tweenStyle == "easein") { curve = TweenCurves.Instance.EaseInCurve; } else if (tweenStyle == "easeout") { curve = TweenCurves.Instance.EaseOutCurve; } else if (tweenStyle == "linear") { curve = TweenCurves.Instance.LinearCurve; } StartCoroutine( TweenValue(Fields[dn], TypeConverter.getObjectForValue(Fields[dn].FieldType.ToString(), data.valueList[index]), duration, curve) ); } else { List <object> values = new List <object>(); values.Add(TypeConverter.getObjectForValue(Fields[dn].FieldType.ToString(), data.valueList[index])); setFieldProp(Fields[dn], values); } } index++; } StartCoroutine(CallAfterDuration(DataLoaded, duration)); }
public void loadData(ControllableData data, float duration = 0, string tweenStyle = null) { if (tweenStyle != null) { tweenStyle = tweenStyle.ToLower(); if (tweenStyle != "easeout" && tweenStyle != "easein" && tweenStyle != "easeinout" && tweenStyle != "linear") { Debug.LogWarning("Unknow tween style !"); tweenStyle = null; } } int index = 0; foreach (string dn in data.nameList) { MemberInfo info; if (Properties.TryGetValue(dn, out info)) { string type = getInfoTypeString(Properties[dn]); if (tweenStyle != null) { var curve = new AnimationCurve(); if (tweenStyle == "easeinout") { curve = TweenCurves.Instance.EaseInOutCurve; } else if (tweenStyle == "easein") { curve = TweenCurves.Instance.EaseInCurve; } else if (tweenStyle == "easeout") { curve = TweenCurves.Instance.EaseOutCurve; } else if (tweenStyle == "linear") { curve = TweenCurves.Instance.LinearCurve; } StartCoroutine( TweenValue(Properties[dn], getObjectForValue(type, data.valueList[index]), duration, curve) ); } else { List <object> values = new List <object>(); values.Add(getObjectForValue(type, data.valueList[index])); setValueProp(Properties[dn], values); } } index++; } StartCoroutine(WaitForTweenEnd(duration)); }