Background control in Coin Flip

This commit is contained in:
Pengu123 2022-05-06 22:23:52 +02:00
parent 286b778676
commit 06c4bf0c16
2 changed files with 89 additions and 3 deletions

View file

@ -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

View file

@ -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<Param>()
{
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<Param>()
{
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<Param>()
{
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<Param>()
{
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);
}
}
}