public VFXProperty(FieldInfo info) { name = info.Name; m_serializedType = info.FieldType; attributes = VFXPropertyAttribute.Create(info.GetCustomAttributes(true)); }
public static object Load(System.Type type, string text, object oldValue) { if (type == null) { return(null); } if (type.IsPrimitive) { if (string.IsNullOrEmpty(text)) { try { return(Activator.CreateInstance(type)); } catch (MissingMethodException) { Debug.LogError(type.Name + " Doesn't seem to have a default constructor"); throw; } } return(Convert.ChangeType(text, type, CultureInfo.InvariantCulture)); } else if (typeof(UnityEngine.Object).IsAssignableFrom(type)) { object obj = new ObjectWrapper(); EditorJsonUtility.FromJsonOverwrite(text, obj); return(((ObjectWrapper)obj).obj); } else if (type.IsAssignableFrom(typeof(AnimationCurve))) { AnimCurveWrapper sac = new AnimCurveWrapper(); JsonUtility.FromJsonOverwrite(text, sac); AnimationCurve curve = oldValue != null ? (AnimationCurve)oldValue : new AnimationCurve(); if (sac.frames != null) { Keyframe[] keys = new UnityEngine.Keyframe[sac.frames.Length]; for (int i = 0; i < sac.frames.Length; ++i) { keys[i].time = sac.frames[i].time; keys[i].value = sac.frames[i].value; keys[i].inTangent = sac.frames[i].inTangent; keys[i].outTangent = sac.frames[i].outTangent; if (sac.version == 1) { AnimationUtility.SetKeyLeftTangentMode(ref keys[i], sac.frames[i].leftTangentMode); AnimationUtility.SetKeyRightTangentMode(ref keys[i], sac.frames[i].rightTangentMode); AnimationUtility.SetKeyBroken(ref keys[i], sac.frames[i].broken); } else { AnimationUtility.SetKeyLeftTangentMode(ref keys[i], (TangentMode)((sac.frames[i].tangentMode & kLeftTangentMask) >> 1)); AnimationUtility.SetKeyRightTangentMode(ref keys[i], (TangentMode)((sac.frames[i].tangentMode & kRightTangentMask) >> 5)); AnimationUtility.SetKeyBroken(ref keys[i], (sac.frames[i].tangentMode & kBrokenMask) != 0); } } curve.keys = keys; curve.preWrapMode = sac.preWrapMode; curve.postWrapMode = sac.postWrapMode; } return(curve); } else if (type.IsAssignableFrom(typeof(Gradient))) { GradientWrapper gw = new GradientWrapper(); Gradient gradient = oldValue != null ? (Gradient)oldValue : new Gradient(); JsonUtility.FromJsonOverwrite(text, gw); gradient.mode = gw.gradientMode; GradientColorKey[] colorKeys = null; if (gw.colorKeys != null) { colorKeys = new GradientColorKey[gw.colorKeys.Length]; for (int i = 0; i < gw.colorKeys.Length; ++i) { colorKeys[i].color = gw.colorKeys[i].color; colorKeys[i].time = gw.colorKeys[i].time; } } else { colorKeys = new GradientColorKey[0]; } GradientAlphaKey[] alphaKeys = null; if (gw.alphaKeys != null) { alphaKeys = new GradientAlphaKey[gw.alphaKeys.Length]; for (int i = 0; i < gw.alphaKeys.Length; ++i) { alphaKeys[i].alpha = gw.alphaKeys[i].alpha; alphaKeys[i].time = gw.alphaKeys[i].time; } } else { alphaKeys = new GradientAlphaKey[0]; } gradient.SetKeys(colorKeys, alphaKeys); return(gradient); } else if (type == typeof(string)) { if (string.IsNullOrEmpty(text)) { return(""); } return(text.Substring(1, text.Length - 2).Replace("\\\"", "\"")); } else if (type == typeof(SerializableType)) { var obj = new SerializableType(text.Substring(1, text.Length - 2)); return(obj); } else if (type.IsArrayOrList()) { List <string> elements = ParseArray(text); if (elements == null) { return(null); } if (type.IsArray) { int listCount = elements.Count; Array arrayObj = (Array)Activator.CreateInstance(type, new object[] { listCount }); for (int index = 0; index < listCount; index++) { arrayObj.SetValue(Load(type.GetElementType(), elements[index], null), index); } return(arrayObj); } else //List { int listCount = elements.Count; IList listObj = (IList)Activator.CreateInstance(type, new object[0]); for (int index = 0; index < listCount; index++) { listObj.Add(Load(type.GetElementType(), elements[index], null)); } return(listObj); } } else { try { object obj = Activator.CreateInstance(type); EditorJsonUtility.FromJsonOverwrite(text, obj); return(obj); } catch (MissingMethodException) { Debug.LogError(type.Name + " Doesn't seem to have a default constructor"); throw; } } }
public VFXProperty(Type type, string name, params VFXPropertyAttribute[] attributes) { m_serializedType = type; this.name = name; this.attributes = attributes; }