Ejemplo n.º 1
0
            public void Execute(ref GeneralTeleportParameters gtp, [ReadOnly] ref ControllersInteractionType cit, [ReadOnly] ref BaseInputCapture bic)
            {
                switch (gtp.CurrentTeleportState)
                {
                case ETeleportState.None:
                    if (InteractionChecker.IsInteracting(bic, cit))
                    {
                        gtp.CurrentTeleportState = ETeleportState.Selecting;
                    }
                    break;

                case ETeleportState.Selecting:
                    if (InteractionChecker.IsNotInteracting(bic, cit))
                    {
                        gtp.CurrentTeleportState = ETeleportState.Teleporting;
                        gtp.HasTeleported        = false;
                    }
                    break;

                case ETeleportState.Teleporting:
                    if (gtp.HasTeleported)
                    {
                        gtp.CurrentTeleportState = ETeleportState.None;
                    }
                    break;
                }
            }
Ejemplo n.º 2
0
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity e, ref FlyDirection direction, ref TouchpadInputCapture tic, ref InteractionThumbPosition itp, ref BaseInputCapture bic, ref ControllersInteractionType cit) =>
            {
                // If user just started to press/touch the thumbstick
                if (InteractionChecker.IsInteractingTouchpad(bic, cit, itp, tic, true, false))
                {
                    direction.FlightDirection = tic.ThumbPosition.y;

                    if (!EntityManager.HasComponent(e, typeof(IsFlying)))
                    {
                        PostUpdateCommands.AddComponent(e, new IsFlying());
                    }
                    if (EntityManager.HasComponent(e, typeof(IsDecelerating)))
                    {
                        PostUpdateCommands.RemoveComponent <IsDecelerating>(e);
                    }
                }
                else if (EntityManager.HasComponent(e, typeof(IsFlying)))
                {
                    PostUpdateCommands.RemoveComponent <IsFlying>(e);
                    PostUpdateCommands.AddComponent(e, new IsDecelerating());
                }
            });
        }
Ejemplo n.º 3
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
 }
