private void OnEnable()
    {
        scriptableScene = target as ScriptableScene;

        scenePathProperty = serializedObject.FindProperty(scenePathPropName);
        sceneStartingPositionsNamesProperty = serializedObject.FindProperty(sceneStartingPositionsNamesPropName);
    }
    public static ScriptableScene CreateScriptableScene()
    {
        // Create the instance of the scriptableObject
        ScriptableScene newScene = CreateInstance <ScriptableScene>();

        newScene.sceneStartingPositionsNames = new string[0];

        return(newScene);
    }
    public static void RemoveScriptableScene(ScriptableScene sceneToRemove)
    {
        // If there isn't an AllConditions instance yet, put a message in the console and return.
        if (!AllGameScriptableScenes.Instance)
        {
            Debug.LogError("AllGameScriptableScenes has not been created yet.");
            return;
        }

        ScriptableObjectUtility.RemoveScriptableObject(AllGameScriptableScenes.Instance, ref sceneToRemove, ref AllGameScriptableScenes.Instance.scriptableScenes);
    }
    private void AddScriptableScene()
    {
        // If there isn't an AllConditions instance yet, put a message in the console and return.
        if (!AllGameScriptableScenes.Instance)
        {
            Debug.LogError("AllGameScriptableScenes has not been created yet.");
            return;
        }

        ScriptableScene newScene = ScriptableSceneEditor.CreateScriptableScene();

        newScene.name = NEW_SCENE_BASE_NAME;

        ScriptableObjectUtility.AddScriptableObject(AllGameScriptableScenes.Instance, ref newScene, ref AllGameScriptableScenes.Instance.scriptableScenes, "Created new Scriptable Scene");
    }
Example #5
0
    public override void OnInspectorGUI()
    {
        // Get the corresponding ScriptableScene that contains the currently open Scene in Unity Editor
        string          currentUnityEditorOpenSceneName = EditorSceneManager.GetActiveScene().name;
        ScriptableScene currentScriptableScene          = ScriptableObjectUtility.GetScriptableObjectByName <ScriptableScene>(currentUnityEditorOpenSceneName, AllGameScriptableScenes.Instance.scriptableScenes);

        // If there is a Unity Scene that doesn't have a ScriptableScene reference
        // Inform to the developer
        if (!currentScriptableScene)
        {
            string textMessagee = "No ScriptableScene found for Unity Scene: "
                                  + currentUnityEditorOpenSceneName + ". Create one for this Unity Scene!";

            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.HelpBox(textMessagee, MessageType.Error);
            EditorGUILayout.EndVertical();

            return;
        }


        int posListSize = currentScriptableScene.sceneStartingPositionsNames.Length;

        // No starting Positions Names in the ScriptableScene
        if (posListSize == 0)
        {
            string textMessage = "No Starting Position Names found in " + currentUnityEditorOpenSceneName +
                                 " Scriptable Scene. You may had forgotten to add Starting Positions Names to the ScriptableScene " +
                                 "or may your game doesn't implement starting positions in scenes.";

            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.HelpBox(textMessage, MessageType.Warning);
            EditorGUILayout.EndVertical();

            return;
        }

        // Add all the startnig Position names present in the ScriptableScenes to the option list
        List <string> options = new List <string>(posListSize);

        for (int i = 0; i < posListSize; i++)
        {
            options.Add(currentScriptableScene.sceneStartingPositionsNames[i]);
        }

        // Check if there is already a StartingPointName
        if (targetStartingPosition.startingPointName != null &&
            !targetStartingPosition.startingPointName.Equals(""))
        {
            for (int i = 0; i < options.Count; i++)
            {
                if (options[i].Equals(targetStartingPosition.startingPointName))
                {
                    selectStartingPosName = i;
                    break;
                }
            }
        }

        EditorGUILayout.BeginVertical(GUI.skin.box);
        GUILayout.Space(5);
        selectStartingPosName = EditorGUILayout.Popup("Starting Position Name", selectStartingPosName, options.ToArray());
        GUILayout.Space(5);
        EditorGUILayout.EndVertical();

        targetStartingPosition.startingPointName = options[selectStartingPosName];
    }
