private void Initialize() { grabbable = GetComponent <VR_Grabbable>(); audioSource = GetComponent <AudioSource>(); hapticsController = GetComponent <VR_Haptics>(); twoHandGrabbable = transform.GetComponentInChildren <VR_TwoHandGrabbable>(); if (twoHandGrabbable != null) { twoHandGrabbable.SetApplyTwoHandTransformManually(true); } if (reloadMode == ReloadMode.Realistic) { if (magazineDropZone != null && magazineDropZone.StartingDrop != null) { CurrentMagazine = magazineDropZone.StartingDrop.GetComponent <VR_WeaponMag>(); if (CurrentMagazine != null) { CurrentMagazine.SetOwner(this); //say to the grabbable that ignore disabling and enabling the mag collider grabbable.IgnoreCollider(CurrentMagazine.GetComponent <Collider>()); } } magazineDropZone.OnDrop.AddListener(OnMagazineDropStateChange); magazineDropZone.OnUnDrop.AddListener(OnMagazineUnDropStateChange); } }
private void Awake() { grabbable = GetComponent <VR_Grabbable>(); thisDamageableList = transform.GetComponentsInChildren <Damageable>().ToList(); rayLength = Vector3.Distance(weaponStartRayMarker.position, weaponEndRayMarker.position); }
private void OnEnable() { onGrabStateChange = serializedObject.FindProperty("onGrabStateChange"); perfectGrab = serializedObject.FindProperty("perfectGrab"); grabDistance = serializedObject.FindProperty("interactDistance"); grabFlyTime = serializedObject.FindProperty("grabFlyTime"); shouldFly = serializedObject.FindProperty("shouldFly"); startOnRightcController = serializedObject.FindProperty("startOnRightcController"); startOnLeftController = serializedObject.FindProperty("startOnLeftController"); autoGrab = serializedObject.FindProperty("autoGrab"); grabButton = serializedObject.FindProperty("interactButton"); grabLayer = serializedObject.FindProperty("grabLayer"); unGrabLayer = serializedObject.FindProperty("unGrabLayer"); enableCollidersOnGrab = serializedObject.FindProperty("enableColliderOnGrab"); jointBreakForce = serializedObject.FindProperty("jointBreakForce"); jointBreakTorque = serializedObject.FindProperty("jointBreakTorque"); usePerHandSettings = serializedObject.FindProperty("usePerHandSettings"); rightHandSettings = serializedObject.FindProperty("rightHandSettings"); leftHandSettings = serializedObject.FindProperty("leftHandSettings"); handSettings = serializedObject.FindProperty("handSettings"); setJointSettings = serializedObject.FindProperty("setJointSettings"); preserveKinematicState = serializedObject.FindProperty("preserveKinematicState"); useDistanceGrab = serializedObject.FindProperty("useDistanceGrab"); ignoreColliderList = serializedObject.FindProperty("ignoreColliderList"); grabMode = serializedObject.FindProperty("grabMode"); recoilDirection = serializedObject.FindProperty("recoilDirection"); toggleGrab = serializedObject.FindProperty("toggleGrab"); #if SDK_STEAM_VR useSteamRotationOffset = serializedObject.FindProperty("useSteamRotationOffset"); #endif targetScript = (VR_Grabbable)target; }
private void Awake() { thisGrabbable = GetComponent <VR_Grabbable>(); player = GameObject.FindGameObjectWithTag("Player").transform; if (stringController == null) { stringController = transform.GetComponentInChildren <BowStringController>(); } bowStringController.Grabbable.OnGrabStateChange.AddListener(OnStringGrabStateChange); thisGrabbable.OnGrabStateChange.AddListener(OnThisGrabStateChange); leftController = VR_Manager.instance.LeftController; rightController = VR_Manager.instance.RightController; //try to get the grabzone if (arrowGrabZone == null && bowControlMode == BowControlMode.Realistic) { arrowGrabZone = FindArrowGrabbableZone(); if (arrowGrabZone == null) { Debug.LogError("Realistic bow needs a arrow grabzone in order to work!"); } } if (arrowGrabZone != null) { arrowGrabZone.enabled = false; } }
private void OnBulletInserted(VR_Grabbable bullet) { if (bullet == null && reloadMode == ReloadMode.Launcher) { insertedBullet = null; return; } if (reloadMode == ReloadMode.Launcher) { insertedBullet = bullet.GetComponent <Bullet>(); } bulletsCounter++; UpdateUI(); if (reloadMode != ReloadMode.Launcher) { Destroy(bullet.gameObject); } if (bulletsCounter >= clipSize && reloadMode != ReloadMode.Launcher) { bulletInsertPoint.enabled = false; } }
private void ProcessHit(RaycastHit hitInfo) { TryDoDamage(hitInfo.collider); //enable grabbable VR_Grabbable thisGrabbable = GetComponent <VR_Grabbable>(); if (thisGrabbable != null) { thisGrabbable.enabled = true; } float sqrDistance = (arrowHead.position - hitInfo.point).sqrMagnitude; //check that the arrow is no to much inside object if (sqrDistance > arrowDepth * arrowDepth) { transform.position = hitInfo.point - transform.forward * arrowDepth; } Rigidbody rb = hitInfo.collider.GetComponent <Rigidbody>(); if (rb != null) { StickToRigidBody(rb); } else { VR_Grabbable grabbable = VR_Manager.instance.GetGrabbableFromCollider(hitInfo.collider); rb = grabbable != null?grabbable.GetComponent <Rigidbody>() : null; if (rb != null && !rb.isKinematic) { StickToRigidBody(rb); } else { //m_rb.isKinematic = true; if (shouldParent && hitInfo.collider.transform.localScale == Vector3.one) { transform.parent = hitInfo.collider.transform; rb.constraints = RigidbodyConstraints.FreezeAll; } else { thisRB.isKinematic = true; } } } hitSomething = true; launched = false; }
public HandPreviewSave(VR_Grabbable grabbable) { handSettings = grabbable.HandSettings; leftSettings = grabbable.LeftHandSettings; rightSettings = grabbable.RightHandSettings; handSettingsInteractPointLocalPosition = handSettings.interactPoint.localPosition; leftHandSettingsInteractPointLocalPosition = leftSettings.interactPoint.localPosition; rightHandSettingsInteractPointLocalPosition = rightSettings.interactPoint.localPosition; }
protected override void Awake() { base.Awake(); grabbable = GetComponent <VR_Grabbable>(); grabbable.OnGrabStateChange.AddListener(OnGrabStateChange); //calculate arrow size size = Vector3.Distance(transform.position, arrowHead.position); }
private void OnMagazineUnDropStateChange(VR_Grabbable undropGrabbable) { if (undropGrabbable != null) { VR_WeaponMag mag = undropGrabbable.GetComponent <VR_WeaponMag>(); if (mag != null) { mag.SetOwner(null); CurrentMagazine = null; } } }
private void OnMagazineDropStateChange(VR_Grabbable dropGrabbable) { if (dropGrabbable != null) { VR_WeaponMag mag = dropGrabbable.GetComponent <VR_WeaponMag>(); if (mag != null) { mag.SetOwner(this); CurrentMagazine = mag; } } }
private void OnCollisionEnter(Collision other) { //in this way we can respond to hits from objects and apply damage, //like the player throwing a box to a enemy if (other.rigidbody != null) { VR_Grabbable grabbable = VR_Manager.instance.GetGrabbableFromCollider(other.collider); if (grabbable != null && grabbable.ObjectWasThrow && grabbable.LastInteractController != null) { GameObject sender = grabbable.LastInteractController.transform.root.gameObject; ProcessHit(other.rigidbody, sender); } } }
private void EnterPreviewMode(VR_Controller controller) { targetScript = (HandVisualizerTool)target; grabbable = targetScript.GetComponent <VR_Grabbable>(); grabbable.gameObject.AddComponent <GameObjectMarker>(); EditorSceneManager.MarkAllScenesDirty(); EditorSceneManager.SaveOpenScenes(); grabbableClone = Instantiate(grabbable, grabbable.transform.position, grabbable.transform.rotation); activeController = Instantiate(controller, grabbable.RightInteractPoint.position, Quaternion.identity); grabbableClone.SetEditorGrabPositionAndRotation(activeController); HandPreviewManager.EnterPreviewMode(grabbableClone.transform.root.gameObject); }
private void Start() { weaponGrabbable = weapon.GetComponent <VR_Grabbable>(); weaponGrabbable.OnGrabStateChange.AddListener(OnWeaponGrabStateChange); if (weapon.ReloadMode == ReloadMode.UI) { string bullets = weapon.BulletsCounter.ToString(); rightBulletCounter.text = bullets; leftBulletCounter.text = bullets; reloadBar.gameObject.SetActive(false); } rightBulletCounter.gameObject.SetActive(false); leftBulletCounter.gameObject.SetActive(false); reloadBar.gameObject.SetActive(false); }
public static void EnterPreviewMode(GameObject clone) { Scene originalScene = EditorSceneManager.GetActiveScene(); originalScenePath = EditorApplication.currentScene; Scene previewScene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Additive); EditorSceneManager.MoveGameObjectToScene(clone, previewScene); EditorSceneManager.UnloadSceneAsync(originalScene); previewModeEnable = true; inspectedGrabbable = GameObject.FindObjectOfType <VR_Grabbable>(); activeController = GameObject.FindObjectOfType <VR_Controller>(); OverrideGrabAnimation(); activeController.Animator.SetBool("IsGrabbing", true); EditorApplication.update += Update; }
private void OnEnable() { onGrabStateChange = serializedObject.FindProperty("onGrabStateChange"); perfectGrab = serializedObject.FindProperty("perfectGrab"); grabDistance = serializedObject.FindProperty("interactDistance"); shouldFly = serializedObject.FindProperty("shouldFly"); startOnRightcController = serializedObject.FindProperty("startOnRightcController"); startOnLeftController = serializedObject.FindProperty("startOnLeftController"); autoGrab = serializedObject.FindProperty("autoGrab"); grabButton = serializedObject.FindProperty("interactButton"); grabLayer = serializedObject.FindProperty("grabLayer"); unGrabLayer = serializedObject.FindProperty("unGrabLayer"); enableCollidersOnGrab = serializedObject.FindProperty("enableColliderOnGrab"); usePerHandSettings = serializedObject.FindProperty("usePerHandSettings"); rightHandSettings = serializedObject.FindProperty("rightHandSettings"); leftHandSettings = serializedObject.FindProperty("leftHandSettings"); handSettings = serializedObject.FindProperty("handSettings"); preserveKinematicState = serializedObject.FindProperty("preserveKinematicState"); slideAxis = serializedObject.FindProperty("slideAxis"); grabMode = serializedObject.FindProperty("grabMode"); targetScript = (VR_Grabbable)target; }
public void LoadInto(VR_Grabbable grabbable) { CopyTo(handSettings, grabbable.HandSettings); CopyTo(rightSettings, grabbable.RightHandSettings); CopyTo(leftSettings, grabbable.LeftHandSettings); if (grabbable.HandSettings.interactPoint != null) { Debug.Log(grabbable.HandSettings.interactPoint.localPosition); Debug.Log(handSettingsInteractPointLocalPosition); grabbable.HandSettings.interactPoint.localPosition = handSettingsInteractPointLocalPosition; } if (grabbable.LeftHandSettings.interactPoint != null) { grabbable.LeftHandSettings.interactPoint.localPosition = leftHandSettingsInteractPointLocalPosition; } if (grabbable.RightHandSettings.interactPoint != null) { grabbable.RightHandSettings.interactPoint.localPosition = rightHandSettingsInteractPointLocalPosition; } }
private void Start() { //disable grenade.enabled = false; rb = GetComponent <Rigidbody>(); thisCollider = GetComponent <Collider>(); thisGrabbable = GetComponent <VR_Grabbable>(); thisGrabbable.OnGrabStateChange.AddListener(OnThisGrabStateChange); thisGrabbable.enabled = false; granadeGrabbable.OnGrabStateChange.AddListener(OnGrenadeGrabStateChange); if (thisCollider != null) { granadeGrabbable.IgnoreCollider(thisCollider); thisCollider.enabled = false; } if (rb != null) { rb.isKinematic = true; } }