Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(mouseButton))
        {
            /*Debug.Log("MX:" + Camera.main.ScreenToWorldPoint(Input.mousePosition).x + " MY:" + Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
             * Debug.Log("Target Position: " + position + (target == null ? Vector3.zero : target.position));
             */

            if (position == Vector3.zero || position == null)
            {
                ifMouseClicked.Invoke(Vector2.zero);
            }

            else
            {
                Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
                mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
                if (Vector2.Distance(mousePosition, position + (target == null ? Vector3.zero : target.position)) <= 2)
                {
                    Debug.Log("Clicked in position");
                    ifMouseClicked.Invoke(Camera.main.ScreenToWorldPoint(Input.mousePosition));
                }
            }
        }
    }
Beispiel #2
0
    void Start()
    {
        currentSettings = SaveLoader.LoadSettings();
        currentProgress = SaveLoader.LoadProgress();

        SubscribeToEvents();

        if (currentProgress.Level == currentLevel)
        {
            // for (int i = 0; i < currentProgress.COINs; i++) onLanternLited?.Invoke();
            if (currentProgress.COINs == 3)
            {
                OpenLevelDoor();
            }
        }
        else
        {
            OnNextLevelEnter();
        }

        onAssignCheckpoint?.Invoke(currentProgress.LastCheckpoint);

        onGameStarted?.Invoke(currentProgress);

        Debug.Log(currentProgress.COINs);
    }
Beispiel #3
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.GetComponent <PlayerController>())
     {
         onNewCheckPoint?.Invoke(transform.position);
     }
 }
 public void Start()
 {
     Task.Run(() =>
     {
         while (true)
         {
             PositionEvent?.Invoke(_instance, new EventArgs {
                 X = _x, Y = _y
             });
             Thread.Sleep(3000);//ogni 3s aggiorna posizione
         }
     });
 }
Beispiel #5
0
    void Update()
    {
        if (spawningPlayers.Count > 0)
        {
            while (spawningPlayers.Count > 0)
            {
                var        userId = spawningPlayers.Dequeue();
                GameObject p      = Instantiate(NetworkPlayerPrefab);
                p.transform.parent         = transform;
                p.name                     = userId;
                playerPool[userId].created = p;
            }
        }

        foreach (var a in playerPool)
        {
            UpdateReceivePositionFromPlayer(a.Key, a.Value.playerPosition.position, a.Value.playerPosition.velocity);
            var anim = a.Value.animation;
            UpdateReceiveAnimation(a.Key, anim.HP, anim.IsGrounded, anim.Movement, anim.Dir, anim.Flap, anim.PumpProgress);
        }

        if (queuePositionChange)
        {
            queuePositionChange = false;
            OnSelfPositionUpdate.Invoke(positionChange);
        }

        if (queuePlayerCollision)
        {
            queuePlayerCollision = false;
            OnPlayerCollision.Invoke(collisionPosition);
        }

        //Delete player queue
        if (deletePlayerQueue.Count > 0)
        {
            while (deletePlayerQueue.Count > 0)
            {
                var userId = deletePlayerQueue.Dequeue();
                Destroy(playerPool[userId].created);
                playerPool.Remove(userId);
            }
        }

        if (queueRedZoneChange)
        {
            queueRedZoneChange = false;
            OnRedZoneChange.Invoke(redZoneFloat);
        }
    }
        private async void CheckPosition()
        {
            await Task.Run(async() =>
            {
                while (true)
                {
                    if (_mediaPlayer != null && _mediaPlayer.IsPlaying)
                    {
                        PositionEvent?.Invoke(_mediaPlayer.CurrentPosition, _mediaPlayer.Duration);
                    }

                    await Task.Delay(1000);
                }
            });
        }
    IEnumerator Start()
    {
        while (true)
        {
            Position newPosition = new Position
            {
                x = transform.localPosition.x,
                y = transform.localPosition.y
            };

            OnPositionUpdate.Invoke(JsonUtility.ToJson(newPosition));

            yield return(new WaitForSeconds(.1f));
        }
    }
        private void OnCollisionEnter2D(Collision2D collision)
        {
            Bubble bubble     = collision.gameObject.GetComponent <Bubble>();
            bool   hitTopWall = collision.gameObject.tag.Equals("TopWall");

            if (bubble == null && hitTopWall == false)
            {
                return;
            }
            _rigidbody.bodyType = RigidbodyType2D.Static;
            if (_hasHitSomething == false)
            {
                HitSomething.Invoke(this, transform.position);
                _hasHitSomething = true;
            }
        }
