protected override void PickupObject(SteamVR_Action_Boolean fromaction, SteamVR_Input_Sources fromsource) { if (primaryHand.hoveringInteractable) { Takeable takeable = primaryHand.hoveringInteractable.GetComponent <Takeable>(); if (takeable.preTaskObject) { takeable.takeObject(primaryHand); return; } grabbedObject = takeable; initTorsoPosition = hmd.transform.position - new Vector3(0, 0.25f, 0); initObjDistance = getDistanceFromTorso(grabbedObject.transform.position); initHandDistance = getDistanceFromTorso(primaryHand.transform.position); initHandPosition = primaryHand.transform.position; vectorOffset = grabbedObject.transform.position - (initTorsoPosition + initObjDistance * ((initHandPosition - initTorsoPosition) / initHandDistance)); renderedRay.gameObject.SetActive(false); lastScaledHandPos = primaryHand.transform.position; initHandRot = primaryHand.transform.rotation; initObjRot = grabbedObject.transform.rotation; takeable.takeObject(primaryHand); } else { base.PickupObject(fromaction, fromsource); } }
public bool AddItem(Takeable item) { if (Items.Count >= 10) { return(false); } else { Rigidbody itemRigidbody = item.GetComponent <Rigidbody>(); if (itemRigidbody) { itemRigidbody.isKinematic = true; } Collider itemCollider = item.GetComponent <Collider>(); if (itemCollider) { itemCollider.enabled = false; } MeshRenderer renderer = item.GetComponent <MeshRenderer>(); if (renderer) { renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } item.transform.parent = InventorySpot; item.transform.localPosition = Vector3.zero; item.transform.localRotation = Quaternion.identity; uint index = (uint)Items.Count; Items.Add(item); item.gameObject.SetActive(false); _uiItems[index].gameObject.SetActive(true); SetCurrentItem(index); return(true); } }
private void GrabOrReleaseObject() { // grab object of both grab buttons are pressed if (pickupPressedPrimaryHand && pickupPressedSecondaryHand) { // Record a miss if no object is selected if (selectionSphere.hoveringInteractable == null) { TaskController.Instance.ObjectSelected(null, null, primaryHand); return; } // set grabbed object grabbedObject = selectionSphere.hoveringInteractable.GetComponent <Takeable>(); // disable hover effect primaryHand.HoverLock(null); // set parent of the grabbed object to the selection sphere if it is not a pre task object if (!grabbedObject.preTaskObject) { originalParent = grabbedObject.transform.parent; grabbedObject.transform.SetParent(selectionSphere.transform); } // handle object grabbing (start time measurement etc.) grabbedObject.takeObject(primaryHand); } // release object if currently grabbed else if (grabbedObject != null) { ReleaseObject(); } }
public virtual void OnPointerClick(PointerEventArgs e) { if (PointerClick != null) { PointerClick(this, e); } Debug.Log("Click"); //canvas if (e.target.name == "Button") { SceneManager.LoadScene("MainScene"); } //bomb interaction Takeable takeable = e.target.GetComponent <Takeable>(); if (!isGrab) { Debug.Log(pose.inputSource + " PointerGrab"); PickUp(takeable); isGrab = true; } else { Debug.Log(pose.inputSource + " PointerFire"); Drop(); isGrab = false; } }
public override void ReleaseObject() { if (grabbedObject) { grabbedObject.ReleaseObject(); } renderedRay.gameObject.SetActive(true); grabbedObject = null; }
private void take(Takeable theObject) { inHand = theObject; inHand.transform.parent = gameObject.transform; inHand.transform.localPosition = new Vector2(0.69f, 0f); var type = whichRoom.GetComponent <TypeRoom>().getTypeRoom(); inHand.GetComponent <SpriteRenderer>().sprite = type == Lightness.LIGHT ? inHand.getCarriedLight() : inHand.getCarriedDark(); }
private void Update() { if (!useController && leapServiceProvider.CurrentFrame.Hands.Count > 0) { if (primaryHand.mainRenderModel) { primaryHand.mainRenderModel.gameObject.SetActive(false); } primaryHand.hoverSphereTransform.position = leapServiceProvider.CurrentFrame.Hands[0].PalmPosition.ToVector3(); primaryHand.hoverSphereTransform.rotation = leapServiceProvider.CurrentFrame.Hands[0].Rotation.ToQuaternion(); if (leapServiceProvider.CurrentFrame.Hands[0].GrabStrength > 0.9f) { if (!isGrabbing) { grabbedThisFrame = true; isGrabbing = true; } } else { isGrabbing = false; } if (grabbedThisFrame && grabbedObject == null) { if (primaryHand.hoveringInteractable != null) { Takeable toGrab = primaryHand.hoveringInteractable.GetComponent <Takeable>(); if (toGrab != null) { toGrab.takeObject(primaryHand); if (!TaskController.Instance.IsSelectionTask()) { grabbedObject = toGrab; originalParent = grabbedObject.transform.parent; grabbedObject.transform.SetParent(primaryHand.hoverSphereTransform); } } } else { TaskController.Instance.ObjectSelected(null, null, primaryHand); } } else if (!isGrabbing) { if (grabbedObject != null) { grabbedObject.transform.SetParent(originalParent); grabbedObject.ReleaseObject(); grabbedObject = null; } } } grabbedThisFrame = false; }
public override void ReleaseObject() { if (grabbedObject) { grabbedObject.transform.SetParent(originalParent); grabbedObject.ReleaseObject(); grabbedObject = null; } center.transform.localScale = Vector3.one; }
public override void ReleaseObject() { if (!grabbedObject) { return; } grabbedObject.transform.SetParent(originalParent); grabbedObject.ReleaseObject(); grabbedObject = null; }
public void release() { if (releaseArea) { releaseArea.put(inHand); inHand = null; } else { Debug.LogError("Can't release here"); // TODO Can't release here : play sound? } }
public void put(Takeable takeable) { Debug.Log("Putting takeable " + takeable.name + " in release area"); if (takeable && takeable.getTheType() == typeObjectToGoHere) { takeable.transform.parent = transform; takeable.GetComponent <SpriteRenderer>().sprite = renderedArea; this.takeable = takeable; if (releaseAction) { releaseAction.doOnRelease(); } takeable.transform.localPosition = positionReleasedObject.localPosition; } }
public override void OnInventoryInteract(Takeable other) { if (other == Key) { Debug.Log("Yay! The key worked"); Locked = !Locked; } else { if (Locked) { Debug.Log("I can't unlock the jukebox with this."); } else { Debug.Log("I'm not sure how to use these things together."); } } }
/// <summary> /// Releases the current objects and resets the technique if necessary. /// </summary> public override void ReleaseObject() { grabActive = false; grabDisabled = false; rotationLever.gameObject.SetActive(false); translationLever.gameObject.SetActive(false); barMaterial.SetMainColorAlpha(0.5f); if (currentTakeable != null) { currentTakeable.ReleaseObject(); currentTakeable = null; lastHandPositions = new List <Vector3>(); if (rotationMode) { lastFullGrabTime = 0f; } rotationMode = false; } else { lastFullGrabTime = 0f; } }
public void Drop() { //Null check if (!m_CurrentTakeable) { return; } //m_CurrentTakeable.transform.position = reference.position; //m_CurrentTakeable.transform.rotation = reference.rotation; //fire Rigidbody targetBody = m_CurrentTakeable.gameObject.GetComponent <Rigidbody>(); targetBody.AddRelativeForce(Vector3.forward * m_Force, ForceMode.Impulse); //StartCoroutine(TrackLifetime()); //Detach m_Joint.connectedBody = null; //clear m_CurrentTakeable.m_ActivePointer = null; m_CurrentTakeable = null; }
/// <summary> /// Grabs the targetable object if it is not a pre selection object. /// </summary> private void Grab() { if (TaskController.Instance.currentGameObjects.Count == 0) { return; } if (Time.realtimeSinceStartup - lastFullGrabTime <= rotationModeTimeWindow) { rotationMode = true; rotationLever.gameObject.SetActive(true); } Takeable takeable = TaskController.Instance.currentGameObjects[0].GetComponent <Takeable>(); takeable.takeObject(primaryHand); if (!takeable.preTaskObject && takeable.GetComponent <Interactable>() != null) { currentTakeable = takeable; startGrabObjectPosition = currentTakeable.transform.position; barMaterial.SetMainColorAlpha(1); if (!rotationMode) { translationLever.gameObject.SetActive(true); } } else { // disable grab until the next release so the start task object is // not grabbed directly after the pre selection task object is grabbed grabDisabled = true; } startGrabHandPosition = GetHandPos(); }
public void PickUp(Takeable takeable) { //get obj m_CurrentTakeable = takeable; //null check if (!m_CurrentTakeable) { return; } //already held check if (m_CurrentTakeable.m_ActivePointer) { m_CurrentTakeable.m_ActivePointer.Drop(); } //pleassssssseeeeee // Enemy_ranged script = m_CurrentTakeable.gameObject.GetComponent<Enemy_ranged>(); // StopCoroutine(script.FireObject()); //position m_CurrentTakeable.transform.position = reference.position; m_CurrentTakeable.transform.rotation = reference.rotation; //Attach Rigidbody targetBody = m_CurrentTakeable.GetComponent <Rigidbody>(); targetBody.isKinematic = false; m_Joint.connectedBody = targetBody; takeable.StopMove = true; //set active pointer m_CurrentTakeable.m_ActivePointer = this; }
public virtual void OnInventoryInteract(Takeable other) { }
static DungeonMockData() { int dungeonId = 1; string dungeonDescription = "Dies ist ein vordefiniertes Mock-Dungeon, welches die Benutzung eines Dungeons näher beleuten soll."; string dungeonEpoch = "Mittelalter"; IRace Orks = new RaceSkeleton("Ork", "Orks sind schlimme Wesen.", 50, 20, 10); IRace Elfen = new RaceSkeleton("Elf", "Elfen sind tolle Wesen.", 40, 10, 30); List <IRace> configuredRaces = new List <IRace> { Orks, Elfen }; IClass Berserker = new ClassSkeleton("Berserker", "Bererker sind stake Krieger.", 50, 30, 10); IClass Magier = new ClassSkeleton("Magier", "Magier haben ein langes Durchhaltevermögen.", 60, 10, 40); List <IClass> configuredClasses = new List <IClass> { Berserker, Magier }; IInspectable Baum = new Inspectable("Baum", "Dies ist ein großer Baum"); IInspectable Busch = new Inspectable("Busch", "In dem Busch raschelt es."); Consumable Flasche = new Consumable("Flasche", "Diese Flasche ist voller Alkohol.", "Du freust dich über den Erfolg des Prototyps von Team Apollon!", 1); Takeable Stab = new Takeable("Stab", "Dies ist ein sonderbarer Stab.", 1); List <IInspectable> configuredInspectables = new List <IInspectable> { Baum, Busch, Flasche, Stab }; IRoom Room1 = new RoomSkeleton(0, "Dies ist der erste Raum des Dungeons.") { Inspectables = new List <IInspectable> { Busch, Baum }, DirectionsToNeigbors = new List <Interfaces.Direction.EDirections> { EDirections.NORDEN } }; IRoom Room2 = new RoomSkeleton(1, "Dies ist der zweite Raum des Dungeons.") { Inspectables = new List <IInspectable> { Baum, Flasche }, DirectionsToNeigbors = new List <Interfaces.Direction.EDirections> { EDirections.NORDEN, EDirections.SÜDEN, EDirections.OSTEN, EDirections.WESTEN } }; IRoom Room3 = new RoomSkeleton(2, "Dies ist der dritte Raum des Dungeons.") { Inspectables = new List <IInspectable> { Baum, Stab }, DirectionsToNeigbors = new List <Interfaces.Direction.EDirections> { EDirections.SÜDEN } }; IRoom Room4 = new RoomSkeleton(3, "Dies ist der vierte Raum des Dungeons.") { Inspectables = new List <IInspectable> { Baum, Flasche }, DirectionsToNeigbors = new List <Interfaces.Direction.EDirections> { EDirections.WESTEN } }; IRoom Room5 = new RoomSkeleton(4, "Dies ist der fünfte Raum des Dungeons.") { Inspectables = new List <IInspectable> { Baum, Stab, Flasche }, DirectionsToNeigbors = new List <Interfaces.Direction.EDirections> { EDirections.OSTEN } }; List <IRoom> rooms = new List <IRoom> { Room1, Room2, Room3, Room4, Room5 }; Neighborship Neighborship1 = new Neighborship(0, EDirections.NORDEN, 1); Neighborship Neighborship2 = new Neighborship(1, EDirections.NORDEN, 2); Neighborship Neighborship3 = new Neighborship(1, EDirections.OSTEN, 3); Neighborship Neighborship4 = new Neighborship(1, EDirections.WESTEN, 4); List <INeighborship> neighborships = new List <INeighborship> { Neighborship1, Neighborship2, Neighborship3, Neighborship4 }; int defaultRoomId = 0; Dungeon = new DungeonSkeleton(dungeonEpoch) { DungeonId = dungeonId, DungeonDescription = dungeonDescription, ConfiguredRaces = configuredRaces, ConfiguredClasses = configuredClasses, ConfiguredInspectables = configuredInspectables, Neighborships = neighborships, Rooms = rooms, DefaultRoomId = defaultRoomId }; }
public IEnumerator FireObject() { canAttack = false; // Create delay btw firing yield return(new WaitForSeconds(1.0f)); //we don't want it to be next frame canAttack = true; // Create BuckyBall GameObject myProjectile; myProjectile = Instantiate(projectile, transform.position, Quaternion.identity); RangedMonsterBombManager ranged = myProjectile.GetComponent <RangedMonsterBombManager>(); ranged.mother = this.gameObject; //Debug.Log("Ball made"); //Move Projectile to the position of Monster + add some offset myProjectile.transform.position = rangedMonsterTransform.position + new Vector3(-0.1f, 0.5f, -0.5f); //Calculate distance btw target and the ball float targetDistance = Vector3.Distance(myProjectile.transform.position, targetEntity.transform.position); // Calculate the velocity needed to throw the object to the target at specified angle // sin2a = gd/(v*v) // angle of reach is the angle a at which a projectile must be launced // in order to go a distance d, given the initial velocity v. float projectileVelocity = Mathf.Sqrt(targetDistance / (Mathf.Sin(2 * launchAngle * Mathf.Deg2Rad) / gravity)); //Extract the x and y component of the velocity float vX = projectileVelocity * Mathf.Cos(launchAngle * Mathf.Deg2Rad); float vY = projectileVelocity * Mathf.Sin(launchAngle * Mathf.Deg2Rad); // Calculate flight Duration(time) float flightDuration = targetDistance / vX; // Rotate projectile to face the target. // Assign the direction the projectile will look // LookRotation first argument is forward(the direction to look in) myProjectile.transform.rotation = Quaternion.LookRotation(targetEntity.transform.position - myProjectile.transform.position); Takeable takeable = myProjectile.GetComponent <Takeable>(); float elapseTime = 0; while (elapseTime < flightDuration && !takeable.StopMove) { //Debug.Log("Flying ball"); // while flying // the components of the velocity of the objects // horizontal component remains unchanged v*cosa // vertical component changes linearly, because the acceleration due to the gravity is constant. // it will be v*sina - gt myProjectile.transform.Translate(0, (vY - (gravity * elapseTime)) * Time.deltaTime, vX * Time.deltaTime); elapseTime += Time.deltaTime; //wait until next frame... which means no wait! yield return(null); } //yield return new WaitForSeconds(1.0f); //we don't want it to be next frame }
public override void OnInventoryInteract(Takeable other) { InventoryManager.Instance.AddItem(this); }