Ejemplo n.º 4
0
 public void Execute(ref LinearUserRotation lur, [ReadOnly] ref ControllersInteractionType cit, [ReadOnly] ref BaseInputCapture bic)
 {
     if (lur.CurrentRotationSpeed > 0.0f && InteractionChecker.IsNotInteracting(bic, cit))
     {
         // Setting the current speed of the user to 0
         lur.CurrentRotationSpeed = 0.0f;
     }
 }
    public void nextSprite()
    {
        GameObject agent_to_add = new GameObject("agent #" + sprite_index);

        //https://forum.unity.com/threads/converting-texture-to-texture2d.25991/
        Sprite sprite_to_handle = wrap_image_into_sprite(sprite_to_add.texture as Texture2D);
        //https://forum.unity.com/threads/how-to-programmatically-add-sprite-to-spriterenderer.257990/
        SpriteRenderer rend_agent = agent_to_add.AddComponent(typeof(SpriteRenderer)) as SpriteRenderer;

        rend_agent.sprite = sprite_to_handle;
        //move the transform far far away so it doesn't display on our screen until we want it to, since it's not a prefab
        rend_agent.transform.position = new Vector3(-9000.0f, -9000.0f, -9000.0f);

        if (collect_selected)
        {
            agent_to_add.tag = "Collect";
        }

        if (avoid_selected)
        {
            agent_to_add.tag = "Avoid";
        }

        if (!defeat_selected)
        {
            BoxCollider2D col = agent_to_add.AddComponent(typeof(BoxCollider2D)) as BoxCollider2D;
            col.isTrigger = true;
        }

        if (defeat_selected)
        {
            agent_to_add.tag = "Defeat";
            //https://answers.unity.com/questions/774087/how-to-create-change-edge-collider-from-code.html
            EdgeCollider2D col     = agent_to_add.AddComponent(typeof(EdgeCollider2D)) as EdgeCollider2D;
            List <Vector2> col_pts = new List <Vector2>();
            col_pts.Add(new Vector2(-1.0f, -0.5f));
            col_pts.Add(new Vector2(-1.0f, 1.0f));
            col_pts.Add(new Vector2(1.0f, 1.0f));
            col_pts.Add(new Vector2(1.0f, -0.5f));
            col.points    = col_pts.ToArray();
            col.isTrigger = true;
        }

        //https://answers.unity.com/questions/1136397/how-to-add-a-script-to-a-gameobject-during-runtime.html
        InteractionChecker script = agent_to_add.AddComponent <InteractionChecker>();

        Debug.Log("Now adding sprite at index: " + sprite_index);
        moving_agents[sprite_index] = agent_to_add;
        sprite_index++;
        clear_sprite_helper();

        if (sprite_index >= moving_agents.Length)
        {
            deactivate_sprite_loader();
            loadEntireGame(Random.Range(3, 5));
        }
    }
            public void Execute(ref LinearUserRotation lur, [ReadOnly] ref ControllersInteractionType cit, [ReadOnly] ref BaseInputCapture bic, [ReadOnly] ref LinearRotationDeceleration lrd)
            {
                if (lur.CurrentRotationSpeed > 0.0f && InteractionChecker.IsNotInteracting(bic, cit))
                {
                    // maxSpeedTimeDeltaTime : To calculate the current speed according to deltaTime, Max Speed and acceleration factor
                    float maxSpeedTimeDeltaTime = DeltaTime * lrd.DecelerationFactor * (lur.MaxRotationSpeed / 50);

                    // Setting the current speed of the user
                    lur.CurrentRotationSpeed -= maxSpeedTimeDeltaTime;

                    RotationAxis[0] = new float3(0, lur.LastThumbXPos, 0);
                    CurrentSpeed[0] = lur.CurrentRotationSpeed;
                }
            }
            public void Execute(ref LinearUserRotation lur, [ReadOnly] ref ControllersInteractionType cit, [ReadOnly] ref BaseInputCapture bic, [ReadOnly] ref TouchpadInputCapture tic)
            {
                if (InteractionChecker.IsInteractingSimple(bic, cit))
                {
                    // maxSpeedTimeDeltaTime : To calculate the current speed according to deltaTime, Max Speed and acceleration factor
                    float maxSpeedTimeDeltaTime = DeltaTime * lur.AccelerationFactor * (lur.MaxRotationSpeed / 50);

                    // Setting the current speed of the user
                    lur.CurrentRotationSpeed += maxSpeedTimeDeltaTime;

                    lur.LastThumbXPos = tic.ThumbPosition.x;
                    RotationAxis[0]   = new float3(0, lur.LastThumbXPos, 0);
                    CurrentSpeed[0]   = lur.CurrentRotationSpeed;
                }
            }
        protected override void OnUpdate()
        {
            if (!VRSF_Components.SetupVRIsReady)
            {
                return;
            }

            Entities.ForEach((ref NonLinearUserRotation nlur, ref ControllersInteractionType cit, ref BaseInputCapture bic, ref TouchpadInputCapture tic) =>
            {
                if (!nlur.HasAlreadyRotated && InteractionChecker.IsInteracting(bic, cit) && math.abs(tic.ThumbPosition.x) > 0.5f)
                {
                    VRSF_Components.RotateVRCameraAround(new float3(0.0f, tic.ThumbPosition.x, 0.0f), nlur.DegreesToRotate);
                    nlur.HasAlreadyRotated = true;
                }
                else if (nlur.HasAlreadyRotated && math.abs(tic.ThumbPosition.x) < 0.5f)
                {
                    nlur.HasAlreadyRotated = false;
                }
            });
        }
Ejemplo n.º 9
0
 private void Awake()
 {
     Instance = this;
 }