示例#1
0
    void Update()
    {
        #region GamePlay
        if (!devMode)
        {
            //Create draw area
            if (Input.GetMouseButtonDown(0))
            {
                if (!clickListener.IsClickedTwice())
                {
                    displayDrawing = true;

                    drawArea = new Rect(0, 0, Screen.width, Screen.height);
                }
            }

            if (Input.GetMouseButton(0))
            {
                if (mana.GetMana() > 50)
                {
                    ductTape = true;
                }
                if (ductTape)
                {
                    GameConfig.gameSpeed = 0.25f;
                }
                else
                {
                    GameConfig.gameSpeed = 1;
                }

                if (mana.GetMana() < 1f)
                {
                    GameConfig.gameSpeed = 1f;
                    ductTape             = false;
                }
            }

            //Destroy draw area
            if (Input.GetMouseButtonUp(0))
            {
                GameConfig.gameSpeed = 1f;
                ductTape             = false;

                displayDrawing = false;

                if (drawing)
                {
                    recognized = true;

                    Gesture candidate     = new Gesture(points.ToArray());
                    Result  gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray());

                    message = gestureResult.GestureClass + " " + gestureResult.Score;
                    Debug.Log(gestureResult.Score);
                    Debug.Log(gestureResult.GestureClass);
                    if (gestureResult.Score > REQUIRED_SCORE)
                    {
                        if (!drawnWellEnough)
                        {
                            drawnWellEnough = true;
                        }
                        if (castManager.activeSpells < 1)
                        {
                            spellSpawner.FireSpell(gestureResult.GestureClass);
                            castManager.activeSpells++;
                        }
                    }
                    else
                    {
                        Debug.Log("Too poorly drawn");
                        if (drawnWellEnough)
                        {
                            drawnWellEnough = false;
                        }
                    }

                    drawing = false;
                }



                //Use to remove area
                drawArea = new Rect(0, 0, 0, 0);
            }
        }
        #endregion

        #region DevMode
        else
        {
            //Create draw area
            if (Input.GetMouseButtonDown(1))
            {
                if (!clickListener.IsClickedTwice())
                {
                    displayDrawing = true;

                    drawArea = new Rect(0, 0, Screen.width, Screen.height);
                }
            }

            if (Input.GetMouseButton(1))
            {
                if (mana.GetMana() > 50)
                {
                    ductTape = true;
                }
                if (ductTape)
                {
                    GameConfig.gameSpeed = 0.25f;
                }
                else
                {
                    GameConfig.gameSpeed = 1;
                }

                if (mana.GetMana() < 1f)
                {
                    GameConfig.gameSpeed = 1f;
                    ductTape             = false;
                }
            }

            //Destroy draw area
            if (Input.GetMouseButtonUp(1))
            {
                GameConfig.gameSpeed = 1f;
                ductTape             = false;

                displayDrawing = false;

                if (drawing)
                {
                    recognized = true;

                    Gesture candidate     = new Gesture(points.ToArray());
                    Result  gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray());

                    message = gestureResult.GestureClass + " " + gestureResult.Score;
                    Debug.Log(gestureResult.Score);
                    Debug.Log(gestureResult.GestureClass);
                    if (gestureResult.Score > REQUIRED_SCORE)
                    {
                        if (!drawnWellEnough)
                        {
                            drawnWellEnough = true;
                        }
                        if (castManager.activeSpells < 1)
                        {
                            spellSpawner.FireSpell(gestureResult.GestureClass);
                            castManager.activeSpells++;
                        }
                    }
                    else
                    {
                        Debug.Log("Too poorly drawn");
                        if (drawnWellEnough)
                        {
                            drawnWellEnough = false;
                        }
                    }

                    drawing = false;
                }

                //Use to remove area
                drawArea = new Rect(0, 0, 0, 0);
            }
        }
        #endregion


        #region DetermineInputDevicePos

        if (platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer)
        {
            if (Input.touchCount > 0)
            {
                virtualKeyPosition = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y);
            }
        }
        else
        {
            if (Input.GetMouseButton(0))
            {
                virtualKeyPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y);
            }
        }
        #endregion

        #region MouseIsUsed
        //Checks if the mouse is within the draw area
        if (drawArea.Contains(virtualKeyPosition))
        {
            if (Input.GetMouseButtonDown(0))
            {
                ++strokeId;

                Transform tmpGesture = Instantiate(gestureOnScreenPrefab, transform.position, transform.rotation) as Transform;
                currentGestureLineRenderer = tmpGesture.GetComponent <LineRenderer>();

                gestureLinesRenderer.Add(currentGestureLineRenderer);

                vertexCount = 0;
            }

            if (Input.GetMouseButton(0))
            {
                if (!drawing)
                {
                    drawing = true;
                }

                points.Add(new Point(virtualKeyPosition.x, -virtualKeyPosition.y, strokeId));

                currentGestureLineRenderer.SetVertexCount(++vertexCount);
                currentGestureLineRenderer.SetPosition(vertexCount - 1, Camera.main.ScreenToWorldPoint(new Vector3(virtualKeyPosition.x, virtualKeyPosition.y, 10)));
            }

            #endregion
        }

        //Compare and clean drawings when drawing area is removed
        if (!displayDrawing)
        {
            recognized = false;
            strokeId   = -1;

            points.Clear();

            foreach (LineRenderer lineRenderer in gestureLinesRenderer)
            {
                lineRenderer.SetVertexCount(0);
                Destroy(lineRenderer.gameObject);
            }

            gestureLinesRenderer.Clear();
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (gameCon.PlayerCanWalk() && !locked)
        {
            locked = !locked;
            animator.SetBool("Walking", true);
        }

        #region Keys
        if (usingKeys)
        {
            Vector3 pos = transform.position;

            Vector3 velocity = new Vector3(Input.GetAxis("Horizontal") * (movementSpeed * Time.deltaTime * GameConfig.gameSpeed), Input.GetAxis("Vertical") * (movementSpeed * Time.deltaTime * GameConfig.gameSpeed), 0);
            pos += velocity;
            if (pos.x > 8.5f)
            {
                pos.x = 8.5f;
            }
            else if (pos.x < -8.5f)
            {
                pos.x = -8.5f;
            }
            if (pos.y > -2)
            {
                pos.y = -2;
            }
            else if (pos.y < -5)
            {
                pos.y = -5;
            }
            transform.position = pos;
        }
        #endregion

        #region Drag
        if (usingDragMovement)
        {
            // drag controls start
            if (Input.GetMouseButton(0) && marked)
            {
                targetPos            = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
                destination.position = targetPos;
            }

            if (Input.GetMouseButtonUp(0))
            {
                marked = false;
            }
            // drag controls end



            if (Input.GetMouseButtonDown(0))
            {
                //Use mouse clicks if keys aren't being used
                Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit = Physics2D.GetRayIntersection(ray, Mathf.Infinity);

                //Make sure clicked collider isn't empty
                if (hit.collider != null)
                {
                    if (!marked)
                    {
                        if (hit.collider.gameObject.CompareTag("ClickBox"))
                        {
                            Debug.Log(hit.collider.gameObject.tag);
                            marked = true;
                        }
                    }
                }
            }

            //Cancel move command if drawing window is opened
            if (Input.GetMouseButtonDown(1) && marked)
            {
                marked = false;
            }

            if (Vector2.Distance(transform.position, destination.position) > desiredDistance)
            {
                transform.position = Vector2.MoveTowards(transform.position, destination.position, (movementSpeed * Time.deltaTime));
            }
            else
            {
                destination.position = transform.position;
            }
        }
        #endregion

        #region DoubleClick
        else if (!usingDragMovement && gameCon.GamePlayIsActive())
        {
            //Check for double clicks
            if (clickListener.IsClickedTwice())
            {
                //Set target position based on the clicked location
                targetPos            = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
                destination.position = targetPos;
                clickListener.SetBoolTwice();
            }

            //Move towards target point if it's not close enough
            if (Vector2.Distance(transform.position, destination.position) > desiredDistance)
            {
                if (inBossScene)
                {
                    animator.SetBool("Walking", true);
                }
                transform.position = Vector2.MoveTowards(transform.position, destination.position, (movementSpeed * Time.deltaTime));
            }
            //Reset target position to player position if target has been reached
            else
            {
                if (inBossScene)
                {
                    animator.SetBool("Walking", false);
                }
                destination.position = transform.position;
            }
        }
    }