예제 #1
0
    /**
     * When the door is clicked, this function is called, and if the door can be opened, it moves player and generate monsters by calling functions in gameManager and boardManager.
     */
    private void OnMouseUpAsButton()
    {
        Debug.Log(isOpened + " " + gameManager.CurrentSituation);
        if (isOpened && !gameManager.CurrentSituation)
        {
            if (GetComponentsInChildren <UnityEngine.UI.Image>().Length == 1)
            {
                switch (tag)
                {
                case "EastDoor": direction = BoardManager.Direction.Right; break;

                case "WestDoor": direction = BoardManager.Direction.Left; break;

                case "NorthDoor": direction = BoardManager.Direction.UpSide; break;

                case "SouthDoor": direction = BoardManager.Direction.DownSide; break;

                default: break;
                }

                boardManager.MoveNextFloor();
                gameManager.EndPlayerTurn(Unit.Action.Move);
                gameManager.GenerateItems(boardManager.XPos, boardManager.YPos);
                gameManager.GenerateMonsters(boardManager.XPos, boardManager.YPos);
                gameManager.GenerateNPCs(boardManager.XPos, boardManager.YPos);
            }
            else
            {
                Player player = GameObject.Find("Player").GetComponent <Player>();
                if (transform.GetChild(0) == null)
                {
                    Debug.Log("문짝에서 자물쇠 오브젝트를 못찾았대 ㅋ");
                    return;
                }
                else
                {
                    if (player.InventoryList.CheckItem(ItemManager.Label.BlackCard))
                    {
                        player.UseItem(player.InventoryList.Getindex(ItemManager.Label.BlackCard));
                        Destroy(GetComponentsInChildren <UnityEngine.UI.Image>()[1].gameObject);
                    }
                    else
                    {
                        MessageMaker messageMaker = GameObject.Find("Logger").GetComponent <MessageMaker>();
                        messageMaker.MakeCannotMessage(ItemManager.Label.BlackCard);
                    }
                }
            }
        }
    }
