public static void SetItemsParent(Container cn, Transform Parent) { for (short i = 0; i <= cn.MaxCapacity(); i++) { string ItemName = cn.GetItemAt(i); if (ItemName != "") { GameObject item = cn.GetGameObjectAt(i); //GameObject.Find (cn.GetItemAt(i)); if (item != null) { item.transform.parent = Parent; if (Parent == GameWorldController.instance.LevelMarker()) { GameWorldController.MoveToWorld(item); } else { GameWorldController.MoveToInventory(item); } if (item.GetComponent <Container>() != null) { Container.SetItemsParent(item.GetComponent <Container>(), Parent); } } } } }
public virtual ObjectInteraction Pickup(ObjectInteraction objPicked, PlayerInventory pInv) { //completes the pickup. //FIELD PICKUP objPicked.PickedUp=true; if (objPicked.GetComponent <Container>() != null) { Container.SetPickedUpFlag(objPicked.GetComponent <Container>(), true); Container.SetItemsParent(objPicked.GetComponent <Container>(), GameWorldController.instance.InventoryMarker.transform); Container.SetItemsPosition(objPicked.GetComponent <Container>(), GameWorldController.instance.InventoryMarker.transform.position); } //UWHUD.instance.CursorIcon=objPicked.GetInventoryDisplay().texture; pInv.ObjectInHand = objPicked; if (objPicked.GetComponent <Rigidbody>() != null) { FreezeMovement(objPicked.gameObject); } objPicked.transform.position = GameWorldController.instance.InventoryMarker.transform.position; objPicked.transform.parent = GameWorldController.instance.InventoryMarker.transform; GameWorldController.MoveToInventory(objPicked); pInv.ObjectInHand = objPicked; objPicked.Pickup(); if (WindowDetectUW.ContextUIEnabled) { if (MouseLookEnabled) { WindowDetectUW.SwitchFromMouseLook(); } } return(objPicked); }
public static void SetItemsParent(Container cn, Transform Parent) { for (int i = 0; i < cn.MaxCapacity(); i++) { string ItemName = cn.GetItemAt(i); if (ItemName != "") { GameObject item = GameObject.Find(cn.GetItemAt(i)); if (item != null) { item.transform.parent = Parent; if (item.GetComponent <Container>() != null) { Container.SetItemsParent(item.GetComponent <Container>(), Parent); } } } } }
public virtual void Pickup(ObjectInteraction objPicked, PlayerInventory pInv) { //completes the pickup. objPicked.PickedUp = true; if (objPicked.GetComponent <Container>() != null) { Container.SetPickedUpFlag(objPicked.GetComponent <Container>(), true); Container.SetItemsParent(objPicked.GetComponent <Container>(), InvMarker.transform); Container.SetItemsPosition(objPicked.GetComponent <Container>(), InvMarker.transform.position); } CursorIcon = objPicked.GetInventoryDisplay().texture; pInv.ObjectInHand = objPicked.transform.name; //////pInv.JustPickedup=true;//To stop me throwing it away immediately. if (objPicked.GetComponent <Rigidbody>() != null) { WindowDetect.FreezeMovement(objPicked.gameObject); } objPicked.transform.position = InvMarker.transform.position; objPicked.transform.parent = InvMarker.transform; objPicked.Pickup(); //Call pickup event for this object. }
public virtual ObjectInteraction Pickup(ObjectInteraction objPicked, PlayerInventory pInv) { //completes the pickup. objPicked.PickedUp = true; if (objPicked.GetComponent <Container>() != null) { Container.SetPickedUpFlag(objPicked.GetComponent <Container>(), true); Container.SetItemsParent(objPicked.GetComponent <Container>(), GameWorldController.instance.InventoryMarker.transform); Container.SetItemsPosition(objPicked.GetComponent <Container>(), GameWorldController.instance.InventoryMarker.transform.position); } UWHUD.instance.CursorIcon = objPicked.GetInventoryDisplay().texture; pInv.ObjectInHand = objPicked.transform.name; if (objPicked.GetComponent <Rigidbody>() != null) { GameWorldController.FreezeMovement(objPicked.gameObject); } objPicked.transform.position = GameWorldController.instance.InventoryMarker.transform.position; objPicked.transform.parent = GameWorldController.instance.InventoryMarker.transform; GameWorldController.MoveToInventory(objPicked); pInv.ObjectInHand = objPicked.transform.name; objPicked.Pickup(); return(objPicked); }
/// <summary> /// Throws the object in hand along a vector in the 3d view. /// </summary> protected override void ThrowObjectInHand() { base.ThrowObjectInHand(); if (UWCharacter.Instance.playerInventory.GetObjectInHand() != "") { //The player is holding something if (UWCharacter.Instance.playerInventory.JustPickedup == false) //To prevent the click event dropping an object immediately after pickup { //Determine what is directly in front of the player via a raycast //If something is in the way then cancel the drop //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Ray ray; if (UWCharacter.Instance.MouseLookEnabled == true) { ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)); } else { ray = Camera.main.ScreenPointToRay(Input.mousePosition); } RaycastHit hit = new RaycastHit(); float dropRange = 0.5f; if (!Physics.Raycast(ray, out hit, dropRange)) { //No object interferes with the drop //Calculate the force based on how high the mouse is float force = Input.mousePosition.y / Camera.main.pixelHeight * 200; //float force = Camera.main.ViewportToWorldPoint(Input.mousePosition).y/Camera.main.pixelHeight *200; //Get the object being dropped and moved towards the end of the ray GameObject droppedItem = UWCharacter.Instance.playerInventory.GetGameObjectInHand(); //GameObject.Find(UWCharacter.Instance.playerInventory.ObjectInHand); droppedItem.GetComponent <ObjectInteraction>().PickedUp = false; //Back in the real world droppedItem.GetComponent <ObjectInteraction>().Drop(); droppedItem.GetComponent <ObjectInteraction>().UpdateAnimation(); GameWorldController.MoveToWorld(droppedItem); droppedItem.transform.parent = GameWorldController.instance.DynamicObjectMarker(); if (droppedItem.GetComponent <Container>() != null) { //Set the picked up flag recursively for container items. Container.SetPickedUpFlag(droppedItem.GetComponent <Container>(), false); Container.SetItemsParent(droppedItem.GetComponent <Container>(), GameWorldController.instance.DynamicObjectMarker()); Container.SetItemsPosition(droppedItem.GetComponent <Container>(), UWCharacter.Instance.playerInventory.InventoryMarker.transform.position); } droppedItem.transform.position = ray.GetPoint(dropRange - 0.1f); //UWCharacter.Instance.transform.position; GameWorldController.UnFreezeMovement(droppedItem); if (Camera.main.ScreenToViewportPoint(Input.mousePosition).y > 0.4f) { //throw if above a certain point in the view port. Vector3 ThrowDir = ray.GetPoint(dropRange) - ray.origin; //Apply the force along the direction. if (droppedItem.GetComponent <Rigidbody>() != null) { droppedItem.GetComponent <Rigidbody>().AddForce(ThrowDir * force); } } //Clear the object and reset the cursor UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault; UWCharacter.Instance.playerInventory.SetObjectInHand(""); } } else { UWCharacter.Instance.playerInventory.JustPickedup = false; //The next click event will allow dropping. } } }