Ejemplo n.º 1
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        Vector4 newVal = Vector4.zero;
        var     label  = new GUIContent(DisplayName);

        BeginMaterialProperty(Property);

        switch (Mode)
        {
        case VectorMode.Vector4:
            newVal = EditorGUILayout.Vector4Field(label.text, Property.vectorValue);
            break;

        case VectorMode.Vector3:
            newVal = EditorGUILayout.Vector3Field(label.text, Property.vectorValue);
            break;

        case VectorMode.Vector2:
            newVal = EditorGUILayout.Vector2Field(label.text, Property.vectorValue);
            break;

        case VectorMode.Euler:
            var value = args.Editor.GetMaterialProperty(Property.name + "EulerUI").vectorValue;
            //var value = (Vector4)args.Editor.GetProperty(MaterialProperty.PropType.Vector, Property.name + "EulerUI").colorValue;
            newVal      = Quaternion.Euler(value) * Vector3.up;
            GUI.changed = true;
            break;
        }

        if (EndMaterialProperty())
        {
            Property.vectorValue = newVal;
        }
    }
Ejemplo n.º 2
0
    private void TextureField(float size, SerializedProperty prop, AlloyFieldDrawerArgs args)
    {
        var rawRef = prop.objectReferenceValue;

        GUILayoutOption[] layout = new GUILayoutOption[2];

        if (rawRef == null &&
            !prop.hasMultipleDifferentValues &&
            (!IsOpen || m_hasParentTexture))
        {
            layout[0] = GUILayout.Width(100.0f);
            layout[1] = GUILayout.Height(16.0f);
        }
        else
        {
            layout[0] = GUILayout.Width(size - 20.0f);
            layout[1] = GUILayout.Height((size - 20.0f) * 0.9f);
        }

        EditorGUI.BeginProperty(new Rect(), null, prop);
        EditorGUI.BeginChangeCheck();

        var tex = EditorGUILayout.ObjectField(rawRef, typeof(Texture), false, layout);

        if (EditorGUI.EndChangeCheck())
        {
            prop.objectReferenceValue = tex;
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 3
0
    protected override bool OnSetOption(int newOption, AlloyFieldDrawerArgs args)
    {
        base.OnSetOption(newOption, args);

        foreach (var material in args.Materials)
        {
            if (Property.floatValue != newOption)
            {
                foreach (var setting in BlendModeOptionConfigs)
                {
                    var keyword = setting.Keyword;

                    if (newOption != setting.Type)
                    {
                        material.DisableKeyword(keyword);
                    }
                    else
                    {
                        material.SetOverrideTag("RenderType", setting.OverrideTag);
                        material.SetInt("_SrcBlend", (int)setting.SrcBlend);
                        material.SetInt("_DstBlend", (int)setting.DstBlend);
                        material.SetInt("_ZWrite", setting.ZWrite);
                        material.EnableKeyword(keyword);
                        material.renderQueue = setting.RenderQueue;
                    }
                }

                material.SetInt(Property.name, newOption);
                EditorUtility.SetDirty(material);
            }
        }

        Undo.RecordObjects(args.Materials, "set " + Property.name);
        return(true);
    }
Ejemplo n.º 4
0
 protected void SetAllTabsOpenedTo(bool open, AlloyFieldDrawerArgs args)
 {
     foreach (var tab in args.AllTabNames)
     {
         args.TabGroup.SetOpen(tab + args.MatInst, open);
     }
 }
Ejemplo n.º 5
0
 public void MaterialPropField(string displayName, AlloyFieldDrawerArgs args)
 {
     if (Property != null)
     {
         args.Editor.MatEditor.DefaultShaderProperty(Property, displayName);
     }
 }
Ejemplo n.º 6
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        bool current = Serialized.floatValue > 0.5f;
        var  label   = new GUIContent(DisplayName);

        EditorGUI.BeginProperty(new Rect(), label, Serialized);
        EditorGUI.BeginChangeCheck();
        current = EditorGUILayout.Toggle(label, current);

        if (EditorGUI.EndChangeCheck())
        {
            Serialized.floatValue = current ? 1.0f : 0.0f;
            Property.floatValue   = current ? 1.0f : 0.0f;
        }

        EditorGUI.EndProperty();

        if (!current)
        {
            if (OffHideFields != null)
            {
                args.PropertiesSkip.AddRange(OffHideFields);
            }
        }
        else
        {
            if (OnHideFields != null)
            {
                args.PropertiesSkip.AddRange(OnHideFields);
            }
        }
    }
Ejemplo n.º 7
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        Vector4 newVal = Serialized.colorValue;
        var     label  = new GUIContent(DisplayName);


        EditorGUI.BeginProperty(new Rect(), label, Serialized);
        EditorGUI.BeginChangeCheck();



        GUILayout.BeginHorizontal();
        GUILayout.Label(label);


        newVal.x = GUILayout.Toggle(newVal.x > 0.5f, "R", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.y = GUILayout.Toggle(newVal.y > 0.5f, "G", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.z = GUILayout.Toggle(newVal.z > 0.5f, "B", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.w = GUILayout.Toggle(newVal.w > 0.5f, "A", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        GUILayout.EndHorizontal();


        if (EditorGUI.EndChangeCheck())
        {
            Serialized.colorValue = newVal;
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 8
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        bool current = Property.floatValue > 0.5f;

        DrawNow(args, true);

        if (!current)
        {
            if (HideFields != null)
            {
                args.PropertiesSkip.AddRange(HideFields);
            }
        }
    }
Ejemplo n.º 9
0
 public override void Draw(AlloyFieldDrawerArgs args) {
     args.Editor.MatEditor.LightmapEmissionProperty();
     
     foreach (var material in args.Materials) {
         // Setup lightmap emissive flags
         MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
         if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0) {
             flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
             
         
             material.globalIlluminationFlags = flags;
         }
     }
 }
Ejemplo n.º 10
0
    protected override bool OnSetOption(int newOption, AlloyFieldDrawerArgs args)
    {
        base.OnSetOption(newOption, args);
        SpeedTreeGeometryType newMode = (SpeedTreeGeometryType)newOption;
        bool setVal = true;

        if (!string.IsNullOrEmpty(RenderQueueOrderField))
        {
            SerializedProperty custom = args.Editor.GetProperty(MaterialProperty.PropType.Float, RenderQueueOrderField);

            if (custom.floatValue > 0.5f)
            {
                setVal = false;
            }
        }

        for (int i = 0; i < args.Materials.Length; i++)
        {
            var material = args.Materials[i];

            for (int j = 0; j < s_speedTreeKeywordSettings.Length; j++)
            {
                SpeedTreeKeywordSetting setting = s_speedTreeKeywordSettings[j];
                string keyword = setting.Keyword;

                if (newMode != setting.GeometryType)
                {
                    material.DisableKeyword(keyword);
                }
                else
                {
                    material.EnableKeyword(keyword);

                    if (setVal)
                    {
                        material.renderQueue = setting.RenderQueue;
                    }
                }
            }

            material.SetInt("_GeometryType", (int)newMode);
            EditorUtility.SetDirty(material);
        }

        Undo.RecordObjects(args.Materials, "Set geometry type");
        return(true);
    }
Ejemplo n.º 11
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        args.Editor.MatEditor.LightmapEmissionProperty();

        foreach (var material in args.Materials)
        {
            // Setup lightmap emissive flags
            MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
            if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
            {
                flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;


                material.globalIlluminationFlags = flags;
            }
        }
    }
Ejemplo n.º 12
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        float sortOrder = Serialized.floatValue - PostAlphaTestQueue;

        // Snap to integers.
        EditorGUI.BeginChangeCheck();
        sortOrder = (int)EditorGUILayout.Slider(DisplayName, sortOrder, 0, 20, GUILayout.MinWidth(20.0f));

        if (EditorGUI.EndChangeCheck())
        {
            Serialized.floatValue = sortOrder + PostAlphaTestQueue;

            foreach (var material in args.Materials)
            {
                material.renderQueue = (int)Serialized.floatValue;
            }
        }
    }
Ejemplo n.º 13
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        TexInst = args.MatInst;

        bool isOpen = TabGroup.Foldout(DisplayName, SaveName, GUILayout.Width(10.0f));

        m_tabOpen.target = isOpen;

        if (m_tabOpen.value)
        {
            EditorGUILayout.BeginFadeGroup(m_tabOpen.faded);
            DrawTextureControls(args);
            EditorGUILayout.EndFadeGroup();
        }

        if (m_tabOpen.isAnimating)
        {
            args.Editor.MatEditor.Repaint();
        }
    }
Ejemplo n.º 14
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        int current = (int)Serialized.floatValue;
        var label   = new GUIContent(DisplayName);

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


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

        EditorGUI.EndProperty();

        args.PropertiesSkip.AddRange(DropOptions[current].HideFields);
    }
