Exemple #1
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length != 2)
            {
                return("[Error] You must provide a component type and a valid path to the game object.");
            }

            // attempt to retrieve the component
            System.Type componentType = null;
            if (ConsoleDaemon.Instance.AvailableComponents.ContainsKey(tokens[0]))
            {
                componentType = ConsoleDaemon.Instance.AvailableComponents[tokens[0]];
            }

            // type did not match?
            if (componentType == null)
            {
                return("[Error] The specified component type could not be found. Please check the spelling.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[1]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the specified game object. Check the path. Paths must be case sensitive.");
            }

            // add the component
            foundObject.AddComponent(componentType);

            return("Added component to the game object");
        }
Exemple #2
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length != 2)
            {
                return("[Error] Incorrect number of parameters. You must provide the true/false/active/inactive flag and a valid path to the game object to modify.");
            }

            // invalid flag provided
            string activeFlag = tokens[0].ToLower();

            if (activeFlag.ToLower() != "active" && activeFlag.ToLower() != "inactive" || activeFlag.ToLower() != "true" && activeFlag.ToLower() != "false")
            {
                return("[Error] Unknown flag. You must provide the true/false/active/inactive flag and a valid path to the game object to modify.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[1]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the specified game object. Check the path. Paths must be case sensitive.");
            }

            foundObject.SetActive(activeFlag == "active" || activeFlag == "true");

            return("Object is now " + activeFlag);
        }
Exemple #3
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length < 2)
            {
                return("[Error] You must provide a valid path to the game object to modify.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[0]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the specified game object. Check the path. Paths must be case sensitive.");
            }

            // check if the coordinates are correct
            Vector3 coordinates = Vector3.zero;

            if (!CommandHelpers.Vector3FromTokens(tokens, 1, ref coordinates))
            {
                return("[Error] The incorrect number of coordinates were given. Coordinates should be x,y,z");
            }

            // update the scale
            foundObject.transform.localScale = coordinates;

            return(foundObject.name + " is now scaled to " + foundObject.transform.localScale + " (local)");
        }
Exemple #4
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length < 3)
            {
                return("[Error] You must provide a valid path to the game object to modify.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[1]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the specified game object. Check the path. Paths must be case sensitive.");
            }

            // is the location being set as local or world?
            bool isLocal = false;

            if (tokens[0].ToLower() == "local")
            {
                isLocal = true;
            }
            else if (tokens[0].ToLower() == "world")
            {
                isLocal = false;
            }
            else
            {
                return("[Error] No indication was provided for if the coordinates are in local or world space.");
            }

            // check if the coordinates are correct
            Vector3 coordinates = Vector3.zero;

            if (!CommandHelpers.Vector3FromTokens(tokens, 2, ref coordinates))
            {
                return("[Error] The incorrect number of coordinates were given. Coordinates should be x,y,z");
            }

            // update the location
            if (isLocal)
            {
                foundObject.transform.localEulerAngles = coordinates;
            }
            else
            {
                foundObject.transform.eulerAngles = coordinates;
            }

            return(foundObject.name + " is now rotated to " + foundObject.transform.eulerAngles + " (world) " + foundObject.transform.localEulerAngles + " (local)");
        }
Exemple #5
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length != 1)
            {
                return("[Error] You must provide a valid path to the game object to query.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[0]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the specified game object. Check the path. Paths must be case sensitive.");
            }

            return(foundObject.name + " has a scale of " + foundObject.transform.localScale + " (local) ");
        }
Exemple #6
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length != 1)
            {
                return("[Error] You must provide a valid path to the game object to query.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[0]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the specified game object. Check the path. Paths must be case sensitive.");
            }

            Dictionary <string, Component> componentMapping = CommandHelpers.GetComponentMapping(foundObject);
            List <string> componentNames = componentMapping.Keys.ToList();

            // find the longest component name
            int longestComponentName = 0;

            foreach (string componentName in componentNames)
            {
                longestComponentName = Mathf.Max(componentName.Length, longestComponentName);
            }

            // build the list of components
            string result = "Found the following components: ";

            foreach (string componentName in componentNames)
            {
                Component component = componentMapping[componentName];
                string    status    = component is Behaviour ? ((component as Behaviour).enabled ? "Enabled" : "Disabled") : "Always Enabled";

                result += System.Environment.NewLine + "    " + componentName.PadRight(longestComponentName) + "    : " + status;
            }

            return(result);
        }
Exemple #7
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length != 1)
            {
                return("[Error] You must provide a valid path to the game object to destroy.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[0]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the specified game object. Check the path. Paths must be case sensitive.");
            }

            GameObject.Destroy(foundObject);

            return("Object destroyed.");
        }
Exemple #8
0
        public static string Execute(string[] tokens)
        {
            // incorrect number of tokens found
            if (tokens.Length == 0)
            {
                return("[Error] You must provide a valid path to the game object to update and optionally a path to the new parent.");
            }

            // attempt to find the object
            GameObject foundObject = CommandHelpers.GetGameObject(tokens[0]);

            // object not found?
            if (foundObject == null)
            {
                return("[Error] Could not find the game object to change. Check the path. Paths must be case sensitive.");
            }

            // attempt to find the new parent object
            GameObject foundParentObject = tokens.Length > 1 ? CommandHelpers.GetGameObject(tokens[1]) : null;

            // object not found?
            if (tokens.Length > 1 && foundParentObject == null)
            {
                return("[Error] Could not find the new parent game object. Check the path. Paths must be case sensitive.");
            }

            // did the user give the same path?
            if (foundObject == foundParentObject)
            {
                return("[Error] The object and the new parent cannot be the same. Please provide two different game objects.");
            }

            // reparent the object
            foundObject.transform.SetParent(foundParentObject != null ? foundParentObject.transform : null);

            return("Parent updated");
        }