IEnumerator AddItemCo(ObtainableItem item, Vector3 point) { //Debug.Log(item+" has been added to the cauldron."); item.transform.parent = transform; var itemRigidbody = item.GetComponent <Rigidbody>(); itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; LeanTween.cancel(item.gameObject); LeanTween.move(item.gameObject, point + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); LeanTween.rotate(item.gameObject, surface.transform.rotation.eulerAngles, 1f).setEase(LeanTweenType.easeInCubic); yield return(new WaitForSeconds(1f)); itemRigidbody.useGravity = true; itemRigidbody.isKinematic = false; yield return(new WaitForSeconds(2f)); items.Add(item); item.isAbleToInteract = true; //itemRigidbody.useGravity = false; //itemRigidbody.isKinematic = true; }
IEnumerator RemoveItemCo(ObtainableItem item) { items.Remove(item); surface.isAbleToInteract = false; var targetPosition = item.transform.position + Vector3.up * 1f; var itemRigidbody = item.GetComponent <Rigidbody>(); itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; LeanTween.cancel(item.gameObject); LeanTween.move(item.gameObject, targetPosition, 1f).setEase(LeanTweenType.easeOutCubic); yield return(new WaitForSeconds(1f)); item.isAbleToInteract = true; item = null; yield return(new WaitForSeconds(1.5f)); // Activate the surface with delay after removing an item, // so the item wont get back to inventory if Player continues to point at the spot after getting the item in hand. surface.isAbleToInteract = true; }
IEnumerator AddItemCo(ObtainableItem item, Vector3 point) { //Debug.Log(item+" has been added to the cauldron."); item.transform.parent = transform; var itemRigidbody = item.GetComponent<Rigidbody>(); itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; LeanTween.cancel(item.gameObject); LeanTween.move(item.gameObject, point + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); LeanTween.rotate(item.gameObject, surface.transform.rotation.eulerAngles, 1f).setEase(LeanTweenType.easeInCubic); yield return new WaitForSeconds(1f); itemRigidbody.useGravity = true; itemRigidbody.isKinematic = false; yield return new WaitForSeconds(2f); items.Add(item); item.isAbleToInteract = true; //itemRigidbody.useGravity = false; //itemRigidbody.isKinematic = true; }
public void Play(ObtainableItem item) { CloseFlap(); item.transform.position = cassettePoint.position; item.transform.parent = transform; item.GetComponent<Rigidbody>().isKinematic = true; item.GetComponent<Rigidbody>().detectCollisions = false; var cassette = item.GetComponent<Cassette>(); if (cassette == null) return; speakers.clip = cassette.audioClip; Invoke("Play", 1.5f); }
IEnumerator RejectItemCo(ObtainableItem item) { Debug.Log(item + " has been rejected by the cauldron."); var itemRigidbody = item.GetComponent <Rigidbody>(); if (itemRigidbody != null) { itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; } LeanTween.move(item.gameObject, transform.position + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); yield return(new WaitForSeconds(1f)); var targetPosition = pointOnSurface.position; LeanTween.move(item.gameObject, targetPosition, 0.5f); yield return(new WaitForSeconds(0.5f)); if (GetComponent <PlaysAudioRemarkOnRadio>()) { var maxIndex = GetComponent <PlaysAudioRemarkOnRadio>().remarks.Count; GetComponent <PlaysAudioRemarkOnRadio>().Play(Random.Range(2, maxIndex)); } audioPlayer.PlayOneShot(1); foreach (GameObject subscriber in subscribers) { subscriber.SendMessage("OnRejectFromCauldron", item, SendMessageOptions.DontRequireReceiver); } LeanTween.move(item.gameObject, transform.position + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); yield return(new WaitForSeconds(1f)); LeanTween.move(item.gameObject, pointForRejected.position, 1f).setEase(LeanTweenType.easeOutCubic); yield return(new WaitForSeconds(1f)); if (itemRigidbody != null) { itemRigidbody.useGravity = true; itemRigidbody.isKinematic = false; } item.isAbleToInteract = true; yield return(new WaitForSeconds(1.5f)); itemRigidbody.isKinematic = true; }
public void Play(ObtainableItem item) { CloseFlap(); item.transform.position = cassettePoint.position; item.transform.parent = transform; item.GetComponent <Rigidbody>().isKinematic = true; item.GetComponent <Rigidbody>().detectCollisions = false; var cassette = item.GetComponent <Cassette>(); if (cassette == null) { return; } speakers.clip = cassette.audioClip; Invoke("Play", 1.5f); }
void DropItem(SteamVR_Controller.Device device) { if (itemInHand != null) { itemInHand.Dispatch(ObtainableItemEventType.OnDropOff, this); itemInHand.owner = null; itemInHand.GetComponent <Rigidbody>().velocity = device.velocity * 1.4f; itemInHand = null; } }
public override void PerformSegue(ObtainableItem item) { base.PerformSegue(item); item.GetComponent <Rigidbody>().isKinematic = true; item.GetComponent <Rigidbody>().detectCollisions = false; radio.OpenFlap(); item.transform.parent = radio.transform; var cassettePoint = radio.cassettePoint; var cassetterUpPosition = cassettePoint.transform.localPosition + (cassettePoint.up + -cassettePoint.forward) * 0.2f; LeanTween.rotateLocal(item.gameObject, cassettePoint.localRotation.eulerAngles, 1f).setEase(LeanTweenType.easeInSine); LeanTween.moveLocal(item.gameObject, cassetterUpPosition, 1f).setOnComplete(delegate() { LeanTween.moveLocal(item.gameObject, cassettePoint.localPosition, 1f).setOnComplete(delegate() { radio.Play(item); }).setEase(LeanTweenType.easeInSine); }).setEase(LeanTweenType.easeInSine); //radio.Play(item); }
public override void PerformSegue(ObtainableItem item) { base.PerformSegue (item); item.GetComponent<Rigidbody>().isKinematic = true; item.GetComponent<Rigidbody>().detectCollisions = false; radio.OpenFlap(); item.transform.parent = radio.transform; var cassettePoint = radio.cassettePoint; var cassetterUpPosition = cassettePoint.transform.localPosition + (cassettePoint.up + -cassettePoint.forward) * 0.2f; LeanTween.rotateLocal(item.gameObject, cassettePoint.localRotation.eulerAngles, 1f).setEase(LeanTweenType.easeInSine); LeanTween.moveLocal(item.gameObject, cassetterUpPosition, 1f).setOnComplete(delegate() { LeanTween.moveLocal(item.gameObject, cassettePoint.localPosition, 1f).setOnComplete(delegate() { radio.Play(item); }).setEase(LeanTweenType.easeInSine); }).setEase(LeanTweenType.easeInSine); //radio.Play(item); }
IEnumerator AddItemCo(ObtainableItem item, RecipeItem recipeItem) { Debug.Log(item + " has been added to the cauldron."); ingredientsUsed += 1; recipeItem.collected += 1; var itemRigidbody = item.GetComponent <Rigidbody>(); if (itemRigidbody != null) { itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; } LeanTween.move(item.gameObject, transform.position + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); yield return(new WaitForSeconds(1f)); var targetPosition = pointInside.position; LeanTween.move(item.gameObject, targetPosition, 0.5f); audioPlayer.PlayOneShotAfterSec(0, 0.25f); if (ingredientsUsed == 1 && GetComponent <PlaysAudioRemarkOnRadio>() != null && !potionIsReady) { GetComponent <PlaysAudioRemarkOnRadio>().Play(0); } yield return(new WaitForSeconds(0.5f)); foreach (GameObject subscriber in subscribers) { subscriber.SendMessage("OnAddToCauldron", recipeItem, SendMessageOptions.DontRequireReceiver); } item.gameObject.SetActive(false); isAbleToInteract = true; if (potionIsReady) { GivePotion(); } }
IEnumerator AddItemCo(ObtainableItem item, RecipeItem recipeItem) { Debug.Log(item+" has been added to the cauldron."); ingredientsUsed += 1; recipeItem.collected += 1; var itemRigidbody = item.GetComponent<Rigidbody>(); if (itemRigidbody != null) { itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; } LeanTween.move(item.gameObject, transform.position + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); yield return new WaitForSeconds(1f); var targetPosition = pointInside.position; LeanTween.move(item.gameObject, targetPosition, 0.5f); audioPlayer.PlayOneShotAfterSec(0, 0.25f); if (ingredientsUsed == 1 && GetComponent<PlaysAudioRemarkOnRadio>() != null && !potionIsReady) GetComponent<PlaysAudioRemarkOnRadio>().Play(0); yield return new WaitForSeconds(0.5f); foreach (GameObject subscriber in subscribers) { subscriber.SendMessage("OnAddToCauldron", recipeItem, SendMessageOptions.DontRequireReceiver); } item.gameObject.SetActive(false); isAbleToInteract = true; if (potionIsReady) GivePotion(); }
IEnumerator RejectItemCo(ObtainableItem item) { Debug.Log(item+" has been rejected by the cauldron."); var itemRigidbody = item.GetComponent<Rigidbody>(); if (itemRigidbody != null) { itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; } LeanTween.move(item.gameObject, transform.position + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); yield return new WaitForSeconds(1f); var targetPosition = pointOnSurface.position; LeanTween.move(item.gameObject, targetPosition, 0.5f); yield return new WaitForSeconds(0.5f); if (GetComponent<PlaysAudioRemarkOnRadio>()) { var maxIndex = GetComponent<PlaysAudioRemarkOnRadio>().remarks.Count; GetComponent<PlaysAudioRemarkOnRadio>().Play(Random.Range(2, maxIndex)); } audioPlayer.PlayOneShot(1); foreach (GameObject subscriber in subscribers) { subscriber.SendMessage("OnRejectFromCauldron", item, SendMessageOptions.DontRequireReceiver); } LeanTween.move(item.gameObject, transform.position + Vector3.up * 1f, 1f).setEase(LeanTweenType.easeOutCubic); yield return new WaitForSeconds(1f); LeanTween.move(item.gameObject, pointForRejected.position, 1f).setEase(LeanTweenType.easeOutCubic); yield return new WaitForSeconds(1f); if (itemRigidbody != null) { itemRigidbody.useGravity = true; itemRigidbody.isKinematic = false; } item.isAbleToInteract = true; yield return new WaitForSeconds(1.5f); itemRigidbody.isKinematic = true; }
IEnumerator RemoveItemCo(ObtainableItem item) { items.Remove(item); surface.isAbleToInteract = false; var targetPosition = item.transform.position + Vector3.up * 1f; var itemRigidbody = item.GetComponent<Rigidbody>(); itemRigidbody.useGravity = false; itemRigidbody.isKinematic = true; LeanTween.cancel(item.gameObject); LeanTween.move(item.gameObject, targetPosition, 1f).setEase(LeanTweenType.easeOutCubic); yield return new WaitForSeconds(1f); item.isAbleToInteract = true; item = null; yield return new WaitForSeconds(1.5f); // Activate the surface with delay after removing an item, // so the item wont get back to inventory if Player continues to point at the spot after getting the item in hand. surface.isAbleToInteract = true; }
void UpdateItemInHand() { if (itemInHand == null || !itemInHand.isAbleToInteract) { return; } var target = sight.target; var targetPosition = Vector3.zero; var targetRotation = itemInHand.transform.rotation; var targetEulerAngle = Vector3.zero; var itemRigidobdy = itemInHand.GetComponent <Rigidbody>(); var highestPointOnTarget = Vector3.zero; var distanceToItem = Vector3.Distance(itemInHand.transform.position, sight.anchor.position); if (itemRigidobdy != null) { highestPointOnTarget = itemRigidobdy.ClosestPointOnBounds(itemInHand.transform.position + Vector3.up * 10); //Debug.DrawLine(highestPointOnTarget, highestPointOnTarget + Vector3.up, Color.red, Time.deltaTime); } var positionChangeRate = 1.5f; var rotationChangeRate = 1.5f; if (distanceToItem < 2f) { positionChangeRate = 3f; //rotationChangeRate = 3f; } if (isLookingBelow) { // Hover the object in a fixed point. targetPosition = waistAnchor.transform.position; if (itemRigidobdy != null) { // Hover objects of a different height on the same level when looking down. targetPosition = waistAnchor.transform.position - (highestPointOnTarget - itemInHand.transform.position); } if (distanceToItem < 2f) { if (itemInHand.customOnGrabRotation != Vector3.zero) { targetRotation = Quaternion.Euler(itemInHand.customOnGrabRotation); } else { targetRotation = Quaternion.identity; } } } else { // Hover the object in front, following a visitor's head. var distanceToFloatingObject = itemInHand.hasItsOwnOnGrabDistance ? itemInHand.onGrabDistance : defaultDistanceToFloatingObject; var centerOfFocusPoint = sight.anchor.position + sight.facingVector * distanceToFloatingObject; // Finding a perpendicular vector to a facing vector (http://docs.unity3d.com/Manual/ComputingNormalPerpendicularVector.html) var orthoToFacingVector = Vector3.Cross(sight.facingVector, -sight.anchor.right); var distanceBelowFocusPoint = 0.1f; var belowFocusPoint = centerOfFocusPoint + orthoToFacingVector * distanceBelowFocusPoint; targetPosition = belowFocusPoint; if (itemRigidobdy != null) { // Align object so its highest point is matching the belowFocusPoint. // It makes the same distance between the reticle and a highest point on target for objects of any size. targetPosition = belowFocusPoint - (highestPointOnTarget - itemInHand.transform.position); } if (distanceToItem < 2f) { if (itemInHand.customOnGrabRotation != Vector3.zero) { targetRotation = Quaternion.Euler(itemInHand.customOnGrabRotation) * Quaternion.LookRotation(sight.anchor.forward); } else { targetRotation = Quaternion.LookRotation(sight.anchor.forward); } } } itemInHand.transform.position = Vector3.Lerp(itemInHand.transform.position, targetPosition, Time.deltaTime * positionChangeRate); itemInHand.transform.rotation = Quaternion.Lerp(itemInHand.transform.rotation, targetRotation, Time.deltaTime * rotationChangeRate); }