Esempio n. 1
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        int current = (int)Property.floatValue;
        var label   = new GUIContent(DisplayName);

        BeginMaterialProperty(Property);

        int newVal = EditorGUILayout.Popup(label, current, DropOptions.Select(option => new GUIContent(option.Name)).ToArray());

        EditorGUI.showMixedValue = false;

        if (!OnSetOption(newVal, args) && EditorGUI.EndChangeCheck())
        {
            Property.floatValue = newVal;
            MaterialEditor.ApplyMaterialPropertyDrawers(args.Materials);
        }

        MatEditor.EndAnimatedCheck();
        args.PropertiesSkip.AddRange(DropOptions[current].HideFields);
    }
Esempio n. 2
0
    protected override void OnAlloyShaderGUI()
    {
        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
        };

        foreach (var animBool in m_openCloseAnim)
        {
            if (animBool.Value.isAnimating)
            {
                MatEditor.Repaint();
            }
        }

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

            if (drawer != null && drawer.ShouldDraw(args))
            {
                drawer.Draw(args);
            }
        }

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

        GUILayout.Space(10.0f);
        AlloyEditor.DrawAddTabGUI(args.TabsToAdd);
    }
Esempio n. 3
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;
            }
        }
    }
Esempio n. 4
0
 void OnUndo()
 {
     MatEditor.Repaint();
 }