/// <summary>
        /// Returns the GameObject with the specified ID, giving preference to quest list
        /// containers, then quest entities, and finally by GameObject name.
        /// </summary>
        /// <param name="id">ID to search for.</param>
        public static GameObject FindGameObjectWithID(string id)
        {
            // Try registered quest list containers first (quest givers, quest journal):
            var qlc = QuestMachine.GetQuestListContainer(id);

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

            //// Otherwise try entities:
            ////--- Replaced by IQuestMachineID below.
            //var entities = GameObject.FindObjectsOfType<QuestEntity>();
            //for (int i = 0; i < entities.Length; i++)
            //{
            //    var entity = entities[i];
            //    if (string.Equals(entity.id, id)) return entity.gameObject;
            //}

            var monobehaviours = GameObject.FindObjectsOfType <MonoBehaviour>();

            for (int i = 0; i < monobehaviours.Length; i++)
            {
                var identifiable = (monobehaviours[i] as IQuestMachineID);
                if (identifiable != null && string.Equals(identifiable.id, id))
                {
                    return(monobehaviours[i].gameObject);
                }
            }

            // Otherwise search scene for GameObject name:
            return(GameObject.Find(id));
        }
Example #2
0
 /// <summary>
 /// Gives all quests to a quester.
 /// </summary>
 /// <param name="questerID">ID of quester.</param>
 public virtual void GiveAllQuestsToQuester(string questerID)
 {
     GiveAllQuestsToQuester(QuestMachine.GetQuestListContainer(questerID));
 }
Example #3
0
 /// <summary>
 /// Adds an instance of a quest to a quester's list. If the quest's maxTimes are reached,
 /// deletes the quest from the giver. Otherwise starts cooldown timer until it can be
 /// given again.
 /// </summary>
 /// <param name="quest">Quest to give to quester.</param>
 /// <param name="questerID">Quester's ID.</param>
 public virtual void GiveQuestToQuester(Quest quest, string questerID)
 {
     GiveQuestToQuester(quest, QuestMachine.GetQuestListContainer(questerID));
 }