Exemple #1
0
        public object OnGUI(string label, object value, System.Type type, out bool isDirty)
        {
            AnyType anyType;
            var     currentType = value == null ? baseType : IL.Help.GetInstanceType(value);

            if (currentType == baseType)
            {
                anyType = (AnyType)selfTypeGUI;
            }
            else
            {
                anyType = (AnyType)TypeEditor.Get(currentType, null);
            }

            value = anyType.OnGUI(label, value, currentType, out isDirty);
            if (anyType.GetFoldout(value))
            {
                using (new IndentLevel())
                {
                    if (ShowTypeSelect(ref value, label, "OnGUI." + (value == null ? "null" : value.GetHashCode().ToString())))
                    {
                        isDirty = true;
                    }
                }
            }

            return(value);
        }
Exemple #2
0
        protected void Reset(string elementType, int arrayCount, bool isListType)
        {
            this.arrayCount  = arrayCount;
            this.elementType = elementType;
            this.isListType  = isListType;
            if (isListType)
            {
                fullTypeName = $"List<{elementType}>";
                for (int i = 0; i < arrayCount - 1; ++i)
                {
                    fullTypeName = $"List<{fullTypeName}>";
                }
            }
            else
            {
                fullTypeName = elementType;
                for (int i = 0; i < arrayCount; ++i)
                {
                    fullTypeName += "[]";
                }
            }

            if (arrayCount == 1)
            {
                typeElement    = IL.Help.GetTypeByFullName(elementType);
                elementTypeGUI = TypeEditor.Get(typeElement, null);
            }
            else
            {
                elementTypeGUI = new ArrayListHot(elementType, arrayCount - 1, isListType);
            }
        }
Exemple #3
0
        public bool AutoSetValue(object value, FieldInfo fieldInfo, GameObject root)
        {
            object vv = fieldInfo.GetValue(value);

            if (vv == null)
            {
                return(false);
            }

            var r = ObjectType.GetFind(root.transform, fieldInfo.Name, typeof(GameObject)) as GameObject;

            if (r == null)
            {
                r = root;
            }

            bool isDirty = false;

            for (int i = 0; i < infos.Count; ++i)
            {
                var field = infos[i];
                isDirty |= TypeEditor.Get(field.FieldType, field).AutoSetValue(vv, field, r);
            }

            return(isDirty);
        }
Exemple #4
0
        public DictionaryTypeEditor(System.Type type, FieldInfo fieldInfo)
        {
            this.type = type;
            IL.Help.GetDictionaryKVType(type, fieldInfo, out keyType, out valueType);

            keyTypeGUI     = TypeEditor.Get(keyType, null);
            valueTypeGUI   = TypeEditor.Get(valueType, null);
            this.fieldInfo = fieldInfo;
        }
Exemple #5
0
        bool ShowTypeSelect(ref object value, string label, string key)
        {
            bool   isDirty = false;
            bool   isSet   = false;
            string newTypename;

            using (new GUIColor(Color.cyan))
            {
                var typeName = GetKey(key);
                if (string.IsNullOrEmpty(typeName) && value != null)
                {
                    typeName = IL.Help.GetInstanceType(value).FullName;
                }

                if (value != null)
                {
                    UnityEditor.EditorGUILayout.LabelField("当前类型:" + IL.Help.GetInstanceType(value).FullName);
                }

                UnityEditor.EditorGUILayout.BeginHorizontal();
                newTypename = IL.Editor.ILMonoEditor.StringPopupT($"设置{label}类型", typeName, allTypes, (System.Type t) => { return(t == null ? "null" : t.FullName); }, "");
                SetKey(key, newTypename);
                if (newTypename == "null")
                {
                    newTypename = string.Empty;
                }
                isSet = GUILayout.Button("设置");
                UnityEditor.EditorGUILayout.EndHorizontal();
            }

            if (isSet)
            {
                var newInstance = string.IsNullOrEmpty(newTypename) ? null : IL.Help.Create(IL.Help.GetTypeByFullName(newTypename));
                if (value != null && newInstance != null)
                {
                    // 赋值下
                    SetValue(newInstance, value);
                }

                if (newInstance != null)
                {
                    var te = TypeEditor.Get(IL.Help.GetInstanceType(newInstance), null);
                    if (te is AnyType)
                    {
                        ((AnyType)te).SetFoldout(newInstance, true);
                    }
                }

                value   = newInstance;
                isDirty = true;
            }

            return(isDirty);
        }
