Ejemplo n.º 1
0
    //Letter touch hanlder
    private void TouchLetterHandle(GameObject ob, bool isTouchBegain, Vector3 touchPos)
    {
        string obTag = ob.tag;// name of button that ray hit it
        bool   flag1 = (obTag == "Letter" || obTag == "TracingPoint" || obTag == "Background") && currentLineRender != null;
        bool   flag2 = (obTag == "TracingPoint");

        if (flag1 && !isTouchBegain)
        {//Touch Moved
            if (obTag == "TracingPoint")
            {
                TracingPoint tracingPoint = ob.GetComponent <TracingPoint>(); //get the current tracing point
                int          currentindex = tracingPoint.index;               //get the tracing point index
                if (tracingPoint.single_touch)
                {                                                             //skip if the touch is single
                    return;
                }

                if (currentindex != previousTracingPointIndex)
                {
                    currentTracingPoints.Add(currentindex);
                    ;                                         //add the current tracing point to the list
                    previousTracingPointIndex = currentindex; //set the previous tracing point
                }
            }
            else if (obTag == "Background")
            {
                clickBeganOrMovedOutOfLetterArea = true;
                EndTouchLetterHandle();
                clickStarted = false;
                return;
            }

            currentPosition   = touchPos;
            currentPosition.z = -5.0f;
            float distance = Mathf.Abs(Vector3.Distance(currentPosition, new Vector3(previousPosition.x, previousPosition.y, currentPosition.z))); //the distance between the current touch and the previous touch
            if (distance <= 0.1f)
            {                                                                                                                                      //0.1 is distance offset
                return;
            }

            previousPosition = currentPosition;                                 //set the previous position

            InstaitaeCirclePoint(currentPosition, currentLineRender.transform); //create circle point

            //add the current point to the current line
            LineRenderer           ln = currentLineRender.GetComponent <LineRenderer>();
            LineRendererAttributes line_attributes = currentLineRender.GetComponent <LineRendererAttributes>();
            int numberOfPoints = line_attributes.NumberOfPoints;
            numberOfPoints++;
            line_attributes.Points.Add(currentPosition);
            line_attributes.NumberOfPoints = numberOfPoints;
            ln.SetVertexCount(numberOfPoints);
            ln.SetPosition(numberOfPoints - 1, currentPosition);
        }
        else if (flag2 && isTouchBegain)
        {                                                                 //Touch Began
            TracingPoint tracingPoint = ob.GetComponent <TracingPoint>(); //get the tracing point
            int          currentindex = tracingPoint.index;               //get the tracing point index
            if (currentindex != previousTracingPointIndex)
            {
                currentTracingPoints.Add(currentindex);   //add the current tracing point to the list
                previousTracingPointIndex = currentindex; //set the previous tracing point

                if (currentLineRender == null)
                {
                    currentLineRender = (GameObject)Instantiate(lineRendererPrefab);//instaiate new line
                    if (setRandomColor)
                    {
                        currentLineRender.GetComponent <LineRendererAttributes>().SetRandomColor();//set a random color for the line
                        setRandomColor = false;
                    }
                }

                Vector3 currentPosition = touchPos;  //ge the current touch position
                currentPosition.z = -5.0f;
                previousPosition  = currentPosition; //set the previous position

                if (tracingPoint.single_touch)
                {
                    InstaitaeCirclePoint(currentPosition, currentLineRender.transform);//create circle point
                }
                else
                {
                    InstaitaeCirclePoint(currentPosition, currentLineRender.transform);//create circle point

                    //add the current point to the current line
                    LineRenderer           ln = currentLineRender.GetComponent <LineRenderer>();
                    LineRendererAttributes line_attributes = currentLineRender.GetComponent <LineRendererAttributes>();
                    int numberOfPoints = line_attributes.NumberOfPoints;
                    numberOfPoints++;
                    if (line_attributes.Points == null)
                    {
                        line_attributes.Points = new List <Vector3>();
                    }

                    line_attributes.Points.Add(currentPosition);
                    line_attributes.NumberOfPoints = numberOfPoints;
                    ln.SetVertexCount(numberOfPoints);
                    ln.SetPosition(numberOfPoints - 1, currentPosition);
                }
            }
        }
    }
