///
    public override void OnInspectorGUI()
    {
        if (m_button_style == null)
        {
            m_button_style                   = new GUIStyle(GUI.skin.button);
            m_button_style.fontSize          = 13;
            m_button_style.alignment         = TextAnchor.MiddleLeft;
            m_button_style.normal.background = m_gbg;
            m_button_style.normal.textColor  = Color.white;
            m_button_style.active.background = m_gbg;
            m_button_style.active.textColor  = Color.white;
        }
        serializedObject.Update();
        RoveMaterials rove_materials = (RoveMaterials)target;

        if (rove_materials.m_materials.Count != m_expand_material.Length)
        {
            m_expand_material = new bool[rove_materials.m_materials.Count];
        }
        EditorGUILayout.BeginVertical("box");
        {
            EditorGUILayout.BeginVertical(m_dark_style);
            {
                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal();
                {
                    int logo_width  = 256;
                    int logo_height = 64;
                    GUILayout.Space((EditorGUIUtility.currentViewWidth / 2) -
                                    (logo_width / 2) - 10);
                    EditorGUILayout.LabelField(new GUIContent(m_logo),
                                               GUILayout.Width(logo_width),
                                               GUILayout.Height(logo_height));
                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.Space(10);
                m_dark_style.normal.background = m_gbg;
                EditorGUILayout.BeginVertical(m_dark_style);
                {
                    m_dark_style.fontSize  = 17;
                    m_dark_style.alignment = TextAnchor.MiddleCenter;
                    EditorGUILayout.LabelField("Materials", m_dark_style);
                    m_dark_style.fontSize  = 12;
                    m_dark_style.alignment = TextAnchor.MiddleLeft;
                    EditorGUILayout.EndVertical();
                }
                m_dark_style.normal.background = m_bg;
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.BeginVertical(m_dark_style);
        {
            m_dark_style.alignment = TextAnchor.MiddleCenter;
            if (!Application.isPlaying)
            {
                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal(m_dark_style);
                {
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Scene-wide material information will " +
                                               "display during play mode.", m_dark_style);
                    GUILayout.Space(10);
                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.Space(10);
            }
            else
            {
                GUILayout.Space(20);
                m_dark_style.fontSize = 17;
                EditorGUILayout.LabelField("Global List", m_dark_style);
                m_dark_style.fontSize = 15;
                GUILayout.Space(20);
                for (int m = 0; m < rove_materials.m_materials.Count; ++m)
                {
                    EditorGUILayout.BeginVertical("box");
                    {
                        EditorGUILayout.BeginVertical(m_dark_style);
                        {
                            m_dark_style.normal.background = m_gbg;
                            EditorGUILayout.BeginHorizontal(m_dark_style);
                            {
                                string material_name = Path.GetFileNameWithoutExtension(
                                    AssetDatabase.GetAssetPath(rove_materials.m_materials[m]));
                                if (GUILayout.Button(material_name, m_button_style))
                                {
                                    m_expand_material[m] = !m_expand_material[m];
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                            m_dark_style.normal.background = m_bg;
                            if (m_expand_material[m])
                            {
                                RoveMaterialEditor material_editor =
                                    (RoveMaterialEditor)RoveMaterialEditor.CreateEditor(
                                        rove_materials.m_materials[m],
                                        typeof(RoveMaterialEditor));
                                material_editor.InspectorProperties(false, 0);
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndVertical();
                    }
                }
                GUILayout.Space(20);
                m_dark_style.fontSize = 17;
                EditorGUILayout.LabelField("Texture Atlas", m_dark_style);
                m_dark_style.fontSize = 15;
                GUILayout.Space(20);
                for (int a = 0; a < RoveMaterials.ATLAS_COUNT; ++a)
                {
                    EditorGUILayout.BeginVertical("box");
                    {
                        EditorGUILayout.BeginVertical(m_dark_style);
                        {
                            string atlas_type;
                            if (a == RoveAtlas.TYPE_ALBEDO)
                            {
                                atlas_type = "Albedo";
                            }
                            else if (a == RoveAtlas.TYPE_NORMAL)
                            {
                                atlas_type = "Normal";
                            }
                            else if (a == RoveAtlas.TYPE_METALLIC)
                            {
                                atlas_type = "Metallic";
                            }
                            else if (a == RoveAtlas.TYPE_EMISSION)
                            {
                                atlas_type = "Emissive";
                            }
                            else
                            {
                                atlas_type = "Undefined";
                            }
                            RoveAtlas atlas = rove_materials.m_atlases[a];
                            m_dark_style.normal.background = m_gbg;
                            EditorGUILayout.BeginHorizontal(m_dark_style);
                            {
                                m_button_style.alignment = TextAnchor.MiddleCenter;
                                if (GUILayout.Button(atlas_type, m_button_style))
                                {
                                    m_expand_atlas[a] = !m_expand_atlas[a];
                                }
                                m_button_style.alignment = TextAnchor.MiddleLeft;
                                EditorGUILayout.EndHorizontal();
                            }
                            m_dark_style.normal.background = m_bg;
                            if (m_expand_atlas[a])
                            {
                                GUILayout.Space(20);
                                EditorGUILayout.BeginHorizontal(m_dark_style);
                                {
                                    GUILayout.Space((EditorGUIUtility.currentViewWidth / 2) -
                                                    (128 / 2) - 25);
                                    EditorGUILayout.LabelField(new GUIContent(atlas.m_texture),
                                                               m_dark_style,
                                                               GUILayout.Width(128),
                                                               GUILayout.Height(128));
                                    EditorGUILayout.EndHorizontal();
                                }
                                GUILayout.Space(20);
                                EditorGUILayout.LabelField(atlas.m_width + " x " + atlas.m_height,
                                                           m_dark_style);
                                GUILayout.Space(20);
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndVertical();
                    }
                }
                m_dark_style.fontSize  = 12;
                m_dark_style.alignment = TextAnchor.MiddleLeft;
            }
            EditorGUILayout.EndVertical();
        }
        serializedObject.ApplyModifiedProperties();
    }
Beispiel #2
0
    ///
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        RoveObject rove_object = (RoveObject)target;

        EditorGUILayout.BeginVertical("box");
        {
            EditorGUILayout.BeginVertical(m_dark_style);
            {
                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal();
                {
                    int logo_width  = 256;
                    int logo_height = 64;
                    GUILayout.Space((EditorGUIUtility.currentViewWidth / 2) -
                                    (logo_width / 2) - 10);
                    EditorGUILayout.LabelField(new GUIContent(m_logo),
                                               GUILayout.Width(logo_width),
                                               GUILayout.Height(logo_height));
                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.Space(10);
                m_dark_style.normal.background = m_gbg;
                EditorGUILayout.BeginVertical(m_dark_style);
                {
                    m_dark_style.fontSize  = 17;
                    m_dark_style.alignment = TextAnchor.MiddleCenter;
                    EditorGUILayout.LabelField("Object", m_dark_style);
                    m_dark_style.fontSize  = 12;
                    m_dark_style.alignment = TextAnchor.MiddleLeft;
                    EditorGUILayout.EndVertical();
                }
                m_dark_style.normal.background = m_bg;
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.BeginVertical(m_dark_style);
        {
            GUILayout.Space(15);
            m_dark_style.fontSize  = 17;
            m_dark_style.alignment = TextAnchor.MiddleCenter;
            EditorGUILayout.LabelField("Sub-Mesh Materials", m_dark_style);
            m_dark_style.fontSize  = 12;
            m_dark_style.alignment = TextAnchor.MiddleLeft;
            GUILayout.Space(15);
            for (int m = 0; m < mp_materials.arraySize; ++m)
            {
                SerializedProperty p_material = mp_materials.GetArrayElementAtIndex(m);
                RoveMaterial       material   = (RoveMaterial)p_material.objectReferenceValue;
                if (material == null)
                {
                    EditorGUILayout.BeginVertical("box");
                    {
                        EditorGUILayout.BeginVertical(m_dark_style);
                        {
                            Rect drop_rect = EditorGUILayout.BeginHorizontal(m_dark_style);
                            {
                                m_dark_style.normal.background = m_gbg;
                                EditorGUILayout.BeginHorizontal(m_dark_style);
                                {
                                    GUIStyle button_style = new GUIStyle(GUI.skin.button);
                                    button_style.fontSize          = 13;
                                    button_style.alignment         = TextAnchor.MiddleLeft;
                                    button_style.normal.background = m_gbg;
                                    button_style.normal.textColor  = Color.white;
                                    button_style.active.background = m_gbg;
                                    button_style.active.textColor  = Color.white;
                                    if (GUILayout.Button("Default Material", button_style))
                                    {
                                    }
                                    if (GUILayout.Button("Select", GUILayout.MaxWidth(75.0f)))
                                    {
                                        EditorGUIUtility.ShowObjectPicker <RoveMaterial>(target,
                                                                                         false, " ", m);
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                                m_dark_style.normal.background = m_bg;
                                EditorGUILayout.EndHorizontal();
                            }
                            if (Event.current.type == EventType.DragUpdated)
                            {
                                if (drop_rect.Contains(Event.current.mousePosition))
                                {
                                    if (DragAndDrop.objectReferences.Length == 1 &&
                                        (DragAndDrop.objectReferences[0].GetType()) ==
                                        typeof(RoveMaterial))
                                    {
                                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                                    }
                                    else
                                    {
                                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                                    }
                                }
                            }
                            else if (Event.current.type == EventType.DragPerform)
                            {
                                if (drop_rect.Contains(Event.current.mousePosition))
                                {
                                    if (DragAndDrop.objectReferences.Length == 1 &&
                                        (DragAndDrop.objectReferences[0].GetType()) ==
                                        typeof(RoveMaterial))
                                    {
                                        DragAndDrop.AcceptDrag();
                                        RoveMaterial dropped_material =
                                            (RoveMaterial)DragAndDrop.objectReferences[0];
                                        p_material.objectReferenceValue = dropped_material;
                                        rove_object.m_materials[m]      = dropped_material;
                                        if (Application.isPlaying)
                                        {
                                            rove_object.ChangeSubMeshMaterial(m, dropped_material);
                                        }
                                    }
                                }
                            }
                            else if (Event.current.commandName == "ObjectSelectorUpdated")
                            {
                                if (EditorGUIUtility.GetObjectPickerControlID() == m)
                                {
                                    RoveMaterial chosen_material =
                                        (RoveMaterial)EditorGUIUtility.GetObjectPickerObject();
                                    p_material.objectReferenceValue = chosen_material;
                                    rove_object.m_materials[m]      = chosen_material;
                                    if (Application.isPlaying)
                                    {
                                        rove_object.ChangeSubMeshMaterial(m, chosen_material);
                                    }
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndVertical();
                    }
                }
                else
                {
                    RoveMaterialEditor material_editor =
                        (RoveMaterialEditor)RoveMaterialEditor.CreateEditor(
                            material, typeof(RoveMaterialEditor));
                    RoveMaterial new_material = material_editor.InspectorProperties(true, m);
                    if (new_material != material)
                    {
                        p_material.objectReferenceValue = new_material;
                        rove_object.m_materials[m]      = new_material;
                        if (Application.isPlaying)
                        {
                            rove_object.ChangeSubMeshMaterial(m, new_material);
                        }
                    }
                }
            }
            EditorGUILayout.EndVertical();
        }
        serializedObject.ApplyModifiedProperties();
    }