/// <summary> /// Parse a string to generate an object. /// Only very limited primitive object types are supported. /// Enums, Vectors and most other structures are automatically supported, /// because the reflection system breaks them down into their primitive components. /// You can add more support here, as needed. /// </summary> static object LeafObjectFromString(Type type, string value, GameObject[] roots) { if (type == typeof(Single)) { return(float.Parse(value)); } if (type == typeof(Double)) { return(double.Parse(value)); } if (type == typeof(Boolean)) { return(Boolean.Parse(value)); } if (type == typeof(string)) { return(value); } if (type == typeof(Int32)) { return(Int32.Parse(value)); } if (type == typeof(UInt32)) { return(UInt32.Parse(value)); } if (typeof(Component).IsAssignableFrom(type)) { // Try to find the named game object GameObject go = ObjectTreeUtil.FindObjectFromFullName(value, roots); return((go != null) ? go.GetComponent(type) : null); } if (typeof(GameObject).IsAssignableFrom(type)) { // Try to find the named game object return(GameObject.Find(value)); } if (typeof(ScriptableObject).IsAssignableFrom(type)) { return(AssetDatabase.LoadAssetAtPath(value, type)); } return(null); }
/// <summary> /// Parse a string to generate an object. /// Only very limited primitive object types are supported. /// Enums, Vectors and most other structures are automatically supported, /// because the reflection system breaks them down into their primitive components. /// You can add more support here, as needed. /// </summary> static object LeafObjectFromString(Type type, string value) { if (type == typeof(Single)) { return(float.Parse(value)); } if (type == typeof(Double)) { return(double.Parse(value)); } if (type == typeof(Boolean)) { return(Boolean.Parse(value)); } if (type == typeof(string)) { return(value); } if (type == typeof(Int32)) { return(Int32.Parse(value)); } if (type == typeof(UInt32)) { return(UInt32.Parse(value)); } if (type.IsSubclassOf(typeof(Component))) { // Try to find the named game object GameObject go = ObjectTreeUtil.FindObjectFromFullName(value); return((go != null) ? go.GetComponent(type) : null); } if (type.IsSubclassOf(typeof(GameObject))) { // Try to find the named game object return(GameObject.Find(value)); } return(null); }
/// <summary> /// Parse a string to generate an object. /// Only very limited primitive object types are supported. /// Enums, Vectors and most other structures are automatically supported, /// because the reflection system breaks them down into their primitive components. /// You can add more support here, as needed. /// </summary> private static object LeafObjectFromString(Type type, string value, GameObject[] roots) { if (type == typeof(float)) { return(float.Parse(value)); } if (type == typeof(double)) { return(double.Parse(value)); } if (type == typeof(bool)) { return(bool.Parse(value)); } if (type == typeof(string)) { return(value); } if (type == typeof(int)) { return(int.Parse(value)); } if (type == typeof(uint)) { return(uint.Parse(value)); } if (type.IsSubclassOf(typeof(Component))) { // Try to find the named game object var go = ObjectTreeUtil.FindObjectFromFullName(value, roots); return(go != null?go.GetComponent(type) : null); } if (type.IsSubclassOf(typeof(GameObject))) { return(GameObject.Find(value)); } return(null); }
public GameObject FindSavedGameObject(GameObject[] roots) { return(ObjectTreeUtil.FindObjectFromFullName(mObjectFullPath, roots)); }