コード例 #1
0
        private void Awake()
        {
            // Fetch World Settings, create entity prefab and fetch entityManager
            var settings      = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
            var prefab        = GameObjectConversionUtility.ConvertGameObjectHierarchy(_planePrefab, settings);
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            // Create the new Fading Plane based on the prefab provided
            var entity = entityManager.Instantiate(prefab);

            // add the cameraFadeParameters component to the newly created entity, and inject the parameters provided in the inspector
            entityManager.AddComponentData(entity, new CameraFadeParameters()
            {
                FadingSpeed            = _fadingSpeed,
                ShouldImmediatlyFadeIn = false,
                OldFadingSpeedFactor   = _fadingSpeed
            });

            // Check if the user want a fade in on start
            CheckFadeInOnSetupVRReady();

            if (_destroyEntityOnSceneUnloaded)
            {
                OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "CameraFadeAuthoring");
            }

#if UNITY_EDITOR
            // Set it's name in Editor Mode for the Entity Debugger Window
            entityManager.SetName(entity, "Camera Fade Entity");
#endif

            Destroy(gameObject);


            /// <summary>
            /// Check if we want to fade in when setupVR is ready. Set the material alpha accordingly, and add a CameraFadeOnStart
            /// component to the entity to activate the CameraFadeOnSetupVRReadySystem
            /// </summary>
            void CheckFadeInOnSetupVRReady()
            {
                // Reset material color alpha based on whether we want to fade in or not when SetupVR is ready
                var newColor = _fadeMaterial.color;

                if (FadeInOnSetupVRReady)
                {
                    newColor.a = 1.0f;
                    entityManager.AddComponentData(entity, new CameraFadeOnStart()
                    {
                        TimeBeforeFadeIn     = TimeBeforeFirstFadeIn,
                        TimeSinceSceneLoaded = 0.0f
                    });
                }
                else
                {
                    newColor.a = 0.0f;
                }

                _fadeMaterial.color = newColor;
            }
        }
コード例 #2
0
        private void ConvertToEntity(OnSetupVRReady _)
        {
            OnSetupVRReady.UnregisterSetupVRCallback(ConvertToEntity);

            // If we're not using the simulator, no need for a simulator rotation entity
            if (VRDF_Components.DeviceLoaded != SetupVR.EDevice.SIMULATOR)
            {
                Destroy(this);
                return;
            }

            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            var entity        = entityManager.CreateEntity
                                (
                typeof(SimulatorRotation)
                                );

            entityManager.SetComponentData(entity, new SimulatorRotation
            {
                RotationSpeed = _rotationSpeed
            });

            if (_destroyEntityOnSceneUnloaded)
            {
                OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "SimulatorRotationAuthoring");
            }

#if UNITY_EDITOR
            // Set it's name in Editor Mode for the Entity Debugger Window
            entityManager.SetName(entity, "Simulator Rotation Entity");
#endif

            Destroy(this);
        }
コード例 #3
0
        private void ConvertToEntity(OnSetupVRReady _)
        {
            OnSetupVRReady.UnregisterSetupVRCallback(ConvertToEntity);

            // If we're not using the simulator, no need for a simulator movement entity
            if (VRDF_Components.DeviceLoaded != SetupVR.EDevice.SIMULATOR)
            {
                Destroy(this);
                return;
            }

            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            var entity        = entityManager.CreateEntity
                                (
                typeof(SimulatorMovements),
                typeof(SimulatorAcceleration)
                                );

            entityManager.SetComponentData(entity, new SimulatorMovements
            {
                WalkSpeed       = _walkSpeed * 0.1f,
                ShiftBoost      = _shiftBoost,
                IsGrounded      = _isGrounded,
                GroundLayerMask = _groundLayerMask
            });

            entityManager.SetComponentData(entity, new SimulatorAcceleration
            {
                AccelerationSpeed     = _accelerationSpeed,
                MaxAccelerationFactor = _maxAccelerationFactor,
                AccelerationTimer     = 0.0f
            });

            if (_destroyEntityOnSceneUnloaded)
            {
                OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "SimulatorMovementsAuthoring");
            }

#if UNITY_EDITOR
            // Set it's name in Editor Mode for the Entity Debugger Window
            entityManager.SetName(entity, "Simulator Movements Entity");
#endif

            Destroy(this);
        }