Beispiel #9
0
        private void TrackTouch()
        {
            if (isStopped)
            {
                return;
            }

            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }

            if (IsPointerOverUIObject())
            {
                return;
            }

            var touchCoords = mainCamera.ScreenToWorldPoint(Input.mousePosition);

            onTouch.Invoke(touchCoords);
        }
        //Discrete 1-Frame Transition Behaviors like Sounds and Events
        //(color changing is in a different function since it is lerped over multiple frames)
        private void ProcessStateEvents(int whichHand)
        {
            if (TriggerHoverOnElementSwitch)
            {
                if ((PrevState[whichHand] != pointerStates.OffCanvas) && (pointerState[whichHand] != pointerStates.OffCanvas))
                {
                    if (currentOverGo[whichHand] != prevOverGo[whichHand])
                    {
                        //When you begin to hover on an element
                        SoundPlayer.PlayOneShot(BeginHoverSound);
                        onHover.Invoke(Pointers[whichHand].transform.position);
                    }
                }
            }

            //Warning: Horrible State Machine ahead...
            if (PrevState[whichHand] == pointerStates.OnCanvas)
            {
                if (pointerState[whichHand] == pointerStates.OnElement)
                {
                    //When you go from hovering on the Canvas to hovering on an element
                    if (!TriggerHoverOnElementSwitch)
                    {
                        SoundPlayer.PlayOneShot(BeginHoverSound);
                        onHover.Invoke(Pointers[whichHand].transform.position);
                    }
                }
                else if (pointerState[whichHand] == pointerStates.PinchingToCanvas)
                {
                    //When you try to interact with the Canvas
                    SoundPlayer.PlayOneShot(BeginMissedSound);
                }
            }
            else if (PrevState[whichHand] == pointerStates.PinchingToCanvas)
            {
                if (pointerState[whichHand] == pointerStates.OnCanvas)
                {
                    //When you unpinch off of Blank Canvas
                    SoundPlayer.PlayOneShot(EndMissedSound);
                }
            }
            else if (PrevState[whichHand] == pointerStates.OnElement)
            {
                if (pointerState[whichHand] == pointerStates.OnCanvas)
                {
                    //When you begin to hover over the Canvas after hovering over an element
                    SoundPlayer.PlayOneShot(EndHoverSound);
                }
                else if (pointerState[whichHand] == pointerStates.PinchingToElement)
                {
                    //When you click on an element
                    SoundPlayer.PlayOneShot(BeginTriggerSound);
                    onClickDown.Invoke(Pointers[whichHand].transform.position);
                }
            }
            else if (PrevState[whichHand] == pointerStates.PinchingToElement)
            {
                if (pointerState[whichHand] == pointerStates.PinchingToCanvas)
                {
                    //When you slide off of an element while holding it
                    //SoundPlayer.PlayOneShot(HoverSound);
                }
                else if (pointerState[whichHand] == pointerStates.OnElement || pointerState[whichHand] == pointerStates.OnCanvas)
                {
                    //When you let go of an element
                    SoundPlayer.PlayOneShot(EndTriggerSound);
                    onClickUp.Invoke(Pointers[whichHand].transform.position);
                }
            }
            else if (PrevState[whichHand] == pointerStates.NearCanvas)
            {
                if (pointerState[whichHand] == pointerStates.TouchingElement)
                {
                    //When you physically touch an element
                    SoundPlayer.PlayOneShot(BeginTriggerSound);
                    onClickDown.Invoke(Pointers[whichHand].transform.position);
                }
                if (pointerState[whichHand] == pointerStates.TouchingCanvas)
                {
                    //When you physically touch Blank Canvas
                    SoundPlayer.PlayOneShot(BeginMissedSound);
                }
            }
            else if (PrevState[whichHand] == pointerStates.TouchingCanvas)
            {
                if (pointerState[whichHand] == pointerStates.NearCanvas)
                {
                    //When you physically lift off of Blank Canvas
                    SoundPlayer.PlayOneShot(EndMissedSound);
                }
            }
            else if (PrevState[whichHand] == pointerStates.TouchingElement)
            {
                if (pointerState[whichHand] == pointerStates.NearCanvas)
                {
                    //When you physically pull out of an element
                    SoundPlayer.PlayOneShot(EndTriggerSound);
                    onClickUp.Invoke(Pointers[whichHand].transform.position);
                }
            }
            else if (PrevState[whichHand] == pointerStates.OffCanvas)
            {
                if (pointerState[whichHand] != pointerStates.OffCanvas)
                {
                    //Record the time the hand entered an interactable state
                    timeEnteredCanvas[whichHand] = Time.time;
                }
            }
        }
