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

79 lines
2.0 KiB
C#
Raw Normal View History

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