120 lines
3.3 KiB
C#
120 lines
3.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using PixelCrushers.DialogueSystem;
|
|
using Sirenix.Utilities;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class ActionTrigger : QuestTriggerBase
|
|
{
|
|
public GameObject[] m_objectsToEnable;
|
|
public GameObject[] m_objectsToDisable;
|
|
public bool m_fireOnStart = false;
|
|
public ActionTrigger[] m_triggersToFire;
|
|
public float m_delay = -1f;
|
|
public ActionResponse m_actionResponse;
|
|
|
|
public MaterialChanger[] m_materialsToChange;
|
|
//[Tooltip("Conversation to get bark content from.")]
|
|
//[ConversationPopup(false)]
|
|
//public string m_conversationBark = string.Empty;
|
|
|
|
|
|
[Serializable]
|
|
public class MaterialChanger
|
|
{
|
|
public Renderer renderer;
|
|
public Material materialToSet;
|
|
}
|
|
// Start is called before the first frame update
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
//gameObject.layer = LayerMask.NameToLayer("Triggers");
|
|
m_wasFired = false;
|
|
if (m_fireOnStart)
|
|
{
|
|
OnAction();
|
|
}
|
|
}
|
|
|
|
IEnumerator FireAction(string actionName)
|
|
{
|
|
OnActionResponse(m_actionResponse);
|
|
if (m_delay > 0)
|
|
{
|
|
yield return new WaitForSeconds(m_delay);
|
|
}
|
|
foreach (var g in m_objectsToEnable)
|
|
{
|
|
if (g != null)
|
|
{
|
|
g.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"ActionTrigger ({gameObject.name}), object to enable null ");
|
|
}
|
|
}
|
|
foreach (var g in m_objectsToDisable)
|
|
{
|
|
if (g != null)
|
|
{
|
|
g.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"ActionTrigger ({gameObject.name}), object to disable null ");
|
|
}
|
|
}
|
|
|
|
foreach (var t in m_triggersToFire)
|
|
{
|
|
if (t != null)
|
|
{
|
|
t.OnAction(actionName);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"ActionTrigger ({gameObject.name}), trigger to fire is null ");
|
|
}
|
|
}
|
|
|
|
if (m_materialsToChange != null)
|
|
{
|
|
foreach (var m in m_materialsToChange)
|
|
{
|
|
if (m.renderer && m.materialToSet)
|
|
m.renderer.material = m.materialToSet;
|
|
}
|
|
}
|
|
|
|
//if (!m_conversationBark.IsNullOrWhitespace())
|
|
//{
|
|
// BarkManager.Instance.PlayBark(m_conversationBark);
|
|
//}
|
|
|
|
|
|
yield return null;
|
|
}
|
|
|
|
[Sirenix.OdinInspector.Button]
|
|
public virtual void OnAction(string actionName = "")
|
|
{
|
|
if (!m_wasFired || !m_fireOnce)
|
|
StartCoroutine(FireAction(actionName));
|
|
m_wasFired = true;
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.tag == "Player")
|
|
{
|
|
OnAction();
|
|
}
|
|
}
|
|
}
|
|
|
|
} |