예제 #1
0
    public static void DisposMethods(System.Type type, Dictionary <string, ClassMethodInfo> cmfDict)
    {
        BindingFlags options = BindingFlags | BindingFlags.Instance | BindingFlags.FlattenHierarchy;

        MethodInfo[] infoArray = type.GetMethods(options);

        foreach (MethodInfo info in infoArray)
        {
            if (info.IsGenericMethod)
            {
                continue;
            }
            if (info.Name.IndexOf('_') > 0)
            {
                continue;
            }
            string          key = type.Namespace + "." + type.Name + "." + info.Name;
            ClassMethodInfo cmf = !cmfDict.ContainsKey(key)?  new ClassMethodInfo() :cmfDict[key];
            cmf.fullName   = key;
            cmf.className  = GetTypeName(type);
            cmf.name       = info.Name;
            cmf.returnName = GetTypeName(info.ReturnType);
            cmf.isStatic   = info.IsStatic;
            cmfDict[key]   = cmf;
            cmf.overrideList.Add(DisposMethodArgs(info.GetParameters()));
        }
    }
예제 #2
0
파일: ButtonUI.cs 프로젝트: Theoriz/GenUI
    public void CreateUI(Controllable target, ClassMethodInfo method)
    {
        LinkedControllable = target;
        Method             = method.methodInfo;

        this.GetComponentInChildren <Text>().text = ParseNameString(method.methodInfo.Name);
        this.GetComponent <Button>().onClick.AddListener(() =>
        {
            target.setMethodProp(method, null);
        });
    }
예제 #3
0
    public static void DisposCtor(System.Type type, Dictionary <string, ClassMethodInfo> cmfDict)
    {
        string fullNamePrefix = type.Namespace + "." + type.Name + "." + "New";
        string newStr         = "New";

        ConstructorInfo[] ctorArray = type.GetConstructors(BindingFlags.Instance | BindingFlags);
        foreach (ConstructorInfo cInfo in ctorArray)
        {
            ClassMethodInfo ctorCmf = !cmfDict.ContainsKey(newStr) ? new ClassMethodInfo() : cmfDict[newStr];
            ctorCmf.fullName   = fullNamePrefix + newStr;
            ctorCmf.className  = GetTypeName(type);
            ctorCmf.name       = newStr;
            ctorCmf.returnName = GetTypeName(type);
            ctorCmf.isStatic   = true;
            cmfDict[newStr]    = ctorCmf;
            ctorCmf.overrideList.Add(DisposMethodArgs(cInfo.GetParameters()));
        }
    }
