void init() { //PROPERTIES oscProperties = new List <KeyValuePair <string, FieldInfo> >(); Type t = GetType(); FieldInfo[] objectFields = t.GetFields(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < objectFields.Length; i++) { FieldInfo info = objectFields[i]; OSCProperty attribute = Attribute.GetCustomAttribute(info, typeof(OSCProperty)) as OSCProperty; if (attribute != null) { oscProperties.Add(new KeyValuePair <string, FieldInfo>(attribute.address, info)); } } //METHODS oscMethods = new List <KeyValuePair <string, MethodInfo> >(); MethodInfo[] methodFields = t.GetMethods(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < methodFields.Length; i++) { MethodInfo info = methodFields[i]; OSCMethod attribute = Attribute.GetCustomAttribute(info, typeof(OSCMethod)) as OSCMethod; if (attribute != null) { oscMethods.Add(new KeyValuePair <string, MethodInfo>(attribute.address, info)); } } }
public virtual void Awake() { if (TargetScript == null) { Debug.LogError("TargetScript of " + this.GetType().ToString() + " is not set ! Aborting initialization."); } this.scriptValueChanged += OnScriptValueChanged; this.uiValueChanged += OnUiValueChanged; //FIELDS Fields = new Dictionary <string, FieldInfo>(); TargetFields = new Dictionary <string, ClassAttributInfo>(); PreviousFieldsValues = new List <object>(); Type t = GetType(); FieldInfo[] objectFields = t.GetFields(BindingFlags.Instance | BindingFlags.Public); FieldInfo[] scriptFields = objectFields; PropertyInfo[] scriptProperties = null; if (TargetScript != null) { scriptFields = TargetScript.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); scriptProperties = TargetScript.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); } for (int i = 0; i < objectFields.Length; i++) { FieldInfo info = objectFields[i]; OSCProperty attribute = Attribute.GetCustomAttribute(info, typeof(OSCProperty)) as OSCProperty; if (attribute != null) { if (info.Name == "currentPreset" && !usePresets) { continue; } Fields.Add(info.Name, info); var fieldAdded = false; for (int j = 0; j < scriptFields.Length; j++) { if (scriptFields[j].Name == info.Name) { var newClassAttributInfo = new ClassAttributInfo(); newClassAttributInfo.Field = scriptFields[j]; TargetFields.Add(scriptFields[j].Name, newClassAttributInfo); fieldAdded = true; break; } } if (!fieldAdded) { for (int j = 0; j < scriptProperties.Length; j++) { if (scriptProperties[j].Name == info.Name) { var newClassAttributInfo = new ClassAttributInfo(); newClassAttributInfo.Property = scriptProperties[j]; TargetFields.Add(scriptProperties[j].Name, newClassAttributInfo); break; } } } PreviousFieldsValues.Add(info.GetValue(this)); } } //METHODS Methods = new Dictionary <string, MethodInfo>(); MethodInfo[] methodFields = t.GetMethods(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < methodFields.Length; i++) { MethodInfo info = methodFields[i]; OSCMethod attribute = Attribute.GetCustomAttribute(info, typeof(OSCMethod)) as OSCMethod; if (attribute != null) { if ((info.Name == "Save" || info.Name == "SaveAs" || info.Name == "Load" || info.Name == "Show") && !usePresets) { continue; } Methods.Add(info.Name, info); } } if (string.IsNullOrEmpty(id)) { id = TargetScript.GetType().Name; } id = id.Replace(' ', '_'); sourceScene = SceneManager.GetActiveScene().name; }
public virtual void Awake() { this.scriptValueChanged += OnScriptValueChanged; this.uiValueChanged += OnUiValueChanged; //PROPERTIES Properties = new Dictionary <string, MemberInfo>(); TargetProperties = new Dictionary <string, MemberInfo>(); PreviousPropertiesValues = new List <object>(); MemberInfo[] objectProperties = GetType().GetMembers(BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public); MemberInfo[] scriptProperties = objectProperties; if (TargetScript == null) { TargetScript = this; } else { objectProperties = TargetScript.GetType().GetMembers(BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public); } Debug.Log("Found " + objectProperties.Length + " fields and properties in " + id); for (int i = 0; i < objectProperties.Length; i++) { MemberInfo info = objectProperties[i]; OSCProperty attribute = Attribute.GetCustomAttribute(info, typeof(OSCProperty)) as OSCProperty; if (attribute != null) { if (info.Name == "currentPreset" && !usePresets) { continue; } String propName = attribute.customName == null ? info.Name : attribute.customName; Properties.Add(propName, info); for (int j = 0; j < scriptProperties.Length; j++) { if (scriptProperties[j].Name == info.Name) { TargetProperties.Add(propName, scriptProperties[j]); break; } } PreviousPropertiesValues.Add(getInfoValue(info)); } } //METHODS Methods = new Dictionary <string, MethodInfo>(); MethodInfo[] methodFields = GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < methodFields.Length; i++) { MethodInfo info = methodFields[i]; OSCMethod attribute = Attribute.GetCustomAttribute(info, typeof(OSCMethod)) as OSCMethod; if (attribute != null) { if ((info.Name == "Save" || info.Name == "SaveAs" || info.Name == "Load" || info.Name == "Show") && !usePresets) { continue; } Methods.Add(info.Name, info); } } if (string.IsNullOrEmpty(id)) { id = TargetScript.GetType().Name; } sourceScene = SceneManager.GetActiveScene().name; }
public virtual void Awake() { //PROPERTIES Properties = new Dictionary <string, FieldInfo>(); PreviousPropertiesValues = new List <object>(); Type t = GetType(); FieldInfo[] objectFields = t.GetFields(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < objectFields.Length; i++) { FieldInfo info = objectFields[i]; OSCProperty attribute = Attribute.GetCustomAttribute(info, typeof(OSCProperty)) as OSCProperty; if (attribute != null) { if (info.Name == "currentPreset" && !usePresets) { continue; } Properties.Add(info.Name, info); //Debug.Log("Intializing " + info.Name + " with " + info.GetValue(this)); PreviousPropertiesValues.Add(info.GetValue(this)); } } //METHODS Methods = new Dictionary <string, MethodInfo>(); MethodInfo[] methodFields = t.GetMethods(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < methodFields.Length; i++) { MethodInfo info = methodFields[i]; OSCMethod attribute = Attribute.GetCustomAttribute(info, typeof(OSCMethod)) as OSCMethod; if (attribute != null) { if ((info.Name == "SavePreset" || info.Name == "LoadPreset") && !usePresets) { continue; } Methods.Add(info.Name, info); } } if (string.IsNullOrEmpty(id)) { id = gameObject.name; } sourceScene = SceneManager.GetActiveScene().name; ControllableMaster.Register(this); presetList = new List <string>(); ReadFileList(); if (presetList.Count > 1) { currentPreset = presetList[0]; } LoadLatestUsedPreset(); }
public void setMethodProp(MethodInfo info, string property, List <object> values) { object[] parameters = new object[info.GetParameters().Length]; OSCMethod attribute = Attribute.GetCustomAttribute(info, typeof(OSCMethod)) as OSCMethod; if (debug) { Debug.Log("Set Method, num expected parameters : " + (attribute.packInArray ? "1 array" : parameters.Length.ToString())); } if (attribute.packInArray) { parameters = new object[1]; parameters[0] = values.ToArray(); info.Invoke(this, parameters); return; } int valueIndex = 0; for (int i = 0; i < parameters.Length; i++) { string typeString = info.GetParameters()[i].ParameterType.ToString(); //Debug.Log("OSC IN Method, arg "+i+" TYPE : " + typeString + ", num values in OSC Message " + values.Count); if (typeString == "System.Single") { if (values.Count >= valueIndex + 1) { parameters[i] = getFloat(values[valueIndex]); valueIndex += 1; } } else if (typeString == "System.Boolean") { if (values.Count >= valueIndex + 1) { parameters[i] = getBool(values[valueIndex]); valueIndex += 1; } } else if (typeString == "System.Int32") { if (values.Count >= valueIndex + 1) { parameters[i] = getInt(values[valueIndex]); valueIndex += 1; } } else if (typeString == "UnityEngine.Vector2") { if (values.Count >= valueIndex + 2) { parameters[i] = new Vector2(getFloat(values[valueIndex]), getFloat(values[valueIndex + 1])); valueIndex += 2; } } else if (typeString == "UnityEngine.Vector3") { if (values.Count >= valueIndex + 3) { parameters[i] = new Vector3(getFloat(values[valueIndex]), getFloat(values[valueIndex + 1]), getFloat(values[valueIndex + 2])); valueIndex += 3; } } else if (typeString == "UnityEngine.Color") { if (values.Count >= valueIndex + 4) { parameters[i] = new Color(getFloat(values[valueIndex + 0]), getFloat(values[valueIndex + 1]), getFloat(values[valueIndex + 2]), getFloat(values[valueIndex + 3])); valueIndex += 4; } else if (values.Count >= i + 3) { parameters[i] = new Color(getFloat(values[valueIndex + 0]), getFloat(values[valueIndex + 1]), getFloat(values[valueIndex + 2]), 1); valueIndex += 3; } } else if (typeString == "System.String") { if (values.Count >= valueIndex + 1) { parameters[i] = values[i].ToString(); valueIndex += 1; } } } info.Invoke(this, parameters); }