using System; using System.Collections; using System.Collections.Generic; using Beyond; using PixelCrushers; using PixelCrushers.DialogueSystem; using UnityEngine; using PixelCrushers.QuestMachine; using Sirenix.OdinInspector; using UnityEngine.Serialization; public class ConditionalGameObjectController : MonoBehaviour, IMessageHandler { [Title("Conditions to Enable Game Objects")] [SerializeField] private Condition m_conditionToEnable; [Title("Conditions to Disable Game Objects")] [SerializeField] private Condition m_conditionToDisable; [InfoBox("When conditions are met gameobjects below will be enable or disable")] [SerializeField] private List m_gameObjectsToEnable = new List(); [FormerlySerializedAs("m_gameObjectstoDisable")] [SerializeField] private List m_gameObjectsToDisable = new List(); private void Awake() { // MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty); //PixelCrushers.SaveSystem.saveDataApplied += OnSaveDataApplied; } void OnSaveDataApplied() { PixelCrushers.SaveSystem.saveDataApplied -= OnSaveDataApplied; ManageObjects(); } private void OnEnable() { MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty); PixelCrushers.SaveSystem.saveDataApplied += OnSaveDataApplied; ManageObjects(); } private void OnDestroy() { //MessageSystem.RemoveListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty); //MessageSystem.RemoveListener(this); //PixelCrushers.SaveSystem.saveDataApplied -= OnSaveDataApplied; } private void OnDisable() { MessageSystem.RemoveListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty); MessageSystem.RemoveListener(this); PixelCrushers.SaveSystem.saveDataApplied -= OnSaveDataApplied; // MessageSystem.RemoveListener(this); //PixelCrushers.SaveSystem.saveDataApplied -= OnSaveDataApplied; } public void OnMessage(MessageArgs messageArgs) { switch (messageArgs.message) { case QuestMachineMessages.QuestStateChangedMessage: ManageObjects(); break; case QuestMachineMessages.QuestCounterChangedMessage: case QuestMachineMessages.RefreshUIsMessage: case QuestMachineMessages.QuestTrackToggleChangedMessage: break; } } private void ManageObjects() { if (m_conditionToEnable.IsTrue(null)) { m_gameObjectsToEnable.ForEach(x => x.SetActive(true)); } if (m_conditionToDisable.IsTrue(null)) { m_gameObjectsToDisable.ForEach(x => x.SetActive(false)); } } }