예제 #4
0
 public static void DisposProperties(System.Type type, Dictionary <string, ClassMethodInfo> cmfDict)
 {
     PropertyInfo[] array = type.GetProperties(BindingFlags | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
     foreach (PropertyInfo info in array)
     {
         string          key = type.Namespace + "." + type.Name + "." + info.Name;
         ClassMethodInfo cmf = !cmfDict.ContainsKey(key) ? new ClassMethodInfo() : cmfDict[key];
         cmf.fullName   = key;
         cmf.className  = GetTypeName(type);
         cmf.name       = info.Name;
         cmf.returnName = GetTypeName(info.PropertyType);
         cmf.isStatic   = false;
         cmf.isCanRead  = info.CanRead;
         cmf.isCanWrite = info.CanRead;
         cmf.isPf       = true;
         cmfDict[key]   = cmf;
     }
 }
예제 #5
0
 public static void DisposField(System.Type type, Dictionary <string, ClassMethodInfo> cmfDict)
 {
     FieldInfo[] array = type.GetFields(BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Instance | BindingFlags);
     foreach (FieldInfo info in array)
     {
         string          key = type.Namespace + "." + type.Name + "." + info.Name;
         ClassMethodInfo cmf = !cmfDict.ContainsKey(key) ? new ClassMethodInfo() : cmfDict[key];
         cmf.fullName   = key;
         cmf.className  = GetTypeName(type);
         cmf.name       = info.Name;
         cmf.returnName = GetTypeName(info.FieldType);
         cmf.isStatic   = info.IsStatic;
         cmf.isCanRead  = true;
         cmf.isCanWrite = true;
         cmf.isPf       = true;
         cmfDict[key]   = cmf;
     }
 }
예제 #6
0
    public void setProp(string property, List <object> values)
    {
        FieldInfo info = getPropInfoForAddress(property);

        if (info != null)
        {
            setFieldProp(info, values);
            return;
        }

        ClassMethodInfo mInfo = getMethodInfoForAddress(property);

        if (mInfo != null)
        {
            setMethodProp(mInfo, values);
            return;
        }
    }
예제 #7
0
파일: UIMaster.cs 프로젝트: Theoriz/GenUI
 private void CreateButton(Transform parent, Controllable target, ClassMethodInfo method)
 {
     //As we can't expose parameter in UI, ignore methods with arguments
     if (method.methodInfo.GetParameters().Length == 0)
     {
         var newButton = Instantiate(MethodButtonPrefab);
         newButton.transform.SetParent(parent);
         newButton.transform.SetSiblingIndex(parent.childCount - 2);
         parent.gameObject.GetComponent <PanelUI>().AddUIElement(newButton.GetComponent <ButtonUI>());
         newButton.GetComponent <ButtonUI>().CreateUI(target, method);
     }
     else
     {
         foreach (var parameter in method.methodInfo.GetParameters())
         {
             //Will do cool stuff in the future
         }
     }
 }
예제 #8
0
    public void setMethodProp(ClassMethodInfo info, List <object> values)
    {
        object[] parameters = new object[info.methodInfo.GetParameters().Length];

        if (debug)
        {
            Debug.Log("Set Method, num expected parameters : " + parameters.Length);
        }

        int valueIndex = 0;

        for (int i = 0; i < parameters.Length; i++)
        {
            string typeString = info.methodInfo.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] = TypeConverter.getFloat(values[valueIndex]);
                    valueIndex   += 1;
                }
            }
            else if (typeString == "System.Boolean")
            {
                if (values.Count >= valueIndex + 1)
                {
                    parameters[i] = TypeConverter.getBool(values[valueIndex]);
                    valueIndex   += 1;
                }
            }
            else if (typeString == "System.Int32")
            {
                if (values.Count >= valueIndex + 1)
                {
                    parameters[i] = TypeConverter.getInt(values[valueIndex]);
                    valueIndex   += 1;
                }
            }
            else if (typeString == "UnityEngine.Vector2")
            {
                if (values.Count >= valueIndex + 2)
                {
                    parameters[i] = new Vector2(TypeConverter.getFloat(values[valueIndex]), TypeConverter.getFloat(values[valueIndex + 1]));
                    valueIndex   += 2;
                }
            }
            else if (typeString == "UnityEngine.Vector2Int")
            {
                if (values.Count >= valueIndex + 2)
                {
                    parameters[i] = new Vector2Int(TypeConverter.getInt(values[valueIndex]), TypeConverter.getInt(values[valueIndex + 1]));
                    valueIndex   += 2;
                }
            }
            else if (typeString == "UnityEngine.Vector3")
            {
                if (values.Count >= valueIndex + 3)
                {
                    parameters[i] = new Vector3(TypeConverter.getFloat(values[valueIndex]), TypeConverter.getFloat(values[valueIndex + 1]), TypeConverter.getFloat(values[valueIndex + 2]));
                    valueIndex   += 3;
                }
            }
            else if (typeString == "UnityEngine.Vector3Int")
            {
                if (values.Count >= valueIndex + 3)
                {
                    parameters[i] = new Vector3Int(TypeConverter.getInt(values[valueIndex]), TypeConverter.getInt(values[valueIndex + 1]), TypeConverter.getInt(values[valueIndex + 2]));
                    valueIndex   += 3;
                }
            }
            else if (typeString == "UnityEngine.Color")
            {
                if (values.Count >= valueIndex + 4)
                {
                    parameters[i] = new Color(TypeConverter.getFloat(values[valueIndex + 0]), TypeConverter.getFloat(values[valueIndex + 1]), TypeConverter.getFloat(values[valueIndex + 2]), TypeConverter.getFloat(values[valueIndex + 3]));
                    valueIndex   += 4;
                }
                else if (values.Count >= i + 3)
                {
                    parameters[i] = new Color(TypeConverter.getFloat(values[valueIndex + 0]), TypeConverter.getFloat(values[valueIndex + 1]), TypeConverter.getFloat(values[valueIndex + 2]), 1);
                    valueIndex   += 3;
                }
            }
            else if (typeString == "System.String")
            {
                if (values.Count >= valueIndex + 1)
                {
                    parameters[i] = values[i].ToString();
                    valueIndex   += 1;
                }
            }
        }

        if (!info.fromTargetScript)
        {
            info.methodInfo.Invoke(this, parameters);
        }
        else
        {
            info.methodInfo.Invoke(TargetScript, parameters);
        }
    }
예제 #9
0
    public virtual void Awake()
    {
        debug = false;

        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>();

        FieldInfo[]    objectFields     = this.GetType().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);

                        PreviousFieldsValues.Add(newClassAttributInfo.GetValue(TargetScript));
                        info.SetValue(this, newClassAttributInfo.GetValue(TargetScript));
                        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);
                            PreviousFieldsValues.Add(newClassAttributInfo.GetValue(TargetScript));
                            info.SetValue(this, newClassAttributInfo.GetValue(TargetScript));

                            break;
                        }
                    }
                }

                // if(addedFieldName != "")
                //     PreviousFieldsValues.Add(TargetFields[addedFieldName].GetValue(this));
            }
        }

        //METHODS
        Methods = new Dictionary <string, ClassMethodInfo>();

        MethodInfo[] methodFields = this.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;
                }
                //Debug.Log("Testing : " + info.Name);

                var classMethodInfo = new ClassMethodInfo();
                classMethodInfo.methodInfo       = info;
                classMethodInfo.fromTargetScript = false;

                var targetScriptMethod = TargetScript.GetType().GetMethod(info.Name);
                if (targetScriptMethod != null)
                {
                    //Debug.Log("Adding : " + targetScriptMethod.Name);
                    classMethodInfo.methodInfo       = targetScriptMethod;
                    classMethodInfo.fromTargetScript = true;

                    Methods.Add(targetScriptMethod.Name, classMethodInfo);
                }
                else
                {
                    Methods.Add(info.Name, classMethodInfo);
                }
            }
        }

        if (string.IsNullOrEmpty(id))
        {
            id = TargetScript.GetType().Name;
        }

        id          = id.Replace(' ', '_');
        sourceScene = SceneManager.GetActiveScene().name;
    }