Exemplo n.º 1
0
        protected override void InitOverride(object target, MemberInfo memberInfo, string label = null)
        {
            Type elementType = null;

            if (memberInfo is PropertyInfo)
            {
                elementType = ((PropertyInfo)memberInfo).PropertyType.GetElementType();
                if (elementType == null)
                {
                    if (((PropertyInfo)memberInfo).PropertyType.IsGenericType)
                    {
                        elementType = ((PropertyInfo)memberInfo).PropertyType.GetGenericArguments()[0];
                    }
                }
            }
            else if (memberInfo is FieldInfo)
            {
                elementType = ((FieldInfo)memberInfo).FieldType.GetElementType();
                if (elementType == null)
                {
                    if (((FieldInfo)memberInfo).FieldType.IsGenericType)
                    {
                        elementType = ((FieldInfo)memberInfo).FieldType.GetGenericArguments()[0];
                    }
                }
            }



            if (elementType != null)
            {
                GameObject editor = EditorsMap.GetPropertyEditor(elementType);
                if (EditorsMap.IsPropertyEditorEnabled(elementType))
                {
                    m_editorPrefab = editor.GetComponent <PropertyEditor>();
                }

                if (m_editorPrefab == null)
                {
                    Debug.LogWarning("Editor for " + memberInfo.Name + " not found");
                    Destroy(gameObject);
                }

                base.InitOverride(target, memberInfo, label);
            }
            else
            {
                if (elementType == null)
                {
                    Debug.LogWarning("Editor for " + memberInfo.Name + " not found");
                    Destroy(gameObject);
                }
            }

            if (StartExpanded)
            {
                Expander.isOn = GetValue().Count < 8;
            }
        }
Exemplo n.º 2
0
        private void CreateElementEditor(MemberInfo memberInfo, Type type)
        {
            if (!EditorsMap.IsPropertyEditorEnabled(type))
            {
                return;
            }
            GameObject editorPrefab = EditorsMap.GetPropertyEditor(type);

            if (editorPrefab == null)
            {
                return;
            }
            PropertyEditor editor = Instantiate(editorPrefab).GetComponent <PropertyEditor>();

            if (editor == null)
            {
                return;
            }

            CustomTypeFieldAccessor accessor = null;

            if (ChildDescriptors == null)
            {
                accessor = new CustomTypeFieldAccessor(this, memberInfo, memberInfo.Name);
            }
            else
            {
                PropertyDescriptor childPropertyDescriptor;
                if (ChildDescriptors.TryGetValue(memberInfo, out childPropertyDescriptor))
                {
                    accessor = new CustomTypeFieldAccessor(
                        this,
                        childPropertyDescriptor.MemberInfo, childPropertyDescriptor.Label);
                }
            }
            if (accessor != null)
            {
                editor.transform.SetParent(Panel, false);
                editor.Init(accessor, accessor.GetType().GetProperty("Value"), accessor.Name, OnValueChanging, OnValueChanged, null, false);
            }
        }
Exemplo n.º 3
0
        private PropertyEditor InstantiatePropertyEditor(PropertyDescriptor descriptor)
        {
            if (descriptor.MemberInfo == null)
            {
                Debug.LogError("desciptor.MemberInfo is null");
                return(null);
            }

            if (descriptor.MemberType == null)
            {
                Debug.LogError("descriptor.MemberType is null");
                return(null);
            }

            GameObject editorGo = EditorsMap.GetPropertyEditor(descriptor.MemberType);

            if (editorGo == null)
            {
                return(null);
            }

            if (!EditorsMap.IsPropertyEditorEnabled(descriptor.MemberType))
            {
                return(null);
            }
            PropertyEditor editor = editorGo.GetComponent <PropertyEditor>();

            if (editor == null)
            {
                Debug.LogErrorFormat("editor {0} is not PropertyEditor", editorGo);
                return(null);
            }
            PropertyEditor instance = Instantiate(editor);

            instance.transform.SetParent(EditorsPanel, false);
            return(instance);
        }