Beispiel #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();
        }
    }