// Update is called once per frame void Update() { if(Input.touchCount>0 || Input.GetMouseButton(1)) { RaycastHit hit; Ray ray; if(Input.touchCount>0) ray = Camera.main.ScreenPointToRay(Input.touches[0].position ); else ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast (ray, out hit )) { if(hit.collider.gameObject.GetComponent<McBlock>() != null ) { _mcBlock = hit.collider.gameObject.GetComponent<McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint( Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz); } } } }
public void SetValue(McBlock mcBlock, int px, int py, int pz, float val) { values.SetVal(mcBlock, px, py, pz, val); if( pz > mcBlock.dimZ -2) if(mcBlock.posZ < BlockCountZ-1) blocks[mcBlock.posX, mcBlock.posY, mcBlock.posZ +1].RequiresUpdate = true; if( pz < 2) if(mcBlock.posZ > 0) blocks[mcBlock.posX, mcBlock.posY, mcBlock.posZ -1].RequiresUpdate = true; if( py > mcBlock.dimY-2) if(mcBlock.posY < BlockCountY-1) blocks[mcBlock.posX, mcBlock.posY +1, mcBlock.posZ].RequiresUpdate = true; if( py < 2) if(mcBlock.posY > 0) blocks[mcBlock.posX, mcBlock.posY -1, mcBlock.posZ].RequiresUpdate = true; if( px > mcBlock.dimX-2) if(mcBlock.posX < BlockCountX-1) blocks[mcBlock.posX +1, mcBlock.posY, mcBlock.posZ].RequiresUpdate = true; if( px < 2) if(mcBlock.posX > 0) blocks[mcBlock.posX -1, mcBlock.posY, mcBlock.posZ].RequiresUpdate = true; mcBlock.RequiresUpdate = true; }
// Update is called once per frame void Update() { if (Input.touchCount > 0 || Input.GetMouseButton(1)) { RaycastHit hit; Ray ray; if (Input.touchCount > 0) { ray = Camera.main.ScreenPointToRay(Input.touches[0].position); } else { ray = Camera.main.ScreenPointToRay(Input.mousePosition); } if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.GetComponent <McBlock>() != null) { _mcBlock = hit.collider.gameObject.GetComponent <McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint(Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz); } } } }
void Update() { if (materialsSet == false && blockMaterial != null) { foreach (McBlock _block in blocks) { if (_block.renderer != null) { _block.renderer.material = blockMaterial; materialsSet = true; } } } if (Input.touchCount > 0 || Input.GetMouseButton(0)) { RaycastHit hit; Ray ray; if (Input.touchCount > 0) { ray = Camera.main.ScreenPointToRay(Input.touches[0].position); } else { ray = Camera.main.ScreenPointToRay(Input.mousePosition); } if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.GetComponent <McBlock>() != null) { _mcBlock = hit.collider.gameObject.GetComponent <McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint(Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); //Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz + " - "+ _b.i ()); int _x = Mathf.RoundToInt(_a.x * _mcBlock.dimX); int _y = Mathf.RoundToInt(_a.y * _mcBlock.dimY); int _z = Mathf.RoundToInt(_a.z * _mcBlock.dimZ); SetValue(_mcBlock, _x, _y, _z, _b.i() * 0.98f); Debug.DrawLine(Camera.main.transform.position, hit.point); GameObject _exlplodePrefab = Resources.Load("Explosivo/Explosion") as GameObject; GameObject.Instantiate(_exlplodePrefab, hit.point, Quaternion.identity); //_mcBlock.RequiresUpdate = true; } } } }
public mcPoint(float x, float y, float z, int px, int py, int pz, McBlock mcBlock) { this.index = new float[3]; index[0] = x; index[1] = y; index[2] = z; this.px = px; this.py = py; this.pz = pz; this.cntr = 0; this.mcBlock = mcBlock; }
public void SetValue(McBlock mcBlock, int px, int py, int pz, float val) { values.SetVal(mcBlock, px, py, pz, val); if (pz > mcBlock.dimZ - 2) { if (mcBlock.posZ < BlockCountZ - 1) { blocks[mcBlock.posX, mcBlock.posY, mcBlock.posZ + 1].RequiresUpdate = true; } } if (pz < 2) { if (mcBlock.posZ > 0) { blocks[mcBlock.posX, mcBlock.posY, mcBlock.posZ - 1].RequiresUpdate = true; } } if (py > mcBlock.dimY - 2) { if (mcBlock.posY < BlockCountY - 1) { blocks[mcBlock.posX, mcBlock.posY + 1, mcBlock.posZ].RequiresUpdate = true; } } if (py < 2) { if (mcBlock.posY > 0) { blocks[mcBlock.posX, mcBlock.posY - 1, mcBlock.posZ].RequiresUpdate = true; } } if (px > mcBlock.dimX - 2) { if (mcBlock.posX < BlockCountX - 1) { blocks[mcBlock.posX + 1, mcBlock.posY, mcBlock.posZ].RequiresUpdate = true; } } if (px < 2) { if (mcBlock.posX > 0) { blocks[mcBlock.posX - 1, mcBlock.posY, mcBlock.posZ].RequiresUpdate = true; } } mcBlock.RequiresUpdate = true; }
public float GetVal(McBlock mcBlock, int pointPosX, int pointPosY, int pointPosZ) { _x = mcField.BlockResX * mcBlock.posX; _x += pointPosX; _y = mcField.BlockResY * mcBlock.posY; _y += pointPosY; _z = mcField.BlockResZ * mcBlock.posZ; _z += pointPosZ; return(values[_x, _y, _z]); }
public void SetVal(McBlock mcBlock, int pointPosX, int pointPosY, int pointPosZ, float val) { _x = mcField.BlockResX * mcBlock.posX; _x += pointPosX; _y = mcField.BlockResY * mcBlock.posY; _y += pointPosY; _z = mcField.BlockResZ * mcBlock.posZ; _z += pointPosZ; values[_x, _y, _z] = val; }
void Init() { int x; int y; int z; blocks = new McBlock[BlockCountX,BlockCountY,BlockCountZ]; values = new McValues(this); McBlock _mcBlock; GameObject _mcBlockGO; sizeX = BlockCountX * BlockResX; sizeY = BlockCountY * BlockResY; sizeZ = BlockCountZ * BlockResZ; float _h = (1 / BlockCountX); _h += (_h*0.5f); mid = new Vector3( (1f / sizeX) / 2, (1f / sizeY) / 2, (1f / sizeZ) / 2); for(x=0;x<BlockCountX;x++) { for(y=0;y<BlockCountY;y++) { for(z=0;z<BlockCountZ;z++) { _mcBlockGO = new GameObject("MC Block: " + x + "," + y + "," + z); _mcBlockGO.transform.parent = transform; _mcBlock = _mcBlockGO.AddComponent<McBlock>(); _mcBlock.mcField = this; blocks[x,y,z] = _mcBlock; _mcBlock.posX = x; _mcBlock.posY = y; _mcBlock.posZ = z; _mcBlock._dimX = BlockResX; _mcBlock._dimY = BlockResY; _mcBlock._dimZ = BlockResZ; _mcBlock.transform.position = new Vector3((1f / BlockCountX) * x,(1f / BlockCountY) * y,(1f / BlockCountZ) * z); _mcBlock.transform.position += Vector3.one * (1f / BlockCountX) * 0.5f; _mcBlock.transform.position -= Vector3.one * 0.5f; _mcBlock.transform.position += transform.position; _mcBlock.transform.localScale = new Vector3(1f/BlockCountX,1f/BlockCountY,1f/BlockCountZ); } } } }
public void GetValue(McBlock mcBlock, int px, int py, int pz) { values.GetVal(mcBlock, px, py, pz); }
public void SetVal(McBlock mcBlock, int pointPosX, int pointPosY, int pointPosZ, float val) { _x = mcField.BlockResX * mcBlock.posX; _x += pointPosX; _y = mcField.BlockResY * mcBlock.posY; _y += pointPosY; _z = mcField.BlockResZ * mcBlock.posZ; _z += pointPosZ; values[_x,_y,_z] = val; }
public float GetVal(McBlock mcBlock, int pointPosX, int pointPosY, int pointPosZ) { _x = mcField.BlockResX * mcBlock.posX; _x += pointPosX; _y = mcField.BlockResY * mcBlock.posY; _y += pointPosY; _z = mcField.BlockResZ * mcBlock.posZ; _z += pointPosZ; return values[_x,_y,_z]; }
void Update() { if(materialsSet == false && blockMaterial!=null) { foreach(McBlock _block in blocks) if(_block.renderer!=null) { _block.renderer.material = blockMaterial; materialsSet = true; } } if(Input.touchCount>0 || Input.GetMouseButton(0)) { RaycastHit hit; Ray ray; if(Input.touchCount>0) ray = Camera.main.ScreenPointToRay(Input.touches[0].position ); else ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast (ray, out hit )) { if(hit.collider.gameObject.GetComponent<McBlock>() != null ) { _mcBlock = hit.collider.gameObject.GetComponent<McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint( Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); //Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz + " - "+ _b.i ()); int _x = Mathf.RoundToInt(_a.x * _mcBlock.dimX); int _y = Mathf.RoundToInt(_a.y * _mcBlock.dimY); int _z = Mathf.RoundToInt(_a.z * _mcBlock.dimZ); SetValue(_mcBlock, _x, _y, _z, _b.i () * 0.98f); Debug.DrawLine(Camera.main.transform.position, hit.point); GameObject _exlplodePrefab = Resources.Load("Explosivo/Explosion") as GameObject; GameObject.Instantiate(_exlplodePrefab, hit.point, Quaternion.identity); //_mcBlock.RequiresUpdate = true; } } } }
public mcPoint(float x,float y,float z,int px,int py,int pz,McBlock mcBlock) { this.index=new float[3]; index[0]=x;index[1]=y;index[2]=z; this.px=px; this.py=py; this.pz=pz; this.cntr=0; this.mcBlock=mcBlock; }
internal void LoadSection(NbtTag section) { // Make sure we're passed a TAG_Compound named "Environment" if (section is NbtCompound && section.Name == "Environment") { NbtCompound compound = (NbtCompound) section; SurroundingGroundHeight = compound["SurroundingGroundHeight"] != null ? ((NbtShort) compound["SurroundingGroundHeight"]).Value : (short) 0; SurroundingGroundType = compound["SurroundingGroundType"] != null ? (McBlock) ((NbtByte) compound["SurroundingGroundType"]).Value : 0x00; SurroundingWaterHeight = compound["SurroundingWaterHeight"] != null ? ((NbtShort) compound["SurroundingWaterHeight"]).Value : (short) 0; SurroundingWaterType = compound["SurroundingWaterType"] != null ? (McBlock) ((NbtByte) compound["SurroundingWaterType"]).Value : 0x00; CloudHeight = compound["CloudHeight"] != null ? ((NbtShort) compound["CloudHeight"]).Value : (short) 0; CloudColor = compound["CloudColor"] != null ? Color.FromArgb(((NbtInt) compound["CloudColor"]).Value) : Color.Black; SkyColor = compound["SkyColor"] != null ? Color.FromArgb(((NbtInt) compound["SkyColor"]).Value) : Color.Black; FogColor = compound["FogColor"] != null ? Color.FromArgb(((NbtInt) compound["FogColor"]).Value) : Color.Black; SkyBrightness = compound["SkyBrightness"] != null ? ((NbtByte) compound["SkyBrightness"]).Value : (byte) 0x00; } }