Ejemplo n.º 15
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);
    }
Ejemplo n.º 16
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        Vector4 newVal = Property.vectorValue;
        var     label  = new GUIContent(DisplayName);

        BeginMaterialProperty(Property);

        GUILayout.BeginHorizontal();
        GUILayout.Label(label);

        newVal.x = GUILayout.Toggle(newVal.x > 0.5f, "R", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.y = GUILayout.Toggle(newVal.y > 0.5f, "G", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.z = GUILayout.Toggle(newVal.z > 0.5f, "B", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.w = GUILayout.Toggle(newVal.w > 0.5f, "A", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        GUILayout.EndHorizontal();

        if (EndMaterialProperty())
        {
            Property.vectorValue = newVal;
        }
    }
Ejemplo n.º 17
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);
    }
Ejemplo n.º 18
0
 public override void Draw(AlloyFieldDrawerArgs args)
 {
     if (HasMin || HasMax)
     {
         if (HasMin && HasMax)
         {
             FloatFieldSlider(DisplayName, MinValue, MaxValue);
         }
         else if (HasMin)
         {
             FloatFieldMin(DisplayName, MinValue);
         }
         else
         {
             FloatFieldMax(DisplayName, MaxValue);
         }
     }
     else
     {
         PropField(DisplayName);
     }
 }
Ejemplo n.º 19
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        bool current = Property.floatValue > 0.5f;
        var  label   = new GUIContent(DisplayName);


        //EditorGUI.BeginProperty(new Rect(), label, Serialized);

        EditorGUI.showMixedValue = Property.hasMixedValue;

        EditorGUI.BeginChangeCheck();
        current = EditorGUILayout.Toggle(label, current);

        if (EditorGUI.EndChangeCheck())
        {
            Property.floatValue = current ? 1.0f : 0.0f;
            MaterialEditor.ApplyMaterialPropertyDrawers(args.Materials);
        }

        //EditorGUI.EndProperty();

        EditorGUI.showMixedValue = false;


        if (!current)
        {
            if (OffHideFields != null)
            {
                args.PropertiesSkip.AddRange(OffHideFields);
            }
        }
        else
        {
            if (OnHideFields != null)
            {
                args.PropertiesSkip.AddRange(OnHideFields);
            }
        }
    }
