Exemple #1
0
 protected virtual Vector3 AxisDirection(bool local = false)
 {
     return(VRTK_SharedMethods.AxisDirection((int)operateAxis, (local ? transform : null)));
 }
        protected virtual Renderer CreateHighlightModel(GameObject givenOutlineModel, string givenOutlineModelPath)
        {
            if (givenOutlineModel != null)
            {
                givenOutlineModel = (givenOutlineModel.GetComponent <Renderer>() ? givenOutlineModel : givenOutlineModel.GetComponentInChildren <Renderer>().gameObject);
            }
            else if (givenOutlineModelPath != "")
            {
                Transform getChildModel = objectToAffect.transform.Find(givenOutlineModelPath);
                givenOutlineModel = (getChildModel ? getChildModel.gameObject : null);
            }

            GameObject copyModel = givenOutlineModel;

            if (copyModel == null)
            {
                Renderer copyModelRenderer = objectToAffect.GetComponentInChildren <Renderer>();
                copyModel = (copyModelRenderer != null ? copyModelRenderer.gameObject : null);
            }

            if (copyModel == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "VRTK_OutlineObjectCopyHighlighter", "Renderer", "the same or child", " to add the highlighter to"));
                return(null);
            }

            GameObject highlightModel = new GameObject(objectToAffect.name + "_HighlightModel");

            highlightModel.transform.SetParent(copyModel.transform.parent, false);
            highlightModel.transform.localPosition = copyModel.transform.localPosition;
            highlightModel.transform.localRotation = copyModel.transform.localRotation;
            highlightModel.transform.localScale    = copyModel.transform.localScale;
            highlightModel.transform.SetParent(objectToAffect.transform);

            Component[] copyModelComponents = copyModel.GetComponents <Component>();
            for (int i = 0; i < copyModelComponents.Length; i++)
            {
                Component copyModelComponent = copyModelComponents[i];
                if (Array.IndexOf(copyComponents, copyModelComponent.GetType().ToString()) >= 0)
                {
                    VRTK_SharedMethods.CloneComponent(copyModelComponent, highlightModel);
                }
            }

            MeshFilter copyMesh             = copyModel.GetComponent <MeshFilter>();
            MeshFilter highlightMesh        = highlightModel.GetComponent <MeshFilter>();
            Renderer   returnHighlightModel = highlightModel.GetComponent <Renderer>();

            if (highlightMesh != null)
            {
                if (enableSubmeshHighlight)
                {
                    HashSet <CombineInstance> combine = new HashSet <CombineInstance>();
                    for (int i = 0; i < copyMesh.mesh.subMeshCount; i++)
                    {
                        CombineInstance ci = new CombineInstance();
                        ci.mesh         = copyMesh.mesh;
                        ci.subMeshIndex = i;
                        ci.transform    = copyMesh.transform.localToWorldMatrix;
                        combine.Add(ci);
                    }

                    highlightMesh.mesh = new Mesh();
                    highlightMesh.mesh.CombineMeshes(combine.ToArray(), true, false);
                }
                else
                {
                    highlightMesh.mesh = copyMesh.mesh;
                }
                returnHighlightModel.material = stencilOutline;
            }
            highlightModel.SetActive(false);

            VRTK_PlayerObject.SetPlayerObject(highlightModel, VRTK_PlayerObject.ObjectTypes.Highlighter);

            return(returnHighlightModel);
        }
Exemple #3
0
 protected virtual void SetupCollider()
 {
     controlColliders     = VRTK_SharedMethods.ColliderExclude(GetComponentsInChildren <Collider>(), VRTK_SharedMethods.GetCollidersInGameObjects(excludeColliderCheckOn, true, true));
     createCustomCollider = false;
     if (controlColliders.Length == 0)
     {
         controlColliders = new Collider[1] {
             gameObject.AddComponent <BoxCollider>()
         };
         createCustomCollider = true;
         ConfigureColliders();
     }
 }
 private static bool IsDaydreamAvailable()
 {
     return(VRTK_SharedMethods.GetTypeUnknownAssembly("GvrController") != null);
 }
 /// <summary>
 /// The GetOption method is used to return a value from the options array if the given key exists.
 /// </summary>
 /// <typeparam name="T">The system type that is expected to be returned.</typeparam>
 /// <param name="options">The dictionary of options to check in.</param>
 /// <param name="key">The identifier key to look for.</param>
 /// <returns>The value in the options at the given key returned in the provided system type.</returns>
 public virtual T GetOption <T>(Dictionary <string, object> options, string key)
 {
     return((T)VRTK_SharedMethods.GetDictionaryValue(options, key, default(T)));
 }
Exemple #6
0
 /// <summary>
 /// The GetCurrentDirection method returns a Vector3 of the current positive/negative axis direction that the Transform is moving in.
 /// </summary>
 /// <returns>A Vector3 of the direction the Transform is moving across the relevant axis in.</returns>
 public virtual Vector3 GetCurrentDirection()
 {
     return(VRTK_SharedMethods.VectorDirection(previousPosition, transform.localPosition));
 }
