예제 #1
0
    //Passed in by the base editor
    public AlloyTextureFieldDrawer(AlloyInspectorBase editor, MaterialProperty property)
        : base(editor, property)
    {
        m_tabGroup      = AlloyTabGroup.GetTabGroup();
        m_tabOpen.speed = 4.0f;

        m_scale  = Serialized.FindPropertyRelative("m_Scale");
        m_offset = Serialized.FindPropertyRelative("m_Offset");

        m_shaderVarName = Property.name;


        CacheTextureProps(editor, m_shaderVarName, out m_velocityProp, out m_spinProp, out m_uvProp);
    }
예제 #2
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();
        }
    }
예제 #3
0
    public override void OnSceneGUI(Material[] materials)
    {
        if (materials.Length > 1)
        {
            return;
        }

        var material = materials[0];

        if (Mode == TextureVisualizeMode.None || Selection.activeGameObject == null || Selection.objects.Length != 1)
        {
            if (m_oldSelect != null)
            {
                EditorUtility.SetSelectedWireframeHidden(m_oldSelect, false);
            }

            return;
        }

        if (Serialized == null)
        {
            return;
        }

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

        if (Mode == TextureVisualizeMode.None)
        {
            return;
        }

        var trans  = GetTextureTransformation(material);
        var uvMode = 0.0f;
        var uvName = !m_hasParentTexture ? m_shaderVarName + "UV" : m_parentTexture + "UV";

        if (material.HasProperty(uvName))
        {
            uvMode = material.GetFloat(uvName);
        }

        VisualizeMaterial.SetTexture("_MainTex", curTex);
        VisualizeMaterial.SetFloat("_Mode", (int)Mode);
        VisualizeMaterial.SetVector("_Trans", trans);
        VisualizeMaterial.SetFloat("_UV", uvMode);

        var target = Selection.activeGameObject.GetComponent <Renderer>();

        if (target != m_oldSelect && m_oldSelect != null)
        {
            EditorApplication.delayCall += SceneView.RepaintAll;
            EditorUtility.SetSelectedWireframeHidden(target, false);
            return;
        }

        m_oldSelect = target;

        Mesh mesh         = null;
        var  meshFilter   = target.GetComponent <MeshFilter>();
        var  meshRenderer = target.GetComponent <MeshRenderer>();

        if (meshFilter != null && meshRenderer != null)
        {
            mesh = meshFilter.sharedMesh;
        }

        if (mesh == null)
        {
            var skinnedMeshRenderer = target.GetComponent <SkinnedMeshRenderer>();

            if (skinnedMeshRenderer != null)
            {
                mesh = skinnedMeshRenderer.sharedMesh;
            }
        }

        if (mesh != null)
        {
            EditorUtility.SetSelectedWireframeHidden(target, true);

            Graphics.DrawMesh(mesh, target.localToWorldMatrix, VisualizeMaterial, 0, SceneView.currentDrawingSceneView.camera, m_inst);
            SceneView.currentDrawingSceneView.Repaint();
        }
        else
        {
            Debug.LogError("Game object does not have a mesh source.");
        }
    }