예제 #2
0
    void GetInput()
    {
        InputEvent ievent = new InputEvent();

        ievent.init();

                #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
        //Check if Input has registered more than zero touches
        int numTouches = Input.touchCount;
        ievent.touchNum = numTouches;

        //temp storage
        Touch   myTouch;
        Vector2 touchEndpos            = new Vector2();
        BoardManager.Direction swp_dir = BoardManager.Direction.OTHER;
        bool isRotation = false;

        //update all timers
        //update TouchTapCount part 1
        if ((Time.time - multiTapStartTime) >= multiTapCD)
        {
            multiTapStartTime = Time.time;
            TouchTapCount     = 0;
        }

        //collect raw data from the device
        if (numTouches > 0)
        {
            //Store the first touch detected.
            myTouch     = Input.touches[0];
            touchEndpos = myTouch.position;

            if ((numTouches == 2) && numTouches != numTouchlastframe)
            {
                VecStart = Input.touches[0].position - Input.touches[1].position;
            }

            if (myTouch.phase == TouchPhase.Began)
            {
                hasrotated      = false;
                swipeStartPlace = myTouch.position;
                //get the vector between 2 fingers
                if (numTouches == 2)
                {
                    VecStart = myTouch.position - Input.touches[1].position;
                }
                //If so, set touchOrigin to the position of that touch
                touchOrigin = myTouch.position;
                touchTime   = Time.time;
                swp_lock    = true;
                ResetCDTimers();
            }
            else if ((myTouch.phase == TouchPhase.Ended) && swp_lock)               //deals with swipe and multiple taps
            //Set touchEnd to equal the position of this touch
            {
                hasrotated  = false;
                touchEndpos = myTouch.position;
                float x = touchEndpos.x - touchOrigin.x;
                float y = touchEndpos.y - touchOrigin.y;

                if (Mathf.Abs(x) > Mathf.Abs(y) && Mathf.Abs(x) >= minSwipeDist) //right & left
                {
                    if (x > 0)                                                   //right
                    {
                        swp_dir        = BoardManager.Direction.RIGHT;
                        ievent.isRight = true;
                    }
                    else                      //left
                    {
                        swp_dir       = BoardManager.Direction.LEFT;
                        ievent.isLeft = true;
                    }
                }
                else if (Mathf.Abs(y) > Mathf.Abs(x) && Mathf.Abs(y) >= minSwipeDist) //up & down
                {
                    if (y > 0)                                                        //up/front
                    {
                        swp_dir     = BoardManager.Direction.FRONT;
                        ievent.isUp = true;
                    }
                    else                       //down/back
                    {
                        swp_dir       = BoardManager.Direction.BACK;
                        ievent.isDown = true;
                    }
                }

                //update TouchTapCount part 2
                if ((Time.time - multiTapStartTime) < multiTapCD)
                {
                    TouchTapCount     += myTouch.tapCount;
                    ievent.elapsedTime = Time.time - touchTime;
                }

                swp_lock = false;                //flip the lock, until we find another TouchPhase.Began
            }
            else if ((numTouches == 2) && (!hasrotated))
            {
                if (numTouches == 2)                //detect a rotate
                {
                    VecEnd = Input.touches[0].position - Input.touches[1].position;
                    Vector3 cross   = Vector3.Cross((Vector3)VecStart.normalized, (Vector3)VecEnd.normalized);
                    float   crossPz = cross.z;
                    if ((crossPz >= 0) && (Mathf.Abs(crossPz) >= Screen.height * 0.00015f))                   //left
                    {
                        isRotation = true;
                        hasrotated = true;
                        if (Time.time - rotateGestStartTime >= rotateGestCD)
                        {
                            rotateGestStartTime = Time.time;
                            swp_dir             = BoardManager.Direction.LEFT;
                            ievent.isLeft       = true;
                            ievent.elapsedTime  = Time.time - touchTime;
                        }
                    }
                    else if ((crossPz < 0) && (Mathf.Abs(crossPz) >= Screen.height * 0.00015f))                    //right
                    {
                        isRotation = true;
                        hasrotated = true;
                        if (Time.time - rotateGestStartTime >= rotateGestCD)
                        {
                            rotateGestStartTime = Time.time;
                            swp_dir             = BoardManager.Direction.RIGHT;
                            ievent.isRight      = true;
                            ievent.elapsedTime  = Time.time - touchTime;
                        }
                    }
                    ievent.isRotate = true;
                }
            }
            numTouchlastframe  = numTouches;
            ievent.elapsedTime = Time.time - touchTime;
        }
        else
        {
            numTouchlastframe = 0;
        }

        float touchx = touchEndpos.x - touchOrigin.x;
        float touchy = touchEndpos.y - touchOrigin.y;

        if (Mathf.Abs(touchx) >= minSwipeDist)         //right & left
        {
            isSwipe = true;
        }
        else if (Mathf.Abs(touchy) >= minSwipeDist)            //up & down
        {
            isSwipe = true;
        }
        else
        {
            isSwipe = false;
        }

        ievent.cumulativeTouchNum = TouchTapCount;
                #elif UNITY_STANDALONE || UNITY_WEBPLAYER
        if (Input.GetKeyUp(KeyCode.RightArrow))
        {
            ievent.keycode = KeyCode.RightArrow;
        }
        else if (Input.GetKeyUp(KeyCode.LeftArrow))
        {
            ievent.keycode = KeyCode.LeftArrow;
        }
        else if (Input.GetKeyUp(KeyCode.UpArrow))
        {
            ievent.keycode = KeyCode.UpArrow;
        }
        else if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            ievent.keycode = KeyCode.DownArrow;
        }
        else if (Input.GetKeyUp("f"))
        {
            ievent.keycode = KeyCode.F;
        }
        else if (Input.GetKeyUp("e"))
        {
            ievent.keycode = KeyCode.E;
        }
        else if (Input.GetKeyUp("r"))
        {
            ievent.keycode = KeyCode.R;
        }
        else if (Input.GetKeyUp("m"))
        {
            ievent.keycode = KeyCode.M;
        }
        else
        {
            return;
        }
                #endif
        //print(touchTime);
        //if no input, code should not reach here
        PassDataToListeners(ievent);
        NotifyLlisteners();
    }