Ejemplo n.º 1
0
    public void InputText(UnityEngine.UI.Text text)
    {
        if (currentBtts == null)
        {
            return;
        }

        if (text.text == "CLEAR")
        {
            currentBtts = currentBtts.ClearAll(currentArah);
            currentBtts.setToFocus();
        }
        else if (text.text == "DEL")
        {
            if (!currentBtts.wasAnswer)
            {
                currentBtts.currentAnswer = "";
            }
            currentBtts = currentBtts.getPrevBox(currentArah);
            currentBtts.setToFocus();
        }
        else
        {
            if (!currentBtts.wasAnswer)
            {
                currentBtts.currentAnswer = text.text;
            }
            currentBtts = currentBtts.getNextBox(currentArah);
            currentBtts.setToFocus();
        }
    }
Ejemplo n.º 2
0
    public void SetObjSelected(BoxTTS box)
    {
        if ((box.nextHorizontal != null || box.prevHorizontal != null) && (box.nextVertical != null || box.prevVertical != null))
        {
            Debug.Log("Persimpangan");
            SetObjSelected(box, Arah.Horizontal);
            return;
        }

        SoundBase.MAIN.PlaySound("Klik");

        if (Mathf.Abs(RightSoal.localPosition.x) < 1)
        {
            ShowRight();
        }

        int count = boxSelectedParent.childCount;

        for (int i = 0; i < count; i++)
        {
            boxSelectedParent.GetChild(0).GetComponent <BoxTTS>().setToSelected();
            boxSelectedParent.GetChild(0).GetChild(1).gameObject.SetActive(false);
            boxSelectedParent.GetChild(0).SetParent(boxNotSelectedParent);
        }

        List <GameObject> allObj = new List <GameObject>();

        box.activateSelected(ref allObj, ref currentArah, ref currentBtts);


        if (currentBtts == null)
        {
            Debug.Log("BTTS NULL");
            return;
        }


        foreach (GameObject obj in allObj)
        {
            obj.transform.SetParent(boxSelectedParent);
        }
        currentBtts.setToFocus();

        cameraTarget    = currentBtts.transform.position;
        cameraTarget.z  = -10;
        cameraTarget.y -= 3;
        movingCamera    = true;
    }
Ejemplo n.º 3
0
    public void Generate(string data)
    {
        movingCamera = false;
        string a = Resources.Load <TextAsset>("Data/TTS/" + data).text;

        Debug.Log(a);
        soals       = JsonConvert.DeserializeObject <List <Soal> >(a);
        currentBtts = null;
        foreach (Soal s in soals)
        {
            CreateTTS(s);
        }


        Transform box = boxNotSelectedParent.GetChild(Random.RandomRange(0, boxNotSelectedParent.childCount));
    }
Ejemplo n.º 4
0
    public void OnPointerUp(PointerEventData eventData)
    {
        if (isClick)
        {
            Ray ray = Camera.main.ScreenPointToRay(eventData.position);
            Debug.DrawRay(ray.origin, ray.direction * Camera.main.farClipPlane, Color.red, 5);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Camera.main.farClipPlane);
            if (hit.transform != null)
            {
                BoxTTS btts = hit.transform.GetComponent <BoxTTS>();
                if (btts != null)
                {
                    BGT.SetObjSelected(btts);
                }
                Debug.Log(hit.transform.name);
            }


            isClick = false;
        }
    }
Ejemplo n.º 5
0
    public void activateSelected(Arah arah, bool toNext, ref List <GameObject> allBoxObj, ref BoxTTS prior)
    {
        allBoxObj.Add(this.gameObject);
        backCol.gameObject.SetActive(true);

        if (_currentAnswer == "")
        {
            prior = this;
        }

        switch (arah)
        {
        case Arah.Horizontal:

            if (toNext)
            {
                if (nextHorizontal != null)
                {
                    nextHorizontal.activateSelected(Arah.Horizontal, true, ref allBoxObj, ref prior);
                }
                else
                {
                    prior = this;
                }
            }
            else
            {
                if (prevHorizontal != null)
                {
                    prevHorizontal.activateSelected(Arah.Horizontal, false, ref allBoxObj, ref prior);
                }
            }
            break;

        case Arah.Vertical:

            if (toNext)
            {
                if (nextVertical != null)
                {
                    nextVertical.activateSelected(Arah.Vertical, true, ref allBoxObj, ref prior);
                }
                else
                {
                    prior = this;
                }
            }
            else
            {
                if (prevVertical != null)
                {
                    prevVertical.activateSelected(Arah.Vertical, false, ref allBoxObj, ref prior);
                }
            }
            break;
        }
    }
