/// <summary> /// Called when the object is selected in the editor /// </summary> private void OnEnable() { // Grab the serialized objects mTarget = (InteractableCore)target; mTargetSO = new SerializedObject(target); }
/// <summary> /// Tests if this motion should be started. However, the motion /// isn't actually started. /// </summary> /// <returns></returns> public override bool TestActivate() { if (!mIsStartable) { return(false); } if (!mMotionController.IsGrounded) { return(false); } // Raycast if needed if (_IsInteractableRaycastEnabled) { bool lIsFound = false; RaycastHit lHitInfo; // Even though we have a raycast root, we really want to shoot from the camera. We'll check distance with the root later. Vector3 lStart = (mMotionController.CameraTransform != null ? mMotionController.CameraTransform.position : mMotionController._Transform.position); Vector3 lForward = (mMotionController.CameraTransform != null ? mMotionController.CameraTransform.forward : mMotionController._Transform.forward); if (RaycastExt.SafeRaycast(lStart, lForward, out lHitInfo, _InteractableDistance * 5f, _InteractableLayers, mMotionController._Transform)) { bool lIsValid = true; if (mRaycastRoot != null) { float lDistance = Vector3.Distance(lHitInfo.point, mRaycastRoot.position); if (lDistance > _InteractableDistance) { lIsValid = false; } } if (lIsValid) { IInteractableCore lCore = lHitInfo.collider.gameObject.GetComponent <IInteractableCore>(); if (lCore == null) { lCore = lHitInfo.collider.gameObject.GetComponentInParent <IInteractableCore>(); } if (!_IsInteractableCoreRequired && lCore == null) { lIsFound = true; Interactable = lHitInfo.collider.gameObject; } else { if (lCore == null) { lIsValid = false; } if (lIsValid && !lCore.IsEnabled) { lIsValid = false; } if (lIsValid && !lCore.TestActivator(mMotionController._Transform)) { lIsValid = false; } if (lIsValid && lCore.RaycastCollider != null && lHitInfo.collider != lCore.RaycastCollider) { lIsValid = false; } if (lIsValid) { lIsFound = true; InteractableCore = lCore; InteractableCore.StartFocus(); mActiveForm = lCore.Form; } } } } // Deselect any interactable if none is found if (!lIsFound && _IsInteractableRaycastEnabled) { Interactable = null; } } // Test if we're supposed to activate if (_ActionAlias.Length > 0 && mMotionController._InputSource != null) { if (mMotionController._InputSource.IsJustPressed(_ActionAlias)) { // Check if the interactable is going to prepare thier activator. If so, we // aren't going to activate here. The activator will trigger the activation. if (InteractableCore != null) { if (InteractableCore.ForcePosition || InteractableCore.ForceRotation) { mMotionController.StartCoroutine(MoveToTargetInternal(InteractableCore)); } else { return(true); } } // Since we're just dealing with a simple game object, activate else if (Interactable != null) { return(true); } } } return(false); }