Files
Continentis/Assets/OtherPlugins/Sprite Shaders Ultimate/Demo/Scripts/Demo_Trigger.cs

104 lines
2.4 KiB
C#
Raw Normal View History

2025-11-25 21:49:03 -05:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2026-04-01 12:23:27 -04:00
using UnityEngine.UI;
using UnityEngine.EventSystems;
2025-11-25 21:49:03 -05:00
namespace SpriteShadersUltimate.Demo
{
public class Demo_Trigger : MonoBehaviour
{
2026-04-01 12:23:27 -04:00
ShaderFaderSSU fader;
2025-11-25 21:49:03 -05:00
public List<Demo_TriggerEvent> events;
2026-04-01 12:23:27 -04:00
void Start()
2025-11-25 21:49:03 -05:00
{
fader = GetComponent<ShaderFaderSSU>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
2026-04-01 12:23:27 -04:00
if(collision.name == "Player")
{
ChangeState(true);
}
2025-11-25 21:49:03 -05:00
}
private void OnTriggerExit2D(Collider2D collision)
{
2026-04-01 12:23:27 -04:00
if (collision.name == "Player")
{
ChangeState(false);
}
2025-11-25 21:49:03 -05:00
}
public void ChangeState(bool isActive)
{
2026-04-01 12:23:27 -04:00
if (fader != null)
{
fader.isFaded = isActive;
}
2025-11-25 21:49:03 -05:00
if (events != null && isActive)
2026-04-01 12:23:27 -04:00
{
foreach (Demo_TriggerEvent demoEvent in events)
{
2025-11-25 21:49:03 -05:00
StartCoroutine(PlayEvent(demoEvent));
2026-04-01 12:23:27 -04:00
}
}
2025-11-25 21:49:03 -05:00
}
2026-04-01 12:23:27 -04:00
IEnumerator PlayEvent(Demo_TriggerEvent demoEvent)
2025-11-25 21:49:03 -05:00
{
yield return new WaitForSeconds(demoEvent.delay);
demoEvent.Play(transform);
}
}
2026-04-01 12:23:27 -04:00
[System.Serializable]
2025-11-25 21:49:03 -05:00
public class Demo_TriggerEvent
{
2026-04-01 12:23:27 -04:00
[Header("Delay:")]
public float delay;
2025-11-25 21:49:03 -05:00
2026-04-01 12:23:27 -04:00
[Header("Change Fader:")]
public ShaderFaderSSU fader;
2025-11-25 21:49:03 -05:00
public bool faderState;
public bool negateState;
2026-04-01 12:23:27 -04:00
[Header("Snap Player:")]
public bool snapPlayer;
2025-11-25 21:49:03 -05:00
public bool isRelative;
public Vector3 snapPosition;
2026-04-01 12:23:27 -04:00
[Header("Hurt Player:")]
public bool hurtPlayer;
2025-11-25 21:49:03 -05:00
public Vector2 velocity;
public void Play(Transform source)
{
2026-04-01 12:23:27 -04:00
if(fader != null)
2025-11-25 21:49:03 -05:00
{
2026-04-01 12:23:27 -04:00
if(negateState)
{
2025-11-25 21:49:03 -05:00
fader.isFaded = !fader.isFaded;
2026-04-01 12:23:27 -04:00
}
2025-11-25 21:49:03 -05:00
else
2026-04-01 12:23:27 -04:00
{
2025-11-25 21:49:03 -05:00
fader.isFaded = faderState;
2026-04-01 12:23:27 -04:00
}
2025-11-25 21:49:03 -05:00
}
2026-04-01 12:23:27 -04:00
if(snapPlayer)
{
2025-11-25 21:49:03 -05:00
Demo_Player.instance.SnapPosition(isRelative ? source.position + snapPosition : snapPosition);
2026-04-01 12:23:27 -04:00
}
2025-11-25 21:49:03 -05:00
2026-04-01 12:23:27 -04:00
if(hurtPlayer)
{
Demo_Player.instance.GetHurt(velocity);
}
2025-11-25 21:49:03 -05:00
}
}
}