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.GetPositionY(); int sizeX = (int)parentItem.GetSize().x; int sizeY = (int)parentItem.GetSize().y; pos.x = Random.Range(posX, posX + sizeX); pos.y = Random.Range(posZ, posZ + sizeY); } this.Walker.WalkToPosition(pos); this.Walker.OnFinishWalk += this.WalkRandomLoop; }
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.GetPositionY(); int sizeX = (int)_randomWalkParentItem.GetSize().x; int sizeY = (int)_randomWalkParentItem.GetSize().y; pos.x = Random.Range(posX, posX + sizeX); pos.y = Random.Range(posZ, posZ + sizeY); } this.Walker.WalkToPosition(pos); this.Walker.OnFinishWalk += this.WalkRandomLoop; }
public void UpdateItemData(BaseItemScript item) { this._gameData.sceneData.AddOrUpdateItem(item.instanceId, item.itemData.id, item.GetPositionX(), item.GetPositionY()); this.SaveDataBase(); }