added fade boi

This commit is contained in:
cyndrdev 2021-03-11 12:02:34 +00:00
parent 9c4a16ec55
commit a28207bbcd
4 changed files with 270 additions and 88 deletions

File diff suppressed because one or more lines are too long

View File

@ -170,7 +170,7 @@ RectTransform:
m_AnchorMin: {x: 1, y: 1} m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 150, y: 150} m_SizeDelta: {x: 75, y: 75}
m_Pivot: {x: 1, y: 1} m_Pivot: {x: 1, y: 1}
--- !u!222 &5119468870623144694 --- !u!222 &5119468870623144694
CanvasRenderer: CanvasRenderer:
@ -247,6 +247,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 5119468870989674483} - component: {fileID: 5119468870989674483}
- component: {fileID: 5119468870989674482} - component: {fileID: 5119468870989674482}
- component: {fileID: 66718147}
m_Layer: 5 m_Layer: 5
m_Name: Dialogue UI m_Name: Dialogue UI
m_TagString: Untagged m_TagString: Untagged
@ -288,5 +289,19 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_dialogue: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2} _dialogue: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2}
_fadeTime: 0.25
_dialogueGroup: {fileID: 66718147}
_text: {fileID: 5119468870461405386} _text: {fileID: 5119468870461405386}
_portrait: {fileID: 5119468870623144585} _portrait: {fileID: 5119468870623144585}
--- !u!225 &66718147
CanvasGroup:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5119468870989674484}
m_Enabled: 1
m_Alpha: 1
m_Interactable: 0
m_BlocksRaycasts: 0
m_IgnoreParentGroups: 0

View File

@ -2662,11 +2662,11 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.017264387 value: -0.017264402
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0.009297717 value: 0.009297725
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832858914730, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832858914730, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_XAxis.m_InvertInput propertyPath: m_XAxis.m_InvertInput
@ -3256,14 +3256,6 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 2070784762} m_TransformParent: {fileID: 2070784762}
m_Modifications: m_Modifications:
- target: {fileID: 5119468870623144584, guid: fde30a46065b3b144ac612ec0b3e484a, type: 3}
propertyPath: m_SizeDelta.x
value: 75
objectReference: {fileID: 0}
- target: {fileID: 5119468870623144584, guid: fde30a46065b3b144ac612ec0b3e484a, type: 3}
propertyPath: m_SizeDelta.y
value: 75
objectReference: {fileID: 0}
- target: {fileID: 5119468870989674483, guid: fde30a46065b3b144ac612ec0b3e484a, type: 3} - target: {fileID: 5119468870989674483, guid: fde30a46065b3b144ac612ec0b3e484a, type: 3}
propertyPath: m_Pivot.x propertyPath: m_Pivot.x
value: 0.5 value: 0.5

View File

@ -13,6 +13,9 @@ using UnityEditor;
public class DialogueUI : MonoBehaviour public class DialogueUI : MonoBehaviour
{ {
[SerializeField] private DialogueSystem _dialogue; [SerializeField] private DialogueSystem _dialogue;
[SerializeField] private float _fadeTime;
[SerializeField] private CanvasGroup _dialogueGroup;
[SerializeField] private TMP_Text _text; [SerializeField] private TMP_Text _text;
[SerializeField] private GameObject _portrait; [SerializeField] private GameObject _portrait;
@ -49,9 +52,20 @@ public class DialogueUI : MonoBehaviour
private IEnumerator ShowLineCR(string text, float duration) private IEnumerator ShowLineCR(string text, float duration)
{ {
// update text and show portrait // update text and show portrait
float a = 0f;
_dialogueGroup.alpha = a;
_text.text = text; _text.text = text;
_portrait.SetActive( true ); _portrait.SetActive( true );
while ( a < 1f )
{
yield return null;
a += Time.deltaTime / _fadeTime;
_dialogueGroup.alpha = a;
}
_dialogueGroup.alpha = 1f;
// wait until timeout of dismissal // wait until timeout of dismissal
var timer = 0f; var timer = 0f;
while (!_dismissed && timer < duration) while (!_dismissed && timer < duration)
@ -62,6 +76,15 @@ public class DialogueUI : MonoBehaviour
yield return null; yield return null;
} }
while ( a > 0f )
{
yield return null;
a -= Time.deltaTime / _fadeTime;
_dialogueGroup.alpha = a;
}
_dialogueGroup.alpha = 0f;
// hide ui elements // hide ui elements
HideSubtitle(); HideSubtitle();