//全部texture和mat放进各自的list里面 void LoadAsset(string asset, string occid) { var depends = assetsDependDic[asset]; for (int i = 0; i < depends.Count; i++) { //剔除shader if (!depends[i].Contains("shader") && !depends[i].Contains("FBX")) { var url = SceneConfig.GetInstance().prefix + depends[i].Substring(0, depends[i].IndexOf(".")).ToLower() + SceneConfig.GetInstance().suffix; if (!assetWaitingList.Contains(url)) { assetWaitingList.Add(url); totalAssetNum++; //根据assetName将url放进对应的list if (FuncUtil.GetInstance().IsAssetTexture(depends[i])) { textureWaitingList.Add(url); } if (depends[i].Contains(".mat")) { matWaitingList.Add(url); } if (depends[i] == asset) { prefabWaitingList.Add(url); mainAsseturlDict.Add(asset, url); } } } } }
void Start() { wwwReady.Add(new WWW(shaderUrl)); InitGameScene(); MapUtil.GetInstance().LoadMapDataFromXML(SceneConfig.GetInstance().mapDataPath); }
private void LoadLightMapFromHttp(List <string> pathsLightMapFar, List <string> pathsLightMapNear) { if (pathsLightMapFar.Count != 0) { for (int i = 0; i < pathsLightMapFar.Count; i++) { var url = SceneConfig.GetInstance().prefix + pathsLightMapFar[i].Substring(0, pathsLightMapFar[i].IndexOf(".")).ToLower() + SceneConfig.GetInstance().suffix; lightMapList.Add(url, new WWW(url)); totalAssetNum++; } } }
private void InitGameScene() { assetsDependDic = new Dictionary <string, List <string> >(); //assetsLoadedDic = new Dictionary<string, bool>(); assetXmlPath = Application.dataPath + "/" + SceneConfig.GetInstance().sceneConfigList[Application.loadedLevelName]; LoadAssetsXml(); XmlDocument xml = new XmlDocument(); xml.Load(Application.dataPath + "/Resources/XMLLib/Map/Map_" + SceneConfig.GetInstance().sceneConfigList[Application.loadedLevelName]); XmlNodeList rootNode = xml.SelectSingleNode("root").ChildNodes; XmlElement sceneNode = (XmlElement)rootNode.Item(0); sceneName = sceneNode.GetAttribute("name"); sceneID = sceneNode.GetAttribute("ID"); var pathsLightMapFar = FuncUtil.GetInstance().StrToStrList(sceneNode.GetAttribute("pathLightMapFar")); var pathsLightMapNear = FuncUtil.GetInstance().StrToStrList(sceneNode.GetAttribute("pathLightMapNear")); LoadLightMapFromHttp(pathsLightMapFar, pathsLightMapNear); goEffects = new GameObject("Effects"); goMap = new GameObject("Map"); surfaceLayer = new GameObject("SurfaceLayer"); surfaceLayer.transform.parent = goMap.transform; preloadLayer = new GameObject("PerloadLayer"); preloadLayer.transform.parent = goMap.transform; otherLayer = new GameObject("OtherLayer"); otherLayer.transform.parent = goMap.transform; foreach (XmlElement node in sceneNode) { if (node.Name == "Render") { LoadRender(node); } if (node.Name == "Map") { LoadMapFromXML(node); } if (node.Name == "Effects") { LoadEffectFromXML(node, false); } } }
void LoadNextScene() { var sceneName = SceneConfig.GetInstance().GetNextSceneName(); Application.LoadLevel(sceneName); }
private void SetPlayer() { gameState = HeroState.HERO_IDLE; goPlayer = (GameObject)Instantiate(Resources.Load("Prefabs/Unit_121001_Test"), SceneConfig.GetInstance().GetCurrentScenePlayerPos(), new Quaternion(0, 0, 0, 0)); playerCtrl = goPlayer.GetComponent <Animator>(); isPlayerInitialed = true; }
void Update() { MapUtil.GetInstance().ShowAllMapPoint(); if (textureWaitingList.Count == 0 && wwwReady.Count == 0) { isLoadTextureDone = true; } if (matWaitingList.Count == 0 && wwwReady.Count == 0) { isLoadMatDone = true; } if (assetWaitingList.Count > 0 && wwwReady.Count < SceneConfig.GetInstance().maxListSize) { string url = null; if (textureWaitingList.Count > 0) { url = textureWaitingList[0]; textureWaitingList.Remove(url); } else { if (isLoadTextureDone) { if (matWaitingList.Count > 0) { url = matWaitingList[0]; matWaitingList.Remove(url); } else { if (isLoadMatDone) { if (prefabWaitingList.Count > 0) { url = prefabWaitingList[0]; prefabWaitingList.Remove(url); } } } } } if (url != null) { ; assetWaitingList.Remove(url); GetWWW(url); } } //遍历LightMapList,将其中已经完成的www放入done列表 var itr = lightMapList.GetEnumerator(); while (itr.MoveNext()) { if (itr.Current.Value.isDone) { if (!wwwDone.ContainsKey(itr.Current.Key)) { wwwDone.Add(itr.Current.Key, itr.Current.Value); } } } //遍历ready列表,如果加载完成,放入wwwDone for (int i = 0; i < wwwReady.Count; i++) { if (wwwReady[i].isDone) { if (!string.IsNullOrEmpty(wwwReady[i].error)) { Debug.Log(wwwReady[i].url + wwwReady[i].error); } var www = wwwReady[i]; Debug.Log("Add Url to wwwDone " + www.url); wwwDone.Add(www.url, www); wwwReady.Remove(www); } } //所有资源全部加载完成,创建地图 if (wwwDone.Count == totalAssetNum) { SetLightMap(); Debug.Log("wwwDone total :" + wwwDone.Count); InitialGameObject(); MapUtil.GetInstance().AddjustMapPoint(); SetPlayer(); } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (!hit.transform.tag.Contains("surface")) { return; } if (MapUtil.GetInstance().isPointEffective(hit.point)) { Vector3 startPoint = Vector3.zero; if (MapUtil.GetInstance().isPointEffective(goPlayer.transform.position)) { startPoint = goPlayer.transform.position; } else { startPoint = tarPoint; } path = MapUtil.GetInstance().GeneratePath(startPoint, hit.point); if (path.Count > 0) { SetGameState(HeroState.HERO_RUN); } } } } //调整摄像机 if (isPlayerInitialed) { transform.position = Vector3.SmoothDamp(transform.position, goPlayer.transform.position + cameraOffset, ref cameraVelocity, 0.01f); transform.LookAt(goPlayer.transform.position); } //右键换图 if (Input.GetMouseButtonDown(1)) { LoadNextScene(); } }