Created
April 27, 2016 18:45
-
-
Save Thelta/b853849607d3d05dae02e231a93938a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections.Generic; | |
| public class ObjectChunk | |
| { | |
| WorldPos originBlockPos; | |
| List<WorldPos> relativeBlocksPos; | |
| public ObjectChunk(RaycastHit hit) | |
| { | |
| originBlockPos = Terrain.GetBlockPos(hit, true); | |
| relativeBlocksPos = new List<WorldPos>(); | |
| relativeBlocksPos.Add(new WorldPos()); | |
| originBlockPos.print(); | |
| } | |
| public void addNewBlock(RaycastHit hit) | |
| { | |
| WorldPos relativeBlockPos = Terrain.GetBlockPos(hit, true) - originBlockPos; | |
| relativeBlocksPos.Add(relativeBlockPos); | |
| } | |
| public void copyNewObject(RaycastHit hit) | |
| { | |
| WorldPos origin = Terrain.GetBlockPos(hit, true); | |
| Chunk chunk = hit.collider.GetComponent<Chunk>(); | |
| for(int i = 0; i < relativeBlocksPos.Count; i++) | |
| { | |
| Terrain.SetBlock(relativeBlocksPos[i] + origin, chunk, new Block()); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static bool SetBlock(WorldPos pos, Chunk chunk, Block block) | |
| { | |
| chunk.world.SetBlock(pos.x, pos.y, pos.z, block); | |
| return true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class WorldPos | |
| { | |
| public int x, y, z; | |
| public WorldPos() | |
| { | |
| this.x = 0; this.y = 0; this.z = 0; | |
| } | |
| public WorldPos(int x, int y, int z) | |
| { | |
| this.x = x; this.y = y; this.z = z; | |
| } | |
| public override bool Equals(object obj) | |
| { | |
| if (GetHashCode() == obj.GetHashCode()) | |
| return true; | |
| return false; | |
| } | |
| public override int GetHashCode() | |
| { | |
| unchecked | |
| { | |
| int hash = 47; | |
| hash = hash * 227 + x.GetHashCode(); | |
| hash = hash * 227 + y.GetHashCode(); | |
| hash = hash * 227 + z.GetHashCode(); | |
| return hash; | |
| } | |
| } | |
| public static WorldPos operator -(WorldPos c1, WorldPos c2) | |
| { | |
| return new WorldPos(c1.x - c2.x, c1.y - c2.y, c1.z - c2.z); | |
| } | |
| public static WorldPos operator +(WorldPos c1, WorldPos c2) | |
| { | |
| return new WorldPos(c1.x + c2.x, c1.y + c2.y, c1.z + c2.z); | |
| } | |
| public void print() | |
| { | |
| Debug.Log(x + " " + y + " " + z + " "); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment