// Copyright (c) Pixel Crushers. All rights reserved. using UnityEngine; namespace PixelCrushers.QuestMachine { /// /// Activates a GameObject. /// public class ActivateGameObjectQuestAction : QuestAction { [Tooltip("Name of GameObject to activate or deactivate.")] [SerializeField] private StringField m_gameObjectName; [Tooltip("Tick to activate, untick to deactivate.")] [SerializeField] private bool m_state; /// /// Name of GameObject to activate or deactivate. /// public StringField gameObjectName { get { return m_gameObjectName; } set { m_gameObjectName = value; } } /// /// True to activate, false to deactivate. /// public bool state { get { return m_state; } set { m_state = value; } } public override string GetEditorName() { if (StringField.IsNullOrEmpty(gameObjectName)) return "Activate GameObject"; return (state ? "Activate" : "Deactivate") + " GameObject: '" + gameObjectName + "'"; } public override void Execute() { if (StringField.IsNullOrEmpty(gameObjectName)) return; var gameObject = GameObjectUtility.GameObjectHardFind(StringField.GetStringValue(gameObjectName)); if (gameObject == null) { if (QuestMachine.debug) Debug.LogWarning("Quest Machine: ActivateGameObjectQuestAction can't find a GameObject named '" + gameObjectName + "'."); return; } if (QuestMachine.debug) Debug.Log("Quest Machine: Setting GameObject '" + gameObjectName + "' " + (state ? "active." : "inactive.")); gameObject.SetActive(state); } } }