void doUnCollapse() { float rot = cubeloid.transform.eulerAngles.y; while (rot < 0) { rot += 360; } while (rot >= 360) { rot -= 360; } string collapseAxis = Mathf.Abs(rot) < 15 ? "z" : "x"; for (int i = 0; i < cubeloid.transform.childCount; i++) { GameObject cube = cubeloid.transform.GetChild(i).gameObject; CubeData data = (CubeData)cube.GetComponent <CubeData>(); if (i == 0) { iTween.MoveTo(cube, iTween.Hash(collapseAxis, data.preCompressPos, "time", 0.2f, "islocal", true, "oncompletetarget", gameObject, "onComplete", "uncollapseDidComplete")); } else { iTween.MoveTo(cube, iTween.Hash(collapseAxis, data.preCompressPos, "time", 0.2f, "islocal", true)); } iTween.MoveTo(data.reflection.gameObject, iTween.Hash(collapseAxis, data.preCompressPos, "time", 0.2f, "islocal", true)); } }
public void MergeCubes(CubeData cube0, CubeData cube1) { if (cube0 == null || cube1 == null) { return; } int newCubeID = GetPowerOfTwoByCubeNumber(cube0.GetCubeNumber()); if (newCubeID > _maxCubeIndexOnMap) { _maxCubeIndexOnMap = newCubeID; } GameObject _newCubePrefab = _cubePrefabs.GetCubePrefab(newCubeID); Vector3 newCubePosition = cube1.transform.position; Destroy(cube0.gameObject); Destroy(cube1.gameObject); GameObject newCube = Instantiate(_newCubePrefab, newCubePosition, Quaternion.Euler(Random.Range(-180f, 180f), Random.Range(-180f, 180f), Random.Range(-180f, 180f)), _cubesParent); newCube.GetComponent <Rigidbody>()?.AddForce((Vector3.up + Vector3.forward + Random.insideUnitSphere) * MergingPower, ForceMode.Impulse); SpawnMergingEffect(newCube.transform.position); CheckForWin(newCubeID); }
public void CreateNewConfig() { GameObject ConstructModel = GameObject.FindGameObjectWithTag("Construct"); StaticCubes.AddRange(GameObject.FindGameObjectsWithTag("StaticPart")); Parts.AddRange(GameObject.FindGameObjectsWithTag("MovingPart")); MovingPart[] getMovingParts = new MovingPart[Parts.Count]; for (int i = 0; i < Parts.Count; i++) { CubeData[] CubesContained = new CubeData [0]; List <CubeData> CubesContainedList = new List <CubeData>(); for (int j = 0; j < Parts[i].transform.childCount; j++) { if (Parts[i].transform.GetChild(j).tag != "MovingPart") { CubesContainedList.Add(Parts[i].transform.GetChild(j)); } } CubesContained = CubesContainedList.ToArray(); CubesContainedList = null; getMovingParts[i] = Parts[i].transform.parent.tag == "MovingPart" ? new MovingPart(Parts[i], CubesContained.Length, Parts[i].name, Parts[i].transform.parent.name) : new MovingPart(Parts[i], CubesContained.Length, Parts[i].name); getMovingParts[i].AddCube(CubesContained); } CurrentConfigs.Add(new Config(StaticCubes.ToArray(), getMovingParts, ConstructModel.name)); Parts.Clear(); StaticCubes.Clear(); }
private List <CubeData> GetCubes() { var cubesData = new List <CubeData>(); var meshes = FindObjectsOfType <MeshFilter>(); foreach (var mesh in meshes) { if (mesh.sharedMesh.name == "Cube" || mesh.sharedMesh.name == "Cube Instance") { var cubeData = new CubeData(); cubeData.transformData = GetTransformData(mesh.gameObject.transform); cubeData.color = ColorUtility.ToHtmlStringRGB(mesh.gameObject.GetComponent <MeshRenderer>().sharedMaterial.color); cubeData.id = mesh.transform.GetInstanceID(); if (mesh.transform.parent != null) { cubeData.parentId = mesh.transform.parent.GetInstanceID(); } cubesData.Add(cubeData); } } return(cubesData); }
private void SaveSelectedSection() { SectionData selectedSectionData = _levels.LevelDatas[_selectedLevel].Sections[_selectedSection]; selectedSectionData.CubeDatas = new System.Collections.Generic.List <CubeData>(); selectedSectionData.BarrierDatas = new System.Collections.Generic.List <BarrierData>(); foreach (var cube in _grid.GetComponentsInChildren <Cube>()) { CubeData cubeData = new CubeData() { CellPosition = cube.CellPosition, CubeType = cube.CubeType }; selectedSectionData.CubeDatas.Add(cubeData); } foreach (var barrierCube in _grid.GetComponentsInChildren <BarrierCube>()) { BarrierData barrierData = new BarrierData() { StartCellPosition = barrierCube.StartCellPosition, EndCellPosition = barrierCube.EndCellPosition }; selectedSectionData.BarrierDatas.Add(barrierData); } SaveLevelsAsset(_levels); Debug.Log($"Saved {selectedSectionData.CubeDatas.Count} cubes, {selectedSectionData.BarrierDatas.Count} barriers to Level {_selectedLevel}, Section {_selectedSection}"); }
public void solveBFS() { queue1 = new Queue <string[, , ]>(); queue2 = new Queue <string>(); string[,,] solveData = new string[3, 3, 3]; solveData = cubeData.getAllFace(); queue1.Enqueue(solveData); queue2.Enqueue("-1"); while (true) { if (completeCube(queue1.Peek())) { string[,,] aa = new string[3, 3, 3]; aa = queue1.Peek(); Debug.Log(aa[0, 0, 1]); break; } for (int i = 0; i < 6; ++i) { solveRotate(i, queue1.Peek(), queue2.Peek()); } queue1.Dequeue(); queue2.Dequeue(); } Debug.Log(queue2.Peek()); }
// draw a cube in GL Lines private void GLCube(CubeData cube) { float w = cube.size.x; float h = cube.size.y; float d = cube.size.z; float x = cube.center.x; float y = cube.center.y; float z = cube.center.z; GL.Color(cube.color); GL.Vertex3(x - w / 2f, y - h / 2f, z - d / 2f); // 4 GL.Vertex3(x - w / 2f, y - h / 2f, z + d / 2f); // 1 GL.Vertex3(x - w / 2f, y + h / 2f, z + d / 2f); // 2 GL.Vertex3(x - w / 2f, y + h / 2f, z - d / 2f); // 3 GL.Vertex3(x + w / 2f, y - h / 2f, z - d / 2f); // 5 GL.Vertex3(x - w / 2f, y - h / 2f, z - d / 2f); // 4 GL.Vertex3(x - w / 2f, y + h / 2f, z - d / 2f); // 3 GL.Vertex3(x + w / 2f, y + h / 2f, z - d / 2f); // 8 GL.Vertex3(x + w / 2f, y - h / 2f, z + d / 2f); // 6 GL.Vertex3(x + w / 2f, y - h / 2f, z - d / 2f); // 5 GL.Vertex3(x + w / 2f, y + h / 2f, z - d / 2f); // 8 GL.Vertex3(x + w / 2f, y + h / 2f, z + d / 2f); // 7 GL.Vertex3(x - w / 2f, y - h / 2f, z + d / 2f); // 1 GL.Vertex3(x + w / 2f, y - h / 2f, z + d / 2f); // 6 GL.Vertex3(x + w / 2f, y + h / 2f, z + d / 2f); // 7 GL.Vertex3(x - w / 2f, y + h / 2f, z + d / 2f); // 2 }
bool HasCube(CubeCoordinate coordinate) { byte cubeData = grid.GetCubeData(coordinate.ToVector3(CubeCoordinate.CoordinateType.cubeWorld)); CubeData data = CubeData.ToCubeData(cubeData); return(data.HasCube(false)); }
// Update is called once per frame void Update() { square.transform.localPosition = new Vector3(0, 4.5f * cameraScript.getMultiplier(), 0); data = cubeMovement.data; //updating the number of squares int sizeDifference = data.cubePosition.Count - squareList.Count; if (sizeDifference != 0) { if (sizeDifference > 0) { for (int i = 0; i < sizeDifference; i++) { squareList.Add(Instantiate(square)); } } else { for (int i = 0; i < (-1) * sizeDifference; i++) { //since these squares don't interact with the gameplay, any of the squares can be deleted Destroy(squareList[0]); squareList.RemoveAt(0); } } } //now that the number of squares is the same, //updating the position and color for (int i = 0; i < squareList.Count; i++) { squareList[i].transform.position = data.cubePosition[i] + new Vector3(10, 0, 0); squareList[i].GetComponent <SpriteRenderer>().color = gameVariables.cubeColors[data.cubeIndex[i]]; } }
public void LoadPreset(int level) { switch (level) { case 0: CubeData easy = new CubeData(Dificulty.Easy, 3, 3, 3, 0.5); GetComponent <FileManager>().WriteCubeData(easy, "cubeData"); break; case 1: CubeData med = new CubeData(Dificulty.Medium, 5, 5, 5, 0.5); GetComponent <FileManager>().WriteCubeData(med, "cubeData"); break; case 2: CubeData hard = new CubeData(Dificulty.Hard, 10, 10, 10, 0.5); GetComponent <FileManager>().WriteCubeData(hard, "cubeData"); break; default: CubeData def = new CubeData(Dificulty.Easy, 3, 3, 3, 0.5); GetComponent <FileManager>().WriteCubeData(def, "cubeData"); break; } }
public CombinationTrendChartTransformer(string controlId, CubeData input, string uncheckedItems) { _input = input; _controlId = controlId; _uncheckedItems = uncheckedItems; _colorList = new ColorListDataSource(); }
////////////////////////////////////////////// private CubeData GetCubeData(GameObject xChild) { CubeData data; if (xChild.transform.childCount == 0) { return(data = new CubeData() { styleType = CubeObjectStyles.Default, health = 100, objectType = CubeObjectTypes.Empty, rotation = Vector3.zero }); } else { GameObject cubeObject = xChild.transform.GetChild(0).gameObject; return(data = new CubeData() { styleType = cubeObject.GetComponent <CubeObjectScript>().cubeStyle, health = 100, objectType = cubeObject.GetComponent <CubeObjectScript>().cubeType, rotation = (Vector3)cubeObject.transform.rotation.eulerAngles }); } }
public void Instantiate(CubeData data) { var cubeRenderer = GetComponent <Renderer>(); this.name = data.Name; cubeRenderer.material.SetColor("Albedo", data.Colour); }
public void PreviewAction(CubeData data) { if (mode == PreviewMode.cube) { byte d; if (controlType == CharacherCubeControlType.add) { d = data.ToByte(); } else { d = 0; } grid.SetCubeData(transform.position, data.ToByte()); } else { if (controlType == CharacherCubeControlType.copy) { Debug.Log("getorientate:" + PreviewOrientate); GetDataFromPreviewBox(PreviewOrientate); } else { SetDataFromPreviewBox(PreviewOrientate); } } }
public WorldData(World world) { monsters = world.GetMonsterDatas(); worldWidth = world.worldWidth; worldHeight = world.worldHeight; Vector3 pos = world.spawnPos; spawnPos[0] = pos.x; spawnPos[1] = pos.y; spawnPos[2] = pos.z; //处理Cube数据的存储 Cube[,,] cubes = world.GetCubes(); cubeDatas = new CubeData[worldWidth, worldHeight, worldWidth]; for (int x = 0; x < worldWidth; x++) { for (int y = 0; y < worldHeight; y++) { for (int z = 0; z < worldWidth; z++) { if (cubes[x, y, z] != null) { cubeDatas[x, y, z] = new CubeData(cubes[x, y, z]); } } } } }
void TriangulateCube(int index) { Vector3 positon = allCubePoint[index]; CubeData data = CubeData.ToCubeData(datas[index]); data.orientate = data.orientate.AddOrientate(PreviewOrientate); Vector3[] cubeVertices = GetCubeVertices(positon, data.orientate); for (int i = 0; i < 6; i++) { CubeOrientate temp = (CubeOrientate)i; if (i < 4) { temp = temp.SubOrientate(PreviewOrientate); temp = temp.AddOrientate(data.orientate); } if (!CheckAdjacent(index, (CubeSurface)temp)) { TriangulateCubeSurface(cubeVertices, (CubeSurface)i, data); } } }
public static void ConsumeCube(CubeData cube) { Vector2 _pos; if (cube.color == instance.lastCube.color) { instance.multiplier++; _pos = Camera.main.WorldToScreenPoint(cube.objTrans.position); MultiplierControl.ShowMultiplier(cube.color, instance.multiplier, _pos); AudioControl.PlayFX("multiplier"); } else { instance.multiplier = 1; } instance.lastCube = cube; instance.points += cube.points * instance.multiplier; instance.StartCoroutine(instance.destroyCube(cube)); ScoreControl.Set(instance.points); if ((state == PLAYING) && (SpawnManager.RemainCubes() == 0)) { state = SUCCESS; TitleControl.Animate("GOOD JOB!", TitleControl.SUCCESS_ANIM); instance.nextUpdate = Time.time + 2; } }
// Edge decetion along one axis void EdgeDetection(int offsetX, int offsetZ, bool initialCheck = true) { // Assign references to the cube gameobject and cubedata script GameObject cube = map.GridCubeArray()[(int)cubeCoord.x + offsetX, (int)cubeCoord.z + offsetZ]; CubeData cubeData = cube.GetComponent <CubeData>(); // If the cube exsists on the x axis and is not of type metal e.g. (border) if (cube.gameObject != null && cubeData.cubeType != CUBETYPE.BORDER) { // If the edge detection is during map generation if (initialCheck) { // Set the cube as an edge cube - update material cubeData.SetAsEdgeCube(); // If the edge cube is a cyrstal cube change it to a rock cube if (cubeData.cubeType == CUBETYPE.CRYSTAL) { cubeData.SetAsRockCube(); cubeData.SetAsEdgeCube(); } } // Else if the edge dectetion is in game else if (!initialCheck && cubeData.cubeType == CUBETYPE.ROCK && cube.GetComponent <MeshRenderer>() != null) { cubeData.SetAsEdgeCube(); } } }
public void RemoveCube(CubeData cube) { if (Cubes.Contains(cube)) { Cubes.Remove(cube); } }
// Check for player digging and destroy rocks void RockDigging() { // Loop through all cubes in the cubes list foreach (GameObject cube in cubes) { // Check that there are cubes if (cubes.Count > 0 && cube != null) { // Get the cube data CubeData cubeData = cube.GetComponent <CubeData>(); // If the cube can be destroyed and the player is digging and if health of the cubes is greater than 0 if (cubeData.CubeDestructible() && diggingAttacking && cubeData.CurrentHealth() > 0) { cubeData.CubeDamaged(1); } } } // If there are cubes in the cubes list if (cubes.Count > 0) { // Loop through each cube for (int i = 0; i < cubes.Count; i++) { // If the cube has been destroyed remove it from the cubes list if (cubes[i] == null || cubes[i].GetComponent <CubeData>().CubeDestroyed()) { cubes.Remove(cubes[i].gameObject); } } } }
void TriangulateCube(int x, int y, int z, CubeData data) { float cx = transform.position.x + x * CubeMetrics.CUBE_SIDE_LENGTH + CubeMetrics.CUBE_SIDE_LENGTH / 2f; float cy = transform.position.y + y * CubeMetrics.CUBE_SIDE_LENGTH + CubeMetrics.CUBE_SIDE_LENGTH / 2f; float cz = transform.position.z + z * CubeMetrics.CUBE_SIDE_LENGTH + CubeMetrics.CUBE_SIDE_LENGTH / 2f; Vector3 cubePosition = new Vector3(cx, cy, cz) - (Vector3.one * CubeMetrics.CHUNK_WIDTH * CubeMetrics.CUBE_SIDE_LENGTH / 2f); Vector3[] cubeVertices = GetCubeVertices(cubePosition, data.orientate); for (int i = 0; i < 6; i++) { int temp = i; if (temp < 4) { temp = (temp + (int)data.orientate) > 3 ? temp + (int)data.orientate - 4 : temp + (int)data.orientate; } if (!CheckAdjacent(x, y, z, (CubeSurface)temp, data.isTransparent)) { TriangualteCubeSurface(cubeVertices, (CubeSurface)i, data); } } }
void AddPrimitiveData(EntityData entity, PhysicsType type, GameObject go) { switch (type) { case PhysicsType.Cube: CubeData cube = new CubeData(); cube.posX = Round(go.transform.localPosition.x); cube.posY = Round(go.transform.localPosition.y); cube.posZ = Round(go.transform.localPosition.z); cube.quaternionX = Round(go.transform.localRotation.x); cube.quaternionY = Round(go.transform.localRotation.y); cube.quaternionZ = Round(go.transform.localRotation.z); cube.quaternionW = Round(go.transform.localRotation.w); cube.length = Round(go.transform.localScale.x); cube.height = Round(go.transform.localScale.y); cube.width = Round(go.transform.localScale.z); entity.cubeData.Add(cube); break; case PhysicsType.Sphere: SphereData sphere = new SphereData(); sphere.posX = Round(go.transform.localPosition.x); sphere.posY = Round(go.transform.localPosition.y); sphere.posZ = Round(go.transform.localPosition.z); sphere.radius = Round(go.transform.localScale.x / 2); entity.sphereData.Add(sphere); break; } }
private void Start() { Data = new CubeData(10, GetTransform()); MoveSystem = new CubeMove(Data); EventsManager.OnPlancePressed += AddPointToPathWay; _moveSpeedSlider.onValueChanged.AddListener(ChangeSpeedOn); }
public void Execute(CollisionEvent collisionEvent) { Entity entityA = collisionEvent.Entities.EntityA; Entity entityB = collisionEvent.Entities.EntityB; var aEntityIsWall = wallGroup.Exists(entityA); var bEntityIsWall = wallGroup.Exists(entityB); var aEntityIsCube = cubeGroup.Exists(entityA); var bEntityIsCube = cubeGroup.Exists(entityB); if (aEntityIsWall && bEntityIsCube) { CubeData cubeData = cubeGroup[entityB]; var newDirection = reflect(cubeData.Direction, collisionEvent.Normal); cubeData.Direction = new Vector3(newDirection.x, cubeData.Direction.y, newDirection.z); cubeData.Acceleration = .2f; } if (bEntityIsWall && aEntityIsCube) { CubeData cubeData = cubeGroup[entityA]; var newDirection = reflect(cubeData.Direction, collisionEvent.Normal); cubeData.Direction = new Vector3(newDirection.x, cubeData.Direction.y, newDirection.z); cubeData.Acceleration = .2f; } }
public static CubeData Read(byte[] data) { using var mem = new MemoryStream(data); using var reader = new StreamReader(mem); int line = 1; bool readData = false; var state = new CubeData(false, 0, new Vector3(0, 0, 0), new Vector3(1, 1, 1), null); try { while (true) { var str = reader.ReadLine(); var p = str.Split(' '); if (!readData) { if (string.IsNullOrWhiteSpace(str) || str.StartsWith("#") || str.ToLower().StartsWith("title")) { // nothing, this is comment of empty string } else if (p[0] == "LUT_1D_SIZE") { var size = Int32.Parse(p[1]); state = state with { Is3D = false, Size = size, Data = new float[size * 4] }; } else if (p[0] == "LUT_3D_SIZE") { var size = Int32.Parse(p[1]); state = state with { Is3D = true, Size = size, Data = new float[size * size * size * 4] }; } else if (p[0] == "DOMAIN_MIN") { state = state with { DomainMin = new Vector3(float.Parse(p[1]), float.Parse(p[2]), float.Parse(p[3])) } } ; else if (p[0] == "DOMAIN_MAX") { state = state with { DomainMax = new Vector3(float.Parse(p[1]), float.Parse(p[2]), float.Parse(p[3])) } } ; else if (state.Size > 0) { readData = true; } else { throw new InvalidOperationException("Header not found"); } }
void TriangulateCubeSurface(Vector3[] temp, CubeSurface surfaceTo, CubeData data) { float uCoordinate = ((int)surfaceTo * 1.0f) / 6.0f; float vCoordinate = ((int)data.type * 1.0f) / 16f * 1.0f; Vector2 uvBasePoint = new Vector2(uCoordinate, vCoordinate); switch (surfaceTo) { case CubeSurface.up: mesh.AddQuad(temp[0], temp[1], temp[2], temp[3]); break; case CubeSurface.down: mesh.AddQuad(temp[5], temp[4], temp[7], temp[6]); break; case CubeSurface.left: mesh.AddQuad(temp[0], temp[3], temp[7], temp[4]); break; case CubeSurface.right: mesh.AddQuad(temp[2], temp[1], temp[5], temp[6]); break; case CubeSurface.front: mesh.AddQuad(temp[1], temp[0], temp[4], temp[5]); break; case CubeSurface.back: mesh.AddQuad(temp[3], temp[2], temp[6], temp[7]); break; } mesh.AddQuadUV(uvBasePoint, 16); }
///////////////////////////Grid Cubes/////////////////////////// // Record the grid cubes (start and end of game) public void RecordGridCubes(GameObject[,] gridCubes, bool start) { // Loop through all the cubes foreach (GameObject go in gridCubes) { // Add cube to the cube positions dictionary CubeData cubeData = go.GetComponent <CubeData>(); Vector3 cubePos = cubeData.GetCubeCoord(); // Start of the game if (start) { cubePositionsStart.Add(new CubeStat { position = cubePos, type = cubeData.GetCubeType() }); } // End of the game else { cubePositionsEnd.Add(new CubeStat { position = cubePos, type = cubeData.GetCubeType() }); } } }
//private int dayOfTheWeek; // Use this for initialization private void Start() { CubeData cubeDatas = new CubeData (); numOfCubes = cubeDatas.numOfCubes(); //cubeList = GameObject.Find ("Cube" + 0); //Debug.Log (x); }
void DataTest() { for (int i = 0; i < cubes.Length; i++) { Debug.Log(i + ": " + CubeData.ToCubeData(cubes[i]).HasCube); } Debug.Log(grid.chunkDatas.ContainsKey(ChunkCoordinate.ToString())); }
// Generate tyhe grid cubes void GenerateGridCubes() { // Initialise the grid cube array gridCubeArray = new GameObject[gridWidth, gridHeight]; // Build the map grid - loop through height of grid for (int z = 0; z < gridHeight; z++) { // Loop through width of grid for (int x = 0; x < gridWidth; x++) { // Build the grid - instantiate grid cube calculated position - assign the cube as a child of the gridCubes object GameObject cube = Instantiate(gridCube, new Vector3(x * 1.0f, 0.0f, z * 1.0f), Quaternion.identity, gridCubes.transform) as GameObject; cube.transform.localScale = new Vector3(cubeScale, cubeScale, cubeScale); // Assign the grid cube to the array gridCubeArray[x, z] = cube; // Reference to the cube data CubeData cubeData = gridCubeArray[x, z].GetComponent <CubeData>(); // Set the cubes coord in the grid and set all cubes to closed (initially) cubeData.SetCubeCoord(new Vector3(x, 0.0f, z)); cubeData.SetCubeOpen(false); // Random between 0 and 1 - used to select rock type float crystalChance = Random.Range(0.0f, 1.0f); // Set the grid borders as border cubes - Set the gird cube indestructible and the cube type as border if (x == 0 || z == 0 || x == 1 || z == 1 || x == gridWidth - 1 || z == gridHeight - 1 || x == gridWidth - 2 || z == gridHeight - 2) { cubeData.SetAsBorderCube(); } // Set the cube as crystal cubes - Set the gird cube destructible and the cube type as rock else if (crystalChance < crystalCubeChance) { cubeData.SetAsCystalCube(); } // Set the rest of the cubes as rock cubes -- Set the gird cube destructible and the cube type as rock else { cubeData.SetAsRockCube(); } // If the cube is a rock/crystal or border cube if (cubeData.GetCubeType() == CUBETYPE.BORDER || cubeData.GetCubeType() == CUBETYPE.ROCK || cubeData.GetCubeType() == CUBETYPE.CRYSTAL) { // Set the scale and rotation of the grid cubes cube.transform.localScale = new Vector3(cubeScale, cubeScale, cubeScale); cube.transform.rotation = Random.rotation; } } } Debug.Log("MAP - GEN GRID CUBES - COMPLETE"); }
public void Add(MySlimBlock block) { bool isStatic = MyCubeGrid.IsInVoxels(block); var element = new CubeData(isStatic); if (!isStatic) element.CurrentOffset = 0.05f; m_cubes[block.Position] = element; m_cubeChanged = true; }
private IEnumerator TimerToMerging(CubeData cube0, CubeData cube1) { float time = Random.Range(0f, .2f); yield return(new WaitForSeconds(time)); _isCollided = true; CubeMerger.Instance.MergeCubes(cube0, cube1); }
public static void AddCube(Transform cube) { if (cube != null) { CubeData data = new CubeData(); data.posX = cube.position.x; data.posY = cube.position.y; data.posZ = cube.position.z; data.rotX = cube.eulerAngles.x; data.rotY = cube.eulerAngles.y; data.rotZ = cube.eulerAngles.z; collection.cubes.Add(data); } }
public void LoadPreset(int level) { switch (level) { case 0: CubeData easy = new CubeData(Dificulty.Easy, 3, 3, 3, 0.5); GetComponent<FileManager>().WriteCubeData(easy, "cubeData"); break; case 1: CubeData med = new CubeData(Dificulty.Medium, 5, 5, 5, 0.5); GetComponent<FileManager>().WriteCubeData(med, "cubeData"); break; case 2: CubeData hard = new CubeData(Dificulty.Hard, 10, 10, 10, 0.5); GetComponent<FileManager>().WriteCubeData(hard, "cubeData"); break; default: CubeData def = new CubeData(Dificulty.Easy, 3, 3, 3, 0.5); GetComponent<FileManager>().WriteCubeData(def, "cubeData"); break; } }
void Start(){ GameObject[] cubesInScene; cubesInScene = GameObject.FindGameObjectsWithTag ("Cube"); numberOfCubes = cubesInScene.Length; Debug.Log (numberOfCubes); listOfCubeData = new List<CubeData> (); CubeData newCube; for (int i = 0; i < numberOfCubes; i++) { newCube = new CubeData(cubesInScene[i]); listOfCubeData.Add (newCube); } ColorData cols = new ColorData(); int iter = 0; foreach (CubeData cd in listOfCubeData) { cd.cube.GetComponent<Renderer>().material.color = cols.GetAColorToUse(iter % 5); iter++; } }
public Cube(float _length) { Source = new CubeData(_length); Attributes = new CubeAttributes(); }
private void SaveLevel(string s) { LevelManager _levManager = GameObject.Find("_LevelManager").GetComponent<LevelManager>(); CubeData[,,] temp = new CubeData[_levManager.m_Width, 10, _levManager.m_Width]; GameObject[] _cubes = GameObject.FindGameObjectsWithTag("Cube"); for (int i = 0; i < _cubes.Length; i++) { Vector3 _pos = _cubes[i].transform.position; CubeData _data = new CubeData(_pos.x, _pos.y, _pos.z, _cubes[i].transform.localScale, true); temp[(int)Mathf.Abs(_pos.x), (int)Mathf.Abs(_pos.y), (int)Mathf.Abs(_pos.z)] = _data; DestroyImmediate((_cubes[i].gameObject)); } CubeData[,,] array = temp; string fileName = Application.persistentDataPath + "/" + s + ".dat"; BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); bf.Serialize(fs, array); fs.Close(); }
public void WriteCubeData(CubeData data, string fileName) { string json = LitJson.JsonMapper.ToJson(data); var path = Application.dataPath + "/CubeData/"; // フォルダーがない場合は作成する if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.WriteAllText(path + fileName + ".json", json); }
public void WriteData() { GetComponent<FileManager>().WriteCubeData(_newCubeData, "cubeData"); _currentCubeData = _newCubeData; _currentText.columns.text = "Current Columns: " + _currentCubeData.columns.ToString(); _currentText.rows.text = "Current Rows: " + _currentCubeData.rows.ToString(); _currentText.depth.text = "Current Depth: " + _currentCubeData.depth.ToString(); _currentText.margin.text = "Current Margin: " + _currentCubeData.margin.ToString(); }
private void Start() { _currentCubeData = GetComponent<FileManager>().ReadCubeData("cubeData"); _newCubeData = _currentCubeData; _newCubeData.dificulty = Dificulty.Custom; _currentData = GameObject.Find("Current Data"); _newData = GameObject.Find("New Data"); _currentText.columns = _currentData.transform.Find("Columns").GetComponent<Text>(); _currentText.rows = _currentData.transform.Find("Rows").GetComponent<Text>(); _currentText.depth = _currentData.transform.Find("Depth").GetComponent<Text>(); _currentText.margin = _currentData.transform.Find("Margin").GetComponent<Text>(); _currentText.columns.text = "Current Columns: " + _currentCubeData.columns.ToString(); _currentText.rows.text = "Current Rows: " + _currentCubeData.rows.ToString(); _currentText.depth.text = "Current Depth: " + _currentCubeData.depth.ToString(); _currentText.margin.text = "Current Margin: " + _currentCubeData.margin.ToString(); _newText.columns = _newData.transform.Find("Columns").GetComponent<Text>(); _newText.rows = _newData.transform.Find("Rows").GetComponent<Text>(); _newText.depth = _newData.transform.Find("Depth").GetComponent<Text>(); _newText.margin = _newData.transform.Find("Margin").GetComponent<Text>(); }
public bool GreaterThan(CubeData cubeData) { return _fraction.GreaterThan(cubeData.GetFraction()); }
private static void SumConstraints(CubeData me, Dictionary<Vector3I, CubeData> cubes, Vector3I neighbourPos, float myOffset, ref float sum, ref float count, ref float max) { CubeData cube; if (cubes.TryGetValue(neighbourPos, out cube) && cube != me) { var diff = myOffset - cube.TmpOffset; //if (diff < 0.00001f && !cube.IsStatic && !me.IsStatic) //{ // me.Merged = true; // cubes[neighbourPos] = me; //} max = Math.Max(diff, max); sum += diff; count++; } }
private void Refresh() { if (!m_cubeChanged) return; var copy = m_cubes.ToArray(); m_cubes.Clear(); foreach (var c in copy) { var data = new CubeData() { CurrentOffset = c.Value.CurrentOffset, IsStatic = c.Value.IsStatic, DistanceToStatic = c.Value.IsStatic ? 0 : int.MaxValue }; m_cubes.Add(c.Key, data); if (data.IsStatic) { m_tmpCubes.Push(c.Key); } } while (m_tmpCubes.Count > 0) { var pos = m_tmpCubes.Pop(); PropagateNeighbor(m_cubes, m_tmpCubes, pos, Vector3I.UnitX); PropagateNeighbor(m_cubes, m_tmpCubes, pos, Vector3I.UnitY); PropagateNeighbor(m_cubes, m_tmpCubes, pos, Vector3I.UnitZ); PropagateNeighbor(m_cubes, m_tmpCubes, pos, -Vector3I.UnitX); PropagateNeighbor(m_cubes, m_tmpCubes, pos, -Vector3I.UnitY); PropagateNeighbor(m_cubes, m_tmpCubes, pos, -Vector3I.UnitZ); } m_cubeChanged = false; }