Beispiel #11
0
 private void OnPositionChanged(SteamVR_Action_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 axis, Vector2 delta) =>
 positionEvent.Invoke(fromAction, fromSource, axis, delta);
        void Update()
        {
            //sort out mouseover stuff
            MouseoverPoint = Dungeon.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition));
            if (MouseoverPoint != PreviousMouseoverPoint)
            {
                MouseoverChangedEvent.Invoke(MouseoverPoint);
                PreviousMouseoverPoint = MouseoverPoint;
                foreach (var unit in AllUnits)
                {
                    unit.DisableUI();
                }
                var unitUnderMouse        = AllUnits.Find(u => u.transform.position == MouseoverPoint);
                var dungeonTileUnderMouse = (DungeonTile)Dungeon.GetTile(MouseoverPoint);
                if (unitUnderMouse != null)
                {
                    unitUnderMouse.EnableUI();
                }

                var dangerzoneUnderMouse = AllDangerzones.Where(d => d.transform.position == MouseoverPoint)
                                           .Select(d => d.GetComponent <DangerzoneController>()).ToList();
                dangerzoneUnderMouse.AddRange(
                    summoningCircles.Where(s => s.transform.position == MouseoverPoint).
                    Select(s => s.GetComponent <DangerzoneController>()));
                UI.ShowMouseOverInfo(dungeonTileUnderMouse, unitUnderMouse, dangerzoneUnderMouse);
            }

            if (!blockInputs)
            {
                //hot keyboard shortcuts
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    TurnFSM.SetTrigger(GameStateTransitions.Deselect);
                }
                else if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    if (UnitClicked != null && UnitClicked.MyLoadout.Abilities.Length > 0)
                    {
                        AbilityButtonClick(0);
                    }
                }
                else if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    if (UnitClicked != null && UnitClicked.MyLoadout.Abilities.Length > 1)
                    {
                        AbilityButtonClick(1);
                    }
                }
                else if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    if (UnitClicked != null && UnitClicked.MyLoadout.Abilities.Length > 2)
                    {
                        AbilityButtonClick(2);
                    }
                }

                if (Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Escape))
                {
                    TriggerTransition(GameStateTransitions.Deselect);
                }
                if (Input.GetMouseButtonDown(0))
                {
                    RaycastHit2D[] hits = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
                    foreach (var hit in hits)
                    {
                        if (hit.collider != null)
                        {
                            if (hit.collider.CompareTag("Unit"))
                            {
                                UnitClickedEvent.Invoke(hit.collider.GetComponent <UnitController>());
                            }
                            else if (hit.collider.CompareTag("UIHighlights"))
                            {
                                var destination = Dungeon.WorldToCell(hit.point);
                                //TODO: don't hardcode to first ability
                                UIHighlightClickedEvent.Invoke(destination);
                            }
                        }
                    }
                }
            }
        }