private void CalculateBlockNum() { Dictionary <string, PBPartInfo> blockInfos = new Dictionary <string, PBPartInfo>(); mBlockNum = 0; foreach (PPAnimNodeInfo node in AnimNodeInfos.Values) { if (node.Type == NodeType.Block) { PPBlockInfo blockInfo = node as PPBlockInfo; if (blockInfo.Hide) { continue; } if (blockInfos.ContainsKey(blockInfo.Thumb)) { blockInfos[blockInfo.Thumb].Count += blockInfo.Count; } else { blockInfos[blockInfo.Thumb] = new PBPartInfo(blockInfo, blockInfo.Count); } mBlockNum += blockInfo.Count; } } mBlockInfos = blockInfos.Values.ToList(); mBlockTypeNum = mBlockInfos.Count; }
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); }
public override void Init() { base.Init(); PPBlockInfo info = animNodeInfo as PPBlockInfo; this.type = info.Prefab; this.hide = info.Hide; this.partDetail = PBPartDetail.Parse(info.Detail); }
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); } }
public override void SetEditorTransform() { base.SetEditorTransform(); PPBlockInfo info = animNodeInfo as PPBlockInfo; if (!string.IsNullOrEmpty(info.VersatileInfo.SplineInfo)) { var splineAnim = GetComponentInChildren <IPBSplineAnimator>(); splineAnim.SetEditorKeyframe(); } }
/// <summary> /// 外部调用,生成单个零件 /// </summary> public static PPObjLoader LoadBlock(PPPrefabInfo prefabInfo, PPBlockInfo nodeInfo, Transform parent, Action <GameObject> onFinishWithObj) { GameObject obj = new GameObject("PPObjLoader"); obj.transform.SetParent(RootObj); PPObjLoader loader = obj.AddComponent <PPObjLoader>(); loader.mPrefabInfo = prefabInfo; loader.nodeInfo = nodeInfo; loader.parent = parent; loader.onFinishWithObj = onFinishWithObj; loader.StartCoroutine(loader.AsyncLoadBlock()); return(loader); }
public ThumbExportElement ToExport() { //构造prefabinfo var prefabInfo = new PPPrefabInfo() { Name = name, Model = model, Material = material, MaterialInfos = matinfos, Texs = texs }; if (prefabInfo.IsSticker) { prefabInfo.Texture = skins[0].skin_name; } //构造PPBlockInfo var nodeInfo = new PPBlockInfo() { Prefab = name, }; var thumb = nodeInfo.Prefab; nodeInfo.Textures = new PPTextureInfo[texs.Count]; for (var i = 0; i < texs.Count; i++) { var t = texs[i]; nodeInfo.Textures[i] = new PPTextureInfo() { Prefab = t.Name, EditorAngle = t.editor_angle, EditorPos = t.editor_pos }; thumb += "-" + t.Name; } nodeInfo.Thumb = nodeInfo.IsStamp ? nodeInfo.Prefab + "_" + PTUtils.Md5Sum(thumb) : nodeInfo.Prefab; return(new ThumbExportElement() { eulerAngle = angle, PrefabInfo = prefabInfo, BlockInfo = nodeInfo }); }
public static void Test() { var config = "/Users/admin/Desktop/tar_config/configs/config_22007_01_05.txt"; var blockConfig = PBBlockConfigManager.LoadBlockInfosWithoutAnim(config); PPPrefabInfo targetPrefab = null; PPBlockInfo targetBlock = null; foreach (PBPartInfo partInfo in blockConfig.BlockInfos) { if (partInfo.BlockInfo.IsSticker && partInfo.PrefabName.Equals("sticker_prefab_ppbbbmhmf_09_common")) { targetBlock = partInfo.BlockInfo; break; } } foreach (var t in blockConfig.PrefabInfos) { if (t.IsSticker && t.Name.Equals("sticker_prefab_ppbbbmhmf_09_common")) { targetPrefab = t; break; } } if (targetPrefab == null || targetBlock == null) { Debug.LogError("空"); return; } if (!string.IsNullOrEmpty(targetPrefab.Material)) { targetPrefab.MaterialInfos.Add(PBDataBaseManager.Instance.GetMatInfoByName(targetPrefab.Material)); } targetPrefab.Texs.ForEach(t => { t.skin_url = texPrefix + t.Texture + ".png"; t.bin_url = texModelPrefix + t.Model + "/buffer.bin"; t.gltf_url = texModelPrefix + t.Model + "/" + t.Model + ".gltf"; }); var renderinfo = new RenderInfo(); renderinfo.scale = 2; renderinfo.items = new[] { new RenderItem() { name = targetPrefab.Name, model = targetPrefab.Model, material = targetPrefab.Material, matinfos = targetPrefab.MaterialInfos, bin_url = stickerModelPrefix + targetPrefab.Model + "/buffer.bin", gltf_url = stickerModelPrefix + targetPrefab.Model + "/" + targetPrefab.Model + ".gltf", skins = !string.IsNullOrEmpty(targetPrefab.Texture)? new[] { new SkinInfo() { skin_name = targetPrefab.Texture, skin_url = texPrefix + targetPrefab.Texture + ".png", } }:new SkinInfo [0], texs = targetPrefab.Texs } }; File.WriteAllText(Application.dataPath + "/test111.json", JsonUtility.ToJson(renderinfo, true)); Debug.Log("===>>完成"); }
public PBPartInfo(PPBlockInfo blockInfo, int count) { BlockInfo = blockInfo; Count = count; PartDetail = PBPartDetail.Parse(blockInfo.Detail); }