Ejemplo n.º 6
0
    public void activateSelected(ref List <GameObject> allBoxObj, ref Arah currArah, ref BoxTTS prior, Arah arah)
    {
        allBoxObj.Add(this.gameObject);
        backCol.gameObject.SetActive(true);
        setToSelected();

        if (_currentAnswer == "")
        {
            prior = this;
        }


        if (arah == Arah.Horizontal)
        {
            currArah = Arah.Horizontal;
            if (nextHorizontal != null && _currentAnswer != "")
            {
                nextHorizontal.activateSelected(Arah.Horizontal, true, ref allBoxObj, ref prior);
            }
            else if (nextHorizontal != null)
            {
                nextHorizontal.activateSelected(Arah.Horizontal, true, ref allBoxObj);
            }
            else
            {
                prior = this;
            }


            if (prevHorizontal != null && _currentAnswer == "")
            {
                prevHorizontal.activateSelected(Arah.Horizontal, false, ref allBoxObj, ref prior);
            }
            else if (prevHorizontal != null)
            {
                prevHorizontal.activateSelected(Arah.Horizontal, false, ref allBoxObj);
            }
        }
        else if (arah == Arah.Vertical)
        {
            currArah = Arah.Vertical;
            if (nextVertical != null && _currentAnswer != "")
            {
                nextVertical.activateSelected(Arah.Vertical, true, ref allBoxObj, ref prior);
            }
            else if (nextVertical != null)
            {
                nextVertical.activateSelected(Arah.Vertical, true, ref allBoxObj);
            }
            else
            {
                prior = this;
            }



            if (prevVertical != null && _currentAnswer == "")
            {
                prevVertical.activateSelected(Arah.Vertical, false, ref allBoxObj, ref prior);
            }
            else if (prevVertical != null)
            {
                prevVertical.activateSelected(Arah.Vertical, false, ref allBoxObj);
            }
        }
    }
Ejemplo n.º 7
0
    public void activateSelected(ref List <GameObject> allBoxObj, ref Arah currArah, ref BoxTTS prior)
    {
        // Jika dia adalah persimpangan
        if ((nextHorizontal != null || prevHorizontal != null) && (nextVertical != null || prevVertical != null))
        {
            this.gameObject.name = "persimpangan";
            Debug.Log("Persimpangan");
            return;
        }

        allBoxObj.Add(this.gameObject);
        backCol.gameObject.SetActive(true);
        setToSelected();

        if (_currentAnswer == "")
        {
            prior = this;
        }


        if (nextHorizontal != null || prevHorizontal != null)
        {
            currArah = Arah.Horizontal;
            if (nextHorizontal != null && _currentAnswer != "")
            {
                nextHorizontal.activateSelected(Arah.Horizontal, true, ref allBoxObj, ref prior);
            }
            else if (nextHorizontal != null)
            {
                nextHorizontal.activateSelected(Arah.Horizontal, true, ref allBoxObj);
            }
            else
            {
                prior = this;
            }


            if (prevHorizontal != null && _currentAnswer == "")
            {
                prevHorizontal.activateSelected(Arah.Horizontal, false, ref allBoxObj, ref prior);
            }
            else if (prevHorizontal != null)
            {
                prevHorizontal.activateSelected(Arah.Horizontal, false, ref allBoxObj);
            }
        }
        else if (nextVertical != null || prevVertical != null)
        {
            currArah = Arah.Vertical;
            if (nextVertical != null && _currentAnswer != "")
            {
                nextVertical.activateSelected(Arah.Vertical, true, ref allBoxObj, ref prior);
            }
            else if (nextVertical != null)
            {
                nextVertical.activateSelected(Arah.Vertical, true, ref allBoxObj);
            }
            else
            {
                prior = this;
            }



            if (prevVertical != null && _currentAnswer == "")
            {
                prevVertical.activateSelected(Arah.Vertical, false, ref allBoxObj, ref prior);
            }
            else if (prevVertical != null)
            {
                prevVertical.activateSelected(Arah.Vertical, false, ref allBoxObj);
            }
        }
    }
