/// <summary> /// Check if the interaction are click + UP and DOWN /// OR /// if the interaction are touch + UP and DOWN /// </summary> /// <param name="interactionParameters">the interaction parameters to check</param> /// <returns>true if at least one of the consition is respected</returns> private bool InteractionIsUpAndDown(VRInteractionAuthoring interactionParameters) { return(((interactionParameters.InteractionType & EControllerInteractionType.CLICK) == EControllerInteractionType.CLICK && ((interactionParameters.ClickThumbPosition & EThumbPosition.DOWN) == EThumbPosition.DOWN && (interactionParameters.ClickThumbPosition & EThumbPosition.UP) == EThumbPosition.UP)) || ((interactionParameters.InteractionType & EControllerInteractionType.TOUCH) == EControllerInteractionType.TOUCH && ((interactionParameters.TouchThumbPosition & EThumbPosition.DOWN) == EThumbPosition.DOWN && (interactionParameters.TouchThumbPosition & EThumbPosition.UP) == EThumbPosition.UP))); }
private void Init(OnSetupVRReady _) { OnSetupVRReady.UnregisterSetupVRCallback(Init); VRInteractionAuthoring vrInteractionAuthoring = GetComponent <VRInteractionAuthoring>(); // If the device loaded is included in the device using this CBRA if ((vrInteractionAuthoring.DeviceUsingFeature & VRDF_Components.DeviceLoaded) == VRDF_Components.DeviceLoaded) { var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; var archetype = entityManager.CreateArchetype(typeof(BaseInputCapture), typeof(TouchpadInputCapture), typeof(ControllersInteractionType)); var entity = entityManager.CreateEntity(archetype); InteractionSetupHelper.SetupInteractions(ref entityManager, ref entity, vrInteractionAuthoring); entityManager.AddComponentData(entity, new NonLinearUserRotation { DegreesToRotate = this._degreesToRotate }); if (_destroyEntityOnSceneUnloaded) { Core.OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "NonLinearRotationAuthoring"); } #if UNITY_EDITOR // Set it's name in Editor Mode for the Entity Debugger Window entityManager.SetName(entity, "User Non Linear Rotation Entity"); #endif } Destroy(gameObject); }
private void Awake() { VRInteractionAuthoring interactionParameters = GetComponent <VRInteractionAuthoring>(); // If the device loaded is included in the device using this CBRA if ((interactionParameters.DeviceUsingFeature & VRSF_Components.DeviceLoaded) == VRSF_Components.DeviceLoaded) { var entityManager = World.Active.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 (!Core.Utils.InteractionSetupHelper.SetupInteractions(ref entityManager, ref entity, interactionParameters)) { entityManager.DestroyEntity(entity); Destroy(gameObject); return; } // Setting up Raycasting if (!TeleporterSetupHelper.SetupRaycast(ref entityManager, ref entity, interactionParameters, _distanceStepByStep)) { 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 }); entityManager.AddComponentData(entity, new DestroyOnSceneUnloaded()); #if UNITY_EDITOR // Set it's name in Editor Mode for the Entity Debugger Window entityManager.SetName(entity, "StepByStep Teleport Entity"); #endif } Destroy(gameObject); }
private void Init(OnSetupVRReady _) { OnSetupVRReady.UnregisterSetupVRCallback(Init); VRInteractionAuthoring vrInteractionAuthoring = GetComponent <VRInteractionAuthoring>(); // If the device loaded is included in the device using this CBRA if ((vrInteractionAuthoring.DeviceUsingFeature & VRDF_Components.DeviceLoaded) == VRDF_Components.DeviceLoaded) { var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; var entity = entityManager.CreateEntity ( typeof(BaseInputCapture), typeof(TouchpadInputCapture), typeof(ControllersInteractionType), typeof(LinearUserRotation) ); // 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, vrInteractionAuthoring)) { entityManager.DestroyEntity(entity); return; } entityManager.AddComponentData(entity, new LinearUserRotation { CurrentRotationSpeed = 0.0f, MaxRotationSpeed = _maxRotationSpeed, AccelerationFactor = _accelerationFactor }); if (UseDecelerationEffect) { entityManager.AddComponentData(entity, new LinearRotationDeceleration { DecelerationFactor = DecelerationFactor }); } if (_destroyEntityOnSceneUnloaded) { Core.OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref entity, gameObject.scene.buildIndex, "LinearRotationAuthoring"); } #if UNITY_EDITOR // Set it's name in Editor Mode for the Entity Debugger Window entityManager.SetName(entity, "User Linear Rotation Entity"); #endif } Destroy(gameObject); }
private void Awake() { VRInteractionAuthoring interactionParameters = GetComponent <VRInteractionAuthoring>(); // If the device loaded is included in the device using this CBRA if ((interactionParameters.DeviceUsingFeature & VRSF_Components.DeviceLoaded) == VRSF_Components.DeviceLoaded) { if (interactionParameters.ButtonToUse != EControllersButton.TOUCHPAD) { Debug.LogError("<b>[VRSF] :</b> The Fly mode can only be use using the touchpad/thumbstick, as we use the up and down value. Entity won't be created."); Destroy(gameObject); return; } else if (!InteractionIsUpAndDown(interactionParameters)) { Debug.LogError("<b>[VRSF] :</b> The Fly mode can only be use using an UP/DOWN combination, as we use them to calculate the direction. Entity won't be created."); Destroy(gameObject); return; } var entityManager = World.Active.EntityManager; var archetype = entityManager.CreateArchetype ( typeof(BaseInputCapture), typeof(ControllersInteractionType), typeof(VRRaycastOutputs), typeof(VRRaycastOrigin), typeof(VRRaycastParameters), typeof(FlyAcceleration), typeof(FlyDeceleration), typeof(FlyDirection), typeof(FlySpeed) ); var flyModeEntity = entityManager.CreateEntity(archetype); // Setting up Interactions if (!Core.Utils.InteractionSetupHelper.SetupInteractions(ref entityManager, ref flyModeEntity, interactionParameters)) { entityManager.DestroyEntity(flyModeEntity); Destroy(gameObject); return; } // Setting up Raycasting if (!SetupRaycasting(ref entityManager, ref flyModeEntity, interactionParameters)) { entityManager.DestroyEntity(flyModeEntity); Destroy(gameObject); return; } // Setup Specific fly mode calculations stuffs entityManager.SetComponentData(flyModeEntity, new FlySpeed { FlyingSpeedFactor = this.FlyingSpeedFactor, CurrentFlightVelocity = 0.0f }); entityManager.SetComponentData(flyModeEntity, new FlyDirection()); entityManager.SetComponentData(flyModeEntity, new FlyAcceleration { AccelerationEffectFactor = AccelerationEffect, CurrentFlightVelocity = 0.0f, TimeSinceStartFlying = 0.0f }); entityManager.SetComponentData(flyModeEntity, new FlyDeceleration { DecelerationEffectFactor = DecelerationFactor, SlowDownTimer = 0.0f }); // Check for Fly Boundaries var flyBoundaries = GetComponent <FlyBoundariesAuthoring>(); if (flyBoundaries != null) { entityManager.AddComponentData(flyModeEntity, new FlyBoundaries { MaxAvatarPosition = flyBoundaries.MaxAvatarPosition, MinAvatarPosition = flyBoundaries.MinAvatarPosition, UseBoundaries = flyBoundaries.MaxAvatarPosition != Vector3.zero && flyBoundaries.MinAvatarPosition != Vector3.zero }); } entityManager.AddComponentData(flyModeEntity, new DestroyOnSceneUnloaded()); #if UNITY_EDITOR // Set it's name in Editor Mode for the Entity Debugger Window entityManager.SetName(flyModeEntity, "Fly Mode Entity"); #endif } Destroy(gameObject); }
private bool SetupRaycasting(ref EntityManager entityManager, ref Entity entity, VRInteractionAuthoring interactionParameters) { switch (interactionParameters.ButtonHand) { case EHand.LEFT: entityManager.SetComponentData(entity, new VRRaycastOrigin { RayOrigin = ERayOrigin.LEFT_HAND }); break; case EHand.RIGHT: entityManager.SetComponentData(entity, new VRRaycastOrigin { RayOrigin = ERayOrigin.RIGHT_HAND }); break; default: Debug.LogError("<b>[VRSF] :</b> Please specify a valid hand on your UserRotationAuthoring Components."); return(false); } entityManager.SetComponentData(entity, new VRRaycastParameters { MaxRaycastDistance = 1.0f, ExcludedLayer = LayerMask.NameToLayer("IgnoreRaycast") }); entityManager.SetComponentData(entity, new VRRaycastOutputs { RaycastHitVar = new RaycastHitVariable(), RayVar = new Ray() }); return(true); }
public static bool SetupRaycast(ref EntityManager entityManager, ref Entity entity, VRInteractionAuthoring interactionParameters, float distanceRaycast) { switch (interactionParameters.ButtonHand) { case EHand.LEFT: entityManager.SetComponentData(entity, new VRRaycastOrigin { RayOrigin = ERayOrigin.LEFT_HAND }); break; case EHand.RIGHT: entityManager.SetComponentData(entity, new VRRaycastOrigin { RayOrigin = ERayOrigin.RIGHT_HAND }); break; default: Debug.LogError("<b>[VRDF] :</b> Please specify a valid hand on your UserRotationAuthoring Components."); return(false); } var generalTeleportParam = interactionParameters.GetComponent <GeneralTeleportAuthoring>(); entityManager.SetComponentData(entity, new VRRaycastParameters { MaxRaycastDistance = distanceRaycast, ExcludedLayer = generalTeleportParam.ExcludedLayers }); entityManager.SetComponentData(entity, new VRRaycastOutputs { RaycastHitVar = new RaycastHitVariable { IsNull = true }, RayVar = new Ray() }); return(true); }
/// <summary> /// Add the corresponding Input component for the selected button. /// </summary> public static bool AddInputCaptureComponent(ref EntityManager entityManager, ref Entity entity, VRInteractionAuthoring interactionSet) { // Add the BaseInputCapture component to the entity if (entityManager.HasComponent <BaseInputCapture>(entity)) { entityManager.SetComponentData(entity, new BaseInputCapture()); } else { entityManager.AddComponentData(entity, new BaseInputCapture()); } // Add the specific inputCapture component for our button switch (interactionSet.ButtonToUse) { case EControllersButton.A_BUTTON: entityManager.AddComponentData(entity, new AButtonInputCapture()); return(IsTwoHandOculusDevice() && interactionSet.ButtonHand == EHand.RIGHT); case EControllersButton.B_BUTTON: entityManager.AddComponentData(entity, new BButtonInputCapture()); return(IsTwoHandOculusDevice() && interactionSet.ButtonHand == EHand.RIGHT); case EControllersButton.X_BUTTON: entityManager.AddComponentData(entity, new XButtonInputCapture()); return(IsTwoHandOculusDevice() && interactionSet.ButtonHand == EHand.LEFT); case EControllersButton.Y_BUTTON: entityManager.AddComponentData(entity, new YButtonInputCapture()); return(IsTwoHandOculusDevice() && interactionSet.ButtonHand == EHand.LEFT); case EControllersButton.THUMBREST: entityManager.AddComponentData(entity, new ThumbrestInputCapture(interactionSet.ButtonHand)); return(IsTwoHandOculusDevice()); case EControllersButton.BACK_BUTTON: entityManager.AddComponentData(entity, new GoAndGearVRInputCapture()); return(IsOneHandPortableDevice()); case EControllersButton.TRIGGER: entityManager.AddComponentData(entity, new TriggerInputCapture(interactionSet.ButtonHand)); return(true); case EControllersButton.GRIP: entityManager.AddComponentData(entity, new GripInputCapture(interactionSet.ButtonHand)); return(true); case EControllersButton.MENU: if (IsTwoHandOculusDevice() && interactionSet.ButtonHand == EHand.RIGHT) { Debug.LogError("<b>[VRSF] :</b> Menu button aren't supported on the Right Hand for Two Handed Oculus Devices."); return(false); } entityManager.AddComponentData(entity, new MenuInputCapture(interactionSet.ButtonHand)); return(true); case EControllersButton.TOUCHPAD: // We check that the thumbposition give in the inspector is not set as none if (((interactionSet.InteractionType & EControllerInteractionType.TOUCH) == EControllerInteractionType.TOUCH && interactionSet.TouchThumbPosition != EThumbPosition.NONE) || ((interactionSet.InteractionType & EControllerInteractionType.CLICK) == EControllerInteractionType.CLICK && interactionSet.ClickThumbPosition != EThumbPosition.NONE)) { entityManager.AddComponentData(entity, new TouchpadInputCapture(interactionSet.ButtonHand)); entityManager.AddComponentData(entity, new InteractionThumbPosition { TouchThumbPosition = interactionSet.TouchThumbPosition, IsTouchingThreshold = interactionSet.IsTouchingThreshold, ClickThumbPosition = interactionSet.ClickThumbPosition, IsClickingThreshold = interactionSet.IsClickingThreshold }); return(true); } Debug.LogError("<b>[VRSF] :</b> Please Specify valid Thumb Positions to use for your VR Interaction Authoring component.", interactionSet.gameObject); return(false); default: Debug.LogError("<b>[VRSF] :</b> Please Specify valid buttons to use for your VR Interaction Authoring component.", interactionSet.gameObject); return(false); } }
public static bool SetupInteractions(ref EntityManager entityManager, ref Entity entity, VRInteractionAuthoring interactionParameters) { // Add the corresponding input component for the selected button. If the button wasn't chose correctly, we destroy this entity and return. if (!AddInputCaptureComponent(ref entityManager, ref entity, interactionParameters)) { return(false); } // If the Hand wasn't chose correctly, we destroy this entity and return. if (!AddButtonHand(ref entityManager, ref entity, interactionParameters.ButtonHand)) { return(false); } // Add the corresponding interaction type component for the selected button. If the interaction type wasn't chose correctly, we destroy this entity and return. if (!AddInteractionType(ref entityManager, ref entity, interactionParameters.InteractionType, interactionParameters.ButtonToUse)) { return(false); } return(true); }
private void Awake() { VRInteractionAuthoring interactionParameters = GetComponent <VRInteractionAuthoring>(); // If the device loaded is included in the device using this CBRA if ((interactionParameters.DeviceUsingFeature & VRSF_Components.DeviceLoaded) == VRSF_Components.DeviceLoaded) { var entityManager = World.Active.EntityManager; var archetype = entityManager.CreateArchetype ( typeof(BaseInputCapture), typeof(ControllersInteractionType), typeof(VRRaycastOutputs), typeof(VRRaycastOrigin), typeof(VRRaycastParameters), typeof(CurveTeleporterCalculations), typeof(CurveTeleporterRendering), typeof(ParabolPadsEntities), typeof(ParabolPointsParameters), typeof(ParabolCalculations), typeof(RenderMesh), typeof(GeneralTeleportParameters), typeof(TeleportNavMesh) ); var teleporterEntity = entityManager.CreateEntity(archetype); // Setting up Interactions if (!Core.Utils.InteractionSetupHelper.SetupInteractions(ref entityManager, ref teleporterEntity, interactionParameters)) { entityManager.DestroyEntity(teleporterEntity); Destroy(gameObject); return; } // Setting up Raycasting if (!TeleporterSetupHelper.SetupRaycast(ref entityManager, ref teleporterEntity, interactionParameters, PointCount)) { entityManager.DestroyEntity(teleporterEntity); Destroy(gameObject); return; } // Setting up General Teleporter Stuffs TeleporterSetupHelper.SetupTeleportStuffs(ref entityManager, ref teleporterEntity, GetComponent <GeneralTeleportAuthoring>()); // Setup Specific curve teleporter calculations stuffs entityManager.SetComponentData(teleporterEntity, new CurveTeleporterCalculations { Acceleration = Acceleration, InitialVelocity = InitialVelocity }); entityManager.SetComponentData(teleporterEntity, new ParabolCalculations { Origin = GetComponent <VRInteractionAuthoring>().ButtonHand }); entityManager.SetComponentData(teleporterEntity, new ParabolPointsParameters { PointCount = PointCount, PointSpacing = PointSpacing }); // Setup Specific curve teleporter rendering stuffs var parabolMesh = new Mesh { name = "Parabolic Pointer", vertices = new Vector3[0], triangles = new int[0] }; parabolMesh.MarkDynamic(); // This rendermesh is only here to store the mesh, material and layer of the curve teleporter and draw it later in a system entityManager.SetSharedComponentData(teleporterEntity, new RenderMesh { mesh = parabolMesh, material = GraphicMaterial, castShadows = UnityEngine.Rendering.ShadowCastingMode.Off, layer = 0, receiveShadows = false, subMesh = 0 }); entityManager.SetComponentData(teleporterEntity, new CurveTeleporterRendering { //GraphicMaterial = GraphicMaterial, GraphicThickness = GraphicThickness }); // Create the valid and Invalid Pads var selectionPad = GameObjectConversionUtility.ConvertGameObjectHierarchy(SelectionPad, World.Active); var invalidPad = GameObjectConversionUtility.ConvertGameObjectHierarchy(InvalidPad, World.Active); entityManager.SetEnabled(selectionPad, false); entityManager.SetEnabled(invalidPad, false); entityManager.SetComponentData(teleporterEntity, new ParabolPadsEntities { SelectionPadInstance = selectionPad, InvalidPadInstance = invalidPad }); entityManager.AddComponentData(teleporterEntity, new DestroyOnSceneUnloaded()); Destroy(SelectionPad); Destroy(InvalidPad); #if UNITY_EDITOR // Set it's name in Editor Mode for the Entity Debugger Window entityManager.SetName(teleporterEntity, "Curve Teleporter Entity"); entityManager.SetName(selectionPad, "Curve Teleporter Valid Pad Entity"); entityManager.SetName(invalidPad, "Curve Teleporter Invalid Pad Entity"); #endif // Create parabol points as entities, as List can't be used in ComponentData var pointArchetype = entityManager.CreateArchetype ( typeof(Unity.Transforms.Translation), typeof(ParabolPointParent), typeof(ParabolPointTag) ); for (int i = 0; i < PointCount; i++) { var parabolPoint = entityManager.CreateEntity(pointArchetype); entityManager.SetSharedComponentData(parabolPoint, new ParabolPointParent { TeleporterEntityIndex = teleporterEntity.Index }); entityManager.AddComponentData(parabolPoint, new DestroyOnSceneUnloaded()); #if UNITY_EDITOR // Set it's name in Editor Mode for the Entity Debugger Window entityManager.SetName(parabolPoint, "Curve Teleporter Point " + i); #endif } } Destroy(gameObject); }
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); }
/// <summary> /// Check if the device loaded is the Simulator, and if everything is setup correctly in the editor, /// create a new Entity to check the Simulator Inputs. /// </summary> /// <param name="entityManager">Entity manager to use to add the componentData to the entity</param> /// <param name="createdEntity">The entity to which we want to add the SImulator Inputs Support</param> /// <param name="interactionParameters">The VRInteractionAuthoring script we want to simulate</param> public void AddSimulatorButtonProxy(ref EntityManager entityManager, ref Entity createdEntity, VRInteractionAuthoring interactionParameters) { // If the device loaded is the Simulator if (VRDF_Components.DeviceLoaded == SetupVR.EDevice.SIMULATOR) { if (UseMouseButton && SimulationMouseButton != EMouseButton.NONE) { entityManager.AddComponentData(createdEntity, new SimulatorButtonMouse { SimulationMouseButton = SimulationMouseButton }); AddSimulatorButtonProxyComp(ref entityManager, ref createdEntity); } else if (!UseMouseButton && SimulationKeyCode != KeyCode.None) { entityManager.AddComponentData(createdEntity, new SimulatorButtonKeyCode { SimulationKeyCode = SimulationKeyCode }); AddSimulatorButtonProxyComp(ref entityManager, ref createdEntity); } } Destroy(this); /// <summary> /// Add the basic SimulatorButtonProxy component, used in Keyboard and Mouse Input Systems /// </summary> void AddSimulatorButtonProxyComp(ref EntityManager dstManager, ref Entity entity) { dstManager.AddComponentData(entity, new SimulatorButtonProxy { SimulatedButton = interactionParameters.ButtonToUse }); } }