예제 #1
0
    protected override void OnAlloyShaderEnable()
    {
        m_openCloseAnim = new Dictionary <string, AnimBool>();
        m_propInfo      = new Dictionary <MaterialProperty, AlloyFieldDrawer>();

        foreach (var property in MaterialProperties)
        {
            var drawer = AlloyFieldDrawerFactory.GetFieldDrawer(this, property);
            m_propInfo.Add(property, drawer);
        }

        var allTabs = new List <string>();

        foreach (var drawerProp in m_propInfo)
        {
            var drawer = drawerProp.Value;

            if (drawer is AlloyTabDrawer)
            {
                bool isOpenCur = TabGroup.IsOpen(drawer.DisplayName + MatInst);

                var anim = new AnimBool(isOpenCur)
                {
                    speed = 6.0f, value = isOpenCur
                };
                m_openCloseAnim.Add(drawerProp.Key.name, anim);

                allTabs.Add(drawer.DisplayName);
            }
        }

        m_allTabs = allTabs.ToArray();
        //m_menu = new GenericMenu();
        Undo.undoRedoPerformed += OnUndo;
    }
예제 #2
0
    protected override void OnAlloyShaderGUI(MaterialProperty[] properties)
    {
        //Refresh drawer structure if needed
        bool structuralChange = false;

        if (m_fieldDrawers == null || m_fieldDrawers.Length != properties.Length)
        {
            m_fieldDrawers   = new AlloyFieldDrawer[properties.Length];
            structuralChange = true;
        }

        //Rebuild name -> prop cache
        m_stringToProperty.Clear();
        for (int i = 0; i < properties.Length; ++i)
        {
            string propName = properties[i].name;
            m_stringToProperty.Add(propName, properties[i]);
        }

        for (int i = 0; i < properties.Length; ++i)
        {
            string propName = properties[i].name;

            if (m_fieldDrawers[i] == null && !s_knownNulls.Contains(propName) || m_fieldDrawers[i] != null && m_fieldDrawers[i].Property.name != propName)
            {
                m_fieldDrawers[i] = AlloyFieldDrawerFactory.GetFieldDrawer(this, properties[i]);

                if (m_fieldDrawers[i] == null)
                {
                    s_knownNulls.Add(propName);
                }
                else
                {
                    structuralChange = true;
                }
            }
        }

        //If changed, update the animation stuff
        if (structuralChange)
        {
            m_openCloseAnim.Clear();
            var allTabs = new List <string>();

            for (var i = 0; i < m_fieldDrawers.Length; i++)
            {
                var drawer = m_fieldDrawers[i];

                if (!(drawer is AlloyTabDrawer))
                {
                    continue;
                }

                bool isOpenCur = TabGroup.IsOpen(drawer.DisplayName + MatInst);

                var anim = new AnimBool(isOpenCur)
                {
                    speed = 6.0f, value = isOpenCur
                };
                m_openCloseAnim.Add(properties[i].name, anim);
                allTabs.Add(drawer.DisplayName);
            }

            m_allTabs = allTabs.ToArray();
        }


        //Formulate arguments to pass to drawing
        var args = new AlloyFieldDrawerArgs {
            Editor         = this,
            Materials      = Targets.Cast <Material>().ToArray(),
            PropertiesSkip = new List <string>(),
            MatInst        = MatInst,
            TabGroup       = TabGroup,
            AllTabNames    = m_allTabs,
            OpenCloseAnim  = m_openCloseAnim
        };

        for (var i = 0; i < m_fieldDrawers.Length; i++)
        {
            var drawer = m_fieldDrawers[i];

            if (drawer == null)
            {
                continue;
            }

            drawer.Index    = i;
            drawer.Property = properties[i];

            if (drawer.ShouldDraw(args))
            {
                drawer.Draw(args);
            }
        }

        if (!string.IsNullOrEmpty(args.CurrentTab))
        {
            EditorGUILayout.EndFadeGroup();
        }

        GUILayout.Space(10.0f);

        AlloyEditor.DrawAddTabGUI(args.TabsToAdd);

        //If animating -> Repaint
        foreach (var animBool in m_openCloseAnim)
        {
            if (animBool.Value.isAnimating)
            {
                MatEditor.Repaint();
                break;
            }
        }
    }