using System; using System.Collections; using System.Collections.Generic; using CG.Framework; using CG.UTility; using DG.Tweening; using UnityEngine; using UnityEngine.UI; /******************************************************************************* *Create By CG *Function *******************************************************************************/ namespace ZXK.LouDiXvMuNiu { public class ShowTitleUIPrefab : UIBase { private AudioEffectCtrl _audioClipCtrl = null; private bool _playAuding = false; private Action _finishCallback = null; protected override void Awake() { base.Awake(); if (!transform.TryGetComponent(out _audioClipCtrl)) { _audioClipCtrl = gameObject.AddComponent(); } } public void SetTextAudMsg(string content, string audName,Action callback = null) { // Sequence sequence = DOTween.Sequence(); // sequence.Append(transform.GetComponent().DOFade(1.0f, 0.2f)) // .Append(transform.GetComponent().DOFade(0.0f, 0.2f).SetDelay(1.5f).OnComplete(()=> { // if (callback != null) callback(); // Destroy(gameObject); // })); if (callback != null) _finishCallback = callback; transform.GetComponent().DOFade(1.0f, 0.2f); Text textTemp = transform.Find("TxtBG/Text").GetComponent(); if (UtilitiesMng.GetTransCharNum(content) > 68) { textTemp.alignment = TextAnchor.MiddleLeft; } else { textTemp.alignment = TextAnchor.MiddleCenter; } textTemp.text = content; if (string.IsNullOrEmpty(audName)) return; string audioPath = Application.streamingAssetsPath + "/Audios/NiuTips/" + audName + ".mp3"; CG.UTility.UtilitiesMng.LoadAudio(audioPath, (AudioClip clip) => { if (clip) { GetComponent().clip = clip; GetComponent().Play(); _playAuding = true; } }); } private void Update() { if (_playAuding) { if (!GetComponent().isPlaying) { _finishCallback?.Invoke(); GetComponent().DOFade(0.0f, 0.2f); Destroy(gameObject); } } } } }