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 void PickAndSnapPoints() { if (highlightPoints.Count > 0 && destlightPoints.Count > 0) { Transform targetPP = null; Transform originPP = null; float minDis = 100; foreach (var item in highlightPoints) { var originItem = item.refTrans; var refPointType = originItem.GetComponent <RefDot>().refPointType; foreach (var targetItem in destlightPoints) { var targetPointType = targetItem.GetComponent <RefDot>().refPointType; if (RefPointMgr.EnablePair(refPointType, targetPointType)) { var dis = Vector3.Distance(originItem.position, targetItem.position); if (dis < minDis) { minDis = dis; targetPP = targetItem; originPP = originItem; } } } } if (targetPP != null) { Undo.RecordObject(originPP.parent.transform, "Reset refOrigin"); Vector3 originOffset = originPP.transform.position - originPP.parent.transform.position; originPP.parent.transform.position = targetPP.transform.position - originOffset; PBTexture texOrigin = originPP.parent.GetComponent <PBTexture>(); PBTexture texTarget = targetPP.parent.GetComponent <PBTexture>(); if (texOrigin != null) { texOrigin.transform.SetParent(targetPP.parent.transform, true); } else if (texTarget != null) { texTarget.transform.SetParent(originPP.parent.transform, true); } originRefTrans = originPP; } } }