From 7a44ef36f56f34d7d1416bb84ccebc8b1c30d1f2 Mon Sep 17 00:00:00 2001 From: shalliwell Date: Sun, 10 May 2020 09:47:30 +1000 Subject: [PATCH] Portraits toggle active based on showing Portraits now are on stage at all times once asked for to prevent running into issues with unity ui. This caused massive overdraw of MANY portraits that are all invisible. Now we toggle active inactive based before and after tweens. --- .../Scripts/Components/PortraitController.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Assets/Fungus/Scripts/Components/PortraitController.cs b/Assets/Fungus/Scripts/Components/PortraitController.cs index 1e832733..5ac5d350 100644 --- a/Assets/Fungus/Scripts/Components/PortraitController.cs +++ b/Assets/Fungus/Scripts/Components/PortraitController.cs @@ -240,6 +240,8 @@ namespace Fungus rt.pivot = Vector2.one * 0.5f; rt.ForceUpdateRectTransforms(); + po.SetActive(false); + character.State.allPortraits.Add(pi); } } @@ -431,12 +433,11 @@ namespace Fungus if (options.character.State.portrait != null && options.character.State.portrait != options.portrait) { - LeanTween.alpha(options.character.State.portraitImage.rectTransform, 0f, duration) - .setEase(stage.FadeEaseType) - .setRecursive(false); + HidePortrait(options.character.State.portraitImage.rectTransform, duration); } options.character.State.SetPortraitImageBySprite(options.portrait); + options.character.State.portraitImage.rectTransform.gameObject.SetActive(true); LeanTween.alpha(options.character.State.portraitImage.rectTransform, 1f, duration).setEase(stage.FadeEaseType).setRecursive(false); DoMoveTween(options); @@ -457,6 +458,14 @@ namespace Fungus options.character.State.position = options.toPosition; } + protected virtual void HidePortrait(RectTransform rectTransform, float duration) + { + LeanTween.alpha(rectTransform, 0f, duration) + .setEase(stage.FadeEaseType) + .setRecursive(false) + .setOnComplete(() => rectTransform.gameObject.SetActive(false)); + } + /// /// Hide portrait with provided options /// @@ -474,7 +483,7 @@ namespace Fungus // LeanTween doesn't handle 0 duration properly float duration = (options.fadeDuration > 0f) ? options.fadeDuration : float.Epsilon; - LeanTween.alpha(options.character.State.portraitImage.rectTransform, 0f, duration).setEase(stage.FadeEaseType).setRecursive(false); + HidePortrait(options.character.State.portraitImage.rectTransform, duration); DoMoveTween(options);