Ejemplo n.º 20
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        Vector4 newVal = Vector4.zero;
        var     label  = new GUIContent(DisplayName);

        EditorGUI.BeginProperty(new Rect(), label, Serialized);
        EditorGUI.BeginChangeCheck();

        switch (Mode)
        {
        case VectorMode.Vector4:
            newVal = EditorGUILayout.Vector4Field(label.text, Serialized.colorValue);
            break;


        case VectorMode.Vector3:
            newVal = EditorGUILayout.Vector3Field(label.text, (Vector4)Serialized.colorValue);
            break;

        case VectorMode.Vector2:
            newVal = EditorGUILayout.Vector2Field(label.text, (Vector4)Serialized.colorValue);
            break;

        case VectorMode.Euler:
            var value =
                (Vector4)args.Editor.GetProperty(MaterialProperty.PropType.Vector, Property.name + "EulerUI").colorValue;
            newVal      = Quaternion.Euler(value) * Vector3.up;
            GUI.changed = true;
            break;
        }

        if (EditorGUI.EndChangeCheck())
        {
            Serialized.colorValue = newVal;
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 21
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        m_inst = args.MatInst;

        bool isOpen = m_tabGroup.Foldout(DisplayName, SaveName, GUILayout.Width(10.0f));

        m_tabOpen.target = isOpen;

        if (m_tabOpen.value)
        {
            EditorGUILayout.BeginFadeGroup(m_tabOpen.faded);
            AlloyGUI.Vector2Field(Serialized, "Tiling", true);
            AlloyGUI.Vector2Field(Serialized, "Offset", false);


            AlloyTextureFieldDrawer.DrawTextureControls(m_scrollProp, m_spinProp, m_uvProp);
            EditorGUILayout.EndFadeGroup();
        }

        if (m_tabOpen.isAnimating)
        {
            args.Editor.MatEditor.Repaint();
        }
    }
