Exemplo n.º 1
0
    void Update()
    {
        if (!eneded)
        {
            if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) || Input.GetMouseButton(0))
            {
                //lets only include the corrdinates if it is 1 unit > than the last stored one.
                if (corrdinates.Count == 0)
                {
                    init_x = Input.mousePosition.x;
                    init_y = Input.mousePosition.y;
                    corrdinates.Add(new Tuple <float, float>(Input.mousePosition.x, Input.mousePosition.y));
                    pressure.Add(Input.GetTouch(0).pressure);
                }
                else
                {
                    float diff_x = Input.mousePosition.x - corrdinates[corrdinates.Count - 1].Item1;
                    diff_x *= diff_x;
                    float diff_y = Input.mousePosition.y - corrdinates[corrdinates.Count - 1].Item2;
                    diff_y *= diff_y;
                    if (Math.Sqrt(diff_x + diff_y) >= 1)
                    {
                        corrdinates.Add(new Tuple <float, float>(Input.mousePosition.x, Input.mousePosition.y));
                        pressure.Add(Input.GetTouch(0).pressure);
                    }
                }
                Ray   myRay = Camera.main.ScreenPointToRay(Input.mousePosition);
                float rayDistance;
                if (objPlane.Raycast(myRay, out rayDistance))
                {
                    transform.position = myRay.GetPoint(rayDistance);
                }
                RaycastHit test_hit;
                Ray        hit_ray = Generate_Ray(Input.mousePosition);
                //Send a RayCast that sense whether it hits the background gameObject
                if (Physics.Raycast(hit_ray.origin, hit_ray.direction, out test_hit))
                {
                    if (test_hit.collider != null)
                    {
                        if (test_hit.collider.GetComponent <Hit_Box>() != null)
                        {
                            //If it hits the hitbox retreive the information of the hit box.
                            Tuple <Alphabate_manager, int> val = test_hit.collider.GetComponent <Hit_Box>().F_GetsInfo();
                            int           hitBoxId             = val.Item2;
                            HashSet <int> possibleCandidate    = val.Item1.F_GetsPossibleStrokWithHitBoxId(hitBoxId);

                            //Try to determine to current stroke. By finding the intersections.
                            if (stroke_number == -1 && possibleCandidate.Count >= 1)
                            {
                                //If there is no candidate, add all in.
                                if (candidate.Count == 0)
                                {
                                    foreach (int temp in possibleCandidate)
                                    {
                                        candidate.Add(temp);
                                    }
                                }
                                // Peforming Intersection
                                else
                                {
                                    for (int q = 0; q < candidate.Count; q++)
                                    {
                                        if (possibleCandidate.Contains(candidate[q]))
                                        {
                                            candidate.Remove(candidate[q]);
                                        }
                                    }
                                }
                                //if after Intersection not possible solution, then the current one must wrote on two strokes.
                                if (candidate.Count == 0)
                                {
                                    manger.Not_Same();
                                    Destroy(gameObject);
                                    m_CheckOccurence.Clear();
                                }
                                alphbate = val.Item1;
                                if (!m_CheckOccurence.Contains(val.Item2))
                                {
                                    m_CheckOccurence.Add(val.Item2);
                                    m_hitBoxDelete.Add(val.Item2);
                                }
                            }
                            else
                            {
                                if (possibleCandidate.Contains(stroke_number))
                                {
                                    manger.Not_Same();
                                    Destroy(gameObject);
                                    m_CheckOccurence.Clear();
                                }
                                else
                                {
                                    if (!m_CheckOccurence.Contains(val.Item2))
                                    {
                                        m_CheckOccurence.Add(val.Item2);
                                        m_hitBoxDelete.Add(val.Item2);
                                    }
                                }
                            }
                        }
                        else if (test_hit.collider.tag == "Boarders")
                        {
                            manger.HitBoarders();
                        }
                    }
                }
            }
            else if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended))
            {
                eneded = true;
                manger.Insert_Strok(corrdinates, alphbate, m_hitBoxDelete, stroke_number);
                manger.InsertAll(corrdinates);
                manger.InsertPressure(pressure);
            }
        }
    }
Exemplo n.º 2
0
    public void Insert_Strok(List <Tuple <float, float> > input, Alphabate_manager alphabate, List <int> to_be_delete, int stroke_number)
    {
        if (record_mode)
        {
            string path = "Assets/Local_DataBase/Students/" + userName + "/" + stroke_to_record;
            Debug.Log("Track Path: " + path);
            StreamWriter sw = File.AppendText(path);

            float start_x = input[0].Item1;
            float start_y = input[0].Item2;

            // Modified
            sw.WriteLine(start_x + " " + start_y);

            for (int i = 1; i < input.Count; i++)
            {
                // Modified
                //sw.WriteLine((input[i].Item1 - start_x) + " " + (input[i].Item2 - start_y));
                sw.WriteLine((input[i].Item1) + " " + (input[i].Item2));
            }
            sw.Close();
        }
        else
        {
            if (alphabate == null)
            {
                Set_Error_Inactive();
                Error_Write_On_Character.SetActive(true);
                Destroy(current);
                return;
            }
            if (alphabate.Get_Assessment() == null)
            {
                Debug.Log(alphabate.gameObject.name);
                return;
            }
            tester = alphabate.Get_Assessment();
            if (current.GetComponent <Track>().Get_Stroke_Number() == -1)
            {
                Set_Error_Inactive();
                Error_Write_On_Character.SetActive(true);
                Destroy(current);
                return;
            }
            if (!alphabate.Increment_Stroke(current.GetComponent <Track>().Get_Stroke_Number()))
            {
                Set_Error_Inactive();
                Error_Incorrect_Stroke_Order.SetActive(true);
                tester.Add_Incorrect_Stroke();
                Destroy(current);
                return;
            }
            int status = alphabate.remove_Hit(to_be_delete, stroke_number, input);
            if (status == 1)
            {
                Set_Error_Inactive();
                Error_Sequence.SetActive(true);
                tester.IncorrectOrder();
                Destroy(current);
                return;
            }
            else if (status == 2)
            {
                Set_Error_Inactive();
                Error_Connections.SetActive(true);
                tester.ConnectionIssues();
                Destroy(current);
                return;
            }
            if (alphabate.finish())
            {
                Finished_one();
            }
            tester.Load_Standard(current.GetComponent <Track>().Get_Current_Alphabate().Get_Strok_Name() + current.GetComponent <Track>().Get_Stroke_Number());
            tester.compare_Deviation(input);
            if (hit_board)
            {
                tester.Add_Board();
            }
            hit_board = false;
        }
    }