Example #6
0
    public static void drawSceneEditor(ref string sceneName, ref string startingPointInLoadedScene)
    {
        // No instance found of AllGameScriptableScenes
        if (!AllGameScriptableScenes.Instance)
        {
            string textMessage = "No AllGameScriptableScenes Instance found. " +
                                 " Create it in Assets > Create > AKAGF > AllGameScriptableScenes.";

            EditorTools.drawMessage(textMessage, MessageType.Error);
            return;
        }

        // No ScriptableScenes present in the project
        if (AllGameScriptableScenes.Instance.scriptableScenes.Length == 0)
        {
            string textMessage = "No ScriptableScenes found in AllGameScriptableScenes Instance. " +
                                 "You must create scriptable Scenes in order to change between them through a Scene Reaction.";

            EditorTools.drawMessage(textMessage, MessageType.Warning);
            return;
        }


        /* Scenes Popup Menu */
        // Add all the scenes Names present in AllGameScenes as popup options
        int           listSize     = AllGameScriptableScenes.Instance.scriptableScenes.Length;
        List <string> sceneOptions = new List <string>(AllGameScriptableScenes.Instance.scriptableScenes.Length);

        for (int i = 0; i < listSize; i++)
        {
            // Ensure the ScriptableScene has a valid Scene Attached to it
            // by not adding to the list the scriptables Scenes present
            // in AllGameScriptableScenes with the default creation name
            // defined in AKAGF_PATHS struct
            if (!AllGameScriptableScenes.Instance.scriptableScenes[i].name.Equals(AKAGF_PATHS.NEW_SCRIPTABLE_SCENE_BASE_NAME))
            {
                sceneOptions.Add(AllGameScriptableScenes.Instance.scriptableScenes[i].name);
            }
        }

        // All scriptableScenes found don't have a Unity Scene attached to them
        if (sceneOptions.Count == 0)
        {
            string textMessage = "All scriptableScenes found don't have a Unity Scene attached to them" +
                                 " Check it in Project > Resources > AKAGF > SINGLETONS > AllGameScriptableScenes.";

            EditorTools.drawMessage(textMessage, MessageType.Error);
            return;
        }

        int selectedSceneIndex = 0;

        // Check if there is already a SceneName for this Scene Reaction
        if (sceneName != null && !sceneName.Equals(""))
        {
            for (int i = 0; i < sceneOptions.Count; i++)
            {
                if (sceneOptions[i].Equals(sceneName))
                {
                    selectedSceneIndex = i;
                    break;
                }
            }
        }


        selectedSceneIndex = EditorGUILayout.Popup("Scene To Switch", selectedSceneIndex, sceneOptions.ToArray());

        sceneName = sceneOptions[selectedSceneIndex];

        /* Starting Position Popup Menu */
        ScriptableScene scriptableScene = AllGameScriptableScenes.Instance.scriptableScenes[selectedSceneIndex];
        int             posListSize     = scriptableScene.sceneStartingPositionsNames.Length;

        // No starting Positions Names in the ScriptableScene
        if (posListSize == 0)
        {
            string textMessage = "No Starting Position Names found in " + scriptableScene.name +
                                 " Scriptable Scene. You may had forgotten to add Starting Positions Names to the ScriptableScene " +
                                 "or may your game doesn't implement starting positions in scenes.";

            EditorTools.drawMessage(textMessage, MessageType.Info);

            return;
        }

        // Add all the startnig Position names present in the ScriptableScenes to the option list
        List <string> startingPointsOptions = new List <string>(posListSize);

        for (int i = 0; i < posListSize; i++)
        {
            if (!scriptableScene.sceneStartingPositionsNames[i].Equals(""))
            {
                startingPointsOptions.Add(scriptableScene.sceneStartingPositionsNames[i]);
            }
        }

        if (startingPointsOptions.Count != posListSize)
        {
            string textMessage = "There is at least one StartingPositionName with empty value in " +
                                 scriptableScene.name + " Scriptable Scene. You probably forgotten to add Starting Positions Names to the ScriptableScene " +
                                 "in AllGameScriptableScenes Editor. Check it before you continue.";

            EditorTools.drawMessage(textMessage, MessageType.Error);

            return;
        }

        int selectedStartingPositionIndex = 0;

        // Check if there is already a StartingPointName
        if (startingPointInLoadedScene != null &&
            !startingPointInLoadedScene.Equals(""))
        {
            for (int i = 0; i < startingPointsOptions.Count; i++)
            {
                if (startingPointsOptions[i].Equals(startingPointInLoadedScene))
                {
                    selectedStartingPositionIndex = i;
                    break;
                }
            }
        }


        selectedStartingPositionIndex = EditorGUILayout.Popup("Starting Point", selectedStartingPositionIndex, startingPointsOptions.ToArray());
        GUILayout.Space(5);

        startingPointInLoadedScene = startingPointsOptions[selectedStartingPositionIndex];
    }