Exemple #7
0
 /// <summary>
 /// The GetDirectionFromOrigin method returns a Vector3 of the direction across the axis from the original position.
 /// </summary>
 /// <returns>A Vector3 of the direction the Transform is moving across the relevant axis in relation to the original position.</returns>
 public virtual Vector3 GetDirectionFromOrigin()
 {
     return(VRTK_SharedMethods.VectorDirection(localOrigin, transform.localPosition));
 }
 /// <summary>
 /// The GetNormalizedValue method returns the current position value of the pusher normalized between `0f` and `1f`.
 /// </summary>
 /// <returns>The normalized position of the pusher.</returns>
 public override float GetNormalizedValue()
 {
     return(VRTK_SharedMethods.NormalizeValue(GetValue(), originalLocalPosition[(int)operateAxis], PressedPosition()[(int)operateAxis]));
 }
Exemple #9
0
 /// <summary>
 /// The GetPosition method returns a Vector3 of the Transform position in relation to the axis limits.
 /// </summary>
 /// <returns>A Vector3 containing the current Transform position in relation to the axis limits.</returns>
 public virtual Vector3 GetPosition()
 {
     return(VRTK_SharedMethods.VectorHeading(localOrigin, transform.localPosition));
 }
 /// <summary>
 /// The GetNormalizedValue method returns the current rotation value of the rotator normalized between `0f` and `1f`.
 /// </summary>
 /// <returns>The normalized rotation of the rotator.</returns>
 public override float GetNormalizedValue()
 {
     return(VRTK_SharedMethods.NormalizeValue(GetValue(), angleLimits.minimum, angleLimits.maximum));
 }
Exemple #11
0
 private void DoButtonOnePressed(object sender, ControllerInteractionEventArgs e)
 {
     tooltips.ToggleTips(true, VRTK_ControllerTooltips.TooltipButtons.ButtonOneTooltip);
     highligher.HighlightElement(SDK_BaseController.ControllerElements.ButtonOne, highlightColor, highlightTimer);
     VRTK_SharedMethods.SetOpacity(VRTK_DeviceFinder.GetModelAliasController(events.gameObject), dimOpacity);
 }
 protected virtual void SetupInteractableObject()
 {
     controlInteractableObject = GetComponent <VRTK_InteractableObject>();
     if (controlInteractableObject == null)
     {
         controlInteractableObject                  = rotatorContainer.AddComponent <VRTK_InteractableObject>();
         controlInteractableObject.isGrabbable      = true;
         controlInteractableObject.ignoredColliders = (onlyInteractWith.Length > 0 ? VRTK_SharedMethods.ColliderExclude(GetComponentsInChildren <Collider>(true), VRTK_SharedMethods.GetCollidersInGameObjects(onlyInteractWith, true, true)) : new Collider[0]);
         SetupGrabMechanic();
         SetupSecondaryAction();
     }
     ManageInteractableListeners(true);
 }
        /// <summary>
        /// The GetAngleFromStepValue returns the angle the rotator would be at based on the given step value.
        /// </summary>
        /// <param name="givenStepValue">The step value to check the angle for.</param>
        /// <returns>The angle the rotator would be at based on the given step value.</returns>
        public virtual float GetAngleFromStepValue(float givenStepValue)
        {
            float normalizedStepValue = VRTK_SharedMethods.NormalizeValue(givenStepValue, stepValueRange.minimum, stepValueRange.maximum);

            return(controlGrabAttach != null ? Mathf.Lerp(controlGrabAttach.angleLimits.minimum, controlGrabAttach.angleLimits.maximum, Mathf.Clamp01(normalizedStepValue)) : 0f);
        }
 /// <summary>
 /// The SetRestingAngleWithStepValue sets the `Resting Angle` parameter but uses a value within the `Step Value Range`.
 /// </summary>
 /// <param name="givenStepValue">The step value within the `Step Value Range` to set the `Resting Angle` parameter to.</param>
 public virtual void SetRestingAngleWithStepValue(float givenStepValue)
 {
     restingAngle = VRTK_SharedMethods.NormalizeValue(givenStepValue, stepValueRange.minimum, stepValueRange.maximum);
 }
 /// <summary>
 /// The SetAngleTargetWithStepValue sets the `Angle Target` parameter but uses a value within the `Step Value Range`.
 /// </summary>
 /// <param name="givenStepValue">The step value within the `Step Value Range` to set the `Angle Target` parameter to.</param>
 public virtual void SetAngleTargetWithStepValue(float givenStepValue)
 {
     angleTarget         = SetAngleWithNormalizedValue(VRTK_SharedMethods.NormalizeValue(givenStepValue, stepValueRange.minimum, stepValueRange.maximum));
     previousAngleTarget = angleTarget;
 }
        /// <summary>
        /// The GetStepValue method returns the current angle of the rotator based on the step value range.
        /// </summary>
        /// <param name="currentValue">The current angle value of the rotator to get the Step Value for.</param>
        /// <returns>The current Step Value based on the rotator angle.</returns>
        public virtual float GetStepValue(float currentValue)
        {
            float step = Mathf.Lerp(stepValueRange.minimum, stepValueRange.maximum, VRTK_SharedMethods.NormalizeValue(currentValue, angleLimits.minimum, angleLimits.maximum));

            return(Mathf.Round(step / stepSize) * stepSize);
        }