Ejemplo n.º 22
0
 public override bool ShouldDraw(AlloyFieldDrawerArgs args)
 {
     return(true);
 }
Ejemplo n.º 23
0
 public override void Draw(AlloyFieldDrawerArgs args)
 {
     DrawNow(args, false);
 }
Ejemplo n.º 24
0
    protected void DrawNow(AlloyFieldDrawerArgs args, bool optional)
    {
        var firstDrawer = Index == 0;
        var firstTab    = string.IsNullOrEmpty(args.CurrentTab);

        if (firstDrawer)
        {
            GUILayout.Space(-10.0f);
        }
        else if (firstTab)
        {
            GUILayout.Space(5.0f);
        }
        else
        {
            if (args.DoDraw)
            {
                GUILayout.Space(8.0f);
            }

            EditorGUILayout.EndFadeGroup();
        }

        if (!optional || args.Editor.TabIsEnabled(Property))
        {
            bool open;

            if (firstTab && !optional)
            {
                bool openAll = args.AllTabNames.All(tab => args.TabGroup.IsOpen(tab + args.MatInst));
                bool closeOpen;
                bool all = openAll;

                open = args.TabGroup.TabArea(DisplayName, Color, true, m_foldoutAction(all), out closeOpen, DisplayName + args.MatInst);

                if (closeOpen)
                {
                    openAll = !openAll;
                    SetAllTabsOpenedTo(openAll, args);
                }
            }
            else
            {
                bool removed;
                open = args.TabGroup.TabArea(DisplayName, Color, optional, out removed, DisplayName + args.MatInst);

                if (removed)
                {
                    args.Editor.DisableTab(DisplayName, Property, args.MatInst);
                }
            }

            var anim = args.OpenCloseAnim[Property.name];
            anim.target = open;

            args.CurrentTab = Property.name;
            args.DoDraw     = EditorGUILayout.BeginFadeGroup(anim.faded);
        }
        else
        {
            args.DoDraw = false;

            args.TabsToAdd.Add(new AlloyTabAdd {
                Color = Color, Name = DisplayName, Enable = () => args.Editor.EnableTab(DisplayName, Property, args.MatInst)
            });
        }
    }
Ejemplo n.º 25
0
 protected virtual bool OnSetOption(int newOption, AlloyFieldDrawerArgs args) {
     return false;
 }
Ejemplo n.º 26
0
    public override void Draw(AlloyFieldDrawerArgs args) {
        m_inst = args.MatInst;

        if (m_firstDraw) {
            OnFirstDraw();
            m_firstDraw = false;
        }

        var texture = Serialized.FindPropertyRelative(TextureProp);
        var curTex = texture.objectReferenceValue as Texture;

        GUILayout.Space(9.0f);

        GUILayout.BeginHorizontal();

        EditorGUILayout.BeginVertical();

        float oldWidth = EditorGUIUtility.labelWidth;
        EditorGUIUtility.labelWidth = 80.0f;

        bool drewOpen = false;

        if (m_hasParentTexture || !Controls) {
            GUILayout.Label(DisplayName);
        } else {
            bool isOpen = m_tabGroup.Foldout(DisplayName, SaveName, GUILayout.Width(10.0f));
            m_tabOpen.target = isOpen;

            if (EditorGUILayout.BeginFadeGroup(m_tabOpen.faded)) {				
                drewOpen = true;				
                AlloyGUI.Vector2Field(m_scale, "Tiling");
                AlloyGUI.Vector2Field(m_offset, "Offset");
                DrawTextureControls(m_velocityProp, m_spinProp, m_uvProp);
            }

            EditorGUILayout.EndFadeGroup();
    
        }

        if ((EditorGUILayout.BeginFadeGroup(1.0f - m_tabOpen.faded)
                || !Controls)
            && curTex != null
            && !texture.hasMultipleDifferentValues) {

            if (!DrawWarningString(texture)) {
                var oldCol = GUI.color;
                GUI.color = EditorGUIUtility.isProSkin ? Color.gray : new Color(0.3f, 0.3f, 0.3f);

                string name = curTex.name;
                if (name.Length > 17) {
                    name = name.Substring(0, 14) + "..";
                }
                GUILayout.Label(name + " (" + curTex.width + "x" + curTex.height + ")", EditorStyles.whiteLabel);
                GUI.color = oldCol;
            }
        }

        EditorGUILayout.EndFadeGroup();

        if (curTex != null
            && (!m_hasParentTexture || Controls)
            && !texture.hasMultipleDifferentValues) {
            DrawVisualizeButton();
        }

        if (drewOpen) {
            EditorGUILayout.EndVertical();
            TextureField(Mathf.Lerp(74.0f, 100.0f, m_tabOpen.faded), texture, args);
        }
        else {
            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();
            TextureField(74.0f, texture, args);
        }

        EditorGUIUtility.labelWidth = oldWidth;
        GUILayout.EndHorizontal();

        if (IsOpen) {
            GUILayout.Space(10.0f);
        }

        if (m_tabOpen.isAnimating) {
            args.Editor.MatEditor.Repaint();
        }
    }
