Exemple #1
0
    public override void OnInspectorGUI()
    {
        Color      guiColor   = GUI.color;
        SceneAsset sceneAsset = _target.Editor_GetScene();

        if (sceneAsset != null)
        {
            string assetPath;
            int    indexInBuild;

            // -1 -> not in build   0 -> disabled in build   2 -> enabled in build
            int buildState = GetBuildState(out assetPath, out indexInBuild);

            if (buildState == -1)
            {
                GUI.color = new Color(0.6f, 1, 0.6f);
                if (GUILayout.Button("ADD TO BUILD SETTINGS"))
                {
                    AddToBuild(assetPath);
                }
                GUI.color = guiColor;
            }
            else
            {
                GUI.color = new Color(1, 0.6f, 0.6f);
                if (GUILayout.Button("REMOVE FROM BUILD SETTINGS"))
                {
                    RemoveFromBuild(indexInBuild);
                }

                GUI.color = guiColor;
                EditorGUILayout.BeginHorizontal();
                if (EditorGUILayout.Toggle("Included in build", buildState == 1) != (buildState == 1))
                {
                    if (buildState == 1)
                    {
                        DisableInBuild(indexInBuild);
                    }
                    else
                    {
                        EnableInBuild(indexInBuild);
                    }
                }

                bool isInFirstPlace = indexInBuild == 0;
                if (isInFirstPlace)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button(isInFirstPlace ? "Is in first place" : "Put in first place"))
                {
                    PutInFirstInBuild(indexInBuild);
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
            }
        }

        if (sceneAsset != null && sceneAsset.name != _target.SceneName)
        {
            GUI.color = new Color(0.6f, 1, 0.6f);
        }
        else
        {
            GUI.enabled = false;
        }

        if (GUILayout.Button("Refresh Name"))
        {
            _target.Editor_RefreshSceneName();
            EditorUtility.SetDirty(_target);
        }

        GUI.enabled = true;
        GUI.color   = guiColor;

        base.OnInspectorGUI();
    }