コード例 #4
0
        /// <summary>
        /// Create the Entity
        /// </summary>
        /// <param name="_"></param>
        public void ConvertToEntity(OnSetupVRReady _)
        {
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            var entity        = entityManager.CreateEntity
                                (
                typeof(VRRaycastParameters),
                typeof(VRRaycastOrigin),
                typeof(VRRaycastOutputs)
                                );

            // We add the VRRaycastParameters as a struct to the newly created entity
            entityManager.SetComponentData(entity, new VRRaycastParameters
            {
                MaxRaycastDistance = _maxRaycastDistance,
                ExcludedLayer      = _excludedLayer,
                StartPointOffset   = _startPointOffset,
                EndPointOffset     = _endPointOffset
            });

            entityManager.SetComponentData(entity, new VRRaycastOrigin
            {
                RayOrigin = RayOrigin
            });

            entityManager.SetComponentData(entity, new VRRaycastOutputs
            {
                RaycastHitVar = new RaycastHitVariable {
                    IsNull = true
                },
                RayVar = new Ray()
            });

            // If we use the Hovering feature, we then add a VRHovering tag
            if (_useHoverFeature)
            {
                entityManager.AddComponentData(entity, new VRHovering());
            }

            // If we want to destroy this entity when a new scene is loaded
            if (_destroyEntityOnSceneUnloaded)
            {
                OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "VRRaycastAuthoring");
            }

            // If this gameObject has a PointerClickAuthoring, we add the corresponding component to the entity
            var pointerClick = GetComponent <VRClicker.VRClickerAuthoring>();

            if (pointerClick != null)
            {
                pointerClick.AddPointerClickComponents(ref entity, ref entityManager);
            }

            // If this gameObject has a LaserPointerAuthoring, we add the corresponding component to the entity
            var laserPointerAuthoring = GetComponent <LaserPointer.LaserPointerAuthoring>();

            if (laserPointerAuthoring != null)
            {
                laserPointerAuthoring.AddLaserPointerComponents(ref entity, ref entityManager, this);
            }

            // in the case we're using a laser with LineRenderer, we just destroy this script. If not, we destroy the gameObject
            if (GetComponent <LineRenderer>() != null)
            {
                Destroy(this);
            }
            else
            {
                Destroy(gameObject);
            }
        }
コード例 #5
0
        private void Init(OnSetupVRReady _)
        {
            OnSetupVRReady.UnregisterSetupVRCallback(Init);

            VRInteractionAuthoring interactionParameters = GetComponent <VRInteractionAuthoring>();

            // If the device loaded is included in the device using this CBRA
            if ((interactionParameters.DeviceUsingFeature & VRDF_Components.DeviceLoaded) == VRDF_Components.DeviceLoaded)
            {
                var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

                var archetype = entityManager.CreateArchetype
                                (
                    typeof(BaseInputCapture),
                    typeof(ControllersInteractionType),
                    typeof(VRRaycastOutputs),
                    typeof(VRRaycastOrigin),
                    typeof(VRRaycastParameters),
                    typeof(StepByStepComponent),
                    typeof(GeneralTeleportParameters),
                    typeof(TeleportNavMesh)
                                );

                var entity = entityManager.CreateEntity(archetype);

                // Setting up Interactions
                if (!InteractionSetupHelper.SetupInteractions(ref entityManager, ref entity, interactionParameters))
                {
                    entityManager.DestroyEntity(entity);
                    Destroy(gameObject);
                    return;
                }

                // Setting up Raycasting
                if (!TeleporterSetupHelper.SetupRaycast(ref entityManager, ref entity, interactionParameters, 10))
                {
                    entityManager.DestroyEntity(entity);
                    Destroy(gameObject);
                    return;
                }

                // Setting up General Teleporter Stuffs
                TeleporterSetupHelper.SetupTeleportStuffs(ref entityManager, ref entity, GetComponent <GeneralTeleportAuthoring>());

                // Setup Specific sbs teleporter
                entityManager.SetComponentData(entity, new StepByStepComponent
                {
                    DistanceStepByStep   = _distanceStepByStep,
                    StepHeight           = _stepHeight,
                    DebugCalculationsRay = _debugCalculationRays
                });

                if (_destroyEntityOnSceneUnloaded)
                {
                    OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "StepByStepAuthoring");
                }

#if UNITY_EDITOR
                // Set it's name in Editor Mode for the Entity Debugger Window
                entityManager.SetName(entity, "StepByStep Teleport Entity");
#endif
            }

            Destroy(gameObject);
        }
