Example #1
0
    private static void FixGo(GameObject _go, ref bool _hasChange, bool _isRoot)
    {
        MonoBehaviour[] b = _go.GetComponents <MonoBehaviour>();

        foreach (MonoBehaviour bb in b)
        {
            if (bb is AddScript || bb is AddButtonListener)
            {
                continue;
            }

            string typeName = bb.GetType().FullName;

            if (typeName.IndexOf("UnityEngine") == -1)
            {
                AddScript ss = _go.AddComponent <AddScript>();

                ss.scriptName = typeName;

                List <AddAtt> list = new List <AddAtt>();

                FieldInfo[] ff = bb.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

                foreach (FieldInfo fff in ff)
                {
                    object[] yu = fff.GetCustomAttributes(false);

                    foreach (object ob in yu)
                    {
                        if (ob is SerializeField)
                        {
                            object vv = fff.GetValue(bb);

                            if (vv != null)
                            {
                                if (vv.GetType().BaseType == typeof(MonoBehaviour))
                                {
                                    Debug.LogError("SerializeField is a MonoBehaviour! go.name:" + _go.name + "   root.name:" + _go.transform.root.gameObject.name + "   FieldInfo.name:" + fff.Name);
                                }

                                AddAtt att = null;

                                try{
                                    att = new AddAtt(fff.Name, vv);
                                }catch (Exception e) {
                                    throw new Exception("error:" + e.ToString() + "   go:" + _go.name);
                                }

                                list.Add(att);
                            }
                        }
                    }
                }

                ss.atts = list.ToArray();

                AddButtonListener[] buttonListeners = _go.GetComponents <AddButtonListener>();

                List <AddButtonListener> list2 = new List <AddButtonListener>();

                for (int i = 0; i < buttonListeners.Length; i++)
                {
                    if (buttonListeners[i].scriptName == bb.name)
                    {
                        list2.Add(buttonListeners[i]);
                    }
                }

                ss.buttons = new Button[list2.Count];

                ss.buttonMethodNames = new string[list2.Count];

                for (int i = 0; i < list2.Count; i++)
                {
                    ss.buttons[i] = list2[i].button;

                    ss.buttonMethodNames[i] = list2[i].methodName;

                    GameObject.DestroyImmediate(list2[i], true);
                }

                GameObject.DestroyImmediate(bb, true);
                _hasChange = true;
            }
        }

        for (int i = 0; i < _go.transform.childCount; i++)
        {
            FixGo(_go.transform.GetChild(i).gameObject, ref _hasChange, false);
        }

        if (_isRoot && _hasChange)
        {
            _go.AddComponent <AddScriptRoot>();
        }
    }
Example #2
0
    private static void FixGoAtt(GameObject _go, MonoBehaviour _mono, AddScript _script, Dictionary <int, MonoBehaviour> _dic)
    {
        List <AddAtt> list = new List <AddAtt>();

        FieldInfo[] ff = _mono.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

        foreach (FieldInfo fff in ff)
        {
            object[] yu = fff.GetCustomAttributes(false);

            foreach (object ob in yu)
            {
                if (ob is SerializeField)
                {
                    object vv = fff.GetValue(_mono);

                    if (vv != null)
                    {
                        AddAtt att = null;

                        try{
                            att = new AddAtt(fff.Name, vv, _dic);
                        }catch (Exception e) {
                            throw new Exception("error:" + e.ToString() + "   go:" + _go.name);
                        }

                        list.Add(att);
                    }
                }
            }
        }

        _script.atts = list.ToArray();

        AddButtonListener[] buttonListeners = _go.GetComponents <AddButtonListener>();

        List <AddButtonListener> list2 = new List <AddButtonListener>();

        for (int i = 0; i < buttonListeners.Length; i++)
        {
            if (buttonListeners[i].scriptName == _mono.name)
            {
                list2.Add(buttonListeners[i]);
            }
        }

        _script.buttons = new Button[list2.Count];

        _script.buttonMethodNames = new string[list2.Count];

        for (int i = 0; i < list2.Count; i++)
        {
            _script.buttons[i] = list2[i].button;

            _script.buttonMethodNames[i] = list2[i].methodName;

            GameObject.DestroyImmediate(list2[i], true);
        }

        if (_mono is SuperScrollRect)
        {
            SuperScrollRect scroll = _mono as SuperScrollRect;

            _script.superScrollRectContent = scroll.content;

            _script.superScrollRectIsHorizontal = scroll.horizontal;

            _script.superScrollRectIsVertical = scroll.vertical;

            _script.superScrollRectMovementType = scroll.movementType;
        }

        GameObject.DestroyImmediate(_mono, true);
    }
Example #3
0
    private static void FixGo(GameObject _go, ref bool _hasChange)
    {
        MonoBehaviour[] b = _go.GetComponents <MonoBehaviour>();

        foreach (MonoBehaviour bb in b)
        {
            if (bb is AddScript || bb is AddButtonListener)
            {
                continue;
            }

            string typeName = bb.GetType().FullName;

            if (typeName.IndexOf("UnityEngine") == -1)
            {
                AddScript ss = _go.AddComponent <AddScript>();

                ss.scriptName = typeName;

                List <AddAtt> list = new List <AddAtt>();

                FieldInfo[] ff = bb.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

                foreach (FieldInfo fff in ff)
                {
                    object[] yu = fff.GetCustomAttributes(false);

                    foreach (object ob in yu)
                    {
                        if (ob is SerializeField)
                        {
                            object vv = fff.GetValue(bb);

                            AddAtt att = new AddAtt(fff.Name, vv);

                            list.Add(att);
                        }
                    }
                }

                ss.atts = list.ToArray();

                AddButtonListener[] buttonListeners = _go.GetComponents <AddButtonListener>();

                List <AddButtonListener> list2 = new List <AddButtonListener>();

                for (int i = 0; i < buttonListeners.Length; i++)
                {
                    if (buttonListeners[i].scriptName == bb.name)
                    {
                        list2.Add(buttonListeners[i]);
                    }
                }

                ss.buttons = new Button[list2.Count];

                ss.buttonMethodNames = new string[list2.Count];

                for (int i = 0; i < list2.Count; i++)
                {
                    ss.buttons[i] = list2[i].button;

                    ss.buttonMethodNames[i] = list2[i].methodName;

                    GameObject.DestroyImmediate(list2[i], true);
                }

                GameObject.DestroyImmediate(bb, true);
                _hasChange = true;
            }
        }

        for (int i = 0; i < _go.transform.childCount; i++)
        {
            FixGo(_go.transform.GetChild(i).gameObject, ref _hasChange);
        }
    }