Exemplo n.º 1
0
        private void CreateElementEditor(MemberInfo memberInfo, Type type)
        {
            if (!m_editorsMap.IsPropertyEditorEnabled(type))
            {
                return;
            }
            GameObject editorPrefab = m_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, accessor.GetType().GetProperty("Value"), null, accessor.Name, OnValueChanging, OnValueChanged, null, false);
            }
        }
Exemplo n.º 2
0
        public void BuildEditor()
        {
            foreach (Transform t in EditorsPanel)
            {
                Destroy(t.gameObject);
            }

            IMaterialDescriptor selector;

            if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector))
            {
                selector = new MaterialDescriptor();
            }


            object converter = selector.CreateConverter(this);

            MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter);
            if (descriptors == null)
            {
                Destroy(gameObject);
                return;
            }

            for (int i = 0; i < descriptors.Length; ++i)
            {
                MaterialPropertyDescriptor descriptor = descriptors[i];
                PropertyEditor             editor     = null;
                PropertyInfo propertyInfo             = descriptor.PropertyInfo;

                RTShaderPropertyType propertyType = descriptor.Type;

                switch (propertyType)
                {
                case RTShaderPropertyType.Range:
                    if (RangeEditor != null)
                    {
                        RangeEditor range = Instantiate(RangeEditor);
                        range.transform.SetParent(EditorsPanel, false);

                        var rangeLimits = descriptor.Limits;
                        range.Min = rangeLimits.Min;
                        range.Max = rangeLimits.Max;
                        editor    = range;
                    }
                    break;

                default:
                    if (m_editorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                    {
                        GameObject editorPrefab = m_editorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                        GameObject instance     = Instantiate(editorPrefab);
                        instance.transform.SetParent(EditorsPanel, false);

                        if (instance != null)
                        {
                            editor = instance.GetComponent <PropertyEditor>();
                        }
                    }
                    break;
                }


                if (editor == null)
                {
                    continue;
                }

                editor.Init(descriptor.Target, descriptor.Accessor, propertyInfo, descriptor.EraseTargetCallback, descriptor.Label, null, descriptor.ValueChangedCallback, () =>
                {
                    m_editor.IsDirty = true;
                    UpdatePreview(Material);
                });
            }
        }
Exemplo n.º 3
0
 protected virtual void InitEditor(PropertyEditor editor, PropertyDescriptor descriptor)
 {
     editor.Init(descriptor.Target, descriptor.MemberInfo, descriptor.Label, null, descriptor.ValueChangedCallback, null, true, descriptor.ChildDesciptors);
 }
        public void BuildEditor()
        {
            foreach (Transform t in EditorsPanel)
            {
                Destroy(t.gameObject);
            }

            IMaterialDescriptor selector;

            if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector))
            {
                selector = new MaterialDescriptor();
            }


            object converter = selector.CreateConverter(this);

            MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter);
            if (descriptors == null)
            {
                Destroy(gameObject);
                return;
            }

            for (int i = 0; i < descriptors.Length; ++i)
            {
                MaterialPropertyDescriptor descriptor = descriptors[i];
                PropertyEditor             editor     = null;
                object       target       = descriptor.Target;
                PropertyInfo propertyInfo = descriptor.PropertyInfo;
#if !UNITY_WEBGL && PROC_MATERIAL
                if (descriptor.ProceduralDescription == null)
#endif
                {
                    RTShaderPropertyType propertyType = descriptor.Type;

                    switch (propertyType)
                    {
                    case RTShaderPropertyType.Range:
                        if (RangeEditor != null)
                        {
                            RangeEditor range = Instantiate(RangeEditor);
                            range.transform.SetParent(EditorsPanel, false);

                            var rangeLimits = descriptor.Limits;
                            range.Min = rangeLimits.Min;
                            range.Max = rangeLimits.Max;
                            editor    = range;
                        }
                        break;

                    default:
                        if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                        {
                            GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                            GameObject instance     = Instantiate(editorPrefab);
                            instance.transform.SetParent(EditorsPanel, false);

                            if (instance != null)
                            {
                                editor = instance.GetComponent <PropertyEditor>();
                            }
                        }
                        break;
                    }
                }
#if !UNITY_WEBGL && PROC_MATERIAL
                else
                {
                    ProcPropertyDescription input = descriptor.ProceduralDescription;
                    if (input.hasRange)
                    {
                        if (input.type == ProcPropertyType.Float)
                        {
                            if (RangeEditor != null)
                            {
                                RangeEditor range = Instantiate(RangeEditor);
                                range.transform.SetParent(EditorsPanel, false);
                                range.Min = input.minimum;
                                range.Max = input.maximum;
                                //TODO implement step on range editor // = input.step
                                editor = range;
                            }
                        }
                        else
                        {
                            //TODO: Implement range on vector editors

                            if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                            {
                                GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                                GameObject instance     = Instantiate(editorPrefab);
                                instance.transform.SetParent(EditorsPanel, false);

                                if (instance != null)
                                {
                                    editor = instance.GetComponent <PropertyEditor>();
                                }
                            }
                        }
                    }
                    else
                    {
                        //if(input.type == ProceduralPropertyType.Enum)
                        //TODO: Implement enum from string array editor. //input.enumOptions

                        if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                        {
                            GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                            GameObject instance     = Instantiate(editorPrefab);
                            instance.transform.SetParent(EditorsPanel, false);

                            if (instance != null)
                            {
                                editor = instance.GetComponent <PropertyEditor>();
                            }
                        }
                    }
                }
#endif

                if (editor == null)
                {
                    continue;
                }

                editor.Init(target, propertyInfo, descriptor.Label, null, descriptor.ValueChangedCallback, () =>
                {
                    RuntimeEditorApplication.SaveSelectedObjects();
                });
            }
        }
Exemplo n.º 5
0
 //Better name for this is InitPropertyEditor
 protected virtual void InitEditor(PropertyEditor editor, PropertyDescriptor descriptor)
 {
     editor.Init(descriptor.Targets, descriptor.Targets, descriptor.MemberInfo, null, descriptor.Label, null, () => { descriptor.ValueChangedCallback?.Invoke(); OnValueChanged(); }, () => { descriptor.EndEditCallback?.Invoke(); EndEditCallback?.Invoke(); OnEndEdit(); }, true, descriptor.ChildDesciptors, null, null, null, null, OnValueReloaded);
 }