Esempio n. 1
0
        /// <summary>
        /// Finds a game object with the specified name, returning any match in scene before
        /// trying to return any non-scene matches in the project.
        /// </summary>
        /// <returns>
        /// The specified game object.
        /// </returns>
        /// <param name='specifier'>
        /// The name to search for.
        /// </param>
        public static GameObject FindSpecifier(string specifier)
        {
            // Search for active objects in scene:
            GameObject match = GameObject.Find(specifier);

            if (match != null)
            {
                return(match);
            }

            // Search for all objects in scene, including inactive as long as it's a child of an active object:
            match = Tools.GameObjectHardFind(specifier);
            if (match != null)
            {
                return(match);
            }

            // Search for all objects, including loaded-but-not-instantiated (i.e., prefabs):
            foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
            {
                if (string.Compare(specifier, go.name, System.StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(go);
                }
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Finds a game object with the specified name, returning any match in scene before
        /// trying to return any non-scene matches in the project. Checks GameObjects registered
        /// with the specifier as its actor name first.
        /// </summary>
        /// <returns>
        /// The specified game object.
        /// </returns>
        /// <param name='specifier'>
        /// The name to search for.
        /// </param>
        /// <param name='onlyActiveInScene'>Only search active objects in the scene.</param>
        public static GameObject FindSpecifier(string specifier, bool onlyActiveInScene = false)
        {
            if (string.IsNullOrEmpty(specifier))
            {
                return(null);
            }

            // Check for 'tag=' keyword:
            if (SpecifierSpecifiesTag(specifier))
            {
                var tag      = GetSpecifiedTag(specifier);
                var taggedGO = GameObject.FindGameObjectWithTag(tag);
                if (taggedGO != null)
                {
                    return(taggedGO);
                }
                var results = Tools.FindGameObjectsWithTagHard(tag);
                return((results.Length > 0) ? results[0] : null);
            }

            // Search registered actors:
            var t = CharacterInfo.GetRegisteredActorTransform(specifier);

            if (t != null)
            {
                return(t.gameObject);
            }

            // Search for active objects in scene:
            var match = GameObject.Find(specifier);

            if (match != null)
            {
                return(match);
            }

            if (onlyActiveInScene)
            {
                return(null);
            }

            // Search for all objects in scene, including inactive as long as it's a child of an active object:
            match = Tools.GameObjectHardFind(specifier);
            if (match != null)
            {
                return(match);
            }

            // Search for all objects, including loaded-but-not-instantiated (i.e., prefabs):
            foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
            {
                if (string.Compare(specifier, go.name, System.StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(go);
                }
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Sets the observed GameObject to the named GameObject and checks
        /// the condition.
        /// </summary>
        /// <param name="gameObjectName">Game object name.</param>
        public void Check(string gameObjectName)
        {
            var newGameObject = Tools.GameObjectHardFind(gameObjectName);

            if (newGameObject != null)
            {
                observeGameObject = newGameObject;
            }
            Check();
        }
        /// <summary>
        /// Listens for the OnApplyPersistentData message and retrieves the game object's position
        /// and rotation from the Lua Actor[] table.
        /// </summary>
        public void OnApplyPersistentData()
        {
            string spawnpointName = DialogueLua.GetActorField(actorName, "Spawnpoint").asString;

            if (!string.IsNullOrEmpty(spawnpointName))
            {
                var spawnpoint = Tools.GameObjectHardFind(spawnpointName);
                if (spawnpoint == null)
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning("Dialogue System: Persistent Position Data found Actor[" + actorName + "].Spawnpoint value '" + spawnpointName + "' but can't find a GameObject with this name in the scene. Moving actor to saved position instead.", this);
                    }
                }
                else
                {
                    transform.position = spawnpoint.transform.position;
                    transform.rotation = spawnpoint.transform.rotation;
                    if (DialogueDebug.logInfo)
                    {
                        Debug.Log("Dialogue System: Persistent Position Data spawning " + actorName + " at spawnpoint " + spawnpoint, this);
                    }
                }
                DialogueLua.SetActorField(actorName, "Spawnpoint", string.Empty);
                if (spawnpoint != null)
                {
                    return;
                }
            }
            var fieldName      = recordCurrentLevel ? "Position_" + SanitizeLevelName(Tools.loadedLevelName) : "Position";
            var positionString = DialogueLua.GetActorField(actorName, fieldName).asString;

            if (!string.IsNullOrEmpty(positionString))
            {
                if (DialogueDebug.logInfo)
                {
                    Debug.Log("Dialogue System: Persistent Position Data restoring " + actorName + " to position " + positionString, this);
                }
                ApplyPositionString(positionString);
            }
            else
            {
                if (DialogueDebug.logInfo)
                {
                    Debug.Log("Dialogue System: Persistent Position Data Actor[" + actorName + "]." + fieldName + " is blank. Not moving " + actorName, this);
                }
            }
        }