コード例 #6
0
        public void CreateEntity(OnSetupVRReady _)
        {
            OnSetupVRReady.UnregisterSetupVRCallback(CreateEntity);

            var interactionParameters = GetComponent <VRInteractionAuthoring>();

            // If the device loaded is included in the device list using this CBRA
            if ((interactionParameters.DeviceUsingFeature & VRDF_Components.DeviceLoaded) == VRDF_Components.DeviceLoaded)
            {
                var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
                var entity        = entityManager.CreateEntity
                                    (
                    typeof(BaseInputCapture),
                    typeof(ControllersInteractionType),
                    typeof(CBRATag)
                                    );

                // Add the corresponding input, Hand and Interaction type component for the selected button.
                // If the button wasn't chose correctly or any parameter was wrongly set, we destroy this entity and return.
                if (!InteractionSetupHelper.SetupInteractions(ref entityManager, ref entity, interactionParameters))
                {
                    entityManager.DestroyEntity(entity);
                    return;
                }

                // help us check if this CBRA has at least one event. if false, this entity will be destroy.
                bool cbraHasEvents = false;

                if (interactionParameters.InteractionType.HasFlag(EControllerInteractionType.CLICK))
                {
                    // If at least one of the unity event for the click has a persistent listener set in the editor
                    // Add the CBRA Click Events component to the ClickEvents dictionary
                    if (EventHasACallback(OnButtonStartClicking))
                    {
                        cbraHasEvents = true;
                        CBRADelegatesHolder.StartClickingEvents.Add(entity, new Action(delegate { OnButtonStartClicking.Invoke(); }));
                    }
                    if (EventHasACallback(OnButtonIsClicking))
                    {
                        cbraHasEvents = true;
                        CBRADelegatesHolder.IsClickingEvents.Add(entity, new Action(delegate { OnButtonIsClicking.Invoke(); }));
                    }
                    if (EventHasACallback(OnButtonStopClicking))
                    {
                        cbraHasEvents = true;
                        CBRADelegatesHolder.StopClickingEvents.Add(entity, new Action(delegate { OnButtonStopClicking.Invoke(); }));
                    }
                }

                if (interactionParameters.InteractionType.HasFlag(EControllerInteractionType.TOUCH))
                {
                    // If at least one of the unity event for the touch has a persistent listener set in the editor
                    // Add the CBRA Click Events component to the ClickEvents dictionary
                    if (EventHasACallback(OnButtonStartTouching))
                    {
                        cbraHasEvents = true;
                        CBRADelegatesHolder.StartTouchingEvents.Add(entity, new Action(delegate { OnButtonStartTouching.Invoke(); }));
                    }
                    if (EventHasACallback(OnButtonIsTouching))
                    {
                        cbraHasEvents = true;
                        CBRADelegatesHolder.IsTouchingEvents.Add(entity, new Action(delegate { OnButtonIsTouching.Invoke(); }));
                    }
                    if (EventHasACallback(OnButtonStopTouching))
                    {
                        cbraHasEvents = true;
                        CBRADelegatesHolder.StopTouchingEvents.Add(entity, new Action(delegate { OnButtonStopTouching.Invoke(); }));
                    }
                }

                // Check if at least one event response was setup
                if (!cbraHasEvents)
                {
                    Debug.LogError("<Color=red><b>[VRDF] :</b> Please give at least one response to one of the Unity Events for the CBRA on the GameObject.</Color>" + transform.name, gameObject);
                    entityManager.DestroyEntity(entity);
                    return;
                }

                if (_destroyEntityOnSceneUnloaded)
                {
                    OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "CBRA");
                }

                // If we use the simulator, we check for a SimulatorButtonProxy. if not null, we add the simulatorButtonProxy script
                if (VRDF_Components.DeviceLoaded == SetupVR.EDevice.SIMULATOR)
                {
                    GetComponent <Simulator.SimulatorButtonProxyAuthoring>()?.AddSimulatorButtonProxy(ref entityManager, ref entity, interactionParameters);
                }

#if UNITY_EDITOR
                // Set it's name in Editor Mode for the Entity Debugger Window
                entityManager.SetName(entity, string.Format("CBRA Entity from GO {0}", transform.name));
#endif
            }

            Destroy(gameObject);
        }