private IEnumerator _WalkRandomLoop() { yield return(new WaitForSeconds(3)); Vector3 pos = Vector3.zero; if (_randomWalkParentItem == null) { Vector3 randomFreePosition = GroundManager.instance.GetRandomFreePosition(); pos = randomFreePosition; } else { int posX = _randomWalkParentItem.GetPositionX(); int posZ = _randomWalkParentItem.GetPositionZ(); int sizeX = (int)_randomWalkParentItem.GetSize().x; int sizeZ = (int)_randomWalkParentItem.GetSize().z; pos.x = Random.Range(posX, posX + sizeX); pos.z = Random.Range(posZ, posZ + sizeZ); } this.Walker.WalkToPosition(pos); this.Walker.OnFinishWalk += this.WalkRandomLoop; }
public void WalkRandom(BaseItemScript parentItem) { if (!this.itemData.configuration.isCharacter) { return; } this._randomWalkParentItem = parentItem; Vector3 pos = Vector3.zero; if (parentItem == null) { Vector3 randomFreePosition = GroundManager.instance.GetRandomFreePosition(); pos = randomFreePosition; } else { int posX = parentItem.GetPositionX(); int posZ = parentItem.GetPositionZ(); int sizeX = (int)parentItem.GetSize().x; int sizeZ = (int)parentItem.GetSize().z; pos.x = Random.Range(posX, posX + sizeX); pos.z = Random.Range(posZ, posZ + sizeZ); } this.Walker.WalkToPosition(pos); this.Walker.OnFinishWalk += this.WalkRandomLoop; }
public void UpdateBaseItemNodes(BaseItemScript item, Action action) { if (item != null) { Vector3 pos = item.GetPosition(); int x = (int)(pos.x); int z = (int)(pos.z); int sizeX = (int)item.GetSize().x; int sizeZ = (int)item.GetSize().z; for (int indexX = x; indexX < x + sizeX; indexX++) { for (int indexZ = z; indexZ < z + sizeZ; indexZ++) { bool isCellWalkable = false; if ((sizeX > 2 && indexX == x) || (sizeX > 2 && indexX == x + sizeX - 1) || (sizeZ > 2 && indexZ == z) || (sizeZ > 2 && indexZ == z + sizeZ - 1)) { //use this for make outer edge walkable for items have size morethan 2x2 isCellWalkable = true; } if (item.itemData.name == "ArmyCamp") { //make every cell walkable in army camp isCellWalkable = true; } if (action == Action.ADD) { //adding scene item to nodes, so walkable is false this.instanceNodes[indexX, indexZ] = item.instanceId; if (item.itemData.name == "Wall") { this.pathNodesWithoutWall[indexX, indexZ] = true; this.pathNodesWithWall[indexX, indexZ] = false; } else { this.pathNodesWithoutWall[indexX, indexZ] = isCellWalkable; } } else if (action == Action.REMOVE) { if (this.instanceNodes[indexX, indexZ] == item.instanceId) { this.instanceNodes[indexX, indexZ] = -1; this.pathNodesWithoutWall[indexX, indexZ] = true; this.pathNodesWithWall[indexX, indexZ] = true; } } } } } }
void Start() { BaseItemScript baseItem = this.GetComponentInParent <BaseItemScript>(); Vector3 baseSize = baseItem.GetSize(); /* resize each elements for same physical size */ this.ArrowRight.localScale = this.ArrowRight.localScale / baseSize.x; this.ArrowLeft.localScale = this.ArrowLeft.localScale / baseSize.x; this.ArrowTop.localScale = this.ArrowTop.localScale / baseSize.x; this.ArrowBottom.localScale = this.ArrowBottom.localScale / baseSize.x; this.ItemInfoContainer.localScale = this.ItemInfoContainer.localScale / baseSize.x; /* update item info details */ this.NameLabel.text = this.NameLabelShadow.text = baseItem.itemData.name; this.LevelLabel.text = this.LevelLabelShadow.text = "Level 1"; this.Grid.transform.localScale = this.Grid.transform.localScale / baseSize.x; this.Grid.size = new Vector2(baseSize.x, baseSize.z); this.ShowGrid(false); }