Ejemplo n.º 1
0
        // Use this for initialization
        void Start()
        {
            ConsoleDaemon.Instance.OnCommandEntered.AddListener(OnCommandEntered);

            // if there are required scenes make sure all are present
            if (requiredScenes.Count > 0)
            {
                List <string> availableScenes = CommandHelpers.GetSceneNamesInBuild();

                // check if all are present
                bool allPresent = true;
                foreach (string sceneName in requiredScenes)
                {
                    if (!availableScenes.Contains(sceneName.ToLower()))
                    {
                        allPresent = false;
                        break;
                    }
                }

                // not all of the required scenes were present
                if (!allPresent)
                {
                    currentElement = tutorialElements.Count;
                    return;
                }
            }

            AdvanceToNextTutorialElement();
        }
Ejemplo n.º 2
0
        public static string Execute(string[] tokens)
        {
            List <string> sceneNamesInBuild = CommandHelpers.GetSceneNamesInBuild();

            // find the longest scene name
            int longestName = 0;

            foreach (string sceneName in sceneNamesInBuild)
            {
                longestName = Mathf.Max(longestName, sceneName.Length);
            }

            // assemble the list of scenes and their status
            string result = "Known scenes: ";

            foreach (string sceneName in sceneNamesInBuild)
            {
                result += System.Environment.NewLine + "    " + sceneName.PadRight(longestName);
                if (SceneManager.GetSceneByName(sceneName).isLoaded)
                {
                    result += " - Loaded";
                }
                else
                {
                    result += " - Not loaded";
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static string Execute(string[] tokens)
        {
            if (tokens.Length == 0)
            {
                return("[Error] You must provide the name of at least one scene to load.");
            }

            // get the names of the scenes in the build
            List <string> sceneNamesInBuild = CommandHelpers.GetSceneNamesInBuild();

            // force additive if there are multiple scenes
            bool isAdditive = tokens.Length > 1 ? true : false;

            // check that all of the provided scene names are valid
            foreach (string sceneName in tokens)
            {
                string workingSceneName = sceneName.ToLower();

                if (workingSceneName == "additive")
                {
                    isAdditive = true;
                }
                else if (sceneNamesInBuild.IndexOf(workingSceneName) < 0)
                {
                    return("[Error] Unable to load scene \'" + sceneName + "\' as it is not in the build settings.");
                }
            }

            // load the requested scenes
            foreach (string sceneName in tokens)
            {
                // skip if trying to do additive loading
                if (sceneName.ToLower() == "additive")
                {
                    continue;
                }

                SceneManager.LoadScene(sceneName, isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single);
            }

            return("Loaded the requested scenes.");
        }
Ejemplo n.º 4
0
        public static List <string> FetchAutocompleteOptions(string command, string[] tokens)
        {
            // get the names of the scenes in the build
            List <string> sceneNamesInBuild = CommandHelpers.GetSceneNamesInBuild();

            List <string> autocompleteOptions = new List <string>();
            string        baseCommand         = command;;

            // check if the user has already indicated additive
            bool needAdditiveInOptions = true;

            foreach (string token in tokens)
            {
                if (token.ToLower() == "additive")
                {
                    needAdditiveInOptions = false;
                    break;
                }
            }

            // handle additive keyword by sneakily adding it as a scene name unless the tokens already contain that keyword
            if (needAdditiveInOptions)
            {
                sceneNamesInBuild.Add("additive");
            }

            // if there are no tokens then nothing further to do. the current base command is fine
            if (tokens == null || tokens.Length == 0)
            {
            }             // check if the last token exactly matches a scene name
            else if (sceneNamesInBuild.Contains(tokens[tokens.Length - 1].ToLower()))
            {
                // construct the base command
                foreach (string sceneName in tokens)
                {
                    // remove the scene from the available options
                    sceneNamesInBuild.Remove(sceneName.ToLower());

                    baseCommand += " " + (sceneName.Contains(" ") ? "\"" + sceneName + "\"" : sceneName);
                }
            }             // otherwise the token contains a partial name
            else
            {
                // construct the base command (exclude the final token)
                for (int index = 0; index < tokens.Length - 1; ++index)
                {
                    // remove the scene from the available options
                    sceneNamesInBuild.Remove(tokens[index].ToLower());

                    baseCommand += " " + (tokens[index].Contains(" ") ? "\"" + tokens[index] + "\"" : tokens[index]);
                }

                // filter out any scene names that do not match the potential candidates
                string partialName = tokens[tokens.Length - 1].ToLower();
                if (partialName != "additive")
                {
                    for (int index = 0; index < sceneNamesInBuild.Count; ++index)
                    {
                        if (!sceneNamesInBuild[index].StartsWith(partialName))
                        {
                            sceneNamesInBuild.RemoveAt(index);
                            --index;
                        }
                    }
                }
                else
                {
                    baseCommand += " additive";
                }

                // if we ended up with no valid scene names then error out
                if (sceneNamesInBuild.Count == 0)
                {
                    return(null);
                }
            }

            // fill out the list of autocomplete options
            foreach (string sceneName in sceneNamesInBuild)
            {
                string workingSceneName = sceneName.Contains(" ") ? "\"" + sceneName + "\"" : sceneName;

                autocompleteOptions.Add(baseCommand + " " + workingSceneName);
            }

            return(autocompleteOptions);
        }