Ejemplo n.º 2
0
    //Letter touch hanlder
    private void TouchLetterHandle(GameObject ob, bool isTouchBegan, Vector3 touchPos)
    {
        string obTag = ob.tag;        // name of button that ray hit it
        bool   flag1 = (obTag == "TracingPoint");
        bool   flag2 = (obTag == "Letter" || obTag == "TracingPoint" || obTag == "Background") && currentLineRender != null;

        if (flag1 && isTouchBegan)                                                                     //Touch Began
        {
            TracingPoint   tracingPoint = ob.GetComponent <TracingPoint> ();                           //get the tracing point
            TracingPart [] tracingParts = letters [currentLetterIndex].GetComponents <TracingPart> (); //get the tracing parts of the current letter
            foreach (TracingPart part in tracingParts)                                                 //check apakah tracing parts sesuai prioritas
            {
                if (!part.succeded)
                {
                    if (PreviousLettersPartsSucceeded(part, tracingParts))                        //check apakah tracing point mulai dr 0
                    {
                        if (tracingPoint.index != part.order [0])
                        {
                            return;
                        }
                    }
                }
            }

            int currentindex = tracingPoint.index;            //get the tracing point index
            if (currentindex != previousTracingPointIndex)
            {
                currentTracingPoints.Add(currentindex);                 //add the current tracing point to the list
                previousTracingPointIndex = currentindex;               //set the previous tracing point
                if (timeStart == 0.0f)
                {
                    timeStart = Time.time;
                }
                if (currentLineRender == null)
                {
                    currentLineRender = (GameObject)Instantiate(lineRendererPrefab);                     //instaiate new line
                    if (setRandomColor)
                    {
                        currentLineRender.GetComponent <LineRendererAttributes> ().SetRandomColor();                        //set a random color for the line
                        setRandomColor = false;
                    }
                }

                Vector3 currentPosition = touchPos;                //ge the current touch position
                currentPosition.z = -5;
                previousPosition  = currentPosition;               //set the previous position

                if (tracingPoint.single_touch)
                {
                    InstaitaeCirclePoint(currentPosition, currentLineRender.transform);                     //create circle point
                }
                else
                {
                    InstaitaeCirclePoint(currentPosition, currentLineRender.transform);                     //create circle point

                    //add the current point to the current line
                    LineRenderer           ln = currentLineRender.GetComponent <LineRenderer> ();
                    LineRendererAttributes line_attributes = currentLineRender.GetComponent <LineRendererAttributes> ();
                    int numberOfPoints = line_attributes.NumberOfPoints;
                    numberOfPoints++;
                    if (line_attributes.Points == null)
                    {
                        line_attributes.Points = new List <Vector3> ();
                    }

                    line_attributes.Points.Add(currentPosition);
                    line_attributes.NumberOfPoints = numberOfPoints;
                    ln.positionCount = (numberOfPoints);
                    ln.SetPosition(numberOfPoints - 1, currentPosition);
                }
            }
        }
        else if (flag2 && !isTouchBegan)            //Touch Moved
        {
            if (obTag == "TracingPoint")
            {
                TracingPoint tracingPoint = ob.GetComponent <TracingPoint> (); //get the current tracing point
                int          currentindex = tracingPoint.index;                //get the tracing point index
                if (tracingPoint.single_touch)                                 //skip if the touch is single
                {
                    return;
                }

                if (currentindex != previousTracingPointIndex)
                {
                    currentTracingPoints.Add(currentindex);                     //add the current tracing point to the list
                    previousTracingPointIndex = currentindex;                   //set the previous tracing point
                }
            }
            else if (obTag == "Background")
            {
                clickBeganOrMovedOutOfLetterArea = true;
                EndTouchLetterHandle();
                clickStarted = false;
                return;
            }

            currentPosition   = touchPos;
            currentPosition.z = -5.0f;
            float distance = Mathf.Abs(Vector3.Distance(currentPosition, new Vector3(previousPosition.x, previousPosition.y, currentPosition.z))); //the distance between the current touch and the previous touch
            if (distance <= 0.1f)                                                                                                                  //0.1 is distance offset
            {
                return;
            }

            previousPosition = currentPosition;            //set the previous position

            //InstaitaeCirclePoint (currentPosition, currentLineRender.transform);//create circle point

            //add the current point to the current line
            LineRenderer           ln = currentLineRender.GetComponent <LineRenderer> ();
            LineRendererAttributes line_attributes = currentLineRender.GetComponent <LineRendererAttributes> ();
            int numberOfPoints = line_attributes.NumberOfPoints;
            numberOfPoints++;
            line_attributes.Points.Add(currentPosition);
            line_attributes.NumberOfPoints = numberOfPoints;
            ln.positionCount = (numberOfPoints);
            ln.SetPosition(numberOfPoints - 1, currentPosition);
        }
    }