forked from u3dkbe/kbengine_unity3d_warring
-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathloader.cs
More file actions
159 lines (126 loc) · 9.47 KB
/
loader.cs
File metadata and controls
159 lines (126 loc) · 9.47 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using UnityEngine;
using KBEngine;
using System.Collections;
using System;
using System.Xml;
using System.Collections.Generic;
public class loader : MonoBehaviour {
public static loader inst = null;
public string currentSceneName = "login";
private SceneObject loadingbarObj = new SceneObject();
public UnityEngine.Object defaultEntityAsset = null;
public UnityEngine.Object entityHudInfosAsset = null;
public Dictionary<string, Scene> scenes = new Dictionary<string, Scene>();
public LoadAssetsPool loadPool = null;
void Awake ()
{
inst = this;
Common.DEBUG_MSG("go!");
loadingbarObj.asset = new Asset();
loadingbarObj.asset.source = "loadingbar.unity3d";
scenes.Add(currentSceneName, new Scene(currentSceneName, this));
}
// Use this for initialization
void Start () {
StartCoroutine(loadInit());
loadPool = new LoadAssetsPool(this, 5);
installEvents();
Destroy(UnityEngine.GameObject.Find("baseTerrainRes"));
}
void installEvents()
{
new KBEEventProc();
}
// Update is called once per frame
void Update () {
}
public Scene findScene(string name, bool autocreate)
{
Scene scene = null;
if(!scenes.TryGetValue(currentSceneName, out scene))
{
if(autocreate == false)
return null;
scene = new Scene(currentSceneName, this);
scenes.Add(currentSceneName, scene);
}
return scene;
}
IEnumerator loadInit(){
Common.DEBUG_MSG("starting loadInit!");
WWW loadingbarwww = new WWW(Common.safe_url("/StreamingAssets/loadingbar.unity3d"));
WWW defaultEntityAssetwww = new WWW(Common.safe_url("/StreamingAssets/defaultEntityMesh.unity3d"));
WWW entityHudInfosAssetwww = new WWW(Common.safe_url("/StreamingAssets/hud_infos.unity3d"));
//WWW terrainDiffuseShaderwww = new WWW(Common.safe_url("/StreamingAssets/shader_Terrain_Diffuse.unity3d"));
Scene scene = findScene(currentSceneName, true);
scene.loadScene(true, false);
loadingbar.reset(false);
Common.DEBUG_MSG("loadInit is finished!");
// 下载选人场景
scene = findScene("selavatar", true);
scene.loadScene(false, true);
yield return loadingbarwww;
//if (loadingbarwww.error != null)
if (!String.IsNullOrEmpty(loadingbarwww.error))
Common.ERROR_MSG(loadingbarwww.error);
else
{
StartCoroutine(_InstantiateLoadingbarObj(loadingbarwww));
}
yield return defaultEntityAssetwww;
StartCoroutine(_InstantiateDefaultEntityAsset(defaultEntityAssetwww));
yield return entityHudInfosAssetwww;
StartCoroutine(_InstantiateEntityHudInfosAsset(entityHudInfosAssetwww));
//yield return terrainDiffuseShaderwww;
//StartCoroutine(_InstantiateTerrainDiffuseShaderObjs(terrainDiffuseShaderwww));
}
IEnumerator _InstantiateLoadingbarObj(WWW loadingbarwww)
{
AssetBundleRequest request = loadingbarwww.assetBundle.LoadAsync("loadingbar", typeof(UnityEngine.GameObject));
yield return request;
UnityEngine.GameObject go = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(request.asset);
go.name = loadingbarObj.name;
loadingbarObj.gameObject = go;
loadingbarObj.asset.mainAsset = request.asset;
}
IEnumerator _InstantiateEntityHudInfosAsset(WWW entityHudInfosAssetwww)
{
AssetBundleRequest request = entityHudInfosAssetwww.assetBundle.LoadAsync("hud_infos", typeof(UnityEngine.GameObject));
yield return request;
entityHudInfosAsset = request.asset;
Common.DEBUG_MSG("_InstantiateDefaultEntityAsset: " + entityHudInfosAsset);
}
IEnumerator _InstantiateDefaultEntityAsset(WWW defaultEntityAssetwww)
{
AssetBundleRequest request = defaultEntityAssetwww.assetBundle.LoadAsync("defaultEntityMesh", typeof(UnityEngine.GameObject));
yield return request;
//UnityEngine.GameObject go = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(request.asset);
//go.name = loadingbarObj.name;
defaultEntityAsset = request.asset;
Common.DEBUG_MSG("_InstantiateDefaultEntityAsset: " + defaultEntityAsset);
}
IEnumerator _InstantiateTerrainDiffuseShaderObjs(WWW terrainDiffuseShaderwww)
{
terrainDiffuseShaderwww.assetBundle.LoadAll(typeof(Shader));
WorldManager.default_shader_diffuse = (Shader)UnityEngine.GameObject.Instantiate(terrainDiffuseShaderwww.assetBundle.mainAsset);
//if(WorldManager.currinst != null)
if (!System.Object.ReferenceEquals(WorldManager.currinst,null))
{
WorldManager.currinst.onGetDefaultTerrainShaser();
}
yield break;
}
public void enterScene(string scenename)
{
Scene scene = findScene(currentSceneName, true);
scene.unload();
currentSceneName = scenename;
scene = findScene(currentSceneName, true);
Common.DEBUG_MSG("loader::enterScene: " + scenename + " inst=" + scene);
scene.loadScene(true, true);
}
public void autoAttackProxy()
{
TargetManger.autoAttack();
}
}