private static void HighPolygonGenRefpoints(GameObject block, Category category) { string fbxDir = BlockPath.Fbx(category, PolygonType.LOW); GameObject t = AssetDatabase.LoadAssetAtPath <GameObject>(fbxDir + "/" + block.name + ".fbx"); RecursiveGenRefpoints(block.transform, t.transform); }
private static void AssignSingleMaterials(GameObject block, Dictionary <string, string> materials, string materialDir, List <string> missingMaterials) { Renderer[] renders = block.GetComponentsInChildren <Renderer>(true); for (int i = 0; i < renders.Length; i++) { Renderer render = renders[i]; render.receiveShadows = false; render.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; string materialStr; if (!materials.TryGetValue(render.gameObject.name, out materialStr)) { continue; } Material mat = AssetDatabase.LoadAssetAtPath <Material>(materialDir + "/" + materialStr + ".mat"); if (mat == null) { mat = AssetDatabase.LoadAssetAtPath <Material>(BlockPath.MaterialCommon() + "/" + materialStr + ".mat"); } if (mat == null) { missingMaterials.Add(materialStr); continue; } render.sharedMaterial = mat; } }
private static void AssignMultiMaterials(GameObject block, List <string> materials, string materialDir, List <string> missingMaterials) { Renderer render = block.GetComponent <Renderer>(); render.receiveShadows = false; render.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; int index = 0; Material[] mats = render.sharedMaterials; foreach (var materialStr in materials) { if (mats.Length <= index) { break; } Material mat = AssetDatabase.LoadAssetAtPath <Material>(materialDir + "/" + materialStr + ".mat"); if (mat == null) { mat = AssetDatabase.LoadAssetAtPath <Material>(BlockPath.MaterialCommon() + "/" + materialStr + ".mat"); } if (mat == null) { missingMaterials.Add(materialStr); continue; } mats[index] = mat; index++; } render.sharedMaterials = mats; }
public void Create_25Items_AreEqual() { var exp = new ActionType[] { ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnRight, ActionType.TurnRight }; var act = BlockPath.Create(exp); Assert.AreEqual(25, act.Count, "Count"); CollectionAssert.AreEqual(exp, act.Moves.ToArray()); Assert.AreEqual("left,right,down,turnleft,turnright,left,right,down,turnleft,turnright,left,right,down,turnleft,turnright,left,right,down,turnleft,turnright,left,right,down,turnright,turnright", act.ToString()); }
/// <summary> Constructor. </summary> /// <param name="previousBlock"> The previous block that will have <paramref name="nextBlock"/> /// merged into. </param> /// <param name="nextBlock"> The next block that will be merged into /// <paramref name="previousBlock"/>. </param> /// <param name="originalCaretPosition"> The position at which the caret is at. </param> public MergeTextBlockAction(TextBlock previousBlock, TextBlock nextBlock, DocumentCursorHandle originalCaretPosition) { Debug.Assert(previousBlock.NextBlock == nextBlock); _originalCaretPosition = originalCaretPosition; _previousPath = previousBlock.GetBlockPath(); _nextPath = nextBlock.GetBlockPath(); _endOfPreviousBlockHandle = new DocumentCursorHandle(previousBlock.Content.GetCaretAtEnd()); }
public void Add_TurnRightM1_AreEqual() { var exp = new ActionType[] { ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnLeft, ActionType.TurnRight, ActionType.Left, ActionType.Right, ActionType.Down, ActionType.TurnRight, ActionType.TurnRight }; var path = BlockPath.Create(exp.Take(24).ToArray()); var act = path.Add(ActionType.TurnRight); Assert.AreEqual(25, act.Count, "Count"); CollectionAssert.AreEqual(exp, act.Moves.ToArray()); Assert.AreEqual("left,right,down,turnleft,turnright,left,right,down,turnleft,turnright,left,right,down,turnleft,turnright,left,right,down,turnleft,turnright,left,right,down,turnright,turnright", act.ToString()); }
private Texture2D LoadPrefabPreview(string prefabName) { string prefabPath = string.Format("{0}/{1}.prefab", BlockPath.Prefab(category, PolygonType.LOW), prefabName); if (!File.Exists(prefabPath)) { PEPrefabGeneratorUtil.CreateSinglePrefab(prefabName, this, category, PolygonType.LOW); UnityEditor.AssetDatabase.Refresh(); } var texture2D = GetPreviewTex(prefabPath); return(texture2D); }
private Material LoadCommonMatAsset(MaterialInfo matInfo) { //model 工程中 所有的 Material 必须放到 commonres里面,不能放到对应的category里面,所有的material不能重名 string matPath = Path.Combine(BlockPath.MaterialCommon(), matInfo.name); Material mat = null; if (blockMats.ContainsKey(matPath)) { mat = blockMats[matPath]; } else { mat = PBMatLoader.GetMaterial(matInfo); blockMats[matPath] = mat; } return(mat); }
private void PrepareThumbExportElement(BlockDataGroup group, List <ThumbExportElement> elements) { if (!categoryToggles[(int)group.category]) { return; } string prefabDir = BlockPath.Prefab(group.category, PolygonType.HIGH); int[] angle = mThumInfo.GetAngleOfModel(group.modelName); List <string> prefabs = new List <string>(); if (!mColorToggles[0]) { foreach (string color in group.GetColors()) { int indexOfColor = IndexOfColor(color); if (indexOfColor >= 0 && mColorToggles[indexOfColor]) { prefabs.AddRange(group.GetPrefabsByColor(color)); } } } else { prefabs.AddRange(group.GetPrefabs()); } foreach (string prefab in prefabs) { BlockDataItem dataItem = group.GetItems().FirstOrDefault(s => s.prefabName == prefab); elements.Add(new ThumbExportElement() { eulerAngle = new Vector3(angle[0], angle[1], angle[2]), prefabPath = Path.Combine(prefabDir, prefab + ".prefab"), modelName = group.modelName, material = dataItem.material, materialH = dataItem.materialHigh, category = group.category, light = lightNames.Contains(dataItem.colorName) ? dataItem.colorName : "", }); } }
private static void AssignSingleMaterials(List <string> materials, string materialDir, List <ResItem> items, List <ResItem> modelAbInfoItems, List <ResItem> textureInfoItems, List <PEMaterialUtl.MaterialInfo> materialInfos) { foreach (var materialStr in materials) { var abFile = Path.Combine(materialDir, materialStr); if (!File.Exists(abFile + ".mat")) { abFile = Path.Combine(BlockPath.MaterialCommon(), materialStr); } // Debug.LogError(materialDir+">>>>>>>>materialDir>>>>>"+abFile+" -->>>> "+materialStr); var materialInfo = materialInfos.FirstOrDefault(s => s.name == materialStr); // Debug.LogError(materialStr+"-->>>>>materialStr"); if (materialInfo != null) { if (materialInfo.propsTex.Any()) { foreach (var item in materialInfo.propsTex) { // Debug.LogError(item.data+" >>>item.data"); var t = textureInfoItems.FirstOrDefault(b => b.path == item.data); if (t != null) { var resItem = new ResItem { name = item.name }; resItem.hash = t.hash; resItem.size = t.size; resItem.path = t.path; if (items.All(s => s.path != resItem.path)) { items.Add(resItem); } } } } } // AddResItem(materialStr,abFile,items,modelAbInfoItems); } }
/// <summary> /// 给Boss房间添加单向的通路 /// </summary> /// <param name="bossCell"></param> void AddBossRoomPath(GeneratorCell bossCell) { int index = 0; float dis = 0f; float minDis = float.PositiveInfinity; Vector2 bPos = new Vector2(bossCell.x, bossCell.y); foreach (GeneratorCell c in cells) { Vector2 cPos = new Vector2(c.x, c.y); dis = (cPos - bPos).magnitude; if (dis < minDis) { minDis = dis; index = c.index; } } Path path = new Path(); Vector2 startPoint = new Vector2(cells[index].x + cells[index].width / 2, cells[index].y + cells[index].height / 2); Vector2 endPoint = new Vector2(bossCell.x + bossCell.width / 2, bossCell.y + bossCell.height / 2); BlockPath b1 = new BlockPath(); b1.start = startPoint; b1.end = new Vector2(endPoint.x, startPoint.y); BlockPath b2 = new BlockPath(); b2.start = b1.end; b2.end = endPoint; path.path.Add(b1); path.path.Add(b2); paths.Add(path); }
public static GameObject CreateBlock(string prefabName, PolygonType polygonType) { Category category = PBDataBaseManager.Instance.GetCategoryWithPrefabName(prefabName); string dirPath = BlockPath.Prefab(category, polygonType); string prefabPath = dirPath + "/" + prefabName + ".prefab"; if (!File.Exists(prefabPath)) { if (prefabName.StartsWith("sticker_")) { PEPrefabGeneratorUtil.CreateStickerPrefab(prefabName); } else { BlockData blockData = PBDataBaseManager.Instance.GetBlockWithPrefabName(prefabName); PEPrefabGeneratorUtil.CreateSinglePrefab(prefabName, blockData.model, blockData.material, blockData.material_high, category, polygonType); } } GameObject tobj = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath); if (tobj == null) { Debug.LogError(">>>>找不到prefab:" + prefabPath); } GameObject gameObj = GameObject.Instantiate(tobj); gameObj.AddComponent <PEBlockAlign>().SetRefPointTypes(); var boxCollider = gameObj.AddComponent <BoxCollider>(); if (prefabName.StartsWith("sticker")) { boxCollider.size = boxCollider.size + Vector3.up * 0.3f; } return(gameObj); }
/// <summary> /// 将生成好的路径转换成曼哈顿距离的路径 /// </summary> void FindPathBtwBlocks() { foreach (LineSegment l in spanningTree) { Path path = new Path(); Vector2 startPoint = l.p0.Value; Vector2 endPoint = l.p1.Value; BlockPath b1 = new BlockPath(); b1.start = startPoint; b1.end = new Vector2(endPoint.x, startPoint.y); BlockPath b2 = new BlockPath(); b2.start = b1.end; b2.end = endPoint; path.path.Add(b1); path.path.Add(b2); paths.Add(path); } spanningTree.Clear(); }
public SerializedData(TextCaret caret) { _graphemeOffset = caret.Offset.GraphemeOffset; _pathToBlock = caret.Block.GetBlockPath(); }
public MoveCandiate(BlockPath path, Field field) { Path = path; Field = field; }
public static GameObject CreateSinglePrefab(string prefabName, string modelName, string material, string materialHigh, Category category, PolygonType polygonType, bool isTemp = false) { string prefabDir = BlockPath.Prefab(category, polygonType); string fbxDir = BlockPath.Fbx(category, polygonType); string matDir = BlockPath.Material(category, polygonType); List <string> fbxErrors = new List <string>(); List <string> scaleErrors = new List <string>(); List <string> angleErrors = new List <string>(); List <string> materialErrors = new List <string>(); { GameObject t = AssetDatabase.LoadAssetAtPath <GameObject>(fbxDir + "/" + modelName + ".fbx"); if (!File.Exists(fbxDir + "/" + modelName + ".fbx")) { Debug.LogError("fbx 模型文件不存在 >>>>>" + fbxDir + "/" + modelName + ".fbx"); EditorUtility.DisplayDialog("错误", "fbx文件不存在" + fbxDir + "/" + modelName + ".fbx", "确定"); return(null); } GameObject block = GameObject.Instantiate(t); block.name = modelName; Animator animator = block.GetComponent <Animator>(); if (animator != null) { GameObject.DestroyImmediate(animator); } if (polygonType == PolygonType.LOW) { AssignMaterials(block, material, matDir, materialErrors); } else { AssignMaterials(block, materialHigh, matDir, materialErrors); HighPolygonGenRefpoints(block, category); } if (!Directory.Exists(prefabDir)) { Directory.CreateDirectory(prefabDir); } if (!isTemp) { PrefabUtility.CreatePrefab(prefabDir + "/" + prefabName + ".prefab", block, ReplacePrefabOptions.ReplaceNameBased); } if (block.transform.localScale != Vector3.one) { if (!scaleErrors.Contains(modelName)) { scaleErrors.Add(modelName); } } if (block.transform.localEulerAngles != Vector3.zero) { if (!angleErrors.Contains(modelName)) { angleErrors.Add(modelName); } } if (!isTemp) { GameObject.DestroyImmediate(block); } return(block); } }
private static bool CreateBuildingModeResFile(string filePath, List <ResItem> modelAbInfoItems, List <ResItem> textureInfoItems, List <PEMaterialUtl.MaterialInfo> materialInfos, string outputDir, bool isOnline) { var fileName = Path.GetFileNameWithoutExtension(filePath); if (ResPublisher.EXCLUDE_BUILDINGS.Contains(fileName)) { return(false); } #if BLOCK_EDITOR PPBlockConfigInfo configInfo = PBBlockConfigManager.LoadBlockInfosWithoutAnim(filePath); #elif BLOCK_MODEL // var path = "./" + BlockServerUtil.GetBuildAnimPath(isOnline) + "/" + fileName + ".txt"; var path = "./" + BlockServerUtil.GetBuildAnimPath(isOnline) + "/" + fileName + ".txt"; //here change later var configText = File.Exists(path) ? File.ReadAllText(path, Encoding.UTF8) : string.Empty; PPBlockConfigInfo configInfo = PBBlockConfigManager.LoadBlockInfosWithoutAnim(fileName, configText); if (configInfo == null) { Debug.LogError(path + ">>>" + (File.Exists(path) ? "搭建文件内容有问题!" : "搭建文件不存在!")); return(false); } #endif var buildingModelResConfig = new ResConfig { resversion = "100", items = new List <ResItem>() }; foreach (var item in configInfo.BlockInfos) { //地板特殊处理,配置表里面没有地板 if (item.PrefabName == "diban") { AddResItem("diban", "Assets/blockres/lowpolygon/category_1/block_fbxs/diban", buildingModelResConfig.items, modelAbInfoItems); continue; } if (item.PrefabName.StartsWith("sticker")) { CreateStickerItem(item.PrefabName, buildingModelResConfig.items, modelAbInfoItems, textureInfoItems); continue; } var blockData = PBDataBaseManager.Instance.GetDataWithPrefabName(item.PrefabName) as BlockData; Category category = (Category)Enum.Parse((typeof(Category)), blockData.category); string fbxDir = (BlockPath.Fbx(category, PolygonType.LOW)); string matDir = (BlockPath.Material(category, PolygonType.LOW)); AddResItem(blockData.model, (Path.Combine(fbxDir, blockData.model)), buildingModelResConfig.items, modelAbInfoItems); CreateMaterials(blockData.material, matDir, buildingModelResConfig.items, modelAbInfoItems, textureInfoItems, materialInfos); CreateTextures(item, buildingModelResConfig.items, modelAbInfoItems, textureInfoItems); } var config = JsonUtility.ToJson(buildingModelResConfig, true); File.WriteAllText(Path.Combine(outputDir, fileName), config); return(true); }
private static void CreatePrefabsWithDataGroup(List <BlockDataGroup> blockDataGroups, Category category, PolygonType polygonType) { string prefabDir = BlockPath.Prefab(category, polygonType); string fbxDir = BlockPath.Fbx(category, polygonType); string matDir = BlockPath.Material(category, polygonType); List <string> fbxErrors = new List <string>(); List <string> scaleErrors = new List <string>(); List <string> angleErrors = new List <string>(); List <string> materialErrors = new List <string>(); for (int i = 0; i < blockDataGroups.Count; i++) { EditorUtility.DisplayProgressBar(string.Format("生成 {0} Prefabs", polygonType.ToString()), "正在生成,请稍后", i * 1.0f / blockDataGroups.Count); BlockDataGroup blockDataGroup = blockDataGroups[i]; foreach (var dataItem in blockDataGroup.GetItems()) { GameObject t = AssetDatabase.LoadAssetAtPath <GameObject>(fbxDir + "/" + blockDataGroup.modelName + ".fbx"); if (t == null) { if (!fbxErrors.Contains(blockDataGroup.modelName)) { fbxErrors.Add(blockDataGroup.modelName); } continue; } GameObject block = GameObject.Instantiate(t); block.name = blockDataGroup.modelName; Animator animator = block.GetComponent <Animator>(); if (animator != null) { GameObject.DestroyImmediate(animator); } if (polygonType == PolygonType.LOW) { AssignMaterials(block, dataItem.material, matDir, materialErrors); } else { AssignMaterials(block, dataItem.materialHigh, matDir, materialErrors); HighPolygonGenRefpoints(block, category); } if (!Directory.Exists(prefabDir)) { Directory.CreateDirectory(prefabDir); } PrefabUtility.CreatePrefab(prefabDir + "/" + dataItem.prefabName + ".prefab", block, ReplacePrefabOptions.ReplaceNameBased); if (block.transform.localScale != Vector3.one) { if (!scaleErrors.Contains(blockDataGroup.modelName)) { scaleErrors.Add(blockDataGroup.modelName); } } if (block.transform.localEulerAngles != Vector3.zero) { if (!angleErrors.Contains(blockDataGroup.modelName)) { angleErrors.Add(blockDataGroup.modelName); } } GameObject.DestroyImmediate(block); } } EditorUtility.ClearProgressBar(); if (fbxErrors.Count > 0) { DisplayErrorDialog(polygonType.ToString() + " 找不到以下fbx\n", fbxErrors); } if (scaleErrors.Count > 0) { DisplayErrorDialog("以下fbx的默认scale不为1\n", scaleErrors); } if (angleErrors.Count > 0) { DisplayErrorDialog("以下fbx的默认角度不为0\n", angleErrors); } if (materialErrors.Count > 0) { DisplayErrorDialog("以下材质球没找到,请找何屹、唐蜜Check数据库文件\n", materialErrors); } EditorUtility.DisplayDialog("提示", string.Format("生成 {0} Prefab完成!", polygonType.ToString()), "确定"); }