Unity progress bar production

  In the production of the progress bar, can be prepared beforehand Image background image, substantially below the UI hierarchy; prepares an empty node named LoadingWnd, covered the entire interface, the following were added in the background (bg). Officially making progress bar was added message (TextTips) below.

  1, adding UI-Image, a progress bar background, named loadingbg, and use squared background picture processing, picture Type select Sliced.

  2, a copy as a prospect, named loadingfg, replaced with a foreground image, Type changed Filled, select Herizontal way, the level of fill.

  3, at loadingfg, progress indicator added point (ImgPoint)

  4. Add imgPoint text prompts, text displays a progress percentage.

  5, the following working code portions;

 1 using UnityEngine;
 2 using UnityEngine.UI;
 3 
 5 public class LoadingWnd : WindowRoot 
 6 {
 7     public Text txtTips;
 8     public Image imgFG;
 9     public Image imgPoint;
10     public Text txtPrg;
11 
12     private float fgWidth;
13 
14     protected override void InitWnd()
15     {
16         base.InitWnd();
17 
18         fgWidth = imgFG.GetComponent<RectTransform>().sizeDelta.x;
19 
20         SetText(txtTips, "这是一条提示Tips...");
21         SetText(txtTips, "0%");
22         txtPrg.text = "0%";
23         imgFG.fillAmount = 0;
24         imgPoint.transform.localPosition = new Vector3(-449f, 0, 0);
25 
26        
27     }
28     public void SetProgress(float prg)
29     {
30         SetText(txtTips,(int)(prg * 100) + "%");
31         imgFG.fillAmount = prg;
32 
33         float posX = prg * fgWidth - 449;
34         imgPoint.GetComponent<RectTransform>().anchoredPosition = new Vector2(posX, 0);
35     }
36 }

  prg parameters need to be defined in the resource load .cs in line with the actual resource loading progress.

 

Guess you like

Origin www.cnblogs.com/dream-seeker-201907/p/11261133.html