Ejemplo n.º 27
0
 public abstract void Draw(AlloyFieldDrawerArgs args);
Ejemplo n.º 28
0
 protected virtual bool OnSetOption(int newOption, AlloyFieldDrawerArgs args)
 {
     return(false);
 }
Ejemplo n.º 29
0
 public virtual bool ShouldDraw(AlloyFieldDrawerArgs args)
 {
     return(args.DoDraw && !args.PropertiesSkip.Contains(Property.name));
 }
Ejemplo n.º 30
0
 public abstract void Draw(AlloyFieldDrawerArgs args);
Ejemplo n.º 31
0
 public override void Draw(AlloyFieldDrawerArgs args) {
     DrawNow(args, false);
 }
Ejemplo n.º 32
0
    protected void DrawNow(AlloyFieldDrawerArgs args, bool optional) {
        bool first = string.IsNullOrEmpty(args.CurrentTab);

        if (first) {
            GUILayout.Space(5.0f);
        }
        else {
            if (args.DoDraw) {
                GUILayout.Space(10.0f);
            }

            EditorGUILayout.EndFadeGroup();
        }

        if (!optional || args.Editor.TabIsEnabled(Property.name)) {
            bool open;

            if (first && !optional) {
                bool openAll = args.AllTabNames.All(tab => args.TabGroup.IsOpen(tab + args.MatInst));
                bool closeOpen;
                bool all = openAll;



                open = args.TabGroup.TabArea(DisplayName, Color, true, m_foldoutAction(all), out closeOpen, DisplayName + args.MatInst);

                if (closeOpen) {
                    openAll = !openAll;
                    SetAllTabsOpenedTo(openAll, args);
                }
            }
            else {
                bool removed;
                open = args.TabGroup.TabArea(DisplayName, Color, optional, out removed, DisplayName + args.MatInst);

                if (removed) {
                    args.Editor.DisableTab(DisplayName, Property.name, args.MatInst);
                }
            }

            var anim = args.OpenCloseAnim[Property.name];
            anim.target = open;

            args.CurrentTab = Property.name;
            args.DoDraw = EditorGUILayout.BeginFadeGroup(anim.faded);
        }
        else {
            args.DoDraw = false;

            args.TabsToAdd.Add(new AlloyTabAdd { Color = Color, Name = DisplayName, Enable = () => args.Editor.EnableTab(DisplayName, Property.name, args.MatInst) });
        }
    }
Ejemplo n.º 33
0
 public override bool ShouldDraw(AlloyFieldDrawerArgs args) {
     return true;
 }
Ejemplo n.º 34
0
 public void MaterialPropField(string displayName, AlloyFieldDrawerArgs args) {
     if (Property != null) {
         args.Editor.MatEditor.DefaultShaderProperty(Property, displayName);
     }
 }
Ejemplo n.º 35
0
    protected override bool OnSetOption(int newOption, AlloyFieldDrawerArgs args) {
        base.OnSetOption(newOption, args);
        SpeedTreeGeometryType newMode = (SpeedTreeGeometryType) newOption;
        bool setVal = true;

        if (!string.IsNullOrEmpty(RenderQueueOrderField)) {
            SerializedProperty custom = args.Editor.GetProperty(MaterialProperty.PropType.Float, RenderQueueOrderField);
            
            if (custom.floatValue > 0.5f) {
                setVal = false;
            }
        }
        
        for (int i = 0; i < args.Materials.Length; i++) {
            var material = args.Materials[i];

            for (int j = 0; j < s_speedTreeKeywordSettings.Length; j++) {
                SpeedTreeKeywordSetting setting = s_speedTreeKeywordSettings[j];
                string keyword = setting.Keyword;

                if (newMode != setting.GeometryType) {
                    material.DisableKeyword(keyword);
                }
                else {
                    material.EnableKeyword(keyword);

                    if (setVal) {
                        material.renderQueue = setting.RenderQueue;
                    }
                }
            }

            material.SetInt("_GeometryType", (int) newMode);
            EditorUtility.SetDirty(material);
        }

        Undo.RecordObjects(args.Materials, "Set geometry type");
        return true;
    }
