public bool Equals(CubeTile t1, CubeTile t2) { if (t1.dimension != t2.dimension) { return(false); } for (int x = 0; x < t1.dimension; x++) { for (int y = 0; y < t1.dimension; y++) { for (int z = 0; z < t2.dimension; z++) { WFCModule module1 = t1.GetModule(x, y, z); WFCModule module2 = t2.GetModule(x, y, z); if (module1 == null && module2 != null) { return(false); } if (module1 != null && module2 == null) { return(false); } if (module1 == null && module2 == null) { return(true); } if (module1.id != module2.id) { return(false); } } } } return(true); }
public WFCModule GetModule(int x, int y, int z) { GameObject obj = grid[x][y][z]; if (obj) { WFCModule module = obj.GetComponent <WFCModule>(); if (!module) { throw new System.InvalidOperationException($"No WFC module found in non-empty grid slot {x}, {y}, {z}!"); } return(module); } return(null); }
void GetMouseInput() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { WFCModule module = hit.transform.root.GetComponent <WFCModule>(); CubeTileComponent tileComponent = hit.transform.root.GetComponent <CubeTileComponent>(); if (module) { Debug.Log("Module ID: " + module.id); } if (tileComponent) { Debug.Log($"CubeTile {tileComponent.cubeTile.tileIndex} sampled from {tileComponent.cubeTile.sampleCoordinates}, appears {tileFrequencies[tileComponent.cubeTile]} times"); } } } }
void SpawnTile(Vector3 position, CubeTile cubeTile, int distanceBetweenModules) { int sideLength = cubeTile.dimension; GameObject tileObj = new GameObject(cubeTile.gridHashCode.ToString()); CubeTileComponent tileComponent = tileObj.AddComponent <CubeTileComponent>(); tileComponent.SetCubeTile(cubeTile); for (int x = 0; x < sideLength; x++) { for (int y = 0; y < sideLength; y++) { for (int z = 0; z < sideLength; z++) { WFCModule module = cubeTile.GetModule(x, y, z); if (module != null) { Vector3 spawnOffset = new Vector3(x * distanceBetweenModules, y * distanceBetweenModules, z * distanceBetweenModules); GameObject spawnedModule = GameObject.Instantiate(module.gameObject, position + spawnOffset, module.transform.rotation); spawnedModule.transform.SetParent(tileObj.transform, true); } } } } }