private void OnTriggerEnter(Collider other) { var farmSpawn = other.GetComponent <FarmSpawn>(); if (farmSpawn && !farmSpawn.IsGrown()) { farmSpawn.Grow(); Destroy(gameObject); } else { var greenSpawn = other.GetComponent <GreensSpawn>(); if (greenSpawn && !greenSpawn.IsGrown()) { greenSpawn.Grow(); Destroy(gameObject); } else { var block = other.GetComponent <Block>(); if (block && block.IsSand()) { var grassBlockRoot = BlockFactory.Get().GrassBlock(); var grassBlock = grassBlockRoot.GetComponentInChildren <Block>(); WorldPlane.Get().ReplaceBlock(block, grassBlock); Destroy(gameObject); } } } }
protected void Start() { _originalLocalPosition = transform.localPosition; _originalScale = transform.localScale * 1.5f; transform.localScale = _originalScale; _featureToggles = FeatureToggles.Get(); _worldPlane = WorldPlane.Get(); if (isStartingInteractor) { GetComponentInParent <BlockInteractionPalette>().Select(this); Activate(); } _ghost = Instantiate(BlockFactory.Get().interactableGhostTemplate); _ghost.SetActive(false); _nonInteractableGhost = Instantiate(BlockFactory.Get().nonInteractableGhostTemplate); _nonInteractableGhost.SetActive(false); _started = true; }
void Start() { _life = Time.fixedTime; _block = GetComponentInChildren <Block>(); _worldPlane = GameObject.FindWithTag("WorldPlane").GetComponent <WorldPlane>(); _workQueue = WorkQueue.Get(); _blockFactory = BlockFactory.Get(); _block.SetAsUnstable(); }
public static dynamic Add(PortalSettings PortalSettings, CustomBlock CustomBlock, int ForceCount = 0) { dynamic Result = new ExpandoObject(); try { if (BlockFactory.Get(PortalSettings.PortalId, CustomBlock.Name) == null) { if (ForceCount == 0) { CustomBlock.Guid = Guid.NewGuid().ToString().ToLower(); } CustomBlock.PortalID = PortalSettings.PortalId; CustomBlock.CreatedBy = PortalSettings.UserId; CustomBlock.UpdatedBy = PortalSettings.UserId; CustomBlock.CreatedOn = DateTime.UtcNow; CustomBlock.UpdatedOn = DateTime.UtcNow; CustomBlock.Locale = PageManager.GetCultureCode(PortalSettings); BlockFactory.AddUpdate(CustomBlock); CustomBlock cb = BlockFactory.GetAll(PortalSettings.PortalId).Where(b => b.Guid.ToLower() == CustomBlock.Guid.ToLower() && b.Locale == null).FirstOrDefault(); if (cb == null) { cb = CustomBlock; cb.Locale = null; cb.ID = 0; BlockFactory.AddUpdate(cb); } Result.Status = "Success"; Result.Guid = CustomBlock.Guid; } else { if (ForceCount > 0) { CustomBlock.Name = CustomBlock.Name + ForceCount; ForceCount++; Result = Add(PortalSettings, CustomBlock, ForceCount); } else { Result.Status = "Exist"; } } } catch (Exception ex) { Result.Status = ex.Message.ToString(); DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } return(Result); }
private IEnumerator CreateWorld(Vector2 dimensions) { _currentDimensions = dimensions; var yChunks = 8; for (var yChunk = 1; yChunk <= yChunks; yChunk++) { var xChunks = 8; for (var xChunk = 1; xChunk <= xChunks; xChunk++) { var rowHeight = Mathf.Ceil(dimensions.y / yChunks); var yStart = rowHeight * (yChunk - 1); var yMax = rowHeight * yChunk; for (var row = yStart; row < yMax; row++) { var isMiddle = Math.Abs(row % 2) < .5f; var columnHeight = Mathf.Ceil(dimensions.x / xChunks); var xStart = columnHeight * (xChunk - 1); var xMax = columnHeight * xChunk; for (var column = Math.Abs(xStart) < .5f ? -1 : xStart; column < xMax; column++) { Block previousBlock = null; for (var level = Block.LowestLevel; level <= 0; level++) { if (isMiddle && Math.Abs(column - (-1)) < .5f) { continue; } var blockToUse = BlockFactory.Get().grassBlockTemplate; if (level == 0) { var neededLeftColumn = isMiddle ? 0 : -1; var neededRightColumn = dimensions.x - 1; if (column == neededLeftColumn || column == neededRightColumn || row == 0 || row == dimensions.y - 1) { blockToUse = BlockFactory.Get().topWaterBlockTemplate; } else if (WithinRange(column, neededLeftColumn + 1, neededLeftColumn + 3) || WithinRange(column, neededRightColumn - 3, neededRightColumn - 1) || WithinRange(row, 1, 3) || WithinRange(row, dimensions.y - 4, dimensions.y - 2)) { if (WithinRange(column, neededLeftColumn + 1, neededLeftColumn + 2) || WithinRange(column, neededRightColumn - 2, neededRightColumn - 1) || WithinRange(row, 1, 2) || WithinRange(row, dimensions.y - 3, dimensions.y - 2)) { if (WithinRange(column, neededLeftColumn + 1, neededLeftColumn + 1) || WithinRange(column, neededRightColumn - 1, neededRightColumn - 1) || WithinRange(row, 1, 1) || WithinRange(row, dimensions.y - 2, dimensions.y - 2)) { if (Random.value < .7) { blockToUse = BlockFactory.Get().topWaterBlockTemplate; } else { blockToUse = BlockFactory.Get().sandBlockTemplate; } } else if (Random.value < .2) { blockToUse = BlockFactory.Get().topWaterBlockTemplate; } else { blockToUse = BlockFactory.Get().sandBlockTemplate; } } else if (Random.value < .8f) { blockToUse = BlockFactory.Get().sandBlockTemplate; } } } var blockPosition = new Vector3(row, level, column); var blockObject = Instantiate(blockToUse); var block = blockObject.GetComponentInChildren <Block>(); if (level == Block.LowestLevel) { AddAndPositionBlock(block, blockPosition); previousBlock = block; } else { AddBlockOnTopOf(block, blockObject, previousBlock); previousBlock = block; } } } yield return(new WaitForEndOfFrame()); } } } }
// Update is called once per frame void Update() { bool pcKeys = Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1); bool androidKeys = Input.GetKeyDown("joystick button 0") || Input.GetKeyDown("joystick button 2"); bool keys = androidKeys || pcKeys; bool destroyKeys = Input.GetMouseButtonDown(0) || Input.GetKeyDown("joystick button 0"); // .SetBool ("attacking", true); if (keys) { RaycastHit hit; //Debug.DrawRay (vrCamera.transform.position, vrCamera.TransformDirection (Vector3.forward)*1); if (Physics.Raycast(vrCamera.transform.position, vrCamera.TransformDirection(Vector3.forward), out hit, 5)) { Chunk hitc; if (hit.collider.gameObject.name == "Zombie") { World.Instance.character.attack(World.Instance.mob); //old_pos = arm.transform.position; //arm.transform.position = hit.point; //StartCoroutine ("lol"); /*renderer.color = Color.red; * Invoke("ResetColor", flashTime); * * renderer.color = origionalColor; */ NavMeshAgent nav = World.Instance.mob_o.GetComponent <NavMeshAgent>(); Vector3 npcPos = World.Instance.mob_o.transform.position; Vector3 direction1 = (npcPos - World.Instance.player.transform.position).normalized; direction1 = direction1 * 2 / 2; direction1 = new Vector3(direction1.x, 0f, direction1.z); nav.Move(direction1); if (World.Instance.mob.isCharacterDead()) { DestroyImmediate(World.Instance.mob_o); } return; } if (!World.chunks.TryGetValue(hit.collider.gameObject.name, out hitc)) { return; } Vector3 hitBlock; if (destroyKeys) { hitBlock = hit.point - hit.normal / 2.0f; } else { hitBlock = hit.point + hit.normal / 2.0f; } bool update = false; Block b = World.GetWorldBlock(hitBlock); int x = (int)b.position.x; int y = (int)b.position.y; int z = (int)b.position.z; if (destroyKeys) { playerAnimator.SetTrigger("attacking"); update = hitc.chunkData [x, y, z].HitBlock(hitBlock); } else { //update = b.BuildBlock (new Stone (b.position, b.owner)); update = b.BuildBlock(BlockFactory.Get(World.Instance.character.inventory.getSelectedItem().getBlockType(), b.position, b.owner)); } if (update) { List <string> updates = new List <string> (); float thisChunkx = hitc.chunkData[x, y, z].position.x; float thisChunky = hitc.chunkData[x, y, z].position.y; float thisChunkz = hitc.chunkData[x, y, z].position.z; if (x == 0) { updates.Add(World.BuildChunkName(new Vector3(thisChunkx - World.chunkSize, thisChunky, thisChunkz))); } if (x == World.chunkSize - 1) { updates.Add(World.BuildChunkName(new Vector3(thisChunkx + World.chunkSize, thisChunky, thisChunkz))); } if (y == 0) { updates.Add(World.BuildChunkName(new Vector3(thisChunkx, thisChunky - World.chunkSize, thisChunkz))); } if (y == World.chunkSize - 1) { updates.Add(World.BuildChunkName(new Vector3(thisChunkx, thisChunky + World.chunkSize, thisChunkz))); } if (z == 0) { updates.Add(World.BuildChunkName(new Vector3(thisChunkx, thisChunky, thisChunkz - World.chunkSize))); } if (z == World.chunkSize - 1) { updates.Add(World.BuildChunkName(new Vector3(thisChunkx, thisChunky, thisChunkz + World.chunkSize))); } foreach (string cname in updates) { Chunk c; if (World.chunks.TryGetValue(cname, out c)) { //Debug.Log (x + " " + y + " " + z + " "+ hit.collider.gameObject.name + " "+ hitBlock.ToString() + " "+ hit.collider.gameObject.transform.position.ToString()); //Debug.Log (c.chunkData[x,y,z].bType.ToString()); c.ReDraw(); } } World.Instance.meshSurface.UpdateNavMesh(World.Instance.meshSurface.navMeshData); } } } }