Exemple #1
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);
        }
        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 settings      = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
                var entityManager = World.DefaultGameObjectInjectionWorld.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 (!InteractionSetupHelper.SetupInteractions(ref entityManager, ref teleporterEntity, interactionParameters))
                {
                    entityManager.DestroyEntity(teleporterEntity);
                    Destroy(gameObject);
                    return;
                }

                // Setting up Raycasting
                if (!TeleporterSetupHelper.SetupRaycast(ref entityManager, ref teleporterEntity, interactionParameters, 10))
                {
                    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, settings);
                var invalidPad   = GameObjectConversionUtility.ConvertGameObjectHierarchy(InvalidPad, settings);

                entityManager.SetEnabled(selectionPad, false);
                entityManager.SetEnabled(invalidPad, false);

#if UNITY_EDITOR
                // Set it's name in Editor Mode for the Entity Debugger Window
                entityManager.SetName(selectionPad, "Curve Teleporter Selection Pad");
                entityManager.SetName(invalidPad, "Curve Teleporter Invalid Pad");
#endif

                entityManager.SetComponentData(teleporterEntity, new ParabolPadsEntities
                {
                    SelectionPadInstance = selectionPad,
                    InvalidPadInstance   = invalidPad
                });

                if (_destroyEntityOnSceneUnloaded)
                {
                    Core.OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref selectionPad, gameObject.scene.buildIndex, "CurveTeleporterAuthoring");
                    Core.OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref invalidPad, gameObject.scene.buildIndex, "CurveTeleporterAuthoring");
                    Core.OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref teleporterEntity, gameObject.scene.buildIndex, "CurveTeleporterAuthoring");
                }

                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
                    });
                    if (_destroyEntityOnSceneUnloaded)
                    {
                        Core.OnSceneUnloadedEntityDestroyer.CheckDestroyOnSceneUnload(ref entityManager, ref parabolPoint, gameObject.scene.buildIndex, "CurveTeleporterAuthoring");
                    }
#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);
        }