From 06c4bf0c166064f7d0cfd8baeba3b0c70eae603d Mon Sep 17 00:00:00 2001 From: Pengu123 Date: Fri, 6 May 2022 22:23:52 +0200 Subject: [PATCH] Background control in Coin Flip --- Assets/Resources/Games/coinToss.prefab | 6 +- Assets/Scripts/Games/CoinToss/CoinToss.cs | 86 ++++++++++++++++++++++- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/Assets/Resources/Games/coinToss.prefab b/Assets/Resources/Games/coinToss.prefab index 3bf3fe0d4..240a57be0 100644 --- a/Assets/Resources/Games/coinToss.prefab +++ b/Assets/Resources/Games/coinToss.prefab @@ -624,10 +624,14 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: EligibleHits: [] + scheduledInputs: [] firstEnable: 0 + fg: {fileID: 4608248523716601930} + bg: {fileID: 3722363597051273302} + handAnimator: {fileID: 6887173419118620922} isThrowing: 0 audienceReacting: 0 - handAnimator: {fileID: 6887173419118620922} + coin: {fileID: 0} --- !u!1 &9176706498249536598 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Games/CoinToss/CoinToss.cs b/Assets/Scripts/Games/CoinToss/CoinToss.cs index 0dd35d968..29a47553f 100644 --- a/Assets/Scripts/Games/CoinToss/CoinToss.cs +++ b/Assets/Scripts/Games/CoinToss/CoinToss.cs @@ -18,6 +18,26 @@ namespace HeavenStudio.Games.Loaders { new Param("toggle", false, "Audience Reaction", "Enable Audience Reaction"), }), + + new GameAction("set background color", delegate { var e = eventCaller.currentEntity; CoinToss.instance.ChangeBackgroundColor(e.colorA, 0f); }, 0.5f, false, new List() + { + new Param("colorA", CoinToss.defaultBgColor, "Background Color", "The background color to change to") + } ), + new GameAction("fade background color", delegate { var e = eventCaller.currentEntity; CoinToss.instance.FadeBackgroundColor(e.colorA, e.colorB, e.length); }, 1f, true, new List() + { + new Param("colorA", Color.white, "Start Color", "The starting color in the fade"), + new Param("colorB", CoinToss.defaultBgColor, "End Color", "The ending color in the fade") + } ), + + new GameAction("set foreground color", delegate { var e = eventCaller.currentEntity; CoinToss.instance.ChangeBackgroundColor(e.colorA, 0f, true); }, 0.5f, false, new List() + { + new Param("colorA", CoinToss.defaultFgColor, "Background Color", "The background color to change to") + } ), + new GameAction("fade foreground color", delegate { var e = eventCaller.currentEntity; CoinToss.instance.FadeBackgroundColor(e.colorA, e.colorB, e.length, true); }, 1f, true, new List() + { + new Param("colorA", Color.white, "Start Color", "The starting color in the fade"), + new Param("colorB", CoinToss.defaultFgColor, "End Color", "The ending color in the fade") + } ), }); } } @@ -35,13 +55,42 @@ namespace HeavenStudio.Games //Though it would need a bit of code rewrite to make it work with multiple coins public static CoinToss instance { get; set; } - public Boolean isThrowing; - public bool audienceReacting; + private static Color _defaultBgColor; + public static Color defaultBgColor + { + get + { + ColorUtility.TryParseHtmlString("#F7F742", out _defaultBgColor); + return _defaultBgColor; + } + } + + + private static Color _defaultFgColor; + public static Color defaultFgColor + { + get + { + ColorUtility.TryParseHtmlString("#FFFF83", out _defaultFgColor); + return _defaultFgColor; + } + } + + [Header("Backgrounds")] + public SpriteRenderer fg; + public SpriteRenderer bg; + + Tween bgColorTween; + Tween fgColorTween; [Header("Animators")] public Animator handAnimator; + public Boolean isThrowing; + + public bool audienceReacting; + public PlayerActionEvent coin; private void Awake() @@ -104,5 +153,38 @@ namespace HeavenStudio.Games coin.CanHit(false); } + + public void ChangeBackgroundColor(Color color, float beats, bool isFg = false) + { + var seconds = Conductor.instance.secPerBeat * beats; + + if(!isFg) + { + if (bgColorTween != null) + bgColorTween.Kill(true); + } else + { + if (fgColorTween != null) + fgColorTween.Kill(true); + } + + + if (seconds == 0) + { + if(!isFg) bg.color = color; + if (isFg) fg.color = color; + } + else + { + if(!isFg) bgColorTween = bg.DOColor(color, seconds); + if(isFg) fgColorTween = fg.DOColor(color, seconds); + } + } + + public void FadeBackgroundColor(Color start, Color end, float beats, bool isFg = false) + { + ChangeBackgroundColor(start, 0f, isFg); + ChangeBackgroundColor(end, beats, isFg); + } } }