Пример #1
0
        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 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);
        }