/*static public bool xAddObjectToContainer(GameObject objInHand, GameObject objUseOn) * { * Container subContainer = objUseOn.GetComponent<Container>(); * if (subContainer.AddItemToContainer(objInHand.name)) * { * Container ObjInHandContainer=objInHand.GetComponent<Container>(); * if (ObjInHandContainer!=null) * { * subContainer=objInHand.GetComponent<Container>(); * subContainer.ContainerParent=objUseOn.name; * } * return true; * } * else * { * return false; * } * }*/ public void OpenContainer() { playerUW.playerInventory.ContainerOffset = 0; ScrollButtonStatsDisplay.ScrollValue = 0; ObjectInteraction currObjInt = this.gameObject.GetComponent <ObjectInteraction>(); if (currObjInt.PickedUp == false) { //The requested container is open in the game world. This can cause problems! //Debug.Log ("Opening a container in the real world"); SpillContents(); return; } //Sort the container Container.SortContainer(this); GameObject.Find("ContainerOpened").GetComponent <UITexture>().mainTexture = currObjInt.GetEquipDisplay().texture; if (this.isOpenOnPanel == false) { this.isOpenOnPanel = true; ContainerParent = playerUW.playerInventory.currentContainer; } playerUW.playerInventory.currentContainer = this.name; if (playerUW.playerInventory.currentContainer == "") { playerUW.playerInventory.currentContainer = playerUW.name; this.ContainerParent = playerUW.name; } for (int i = 0; i < 8; i++) { string sItem = this.GetItemAt(i); playerUW.playerInventory.SetObjectAtSlot(i + 11, sItem); } }
public void SpillContentsX() { //Removes the contents of a container out in the real world. int counter; TileMap tm = GameWorldController.instance.currentTileMap(); //GameObject.Find("Tilemap").GetComponent<TileMap>(); GameWorldController.FreezeMovement(this.gameObject); ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>(); objInt.SetWorldDisplay(objInt.GetEquipDisplay()); for (short i = 0; i <= MaxCapacity(); i++) { GameObject Spilled = GetGameObjectAt(i); //GameObject.Find (GetItemAt (i)); if (Spilled != null) { if (Spilled.GetComponent <trigger_base>() != null) { Spilled.GetComponent <trigger_base>().Activate(this.gameObject); } bool flag = false; Vector3 randomPoint = this.transform.position; counter = 0; while ((flag == false) && (counter < 25)) { randomPoint = this.transform.position + Random.insideUnitSphere; if (randomPoint.y < this.transform.position.y) { randomPoint.y = this.transform.position.y + 0.1f; } flag = ((!Physics.CheckSphere(randomPoint, 0.5f)) && (tm.ValidTile(randomPoint))); counter++; } if (flag == true) { //No object interferes with the spill RemoveItemFromContainer(i); Spilled.transform.position = randomPoint; Spilled.GetComponent <ObjectInteraction>().PickedUp = false; GameWorldController.UnFreezeMovement(Spilled); } else { //No where to put the item. Put it at the containers position. RemoveItemFromContainer(i); Spilled.transform.position = this.transform.position; Spilled.GetComponent <ObjectInteraction>().PickedUp = false; GameWorldController.UnFreezeMovement(Spilled); } } } GameWorldController.UnFreezeMovement(this.gameObject); }
void DisplayGameObject(ObjectInteraction obj, RawImage Label, Text qtyDisplay, bool isEquipped, ref bool hasChanged) { if (hasChanged == true) { if (obj == null) { Label.texture = Blank; if (qtyDisplay != null) { qtyDisplay.text = ""; } hasChanged = false; return; } hasChanged = false; if (obj != null) { if (isEquipped == true) { Label.texture = obj.GetEquipDisplay().texture; } else { Label.texture = obj.GetInventoryDisplay().texture; if (qtyDisplay != null) { int qty = obj.GetQty(); if (qty <= 1) { qtyDisplay.text = ""; } else { qtyDisplay.text = qty.ToString(); } } } } else { Label.texture = Blank; if (qtyDisplay != null) { qtyDisplay.text = ""; } } } }
public void SpillContents() { TileMap tm = GameWorldController.instance.currentTileMap(); //GameObject.Find("Tilemap").GetComponent<TileMap>(); GameWorldController.FreezeMovement(this.gameObject); ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>(); objInt.UpdatePosition(); objInt.SetWorldDisplay(objInt.GetEquipDisplay()); for (short i = 0; i <= MaxCapacity(); i++) { GameObject Spilled = GetGameObjectAt(i); //GameObject.Find (GetItemAt (i)); if (Spilled != null) { if (Spilled.GetComponent <trigger_base>() != null) { Spilled.GetComponent <trigger_base>().Activate(this.gameObject); } else { ObjectInteraction objSpilled = Spilled.GetComponent <ObjectInteraction>(); Spilled.transform.position = this.transform.position; objSpilled.UpdatePosition(); switch (tm.Tiles[objInt.tileX, objInt.tileY].tileType) { case TileMap.TILE_OPEN: case TileMap.TILE_SLOPE_N: case TileMap.TILE_SLOPE_S: case TileMap.TILE_SLOPE_E: case TileMap.TILE_SLOPE_W: objSpilled.x = (short)Random.Range(1, 7); objSpilled.y = (short)Random.Range(1, 7); break; case TileMap.TILE_DIAG_SE: objSpilled.x = (short)Random.Range(1, 7); objSpilled.y = (short)Random.Range(0, objSpilled.x); break; case TileMap.TILE_DIAG_SW: objSpilled.x = (short)Random.Range(1, 7); objSpilled.y = (short)Random.Range(1, 7 - objSpilled.x); break; case TileMap.TILE_DIAG_NE: objSpilled.x = (short)Random.Range(1, 7); objSpilled.y = (short)Random.Range(8 - objSpilled.x, 8); break; case TileMap.TILE_DIAG_NW: objSpilled.x = (short)Random.Range(1, 7); objSpilled.y = (short)Random.Range(objSpilled.x, 8); break; } objSpilled.zpos = (short)(tm.Tiles[objInt.tileX, objInt.tileY].floorHeight * 4); objSpilled.objectloaderinfo.x = objSpilled.x; objSpilled.objectloaderinfo.y = objSpilled.y; objSpilled.objectloaderinfo.zpos = objSpilled.zpos; objSpilled.transform.position = ObjectLoader.CalcObjectXYZ(_RES, tm, tm.Tiles, GameWorldController.instance.CurrentObjectList().objInfo, objSpilled.objectloaderinfo.index, this.objInt().objectloaderinfo.tileX, this.objInt().objectloaderinfo.tileY, 0); RemoveItemFromContainer(i); Spilled.GetComponent <ObjectInteraction>().PickedUp = false; GameWorldController.UnFreezeMovement(Spilled); } } } }
public void SpillContents() { TileMap tm = CurrentTileMap(); //GameObject.Find("Tilemap").GetComponent<TileMap>(); FreezeMovement(this.gameObject); ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>(); objInt.UpdatePosition(); objInt.SetWorldDisplay(objInt.GetEquipDisplay()); objInt.link = 0; //So items in world will not create infinitly lopping references for (short i = 0; i <= MaxCapacity(); i++) { ObjectInteraction objSpilled = GetItemAt(i); if (objSpilled != null) { if (objSpilled.GetComponent <trigger_base>() != null) { objSpilled.GetComponent <trigger_base>().Activate(this.gameObject); } else { //ObjectInteraction objSpilled = Spilled.GetComponent<ObjectInteraction>(); objSpilled.transform.position = this.transform.position; objSpilled.UpdatePosition(); switch (tm.Tiles[objInt.ObjectTileX, objInt.ObjectTileY].tileType) { case TileMap.TILE_OPEN: case TileMap.TILE_SLOPE_N: case TileMap.TILE_SLOPE_S: case TileMap.TILE_SLOPE_E: case TileMap.TILE_SLOPE_W: objSpilled.xpos = (short)Random.Range(1, 7); objSpilled.ypos = (short)Random.Range(1, 7); break; case TileMap.TILE_DIAG_SE: objSpilled.xpos = (short)Random.Range(1, 7); objSpilled.ypos = (short)Random.Range(0, objSpilled.xpos); break; case TileMap.TILE_DIAG_SW: objSpilled.xpos = (short)Random.Range(1, 7); objSpilled.ypos = (short)Random.Range(1, 7 - objSpilled.xpos); break; case TileMap.TILE_DIAG_NE: objSpilled.xpos = (short)Random.Range(1, 7); objSpilled.ypos = (short)Random.Range(8 - objSpilled.xpos, 8); break; case TileMap.TILE_DIAG_NW: objSpilled.xpos = (short)Random.Range(1, 7); objSpilled.ypos = (short)Random.Range(objSpilled.xpos, 8); break; } objSpilled.zpos = (short)(tm.Tiles[objInt.ObjectTileX, objInt.ObjectTileY].floorHeight * 4); objSpilled.objectloaderinfo.xpos = objSpilled.xpos; objSpilled.objectloaderinfo.ypos = objSpilled.ypos; objSpilled.objectloaderinfo.zpos = objSpilled.zpos; objSpilled.transform.position = ObjectLoader.CalcObjectXYZ(objSpilled.objectloaderinfo.index, 0); RemoveItemFromContainer(i); //FIELD PICKUP Spilled.GetComponent<ObjectInteraction>().PickedUp=false; UnFreezeMovement(objSpilled); } } } }