You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.Events; |
|
using UnityEngine.SceneManagement; |
|
using UnityEngine.UI; |
|
|
|
public class ProgressManage : MonoBehaviour |
|
{ |
|
|
|
private Slider progressSlider;//进度条 |
|
private Text ProgressSliderText;//进度条进度显示文字 |
|
private float nowProcess;//当前加载进度 |
|
private float time; |
|
private float Duration = 0; |
|
private int seconds; |
|
private float frameProcess; |
|
private UnityAction Function { get; set; } |
|
void Awake() |
|
{ |
|
progressSlider = transform.Find("Slider").GetComponent<Slider>(); |
|
ProgressSliderText = transform.Find("Text").GetComponent<Text>(); |
|
} |
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
|
|
} |
|
private void FixedUpdate() |
|
{ |
|
if (seconds < Duration) |
|
{ |
|
nowProcess += frameProcess; |
|
progressSlider.value = nowProcess; |
|
time += Time.deltaTime; |
|
if (time >= 1f) |
|
{ |
|
seconds++; |
|
time = 0f; |
|
} |
|
} |
|
} |
|
private IEnumerator DestoryWindow(float stayTime) |
|
{ |
|
yield return new WaitForSeconds(stayTime); |
|
Function.Invoke(); |
|
Destroy(gameObject); |
|
} |
|
public void SetWindow(string tips, float DurationTime, UnityAction CompleteFunction) |
|
{ |
|
ProgressSliderText.text = tips; |
|
Duration = DurationTime; |
|
Function = CompleteFunction; |
|
StartCoroutine(DestoryWindow(DurationTime)); |
|
frameProcess = 100 / Duration / 50; |
|
transform.SetParent(GameObject.Find("Canvas").transform); |
|
if (transform.parent.GetComponent<CanvasScaler>().referenceResolution.x != 1920) |
|
{ |
|
transform.localScale = new Vector3(0.6f, 0.6f, 1); |
|
} |
|
else |
|
{ |
|
transform.localScale = new Vector3(1, 1, 1); |
|
} |
|
GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 40); |
|
} |
|
}
|
|
|