Ejemplo n.º 36
0
    public override void Draw(AlloyFieldDrawerArgs args) {
        bool current = Serialized.floatValue > 0.5f;
        var label = new GUIContent(DisplayName);

        EditorGUI.BeginProperty(new Rect(), label, Serialized);
        EditorGUI.BeginChangeCheck();
        current = EditorGUILayout.Toggle(label, current);

        if (EditorGUI.EndChangeCheck()) {
            Serialized.floatValue = current ? 1.0f : 0.0f;
            Property.floatValue = current ? 1.0f : 0.0f;
        }

        EditorGUI.EndProperty();

        if (!current) {
            if (OffHideFields != null) {
                args.PropertiesSkip.AddRange(OffHideFields);
            }
        } else {
            if (OnHideFields != null) {
                args.PropertiesSkip.AddRange(OnHideFields);
            }
        }
    }
Ejemplo n.º 37
0
    public override void Draw(AlloyFieldDrawerArgs args) {
        float sortOrder = Serialized.floatValue - PostAlphaTestQueue;

        // Snap to integers.
        EditorGUI.BeginChangeCheck();
        sortOrder = (int)EditorGUILayout.Slider(DisplayName, sortOrder, 0, 20, GUILayout.MinWidth(20.0f));

        if (EditorGUI.EndChangeCheck()) {
            Serialized.floatValue = sortOrder + PostAlphaTestQueue;

            foreach (var material in args.Materials) {
                material.renderQueue = (int)Serialized.floatValue;
            }
        }
    }
Ejemplo n.º 38
0
    public override void Draw(AlloyFieldDrawerArgs args) {
        int current = (int) Serialized.floatValue;
        var label = new GUIContent(DisplayName);

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


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

        EditorGUI.EndProperty();

        args.PropertiesSkip.AddRange(DropOptions[current].HideFields);
    }
