parent
b292baaeaf
commit
30f8e83a6a
12 changed files with 9693 additions and 104 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,7 @@ |
||||
fileFormatVersion: 2 |
||||
guid: bac84382a290ed04eb82c435dcb6cdbf |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,362 @@ |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
using UnityEngine.UI; |
||||
using UnityEngine.Video; |
||||
using OscJack; |
||||
using TMPro; |
||||
|
||||
|
||||
public class MotyOscHandler : MonoBehaviour |
||||
{ |
||||
|
||||
[SerializeField] |
||||
public CanvasGroup intro; |
||||
|
||||
|
||||
[SerializeField] |
||||
public CanvasGroup main; |
||||
|
||||
|
||||
[SerializeField] |
||||
public VideoPlayer videoStandby; |
||||
|
||||
|
||||
[SerializeField] |
||||
public VideoPlayer videoIntro; |
||||
|
||||
|
||||
[SerializeField] |
||||
public VideoPlayer videoEnding; |
||||
|
||||
[SerializeField] |
||||
public Image mask; |
||||
|
||||
[SerializeField] |
||||
public float _fadeDuration = 1f; |
||||
|
||||
[SerializeField] |
||||
public float _hintDuration = 0.5f; |
||||
|
||||
[SerializeField] |
||||
public float _maskDuration = 0.2f; |
||||
[SerializeField] |
||||
public float _lastDurationToShow = 30f; |
||||
|
||||
[SerializeField] |
||||
public TextMeshProUGUI statusText; |
||||
|
||||
[SerializeField] |
||||
public CanvasGroup hint; |
||||
|
||||
private IEnumerator coroutine_hint; |
||||
private IEnumerator coroutine_countdown; |
||||
|
||||
SetChoiceEffect setChoiceEffect; |
||||
|
||||
[SerializeField] |
||||
public TextMeshProUGUI stepText; |
||||
|
||||
[SerializeField] |
||||
public CanvasGroup hintforChat; |
||||
[SerializeField] |
||||
public CanvasGroup hintforStep; |
||||
|
||||
private IEnumerator coroutine_breath; |
||||
|
||||
public CanvasGroup hintforInput; |
||||
|
||||
|
||||
// Start is called before the first frame update |
||||
void Start() |
||||
{ |
||||
setChoiceEffect = main?.GetComponent<SetChoiceEffect>(); |
||||
} |
||||
|
||||
// Update is called once per frame |
||||
void Update() |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
private IEnumerator FadeCanvasGroup(CanvasGroup canvasGroup, float startAlpha, float endAlpha, float duration, float delay = 0f) |
||||
{ |
||||
if (delay > 0f) |
||||
yield return new WaitForSeconds(delay); |
||||
|
||||
canvasGroup.alpha = startAlpha; |
||||
float elapsedTime = 0f; |
||||
|
||||
while (elapsedTime < duration) |
||||
{ |
||||
elapsedTime += Time.deltaTime; |
||||
canvasGroup.alpha = Mathf.Lerp(startAlpha, endAlpha, elapsedTime / duration); |
||||
yield return null; |
||||
} |
||||
|
||||
canvasGroup.alpha = endAlpha; |
||||
} |
||||
|
||||
private IEnumerator DecreaseFill(float duration) |
||||
{ |
||||
float elapsed = 0f; |
||||
mask.fillAmount = 1f; |
||||
|
||||
while (elapsed < duration) |
||||
{ |
||||
elapsed += Time.deltaTime; |
||||
|
||||
if (duration - elapsed > _lastDurationToShow) |
||||
{ |
||||
mask.fillAmount = 0; |
||||
mask.gameObject.SetActive(false); |
||||
} |
||||
else |
||||
{ |
||||
mask.gameObject.SetActive(true); |
||||
mask.fillAmount = Mathf.Lerp(0f, 1f, (duration - elapsed) / _lastDurationToShow); |
||||
} |
||||
yield return null; |
||||
} |
||||
|
||||
mask.fillAmount = 0f; |
||||
} |
||||
|
||||
public void ToggleVideo(string status) |
||||
{ |
||||
switch(status) |
||||
{ |
||||
case "intro": |
||||
videoStandby.gameObject.SetActive(false); |
||||
videoEnding.gameObject.SetActive(false); |
||||
|
||||
videoIntro.time = 0f; |
||||
videoIntro.Play(); |
||||
StartCoroutine(FadeCanvasGroup(intro, intro.alpha, 0f, _fadeDuration)); |
||||
break; |
||||
case "end": |
||||
videoStandby.gameObject.SetActive(false); |
||||
videoEnding.gameObject.SetActive(true); |
||||
|
||||
videoEnding.time = 0f; |
||||
videoEnding.Play(); |
||||
StartCoroutine(FadeCanvasGroup(intro, intro.alpha, 1f, _fadeDuration)); |
||||
break; |
||||
case "standby": |
||||
videoStandby.gameObject.SetActive(true); |
||||
videoEnding.gameObject.SetActive(false); |
||||
|
||||
videoStandby.time = 0f; |
||||
videoStandby.Play(); |
||||
StartCoroutine(FadeCanvasGroup(intro, intro.alpha, 1f, _fadeDuration)); |
||||
break; |
||||
case "reset": |
||||
videoStandby.gameObject.SetActive(false); |
||||
videoEnding.gameObject.SetActive(false); |
||||
StartCoroutine(FadeCanvasGroup(intro, intro.alpha, 0f, _fadeDuration)); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
|
||||
public void onStatus(string status) |
||||
{ |
||||
Debug.Log("/status message received: " + status); |
||||
|
||||
ToggleVideo("reset"); |
||||
|
||||
if (coroutine_hint != null) StopCoroutine(coroutine_hint); |
||||
|
||||
mask.fillAmount = 0f; |
||||
|
||||
switch (status) |
||||
{ |
||||
case "reset": |
||||
intro.alpha = 1.0f; |
||||
main.alpha = 0f; |
||||
// light_mask.alpha = 0f; |
||||
hint.alpha = 0f; |
||||
setChoiceEffect?.Reset(); |
||||
|
||||
ToggleVideo("standby"); |
||||
|
||||
break; |
||||
case "intro": |
||||
// StartCoroutine(FadeCanvasGroup(light_mask, 0f, 1f, _maskDuration)); |
||||
// StartCoroutine(FadeCanvasGroup(intro, 0f, 1f, _fadeDuration, _maskDuration)); |
||||
|
||||
StartCoroutine(FadeCanvasGroup(hint, hint.alpha, 1f, _hintDuration)); |
||||
ToggleVideo("intro"); |
||||
|
||||
break; |
||||
case "go": |
||||
|
||||
// if (light_mask.alpha < 1f) StartCoroutine(FadeCanvasGroup(light_mask, light_mask.alpha, 1f, _fadeDuration)); |
||||
// StartCoroutine(FadeCanvasGroup(intro, intro.alpha, 0f, _fadeDuration)); |
||||
StartCoroutine(FadeCanvasGroup(main, main.alpha, 1f, _fadeDuration)); |
||||
|
||||
break; |
||||
case "end": |
||||
// if (intro.alpha > 0f) StartCoroutine(FadeCanvasGroup(intro, 1f, 0f, _fadeDuration)); |
||||
StartCoroutine(FadeCanvasGroup(main, 1f, 0f, _fadeDuration)); |
||||
// StartCoroutine(FadeCanvasGroup(light_mask, 1f, 0f, _maskDuration, _fadeDuration)); |
||||
if (hint.alpha > 0f) |
||||
{ |
||||
coroutine_hint = FadeCanvasGroup(hint, hint.alpha, 0f, _hintDuration); |
||||
StartCoroutine(coroutine_hint); |
||||
} |
||||
|
||||
ToggleVideo("end"); |
||||
|
||||
break; |
||||
default: |
||||
Debug.LogWarning("Unknown status: " + status); |
||||
break; |
||||
} |
||||
|
||||
} |
||||
public void onCountDown(string time) |
||||
{ |
||||
Debug.Log("/countdown message received: " + time); |
||||
|
||||
if (mask != null) |
||||
{ |
||||
|
||||
if (coroutine_countdown != null) StopCoroutine(coroutine_countdown); |
||||
|
||||
if (time == "0") |
||||
{ |
||||
mask.fillAmount = 0f; |
||||
mask.gameObject.SetActive(false); |
||||
|
||||
} |
||||
else |
||||
{ |
||||
coroutine_countdown = DecreaseFill(float.Parse(time)); |
||||
StartCoroutine(coroutine_countdown); |
||||
} |
||||
} |
||||
|
||||
} |
||||
public void onSpeechPause(string pause) |
||||
{ |
||||
Debug.Log("/speechpause message received: " + pause); |
||||
float pause_time = float.Parse(pause); |
||||
if (pause_time > 0f) |
||||
{ |
||||
StartCoroutine(FadeCanvasGroup(hintforInput, hintforInput.alpha, 0f, pause_time/1000.0f)); |
||||
} |
||||
|
||||
} |
||||
public void onInput(string input) |
||||
{ |
||||
Debug.Log("/input message received: " + input); |
||||
|
||||
|
||||
|
||||
|
||||
if (input.Length == 0) |
||||
{ |
||||
statusText.text = ""; |
||||
// hintforChat.alpha = 0f; |
||||
if (hintforChat.alpha > 0f) |
||||
{ |
||||
StartCoroutine(FadeCanvasGroup(hintforChat, hintforChat.alpha, 0f, _hintDuration)); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
hintforInput.alpha = 1.0f; |
||||
|
||||
if (hint.alpha < 1f) |
||||
{ |
||||
if (coroutine_hint != null) StopCoroutine(coroutine_hint); |
||||
coroutine_hint = FadeCanvasGroup(hint, hint.alpha, 1f, _hintDuration); |
||||
StartCoroutine(coroutine_hint); |
||||
} |
||||
|
||||
|
||||
// statusText.text = input; |
||||
StartCoroutine(TypeWriter(statusText, input)); |
||||
// hintforChat.alpha = 1f; |
||||
// if (hintforChat.alpha < 1f) |
||||
// { |
||||
StartCoroutine(FadeCanvasGroup(hintforChat, hintforChat.alpha, 1f, _hintDuration)); |
||||
// } |
||||
|
||||
if (hint.alpha < 1f) |
||||
{ |
||||
// if (coroutine_hint != null) StopCoroutine(coroutine_hint); |
||||
// coroutine_hint = FadeCanvasGroup(hint, hint.alpha, 1f, _hintDuration); |
||||
// StartCoroutine(coroutine_hint); |
||||
|
||||
if (coroutine_hint != null) StopCoroutine(coroutine_hint); |
||||
coroutine_hint = BreathFade(hint); |
||||
StartCoroutine(coroutine_hint); |
||||
|
||||
} |
||||
} |
||||
|
||||
|
||||
} |
||||
public void onHint(string text) |
||||
{ |
||||
Debug.Log("/hint message received: " + text); |
||||
|
||||
// stepText.text = text; |
||||
StartCoroutine(TypeWriter(stepText, text)); |
||||
|
||||
StartCoroutine(FadeCanvasGroup(hintforStep, hintforStep.alpha, 1f, _hintDuration)); |
||||
|
||||
if (coroutine_breath != null) StopCoroutine(coroutine_breath); |
||||
// coroutine_hint = FadeCanvasGroup(hint, hint.alpha, text.Length > 0 ? 1f : 0f, _hintDuration); |
||||
// StartCoroutine(coroutine_hint); |
||||
|
||||
hintforInput.alpha = 1.0f; |
||||
|
||||
coroutine_breath = BreathFade(hintforStep); |
||||
StartCoroutine(coroutine_breath); |
||||
|
||||
|
||||
} |
||||
private IEnumerator BreathFade(CanvasGroup canvasGroup, float maxAlpha=1f, float minAlpha=0.5f, |
||||
float fadeInDuration=1.2f, float fadeOutDuration=1.2f, int cycles=20) |
||||
{ |
||||
for (int i = 0; i < cycles; i++) |
||||
{ |
||||
// Fade out |
||||
float elapsed = 0f; |
||||
while (elapsed < fadeOutDuration) |
||||
{ |
||||
elapsed += Time.deltaTime; |
||||
canvasGroup.alpha = Mathf.Lerp(maxAlpha, minAlpha, elapsed / fadeOutDuration); |
||||
yield return null; |
||||
} |
||||
canvasGroup.alpha = minAlpha; |
||||
|
||||
// Fade in |
||||
elapsed = 0f; |
||||
while (elapsed < fadeInDuration) |
||||
{ |
||||
elapsed += Time.deltaTime; |
||||
canvasGroup.alpha = Mathf.Lerp(minAlpha, maxAlpha, elapsed / fadeInDuration); |
||||
yield return null; |
||||
} |
||||
canvasGroup.alpha = maxAlpha; |
||||
} |
||||
} |
||||
public IEnumerator TypeWriter(TextMeshProUGUI textComponent, string message, float typeSpeed = 0.2f) |
||||
{ |
||||
|
||||
textComponent.text = ""; |
||||
foreach (char c in message) |
||||
{ |
||||
textComponent.text += c; |
||||
yield return new WaitForSeconds(typeSpeed); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,11 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 6900c568ad7dd3a4d93dc992baf8627f |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@ |
||||
%YAML 1.1 |
||||
%TAG !u! tag:unity3d.com,2011: |
||||
--- !u!84 &8400000 |
||||
RenderTexture: |
||||
m_ObjectHideFlags: 0 |
||||
m_CorrespondingSourceObject: {fileID: 0} |
||||
m_PrefabInstance: {fileID: 0} |
||||
m_PrefabAsset: {fileID: 0} |
||||
m_Name: Moty DisplayTexture |
||||
m_ImageContentsHash: |
||||
serializedVersion: 2 |
||||
Hash: 00000000000000000000000000000000 |
||||
m_ForcedFallbackFormat: 4 |
||||
m_DownscaleFallback: 0 |
||||
m_IsAlphaChannelOptional: 0 |
||||
serializedVersion: 5 |
||||
m_Width: 1280 |
||||
m_Height: 1024 |
||||
m_AntiAliasing: 8 |
||||
m_MipCount: -1 |
||||
m_DepthStencilFormat: 94 |
||||
m_ColorFormat: 8 |
||||
m_MipMap: 0 |
||||
m_GenerateMips: 1 |
||||
m_SRGB: 0 |
||||
m_UseDynamicScale: 0 |
||||
m_BindMS: 0 |
||||
m_EnableCompatibleFormat: 1 |
||||
m_EnableRandomWrite: 0 |
||||
m_TextureSettings: |
||||
serializedVersion: 2 |
||||
m_FilterMode: 1 |
||||
m_Aniso: 0 |
||||
m_MipBias: 0 |
||||
m_WrapU: 1 |
||||
m_WrapV: 1 |
||||
m_WrapW: 1 |
||||
m_Dimension: 2 |
||||
m_VolumeDepth: 1 |
||||
m_ShadowSamplingMode: 2 |
||||
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 2df5ae5caa49d43468c4b8b2f9ca9a36 |
||||
NativeFormatImporter: |
||||
externalObjects: {} |
||||
mainObjectFileID: 8400000 |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,40 @@ |
||||
%YAML 1.1 |
||||
%TAG !u! tag:unity3d.com,2011: |
||||
--- !u!84 &8400000 |
||||
RenderTexture: |
||||
m_ObjectHideFlags: 0 |
||||
m_CorrespondingSourceObject: {fileID: 0} |
||||
m_PrefabInstance: {fileID: 0} |
||||
m_PrefabAsset: {fileID: 0} |
||||
m_Name: Moty Video Texture |
||||
m_ImageContentsHash: |
||||
serializedVersion: 2 |
||||
Hash: 00000000000000000000000000000000 |
||||
m_ForcedFallbackFormat: 4 |
||||
m_DownscaleFallback: 0 |
||||
m_IsAlphaChannelOptional: 0 |
||||
serializedVersion: 5 |
||||
m_Width: 1280 |
||||
m_Height: 1024 |
||||
m_AntiAliasing: 8 |
||||
m_MipCount: -1 |
||||
m_DepthStencilFormat: 94 |
||||
m_ColorFormat: 8 |
||||
m_MipMap: 0 |
||||
m_GenerateMips: 1 |
||||
m_SRGB: 0 |
||||
m_UseDynamicScale: 0 |
||||
m_BindMS: 0 |
||||
m_EnableCompatibleFormat: 1 |
||||
m_EnableRandomWrite: 0 |
||||
m_TextureSettings: |
||||
serializedVersion: 2 |
||||
m_FilterMode: 1 |
||||
m_Aniso: 0 |
||||
m_MipBias: 0 |
||||
m_WrapU: 1 |
||||
m_WrapV: 1 |
||||
m_WrapW: 1 |
||||
m_Dimension: 2 |
||||
m_VolumeDepth: 1 |
||||
m_ShadowSamplingMode: 2 |
||||
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 6c974968dd7933a4daab7dba5fd02dfd |
||||
NativeFormatImporter: |
||||
externalObjects: {} |
||||
mainObjectFileID: 8400000 |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
Loading…
Reference in new issue