private GameObject InnerLoadBlock(PPBlockInfo nodeInfo, Transform parent, BlockLoadInfo blockLoadInfo) { if (mIsStop) { return(null); } string prefabName = nodeInfo.Prefab; PPTextureInfo[] textures = nodeInfo.Textures; GameObject gameObj; GameObject[] texObjs = new GameObject[textures.Length]; #if BLOCK_EDITOR gameObj = PEBlockLoader.CreateBlock(prefabName, (PolygonType)mPolygonType); for (int tIndex = 0; tIndex < textures.Length; tIndex++) { texObjs[tIndex] = PEBlockLoader.CreateTexture(textures[tIndex].Prefab); } #else //Hide block 还是要创建出来,可能以后搭建中会用到该block的信息,它是作为搭建辅助件用的 var prefabInfo = GetPrefabInfoByName(prefabName); gameObj = nodeInfo.Hide ? new GameObject() : PPLoader.CreateBlock(prefabInfo, () => blockLoadInfo.AllocateBlock()); for (var tIndex = 0; tIndex < textures.Length; tIndex++) { texObjs[tIndex] = PPLoader.CreateTexture(prefabInfo.GetPrefabTexInfo(textures[tIndex].Prefab), () => blockLoadInfo.AllocateTexture()); } #endif gameObj.name = prefabName; gameObj.transform.SetParent(parent, false); PBBlock pbblock = gameObj.AddComponent <PBBlock>(); pbblock.animNodeInfo = nodeInfo; pbblock.Init(); //for texture for (int tIndex = 0; tIndex < texObjs.Length; tIndex++) { GameObject texObj = texObjs[tIndex]; texObj.name = textures[tIndex].Prefab; texObj.transform.SetParent(gameObj.transform, false); PBTexture pbTex = texObj.AddComponent <PBTexture>(); pbTex.info = textures[tIndex]; pbTex.Init(); } //for splines PBVersatileInterface.OnLoadBlockObj(gameObj, nodeInfo.VersatileInfo, true); if (mAnimNodes != null) { mAnimNodes.Add(nodeInfo.Id, gameObj); } return(gameObj); }
private static void ProcessNodes(XmlNode node, Dictionary <int, PPAnimNodeInfo> animNodeInfos, PPSectionInfo parentSection) { XmlNodeList sections = node.SelectNodes("section"); for (int i = 0; i < sections.Count; i++) { XmlNode sectionNode = sections[i]; PPSectionInfo sectionInfo = new PPSectionInfo(); sectionInfo.Index = sectionInfo.Id = int.Parse(sectionNode.Attributes["id"].Value); sectionInfo.Name = sectionNode.Attributes["name"] != null ? sectionNode.Attributes["name"].Value : "section_" + sectionInfo.Index; sectionInfo.Type = NodeType.Section; XmlNode editorNode = sectionNode.SelectSingleNode("editor"); editorNode.GetPosInfo(out sectionInfo.EditorPos) .GetAngleInfo(out sectionInfo.EditorAngle); //for versatile PBVersatileInterface.LoadFromXml(sectionNode, sectionInfo.VersatileInfo); animNodeInfos.Add(sectionInfo.Index, sectionInfo); parentSection.AddSubNode(sectionInfo); ProcessNodes(sectionNode, animNodeInfos, sectionInfo); } XmlNodeList blocks = node.SelectNodes("block"); for (int i = 0; i < blocks.Count; i++) { XmlNode blockNode = blocks[i]; PPBlockInfo blockInfo = new PPBlockInfo(); XmlNode editorNode = blockNode.SelectSingleNode("editor"); editorNode.GetPosInfo(out blockInfo.EditorPos) .GetAngleInfo(out blockInfo.EditorAngle); blockInfo.Prefab = blockNode.Attributes["type"].Value; blockInfo.Thumb = blockNode.Attributes["thumb"] != null ? blockNode.Attributes["thumb"].Value : blockInfo.Prefab; blockInfo.Detail = blockNode.Attributes["partDetail"] != null ? blockNode.Attributes["partDetail"].Value : ""; blockInfo.Count = blockNode.Attributes["count"] != null?int.Parse(blockNode.Attributes["count"].Value) : 1; blockInfo.Hide = blockNode.Attributes["hide"] != null && blockNode.Attributes["hide"].Value.Equals("1"); blockInfo.Type = NodeType.Block; blockInfo.Index = blockInfo.Id = int.Parse(blockNode.Attributes["id"].Value); //for textures blockInfo.ParseTextures(blockNode.SelectNodes("texture")); //for versatile blocks PBVersatileInterface.LoadFromXml(blockNode, blockInfo.VersatileInfo); animNodeInfos.Add(blockInfo.Index, blockInfo); parentSection.AddSubNode(blockInfo); } }
private IEnumerator AsyncLoadBlocks() { mPolygonType = loadConfig.polygonType; //init LoadBlockInfo var blockList = OrderLoadList(loadConfig, sectionInfo); var actualBlocks = blockList.Where(t => t.nodeInfo.Type == NodeType.Block).ToList(); var texCount = 0; var blockCount = actualBlocks.Count; actualBlocks.ForEach(t => { texCount += ((PPBlockInfo)t.nodeInfo).Textures.Length; }); mBlockLoadInfo = new BlockLoadInfo() .SetBlockSumCount(blockCount) .SetTexSumCount(texCount); //start load blocks if (loadConfig.LoadSpeed == -1) { InnerLoadBlocks(blockList); } else { yield return(AsyncInnerLoadBlocks(blockList)); } while (!mIsStop && !mBlockLoadInfo.Finish) { yield return(null); } //for spline foreach (GameObject obj in mAnimNodes.Values) { if (mIsStop) { yield break; } if (PBVersatileInterface.BuildFromInfo(obj)) { yield return(null); } } if (mIsStop) { yield break; } onFinish?.Invoke(); mAnimNodes = null; mBlockLoadInfo = null; }
private IEnumerator AsyncLoadBlock() { mBlockLoadInfo = new BlockLoadInfo() .SetBlockSumCount(1) .SetTexSumCount(nodeInfo.Textures.Length); var blockObj = InnerLoadBlock(nodeInfo, parent, mBlockLoadInfo); while (!mBlockLoadInfo.Finish) { yield return(null); } PBVersatileInterface.OnLoadBlockObj(blockObj, nodeInfo.VersatileInfo, false); onFinishWithObj?.Invoke(blockObj); mBlockLoadInfo = null; }