forked from u3dkbe/kbengine_unity3d_warring
-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathloadingbar_backgroundpic.cs
More file actions
96 lines (81 loc) · 5.21 KB
/
loadingbar_backgroundpic.cs
File metadata and controls
96 lines (81 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using UnityEngine;
using KBEngine;
using System;
using System.Collections;
public class loadingbar_backgroundpic : MonoBehaviour {
public static UITexture obj = null;
public static loadingbar_backgroundpic inst = null;
public static Shader Transparent_Colored = null;
private float fadeMax = 1.5f;
private float fadeTime;
public bool startFadeOut = false;
void Awake ()
{
obj = GetComponent<UITexture>();
inst = this;
}
// Use this for initialization
void Start () {
obj.shader = Transparent_Colored;
loader.inst.StartCoroutine(getFullTexture());
NGUITools.SetActive(obj.gameObject, false);
}
IEnumerator getFullTexture(){
// if(obj.mainTexture == null || obj.mainTexture.name == "" || obj.mainTexture.name.IndexOf("_min") > -1)
{
//string[] res = obj.mainTexture.name.Split(new char[]{'_', 'm', 'i', 'n'});
System.Random Random1 = new System.Random();
string path = "/ui/bg/loadingscreen_" + Random1.Next(1,6) + ".jpg";
Common.DEBUG_MSG("loadingbar_backgroundpic::getFullTexture: starting download(" + Common.safe_url(path) + ") backgroundpic! curr=" + obj.mainTexture.name);
WWW www = new WWW(Common.safe_url(path));
yield return www;
//if (www.error != null)
if (!String.IsNullOrEmpty(www.error))
{
Common.ERROR_MSG(www.error);
}
//else if (www.texture != null)
else if (!(System.Object.ReferenceEquals(www.texture,null)))
{
obj.mainTexture = www.texture;
obj.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
}
Common.DEBUG_MSG("loadingbar_backgroundpic::getFullTexture: download backgroundpic is finished!");
}
}
// Update is called once per frame
void Update () {
}
void FixedUpdate () {
if(startFadeOut == true)
{
Color c = obj.color;
if (fadeTime <= 0.0f)
{
NGUITools.SetActive(obj.gameObject, false);
c.a = 1.0f;
obj.color = c;
Common.DEBUG_MSG("fadeout_close: over, shader=" + obj.shader);
startFadeOut = false;
loader.inst.StartCoroutine(getFullTexture());
}
else
{
c.a = Mathf.InverseLerp(0.0f, 1.0f, fadeTime / fadeMax);
if(fadeTime <= 0.8f)
{
NGUITools.SetActive(loadingbar.label.gameObject, false);
}
}
obj.color = c;
//Common.DEBUG_MSG("fadeout: a=" + obj.color.a);
fadeTime -= Time.deltaTime;
}
}
public void fadeout_close()
{
fadeTime = fadeMax;
startFadeOut = true;
NGUITools.SetActive(loadingbar.obj.gameObject, false);
}
}