private void ResolveComponent(RuntimeAnimationProperty property, RuntimeAnimation target)
        {
            Type componentType = property.ComponentType;

            if (componentType == null)
            {
                return;
            }

            m_voidComponentEditor.Components = new[] { target.GetComponent(componentType) };

            PropertyDescriptor[] propertyDescriptors = m_editorsMap.GetPropertyDescriptors(componentType, m_voidComponentEditor);
            for (int i = 0; i < propertyDescriptors.Length; ++i)
            {
                PropertyDescriptor desc = propertyDescriptors[i];
                if (property.PropertyName == desc.MemberInfo.Name)
                {
                    property.Component = desc.Target;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        protected virtual void Start()
        {
            m_parentDialog = GetComponentInParent <Dialog>();
            if (m_parentDialog != null)
            {
                m_parentDialog.IsOkVisible = true;
            }

            HashSet <string> alreadyAddedHs = new HashSet <string>();

            RuntimeAnimationProperty[] alreadyAddedProperties = View.Props;
            for (int i = 0; i < alreadyAddedProperties.Length; ++i)
            {
                RuntimeAnimationProperty property = alreadyAddedProperties[i];
                alreadyAddedHs.Add(property.ComponentTypeName + " " + property.PropertyName);
            }

            MemberInfo enabledProperty = Strong.MemberInfo((Behaviour x) => x.enabled);

            List <RuntimeAnimationProperty> components = new List <RuntimeAnimationProperty>();
            IEditorsMap editorsMap = IOC.Resolve <IEditorsMap>();

            Type[] editableTypes = editorsMap.GetEditableTypes();
            for (int i = 0; i < editableTypes.Length; ++i)
            {
                Type editableType = editableTypes[i];
                if (!(typeof(Component).IsAssignableFrom(editableType)) || typeof(Component) == editableType)
                {
                    continue;
                }
                Component targetComponent = Target.GetComponent(editableType);
                if (targetComponent == null)
                {
                    continue;
                }
                m_voidComponentEditor.Components = new[] { targetComponent };

                RuntimeAnimationProperty component = new RuntimeAnimationProperty();
                component.ComponentDisplayName = editableType.Name;
                component.ComponentTypeName    = string.Format("{0},{1}", editableType.FullName, editableType.Assembly.FullName.Split(',')[0]);
                component.Children             = new List <RuntimeAnimationProperty>();
                component.Component            = m_voidComponentEditor.Components[0];

                PropertyDescriptor[] propertyDescriptors = editorsMap.GetPropertyDescriptors(editableType, m_voidComponentEditor);
                for (int j = 0; j < propertyDescriptors.Length; ++j)
                {
                    PropertyDescriptor propertyDescriptor = propertyDescriptors[j];
                    Type memberType = propertyDescriptor.MemberType;
                    if (memberType.IsClass || memberType.IsEnum || typeof(MonoBehaviour).IsAssignableFrom(editableType) && propertyDescriptor.MemberInfo is PropertyInfo)
                    {
                        continue;
                    }

                    if (alreadyAddedHs.Contains(component.ComponentTypeName + " " + propertyDescriptor.MemberInfo.Name))
                    {
                        continue;
                    }

                    RuntimeAnimationProperty property = new RuntimeAnimationProperty();
                    property.Parent               = component;
                    property.ComponentTypeName    = component.ComponentTypeName;
                    property.ComponentDisplayName = component.ComponentDisplayName;
                    property.PropertyName         = propertyDescriptor.MemberInfo.Name;
                    property.PropertyDisplayName  = propertyDescriptor.Label;

                    if (propertyDescriptor.MemberInfo.Name == enabledProperty.Name && propertyDescriptor.MemberInfo.DeclaringType == enabledProperty.DeclaringType)
                    {
                        property.AnimationPropertyName = "m_Enabled";
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(propertyDescriptor.AnimationPropertyName))
                        {
                            Type componentType = property.ComponentType;
                            if (typeof(Component).IsAssignableFrom(componentType) && !typeof(MonoBehaviour).IsAssignableFrom(componentType))
                            {
                                //Trying to derive serialized property name
                                string aPropName = propertyDescriptor.MemberInfo.Name;
                                property.AnimationPropertyName = "m_" + Char.ToUpper(aPropName[0]) + aPropName.Substring(1);
                            }
                            else
                            {
                                property.AnimationPropertyName = propertyDescriptor.MemberInfo.Name;
                            }
                        }
                        else
                        {
                            property.AnimationPropertyName = propertyDescriptor.AnimationPropertyName;
                        }
                    }

                    property.Component = propertyDescriptor.Target;


                    component.Children.Add(property);
                }

                if (component.Children.Count > 0)
                {
                    components.Add(component);
                }

                m_voidComponentEditor.Components = null;
            }

            m_propertiesTreeView.Items = components;
        }
Exemplo n.º 3
0
        public void BuildEditor()
        {
            IComponentDescriptor componentDescriptor = GetComponentDescriptor();

            if (componentDescriptor != null)
            {
                m_converter = componentDescriptor.CreateConverter(this);
            }

            PropertyDescriptor[] descriptors = m_editorsMap.GetPropertyDescriptors(Component.GetType(), this, m_converter);
            if (descriptors == null || descriptors.Length == 0)
            {
                if (ExpanderGraphics != null)
                {
                    ExpanderGraphics.SetActive(false);
                }

                return;
            }

            ISettingsComponent     settingsComponent = IOC.Resolve <ISettingsComponent>();
            BuiltInWindowsSettings settings;

            if (settingsComponent == null)
            {
                settings = BuiltInWindowsSettings.Default;
            }
            else
            {
                settings = settingsComponent.BuiltInWindowsSettings;
            }

            if (ResetButton != null)
            {
                ResetButton.gameObject.SetActive(componentDescriptor != null ?
                                                 componentDescriptor.GetHeaderDescriptor(m_editor).ShowResetButton :
                                                 settings.Inspector.ComponentEditor.ShowResetButton);
            }

            if (RemoveButton != null)
            {
                bool showRemoveButton = componentDescriptor != null?
                                        componentDescriptor.GetHeaderDescriptor(m_editor).ShowRemoveButton:
                                        settings.Inspector.ComponentEditor.ShowRemoveButton;

                if (showRemoveButton)
                {
                    bool canRemove = m_project == null || m_project.ToAssetItem(Component.gameObject) == null;
                    if (!canRemove)
                    {
                        showRemoveButton = false;
                    }
                }

                RemoveButton.gameObject.SetActive(showRemoveButton);
            }

            if (EnabledEditor != null && EnabledProperty != null)
            {
                EnabledEditor.gameObject.SetActive(componentDescriptor != null ?
                                                   componentDescriptor.GetHeaderDescriptor(m_editor).ShowEnableButton :
                                                   settings.Inspector.ComponentEditor.ShowEnableButton);
            }

            if (Expander == null)
            {
                BuildEditor(componentDescriptor, descriptors);
            }
            else
            {
                if (componentDescriptor != null ? !componentDescriptor.GetHeaderDescriptor(m_editor).ShowExpander : !settings.Inspector.ComponentEditor.ShowExpander)
                {
                    Expander.isOn    = true;
                    Expander.enabled = false;
                }

                if (Expander.isOn)
                {
                    if (ExpanderGraphics != null)
                    {
                        ExpanderGraphics.SetActive(componentDescriptor != null ? componentDescriptor.GetHeaderDescriptor(m_editor).ShowExpander : settings.Inspector.ComponentEditor.ShowExpander);
                    }
                    BuildEditor(componentDescriptor, descriptors);
                }
            }
        }