136 lines
5.3 KiB
C#
136 lines
5.3 KiB
C#
using Invector;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace Beyond
|
|
{
|
|
[vClassHeader("Trigger Footbridge Action", false)]
|
|
public class vTriggerFootbridgeAction : vMonoBehaviour
|
|
{
|
|
[vEditorToolbar("Settings")]
|
|
[Header("Trigger Action Options")]
|
|
[vHelpBox("Disable Selected HUD OnValidate, and enable OnInvalidate. Script ActionTriggerEvent.cs")]
|
|
public bool disableHUD = true;
|
|
|
|
private bool entrance;
|
|
|
|
[Tooltip("Automatically execute the action without the need to press a Button")]
|
|
public bool autoAction;
|
|
|
|
[Header("Enter")]
|
|
[Tooltip("Trigger an Animation - Use the exactly same name of the AnimationState you want to trigger")]
|
|
public string playAnimation = "EnterFootbridge";
|
|
public float playTransitionDuration = 0.25f;
|
|
|
|
[Header("Exit")]
|
|
[Tooltip("Trigger an Animation - Use the exactly same name of the AnimationState you want to trigger")]
|
|
public string exitAnimationStart = "ExitFootbridgeStart";
|
|
public float exitStartTransitionDuration = 0.25f;
|
|
public string exitAnimationEnd = "ExitFootbridgeEnd";
|
|
public float exitEndTransitionDuration = 0.25f;
|
|
|
|
[Tooltip("Use this to limit the trigger to active if forward of character is close to this forward")]
|
|
public bool activeFromForward;
|
|
[Tooltip("Rotate Character for this rotation when active")]
|
|
public bool useTriggerRotation;
|
|
|
|
|
|
[Tooltip("Target Character parent, used to movable ladders to set character child of target, keep empty if ladder is static")]
|
|
public Transform targetCharacterParent;
|
|
|
|
[vEditorToolbar("MatchTarget")]
|
|
[Tooltip("Use a transform to help the character climb any height, take a look at the Example Scene ClimbUp, StepUp, JumpOver objects.")]
|
|
public Transform matchTarget;
|
|
[Tooltip("Use a empty gameObject as a reference for the character to exit")]
|
|
public Transform exitMatchTarget;
|
|
public AnimationCurve enterPositionXZCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
|
|
public AnimationCurve enterPositionYCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
|
|
public AnimationCurve exitPositionXZCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
|
|
public AnimationCurve exitPositionYCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
|
|
public AnimationCurve enterRotationCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
|
|
public AnimationCurve exitRotationCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
|
|
public UnityEvent OnDoAction;
|
|
public UnityEvent OnPlayerEnter;
|
|
public UnityEvent OnPlayerStay;
|
|
public UnityEvent OnPlayerExit;
|
|
|
|
private vTriggerFootbridgeAction second;
|
|
private TriggerDescriptor m_descriptor;
|
|
|
|
public bool Entrance
|
|
{
|
|
get => entrance;
|
|
set
|
|
{
|
|
entrance = value;
|
|
if (Second != null)
|
|
{
|
|
Second.entrance = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public vTriggerFootbridgeAction Second { get => second; set => second = value; }
|
|
|
|
private void OnFootbridgeTriggerEnter(GameObject gameObject)
|
|
{
|
|
if (disableHUD)
|
|
{
|
|
Debug.Log("Player Enter, Hide UI");
|
|
ActionTriggerEvent.ActionTriggerEnter?.Invoke(m_descriptor);
|
|
}
|
|
}
|
|
|
|
private void OnFootbridgeTriggerExit(GameObject gameObject)
|
|
{
|
|
if (disableHUD)
|
|
{
|
|
ActionTriggerEvent.ActionTriggerExit?.Invoke(m_descriptor);
|
|
}
|
|
}
|
|
|
|
protected virtual void Start()
|
|
{
|
|
FindSecond();
|
|
m_descriptor = new TriggerDescriptor(gameObject, TriggerDescriptor.TriggerType.Generic);
|
|
entrance = false;
|
|
OnPlayerEnter.AddListener(() => OnFootbridgeTriggerEnter(gameObject));
|
|
OnPlayerExit.AddListener(() => OnFootbridgeTriggerExit(gameObject));
|
|
}
|
|
|
|
private void FindSecond()
|
|
{
|
|
if(transform.parent != null)
|
|
{
|
|
vTriggerFootbridgeAction[] vTriggerFootbridgeActionAll = transform.parent.GetComponentsInChildren<vTriggerFootbridgeAction>();
|
|
foreach (var item in vTriggerFootbridgeActionAll)
|
|
{
|
|
if(item != this)
|
|
{
|
|
Second = item;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
Debug.LogError("There is no Second vTriggerFootbridgeAction.");
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
if (activeFromForward)
|
|
{
|
|
Gizmos.color = Color.blue;
|
|
Gizmos.DrawLine(transform.position, transform.position + transform.forward * 2f);
|
|
}
|
|
if (targetCharacterParent != null)
|
|
{
|
|
Gizmos.color = Color.red;
|
|
Gizmos.DrawLine(targetCharacterParent.transform.position, targetCharacterParent.transform.position + targetCharacterParent.transform.forward * 5f);
|
|
}
|
|
}
|
|
}
|
|
}
|