Exemple #6
0
        public object OnGUI(string label, object value, System.Type type, out bool isDirty)
        {
            var current = value;

            if (current != null)
            {
                int hashcode  = current.GetHashCode();
                var isFoldout = false;
                if (!isFoldouts.TryGetValue(hashcode, out isFoldout))
                {
                    isFoldouts.Add(hashcode, isFoldout);
                }

                try
                {
                    UnityEditor.EditorGUILayout.BeginHorizontal();
                    isFoldout = UnityEditor.EditorGUILayout.Foldout(isFoldout, label);
                    if (copyRoot != null && GUILayout.Button("复制初始化"))
                    {
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        GameObject root = copyRoot.GetValue(current) as GameObject;
                        if (root != null)
                        {
                            sb.AppendLine("var rt = root.transform;");
                            sb.AppendLine("Transform rtm = null;");
                            foreach (var d in infos)
                            {
                                if (d.Name == "root")
                                {
                                    continue;
                                }

                                if (isInherited(d.FieldType, typeof(Component)))
                                {
                                    Component v = (Component)d.GetValue(current);
                                    if (v != null)
                                    {
                                        if (d.FieldType == typeof(Transform))
                                        {
                                            sb.AppendFormat("{0} = (rtm = rt.Find(\"{0}\")) == null ? null : rtm;", d.Name, GetPath(root, v.gameObject));
                                        }
                                        else if (d.FieldType == typeof(RectTransform))
                                        {
                                            sb.AppendFormat("{0} = (rtm = rt.Find(\"{0}\")) == null ? null : (RectTransform)rtm;", d.Name, GetPath(root, v.gameObject));
                                        }
                                        else
                                        {
                                            sb.AppendFormat("{0} = (rtm = rt.Find(\"{1}\")) == null ? null : rtm.GetComponent<{2}>();", d.Name, GetPath(root, v.gameObject), d.FieldType.Name);
                                        }

                                        sb.AppendLine();
                                    }
                                }
                                else if (d.FieldType == typeof(GameObject))
                                {
                                    GameObject v = (GameObject)d.GetValue(current);
                                    if (v != null)
                                    {
                                        sb.AppendFormat("{0} = (rtm = rt.Find(\"{1}\")) == null ? null : rtm.gameObject;", d.Name, GetPath(root, v.gameObject), d.FieldType.Name);
                                        sb.AppendLine();
                                    }
                                }
                            }

                            GUIUtility.systemCopyBuffer = sb.ToString();
                            wxb.L.Log(sb.ToString());
                        }
                    }
                }
                finally
                {
                    UnityEditor.EditorGUILayout.EndHorizontal();
                }

                isFoldouts[hashcode] = isFoldout;
                if (!isFoldout)
                {
                    isDirty = false;
                    return(false);
                }
            }

            isDirty = false;
            if (value == null)
            {
                value   = IL.Help.Create(type);
                isDirty = true;
            }

            for (int i = 0; i < infos.Count; ++i)
            {
                var    field = infos[i];
                object v     = null;
                try
                {
                    v = field.GetValue(value);
                }
                catch (System.Exception ex)
                {
                    wxb.L.LogException(ex);
                }
                if (v == null && (!IL.Help.isType(field.FieldType, typeof(Object))))
                {
                    v = IL.Help.Create(field.FieldType);
                    field.SetValue(value, v);
                    isDirty = true;
                }

                isDirty |= TypeEditor.Get(field.FieldType, field).OnGUI(value, field);
            }

            return(value);
        }
Exemple #7
0
 public RefTypeEditor(System.Type type)
 {
     this.type = type;
     typeGUI   = TypeEditor.Get(type, null);
 }