public BuildCell GetCellAtPos(Vector3 pos) { Vector3 localPos = transform.InverseTransformPoint(pos); int gridX = Mathf.CeilToInt(localPos.x / cellSize) + maxCols / 2; int gridY = Mathf.CeilToInt(localPos.y / cellSize) + maxRows / 2; BuildCell c = grid.GetCellAt(gridX, gridY); return(grid.GetCellAt(gridX, gridY)); }
public bool IsMouseOverValidSlot(Vector3 pos) { BuildCell c = GetCellAtPos(pos); if (c == null) { return(false); } return(grid.CheckValidBuildPos(c.col, c.row)); }
private void Update() { if (curBuildable == null || !curBuildable.enabled) { GameObject o = Instantiate(buildPiecePrefabs[(int)(Random.value * buildPiecePrefabs.Length)]) as GameObject; curBuildable = o.GetComponent <Buildable>(); } BuildCell cell = body.GetCellAtPos(Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (cell != null) { buildCursor.transform.position = body.transform.TransformPoint(cell.localPos); } }
private void CheckMousePos() { mouseWorldPos = cam.ScreenToWorldPoint(Input.mousePosition); mouseWorldPos.z = 0f; if (body.IsMouseOverValidSlot(mouseWorldPos)) { targetCell = body.GetCellAtPos(mouseWorldPos); snapping = true; } else { snapping = false; targetingValidPlacement = false; } }
/// <summary> /// 递归寻找所有该放入一个bundle的资源 /// </summary> /// <param name="_path"></param> /// <param name="fatherBundleName"></param> private static void SearchDPS(string _path, string fatherBundleName) { foreach (var dps in AssetDatabase.GetDependencies(_path, false)) { if (dps == _path) { continue; } BuildCell _bc = assetList.Find(temp => temp.assetName == dps); if (_bc.referenceCount == 1) { AssetImporter assetImporterdps = AssetImporter.GetAtPath(_bc.assetName); assetList[assetList.IndexOf(_bc)] = new BuildCell(_bc.referenceCount, _bc.assetName, fatherBundleName); assetImporterdps.assetBundleName = fatherBundleName; SearchDPS(dps, fatherBundleName); } } }
public void Initialize(int cols, int rows, float cellSize) { this.cols = cols; this.rows = rows; this.cellSize = cellSize; grid = new BuildCell[cols, rows]; for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { grid[i, j] = new BuildCell(); grid[i, j].col = i; grid[i, j].row = j; grid[i, j].localPos = new Vector3((i - cols / 2) * cellSize - cellSize * 0.5f, (j - rows / 2) * cellSize - cellSize * 0.5f, 0f); } } }
public bool CheckValidPlacement(BuildCell cell, BodyPart part, Dir facing) { return(cell.part == null); }
public static void Calculate() { assetList.Clear(); string sourcePath = EditorUtility.OpenFolderPanel("SeletionPanel", Application.dataPath, ""); if (string.IsNullOrEmpty(sourcePath)) { Debug.Log("路径为空!!"); return; } Pack(sourcePath); #region 遍历所有要打包的资源,计算出被直接引用的次数 foreach (BuildCell bc in assetList) { //获取的直接依赖中有自己 foreach (var dps in AssetDatabase.GetDependencies(bc.assetName, false)) { if (dps == bc.assetName) { continue; } else { //将被直接依赖资源的计数器加1(在父级的其他依赖中没有我,则为直接依赖) int dpsBCint = assetList.FindIndex(temp => temp.assetName == dps); if (dpsBCint >= 0) { assetList[dpsBCint] = new BuildCell(assetList[dpsBCint].referenceCount + 1, assetList[dpsBCint].assetName, null); } } } } #endregion #region 给资源设置AssetBundleName foreach (BuildCell bc in assetList) { if (bc.bundleName != null) { continue; } if (bc.referenceCount == 0 || bc.referenceCount >= 2) { //在代码中给资源设置AssetBundleName AssetImporter assetImporter = AssetImporter.GetAtPath(bc.assetName); //string assetName = AssetDatabase.AssetPathToGUID(_assetPath); string bundleName = bc.assetName.Replace("Assets/", "").Replace(Path.GetExtension(bc.assetName), "").ToLower(); assetList[assetList.IndexOf(bc)] = new BuildCell(bc.referenceCount, bc.assetName, bundleName); assetImporter.assetBundleName = bundleName; //收索直接依赖中被依赖数为1的资源, //将所有直接依赖中被依赖数为1的资源的bundle名设为父bundle名。 SearchDPS(bc.assetName, bundleName); } } #endregion #region 将资源名和bundle名作配置表 bundle_Asset baConfig = new bundle_Asset(); foreach (var bc in assetList) { NameKey nk = new NameKey(); nk.Name = bc.assetName; nk.Key = bc.bundleName; baConfig.namekeys.Add(nk); } if (!File.Exists(AssetBundlesOutputPath + "/bundleConfig")) { File.Create(AssetBundlesOutputPath + "/bundleConfig"); } ConfigOperation <bundle_Asset> .Serialize(AssetBundlesOutputPath + "/bundleConfig", baConfig); #endregion #region 打包 string outputPath = Path.Combine(AssetBundlesOutputPath, GetPlatformFolder(EditorUserBuildSettings.activeBuildTarget)); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //根据BuildSetting里面所激活的平台进行打包 BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.UncompressedAssetBundle, EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(); Debug.Log("打包完成"); #endregion }