Пример #1
0
 protected virtual void ManageDestinationMarkerListeners(GameObject markerMaker, bool register)
 {
     if (markerMaker)
     {
         VRTK_DestinationMarker[] worldMarkers = markerMaker.GetComponentsInChildren <VRTK_DestinationMarker>();
         for (int i = 0; i < worldMarkers.Length; i++)
         {
             VRTK_DestinationMarker worldMarker = worldMarkers[i];
             if (worldMarker == this)
             {
                 continue;
             }
             if (register)
             {
                 worldMarker.DestinationMarkerEnter += DoDestinationMarkerEnter;
                 worldMarker.DestinationMarkerExit  += DoDestinationMarkerExit;
                 worldMarker.DestinationMarkerSet   += DoDestinationMarkerSet;
             }
             else
             {
                 worldMarker.DestinationMarkerEnter -= DoDestinationMarkerEnter;
                 worldMarker.DestinationMarkerExit  -= DoDestinationMarkerExit;
                 worldMarker.DestinationMarkerSet   -= DoDestinationMarkerSet;
             }
         }
     }
 }
 /// <summary>
 /// The InitDestinationSetListener method is used to register the teleport script to listen to events from the given game object that is used to generate destination markers. Any destination set event emitted by a registered game object will initiate the teleport to the given destination location.
 /// </summary>
 /// <param name="markerMaker">The game object that is used to generate destination marker events, such as a controller.</param>
 /// <param name="register">Determines whether to register or unregister the listeners.</param>
 public virtual void InitDestinationSetListener(GameObject markerMaker, bool register)
 {
     if (markerMaker != null)
     {
         VRTK_DestinationMarker[] worldMarkers = markerMaker.GetComponentsInChildren <VRTK_DestinationMarker>();
         for (int i = 0; i < worldMarkers.Length; i++)
         {
             VRTK_DestinationMarker worldMarker = worldMarkers[i];
             if (register)
             {
                 worldMarker.DestinationMarkerSet += new DestinationMarkerEventHandler(DoTeleport);
                 if (worldMarker.targetListPolicy == null)
                 {
                     worldMarker.targetListPolicy = targetListPolicy;
                 }
                 worldMarker.SetNavMeshData(navMeshData);
                 worldMarker.SetHeadsetPositionCompensation(headsetPositionCompensation);
             }
             else
             {
                 worldMarker.DestinationMarkerSet -= new DestinationMarkerEventHandler(DoTeleport);
             }
         }
     }
 }
        protected virtual void ManageDestinationMarkers(bool state)
        {
            ManageDestinationMarkerListeners(VRTK_DeviceFinder.GetControllerLeftHand(), state);
            ManageDestinationMarkerListeners(VRTK_DeviceFinder.GetControllerRightHand(), state);

            for (int i = 0; i < VRTK_ObjectCache.registeredDestinationMarkers.Count; i++)
            {
                VRTK_DestinationMarker destinationMarker = VRTK_ObjectCache.registeredDestinationMarkers[i];
                ManageDestinationMarkerListeners(destinationMarker.gameObject, state);
            }
        }
        protected virtual void InitDestinationMarkerListeners(bool state)
        {
            GameObject leftHand  = VRTK_DeviceFinder.GetControllerLeftHand();
            GameObject rightHand = VRTK_DeviceFinder.GetControllerRightHand();

            InitDestinationSetListener(leftHand, state);
            InitDestinationSetListener(rightHand, state);
            for (int i = 0; i < VRTK_ObjectCache.registeredDestinationMarkers.Count; i++)
            {
                VRTK_DestinationMarker destinationMarker = VRTK_ObjectCache.registeredDestinationMarkers[i];
                if (destinationMarker.gameObject != leftHand && destinationMarker.gameObject != rightHand)
                {
                    InitDestinationSetListener(destinationMarker.gameObject, state);
                }
            }
        }