Ejemplo n.º 8
0
    void CreateTTS(Soal soal)
    {
        BoxTTS temp = null;

        if (soal.arah == Arah.Horizontal)
        {
            if (soal.StartPos.x < width.x)
            {
                width.x = soal.StartPos.x;
            }
            if ((soal.StartPos.x + (soal.jawaban.Length - 1) > width.y))
            {
                width.y = (soal.StartPos.x + (soal.jawaban.Length - 1));
            }
        }
        else if (soal.arah == Arah.Vertical)
        {
            if (soal.StartPos.y > width.y)
            {
                height.y = soal.StartPos.y;
            }
            if ((soal.StartPos.y - (soal.jawaban.Length - 1) < height.x))
            {
                height.x = (soal.StartPos.y - (soal.jawaban.Length - 1));
            }
        }



        for (int i = 0; i < soal.jawaban.Length; i++)
        {
            Vector2      pos = new Vector2(soal.StartPos.x + (soal.arah == Arah.Horizontal ? i : 0), soal.StartPos.y - (soal.arah == Arah.Vertical ? i : 0));
            RaycastHit2D ray = Physics2D.CircleCast(pos, 0.1f, Vector2.zero, 0);

            BoxTTS btts = null;

            if (ray.transform != null)
            {
                Debug.DrawRay(ray.transform.position, (soal.arah == Arah.Horizontal ? Vector2.right : Vector2.down) * 0.1f, Color.red, 10);
                Debug.Log(ray.transform.localPosition);
                btts = ray.transform.GetComponent <BoxTTS>();
                if (btts.boxAnswer != soal.jawaban[i].ToString())
                {
                    Debug.LogError("Error : " + soal.id + " answer: (" + soal.jawaban + ") at Value " + i + " must be " + soal.jawaban[i].ToString());
                }
                if (i == 0)
                {
                    btts.transform.GetChild(2).GetComponent <TextMesh>().text = soal.id.ToString();
                    GameObject listSoal = Instantiate(listSoalPrefabs, contentListSoal);
                    listSoal.transform.GetChild(0).GetComponent <UnityEngine.UI.Text>().text = soal.id + ". " + (soal.arah == Arah.Horizontal ? "MENDATAR\n\n" : "MENURUN\n\n") + soal.pertanyaan;
                    listSoal.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => SetObjSelected(btts, soal.arah));
                }
            }
            else
            {
                GameObject box = Instantiate(boxPrefabs, pos, Quaternion.identity, boxNotSelectedParent);
                if (i == 0)
                {
                    box.transform.GetChild(2).GetComponent <TextMesh>().text = soal.id.ToString();
                    GameObject listSoal = Instantiate(listSoalPrefabs, contentListSoal);
                    listSoal.transform.GetChild(0).GetComponent <UnityEngine.UI.Text>().text = soal.id + ". " + (soal.arah == Arah.Horizontal ? "MENDATAR\n\n" : "MENURUN\n\n") + soal.pertanyaan;
                    listSoal.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => SetObjSelected(btts, soal.arah));
                }
                btts = box.GetComponent <BoxTTS>();
            }

            btts.boxAnswer = soal.jawaban[i].ToString();
            //btts.soal = soal;

            if (soal.arah == Arah.Vertical)
            {
                //Debug.Log("Done");
                btts.soalVertical = soal;
                btts.prevVertical = temp;
                if (temp != null)
                {
                    temp.nextVertical = btts;
                }
            }
            else
            {
                btts.soalHorizontal = soal;
                btts.prevHorizontal = temp;
                if (temp != null)
                {
                    temp.nextHorizontal = btts;
                }
            }
            temp = btts;
        }
    }