Ejemplo n.º 39
0
    protected override bool OnSetOption(int newOption, AlloyFieldDrawerArgs args) {
        base.OnSetOption(newOption, args);
        var newMode = (RenderingMode) newOption;
        bool setVal = true;

        if (!string.IsNullOrEmpty(RenderQueueOrderField)) {
            var custom = args.Editor.GetProperty(MaterialProperty.PropType.Float, RenderQueueOrderField);
            
            if (custom.floatValue > 0.5f) {
                setVal = false;
            }
        }
        
        foreach (var material in args.Materials) {
            switch (newMode) {
            case RenderingMode.Opaque:
                material.SetInt("_SrcBlend", (int) BlendMode.One);
                material.SetInt("_DstBlend", (int) BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                
                if (setVal) {
                    material.renderQueue = -1;
                }
                break;
            case RenderingMode.Cutout:
                material.SetInt("_SrcBlend", (int) BlendMode.One);
                material.SetInt("_DstBlend", (int) BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.EnableKeyword("_ALPHATEST_ON");
                
                if (setVal) {
                    material.renderQueue = 2450;
                }
                break;
            case RenderingMode.Fade:
                material.SetInt("_SrcBlend", (int) BlendMode.SrcAlpha);
                material.SetInt("_DstBlend", (int) BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.EnableKeyword("_ALPHABLEND_ON");
                
                if (setVal) {
                    material.renderQueue = 3000;
                }
                break;
            case RenderingMode.Transparent:
                material.SetInt("_SrcBlend", (int) BlendMode.One);
                material.SetInt("_DstBlend", (int) BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                
                if (setVal) {
                    material.renderQueue = 3000;
                }
                break;
            }
            
            material.SetInt("_Mode", (int)newMode);
            EditorUtility.SetDirty(material);
        }
        
        Undo.RecordObjects(args.Materials, "Set blend mode");
        return true;
    }
Ejemplo n.º 40
0
    public override void Draw(AlloyFieldDrawerArgs args) {
        Vector4 newVal = Vector4.zero;
        var label = new GUIContent(DisplayName);

        EditorGUI.BeginProperty(new Rect(), label, Serialized);
        EditorGUI.BeginChangeCheck();

        switch (Mode) {
            case VectorMode.Vector4:
                newVal = EditorGUILayout.Vector4Field(label.text, Serialized.colorValue);
                break;


            case VectorMode.Vector3:
                newVal = EditorGUILayout.Vector3Field(label.text, (Vector4)Serialized.colorValue);
                break;

            case VectorMode.Vector2:
                newVal = EditorGUILayout.Vector2Field(label.text, (Vector4)Serialized.colorValue);
                break;

            case VectorMode.Euler:
                var value =
                    (Vector4)args.Editor.GetProperty(MaterialProperty.PropType.Vector, Property.name + "EulerUI").colorValue;
                newVal = Quaternion.Euler(value) * Vector3.up;
                GUI.changed = true;
                break;
        }

        if (EditorGUI.EndChangeCheck()) {
            Serialized.colorValue = newVal;
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 41
0
    private void TextureField(float size, SerializedProperty prop, AlloyFieldDrawerArgs args) {
        var rawRef = prop.objectReferenceValue;
        GUILayoutOption[] layout = new GUILayoutOption[2];

        if (rawRef == null
            && !prop.hasMultipleDifferentValues
            && (!IsOpen || m_hasParentTexture)) {

            layout[0] = GUILayout.Width(100.0f);
            layout[1] = GUILayout.Height(16.0f);
        }
        else {
            layout[0] = GUILayout.Width(size - 20.0f);
            layout[1] = GUILayout.Height((size - 20.0f) * 0.9f);
        }

        EditorGUI.BeginProperty(new Rect(), null, prop);
        EditorGUI.BeginChangeCheck();

        var tex = EditorGUILayout.ObjectField(rawRef, typeof(Texture), false, layout);

        if (EditorGUI.EndChangeCheck()) {
            prop.objectReferenceValue = tex;
        }

        EditorGUI.EndProperty();

    }
Ejemplo n.º 42
0
    public override void Draw(AlloyFieldDrawerArgs args) {
        Vector4 newVal = Serialized.colorValue;
        var label = new GUIContent(DisplayName);


        EditorGUI.BeginProperty(new Rect(), label, Serialized);
        EditorGUI.BeginChangeCheck();


        
        GUILayout.BeginHorizontal();
        GUILayout.Label(label);


        newVal.x = GUILayout.Toggle(newVal.x > 0.5f, "R", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.y = GUILayout.Toggle(newVal.y > 0.5f, "G", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.z = GUILayout.Toggle(newVal.z > 0.5f, "B", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        newVal.w = GUILayout.Toggle(newVal.w > 0.5f, "A", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
        GUILayout.EndHorizontal();


        if (EditorGUI.EndChangeCheck()) {
            Serialized.colorValue = newVal;
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 43
0
 public override void Draw(AlloyFieldDrawerArgs args)
 {
     args.Editor.MatEditor.DoubleSidedGIField();
 }
Ejemplo n.º 44
0
 public override void Draw(AlloyFieldDrawerArgs args) {
     PropField(DisplayName);
 }
Ejemplo n.º 45
0
 protected void SetAllTabsOpenedTo(bool open, AlloyFieldDrawerArgs args) {
     foreach (var tab in args.AllTabNames) {
         args.TabGroup.SetOpen(tab + args.MatInst, open);
     }
 }
Ejemplo n.º 46
0
    public override void Draw(AlloyFieldDrawerArgs args) {
        m_inst = args.MatInst;

        bool isOpen = m_tabGroup.Foldout(DisplayName, SaveName, GUILayout.Width(10.0f));
        m_tabOpen.target = isOpen;

        if (m_tabOpen.value) {
            EditorGUILayout.BeginFadeGroup(m_tabOpen.faded);
            AlloyGUI.Vector2Field(Serialized, "Tiling", true);
            AlloyGUI.Vector2Field(Serialized, "Offset", false);


            AlloyTextureFieldDrawer.DrawTextureControls(m_scrollProp, m_spinProp, m_uvProp);
            EditorGUILayout.EndFadeGroup();
        }

        if (m_tabOpen.isAnimating) {
            args.Editor.MatEditor.Repaint();
        }
    }
Ejemplo n.º 47
0
    public override void Draw(AlloyFieldDrawerArgs args)
    {
        m_inst = args.MatInst;

        if (m_firstDraw)
        {
            OnFirstDraw();
            m_firstDraw = false;
        }

        var texture = Serialized.FindPropertyRelative(TextureProp);
        var curTex  = texture.objectReferenceValue as Texture;

        GUILayout.Space(9.0f);

        GUILayout.BeginHorizontal();

        EditorGUILayout.BeginVertical();

        float oldWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = 80.0f;

        bool drewOpen = false;

        if (m_hasParentTexture || !Controls)
        {
            GUILayout.Label(DisplayName);
        }
        else
        {
            bool isOpen = m_tabGroup.Foldout(DisplayName, SaveName, GUILayout.Width(10.0f));
            m_tabOpen.target = isOpen;

            if (EditorGUILayout.BeginFadeGroup(m_tabOpen.faded))
            {
                drewOpen = true;
                AlloyGUI.Vector2Field(m_scale, "Tiling");
                AlloyGUI.Vector2Field(m_offset, "Offset");
                DrawTextureControls(m_velocityProp, m_spinProp, m_uvProp);
            }

            EditorGUILayout.EndFadeGroup();
        }

        if ((EditorGUILayout.BeginFadeGroup(1.0f - m_tabOpen.faded) ||
             !Controls) &&
            curTex != null &&
            !texture.hasMultipleDifferentValues)
        {
            if (!DrawWarningString(texture))
            {
                var oldCol = GUI.color;
                GUI.color = EditorGUIUtility.isProSkin ? Color.gray : new Color(0.3f, 0.3f, 0.3f);

                string name = curTex.name;
                if (name.Length > 17)
                {
                    name = name.Substring(0, 14) + "..";
                }
                GUILayout.Label(name + " (" + curTex.width + "x" + curTex.height + ")", EditorStyles.whiteLabel);
                GUI.color = oldCol;
            }
        }

        EditorGUILayout.EndFadeGroup();

        if (curTex != null &&
            (!m_hasParentTexture || Controls) &&
            !texture.hasMultipleDifferentValues)
        {
            DrawVisualizeButton();
        }

        if (drewOpen)
        {
            EditorGUILayout.EndVertical();
            TextureField(Mathf.Lerp(74.0f, 100.0f, m_tabOpen.faded), texture, args);
        }
        else
        {
            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();
            TextureField(74.0f, texture, args);
        }

        EditorGUIUtility.labelWidth = oldWidth;
        GUILayout.EndHorizontal();

        if (IsOpen)
        {
            GUILayout.Space(10.0f);
        }

        if (m_tabOpen.isAnimating)
        {
            args.Editor.MatEditor.Repaint();
        }
    }
Ejemplo n.º 48
0
 public override void Draw(AlloyFieldDrawerArgs args) {
     MaterialPropField(DisplayName, args);
 }
Ejemplo n.º 49
0
 public virtual bool ShouldDraw(AlloyFieldDrawerArgs args) {
     return args.DoDraw && !args.PropertiesSkip.Contains(Property.name);
 }
Ejemplo n.º 50
0
 public override bool ShouldDraw(AlloyFieldDrawerArgs args)
 {
     return(!args.PropertiesSkip.Contains(Property.name));
 }
Ejemplo n.º 51
0
 public override void Draw(AlloyFieldDrawerArgs args) {
     if (HasMin || HasMax) {
         if (HasMin && HasMax) {
             FloatFieldSlider(DisplayName, MinValue, MaxValue);
         }
         else if (HasMin) {
             FloatFieldMin(DisplayName, MinValue);
         }
         else {
             FloatFieldMax(DisplayName, MaxValue);
         }
     }
     else {
         PropField(DisplayName);
     }
 }
Ejemplo n.º 52
0
 public override void Draw(AlloyFieldDrawerArgs args)
 {
     args.Editor.MatEditor.EnableInstancingField();
 }
    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) {
            if (kv.Value == null) {
                continue;
            }

            var drawer = kv.Value;
            if (drawer.ShouldDraw(args)) {
                drawer.Draw(args);
            }
        }


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

        GUILayout.Space(10.0f);

        AlloyEditor.DrawAddTabGUI(args.TabsToAdd);
    }