A bunch of stuff
This commit is contained in:
@@ -3,34 +3,41 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
[RequireComponent(typeof(OutlineFx.OutlineFx))]
|
||||
public class MyButton : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
[SerializeField]
|
||||
private UnityEvent _onClick;
|
||||
|
||||
|
||||
|
||||
// references
|
||||
[SerializeField]
|
||||
private OutlineFx.OutlineFx _outlineFx;
|
||||
|
||||
|
||||
[SerializeField]
|
||||
public bool isActive = true;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (!TryGetComponent(out Collider2D _))
|
||||
{
|
||||
Debug.LogError("MyButton needs a Collider2D to work", gameObject);
|
||||
}
|
||||
|
||||
_outlineFx = GetComponent<OutlineFx.OutlineFx>();
|
||||
|
||||
if (!_outlineFx)
|
||||
{
|
||||
_outlineFx = GetComponent<OutlineFx.OutlineFx>();
|
||||
}
|
||||
_outlineFx.enabled = false;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
_onClick.Invoke();
|
||||
if(isActive)
|
||||
_onClick.Invoke();
|
||||
}
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
_outlineFx.enabled = true;
|
||||
_outlineFx.enabled = isActive;
|
||||
}
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 754378f39f0befc4e9efee4fdad6b35e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
[TrackBindingType(typeof(MyButton))]
|
||||
[TrackClipType(typeof(MyButtonTrackClip))]
|
||||
public class MyButtonTrack : TrackAsset
|
||||
{
|
||||
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
|
||||
{
|
||||
return ScriptPlayable<MyButtonTrackMixer>.Create(graph, inputCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49ae3e466a6f42f46ad7b91a4848b95f
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
public class MyButtonTrackBehaviour : PlayableBehaviour
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99322867652286d46b57271f5374d6fc
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
public class MyButtonTrackClip : PlayableAsset
|
||||
{
|
||||
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
|
||||
{
|
||||
var playable = ScriptPlayable<MyButtonTrackBehaviour>.Create(graph);
|
||||
return playable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f56a4c3fb40a3447ad70f8c9eaa3730
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
public class MyButtonTrackMixer : PlayableBehaviour
|
||||
{
|
||||
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
|
||||
{
|
||||
var myButton = playerData as MyButton;
|
||||
|
||||
myButton!.isActive = false;
|
||||
|
||||
for (var i = 0; i < playable.GetInputCount(); i++)
|
||||
{
|
||||
var inputWeight = playable.GetInputWeight(i);
|
||||
|
||||
if (inputWeight > 0)
|
||||
{
|
||||
myButton.isActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24cbbbadd683a464a958616d2eb17eb5
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(TextMeshProUGUI))]
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class VoiceLinePlayer : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
public class CloseCaption
|
||||
{
|
||||
public string text;
|
||||
public float timing;
|
||||
}
|
||||
|
||||
// singleton
|
||||
public static VoiceLinePlayer Instance { get; private set; }
|
||||
|
||||
|
||||
// references
|
||||
private TextMeshProUGUI _subtitleText;
|
||||
private AudioSource _audioSource;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
SetInstance();
|
||||
_subtitleText = GetComponent<TextMeshProUGUI>();
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
SetInstance();
|
||||
}
|
||||
|
||||
private void SetInstance()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("VoiceLinePlayer Instance already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_audioSource.isPlaying)
|
||||
{
|
||||
_subtitleText.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayLine(AudioClip clip, List<CloseCaption> cc)
|
||||
{
|
||||
_audioSource.clip = clip;
|
||||
_audioSource.Play();
|
||||
foreach (var caption in cc)
|
||||
{
|
||||
StartCoroutine(ShowCaption(caption.text, caption.timing));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ShowCaption(string text, float timing)
|
||||
{
|
||||
yield return new WaitForSeconds(timing);
|
||||
_subtitleText.text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6498748b618b6c4388f8e28a6b66e28
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class VoiceLineTrigger : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioClip _clip;
|
||||
|
||||
[SerializeField]
|
||||
private List<VoiceLinePlayer.CloseCaption> _cc;
|
||||
|
||||
[ContextMenu("Trigger")]
|
||||
public void Trigger()
|
||||
{
|
||||
VoiceLinePlayer.Instance.PlayLine(_clip, _cc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f5510112c83494c952bd74899f39a5
|
||||
Reference in New Issue
Block a user