Exemplo n.º 1
0
    // on the cusror timed click on an active object in a scena
    private void ClickSelectEvent()
    {
        isTimer = false;
        Debug.Log("clickSelectEvent=" + curfocusType + "=" + curfocusObj);
        utility.logDebug("ClickTimed");
        switch (curfocusType)
        {
        case "Next":     // start next scena
            GameObject model = GameObject.Find("Model");
            if (model)
            {
                Destroy(model);
            }
            StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1));
            break;

        case "Test":     // test scenes activity
            GameObject gm = GameObject.Find(curfocusObj);
            StartCoroutine(utility3D.appearObject(gm, false));
            //Debug.Log(testData.selectedObjectsList.Count + "="+ JsonUtility.ToJson(testData.selectedObjectsList));
            testData.selectedObjectsList[testData.selectedObjectsList.Count - 1].objs.Add(
                new TestObject()
            {
                time  = Mathf.RoundToInt(userSceneDataTime[1] * 1000),
                i     = curfocusObjCode[0],
                lx    = curfocusObjCode[5],
                ly    = curfocusObjCode[6],
                lz    = curfocusObjCode[7],
                rx    = curfocusObjCode[8],
                type  = curfocusObjCode[1],        // cur obj type
                color = curfocusObjCode[2],        // cur obj color
            });
            userSceneDataTime[1] = 0f;
            testsConfig[curTestIndex, 4]++;
            // if this is a right object
            if (curfocusObjCode[0] != 0)
            {
                testsConfig[curTestIndex, 3]++;
            }
            //Debug.Log("obj:"+ curfocusObj + " result right:" + testsConfig[curTestIndex, 3] + " total:" + testsConfig[curTestIndex, 4]);
            // if a testing person reach a limit of objects
            if (testsConfig[curTestIndex, 4] >= testsConfig[curTestIndex, 2])
            {
                testEnd();
            }
            else
            {
                string msg = string.Format(Data.getMessage(userLang, "Test_hint"), Data.getMessage(userLang, "color_" + testsConfig[curTestIndex, 1]), Data.getMessage(userLang, "obj_" + testsConfig[curTestIndex, 0]), testsConfig[curTestIndex, 4], testsConfig[curTestIndex, 2]);
                if (isHintDisplay)
                {
                    msg += string.Format(Data.getMessage(userLang, "Test_timer"), Mathf.Floor(testTime).ToString());
                }
                if (hintText)
                {
                    hintText.text = msg;
                }
            }
            // Debug.Log("result2: right:"+testsConfig[curTestIndex, 3] + " total:"+testsConfig[curTestIndex, 4]);
            break;

        case "Keyboard":     // email input scena, typing
            if (curfocusObj.Contains("DEL"))
            {
                string str = TextInput.text;
                if (str.Length > 0)
                {
                    TextInput.text = str.Substring(0, str.Length - 1);
                }
            }
            else
            {
                if (TextInput)
                {
                    TextInput.text += curfocusObj;
                }
            }
            break;

        case "KeyboardDigit":     // input date
            string strDigit = TextInput.text;
            int    pos      = strDigit.IndexOf('X');
            char[] chars    = strDigit.ToCharArray();
            if (curfocusObj.Contains("DEL"))
            {
                Debug.Log(" digts = " + strDigit + " pos=" + pos);
                if (pos > 0)
                {
                    int jDig;
                    for (jDig = pos - 1; jDig >= 0; jDig--)
                    {
                        if (!chars[jDig].Equals(' '))
                        {
                            chars[jDig]    = 'X';
                            TextInput.text = new string(chars);
                            break;
                        }
                    }
                }
            }
            else
            {
                if (TextInput)
                {
                    chars[pos]     = curfocusObj.ToCharArray()[0];
                    TextInput.text = new string(chars);
                    if (pos > 22)
                    {
                        StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1));
                    }
                }
            }
            break;

        case "EnterName":     // save user name
            userData.name = TextInput.text;
            StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1));
            break;

        case "EnterEmail":     // save user email
            userData.email = TextInput.text;
            StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1));
            break;

        case "Exit": Application.Quit(); break;     // exit from app

        case "CloseHelp": if (modalWindow)
            {
                GameObject.Destroy(modalWindow);
            }
            ; rootObj.SetActive(true); break;

        case "ShowHelp":
            rootObj.SetActive(false);
            if (modalWindow)
            {
                GameObject.Destroy(modalWindow);
            }
            string[] arrNameHelp = curfocusObj.Split('_');
            string   msgHelp     = string.Format(Data.getMessage(userLang, "dsc" + arrNameHelp[0]), arrNameHelp[1]);
            modalWindow = utility.ShowMessage(msgHelp, "CloseHelp", Data.getMessage(userLang, "btnClose"), new Vector2(1400, 700), TextAnchor.MiddleCenter, new Vector2(0, 40));
            break;        // exit from app

        case "selOneCol": // select only one color
            StartCoroutine(colorTest.FadeTo(GameObject.Find("b_" + curfocusObj)));
            int colorIndex = 0;
            int.TryParse(curfocusObj, out colorIndex);
            testsConfig[0, 1] = colorIndex;
            testsConfig[1, 1] = colorIndex;
            //Debug.Log(testsConfig[1, 1]);
            StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1));
            break;

        case "selAllCol":     // select colors one by one
            StartCoroutine(colorTest.FadeTo(GameObject.Find("b_" + curfocusObj)));
            int colorI = 0;
            int.TryParse(curfocusObj, out colorI);
            testData.colorTestResult.selected.Add(new TestAnswer {
                id = colorI, nm = 0, t = Mathf.RoundToInt(userSceneDataTime[1] * 1000)
            });
            userSceneDataTime[1] = 0f;
            if (testData.colorTestResult.selected.Count > 6)
            {
                float s = 0; float e = 0; float[] kArray = new float[] { 8.1f, 6.8f, 6, 5.3f, 4.7f, 4, 3.2f, 1.8f };
                for (int i = 0; i < testData.colorTestResult.selected.Count; i++)
                {
                    if (i < 3)
                    {
                        if (testData.colorTestResult.selected[i].id == 0 || testData.colorTestResult.selected[i].id == 6 || testData.colorTestResult.selected[i].id == 7)
                        {
                            s += kArray[i];
                        }
                    }
                    if (i > 4)
                    {
                        if (testData.colorTestResult.selected[i].id == 1 || testData.colorTestResult.selected[i].id == 2 || testData.colorTestResult.selected[i].id == 3 || testData.colorTestResult.selected[i].id == 4)
                        {
                            s += kArray[7 - i];
                        }
                    }
                    if (testData.colorTestResult.selected[i].id == 2 || testData.colorTestResult.selected[i].id == 3 || testData.colorTestResult.selected[i].id == 4)
                    {
                        e += kArray[i];
                    }
                    //Debug.Log("Calculate: i=" +i+" color="+testData.colorTestResult.selected[i].id + " s=" +s+" e="+e); //
                }
                testData.colorTestResult.stress    = Mathf.RoundToInt(100 * s / 42);
                testData.colorTestResult.energy    = Mathf.RoundToInt(100 * (e - 9) / 12);
                testData.colorTestResult.totalTime = Mathf.RoundToInt(userSceneDataTime[0] * 1000);
                //Debug.Log("Color test result= " + JsonUtility.ToJson(testData.colorTestResult));
                StartCoroutine(utility.rotateText(rootObj, false, 5, "NextScene", 1));
            }
            break;

        case "NextQuestion":     // text test action
            int surKey = 0;
            int.TryParse(curfocusObj, out surKey);
            testData.textTestResult.answers.Add(new TestAnswer {
                id = curQuestionKey, nm = surKey, t = Mathf.RoundToInt(userSceneDataTime[1] * 1000)
            });
            userSceneDataTime[1] = 0f;
            //Debug.Log("item = " + JsonUtility.ToJson(testData.textTestResult.answers));
            if (surKey == 0)
            {
                if (Data.Answers["+"].Contains(curQuestionKey))
                {
                    testData.textTestResult.extra++;
                }
                if (Data.Answers["n"].Contains(curQuestionKey))
                {
                    testData.textTestResult.stabil++;
                }
            }
            else
            {
                if (Data.Answers["-"].Contains(curQuestionKey))
                {
                    testData.textTestResult.extra++;
                }
            }
            if (questionsCount > testData.textTestResult.answers.Count)
            {
                StartCoroutine(utility.rotateText(rootObj, false, 5, "NextQuestion", 1));
            }
            else
            {
                float cnt       = Data.getQuestionsCount(userLang) / 2;
                float resExtra  = (testData.textTestResult.extra - cnt / 2) / cnt;
                float resStabil = (testData.textTestResult.stabil - cnt / 2) / cnt;
                testData.textTestResult.totalTime = Mathf.RoundToInt(userSceneDataTime[0] * 1000);
                float    a          = Mathf.Atan2(resStabil, resExtra);
                string[] pTypeName  = new string[2];
                float[]  pTypeValue = new float[2];
                float    mid        = Mathf.PI / 4;
                float    pi_2       = Mathf.PI / 2;
                testData.textTestResult.Power = Mathf.RoundToInt(Mathf.Sqrt(Mathf.Pow(resExtra, 2) + Mathf.Pow(resStabil, 2)));
                float mod_a = Mathf.Abs(a);
                if (mod_a <= mid)
                {
                    pTypeName[0]  = "Choleric";
                    pTypeName[1]  = "Sanguine";
                    pTypeValue[0] = Mathf.Abs(mid + a) / pi_2;
                    pTypeValue[1] = Mathf.Abs(mid - a) / pi_2;
                }
                else if (mod_a >= 3 * mid)
                {
                    pTypeName[0] = "Phlegmatic";
                    pTypeName[1] = "Melancholic";
                    if (a > 0)
                    {
                        pTypeValue[0] = Mathf.Abs(a - 3 * mid) / pi_2;
                        pTypeValue[1] = Mathf.Abs(5 * mid - a) / pi_2;
                    }
                    else
                    {
                        pTypeValue[0] = Mathf.Abs(-5 * mid - a) / pi_2;
                        pTypeValue[1] = Mathf.Abs(-3 * mid - a) / pi_2;
                    }
                }
                else
                {
                    if (testData.textTestResult.stabil > 0)
                    {
                        pTypeName[0]  = "Choleric";
                        pTypeName[1]  = "Melancholic";
                        pTypeValue[0] = Mathf.Abs(3 * mid - a) / pi_2;
                        pTypeValue[1] = Mathf.Abs(mid - a) / pi_2;
                    }
                    else
                    {
                        pTypeName[0]  = "Phlegmatic";
                        pTypeName[1]  = "Sanguine";
                        pTypeValue[0] = Mathf.Abs(-mid - a) / pi_2;
                        pTypeValue[1] = Mathf.Abs(-3 * mid - a) / pi_2;
                    }
                }
                testData.textTestResult.Name1  = pTypeName[0];
                testData.textTestResult.Value1 = Mathf.RoundToInt(100 * pTypeValue[0]);
                testData.textTestResult.Name2  = pTypeName[1];
                testData.textTestResult.Value2 = Mathf.RoundToInt(100 * pTypeValue[1]);
                //Debug.Log("Test result2 = " + JsonUtility.ToJson(testData.textTestResult));
                isActionSave = false;
                testData.snenasMotionData.Add(curSnenaMotionData);
                sendDataToServer();
                dataSended = true;
                StartCoroutine(utility.rotateText(rootObj, false, 5, "NextScene", 1));
            }
            break;

        case "LangSw": animVR = false; StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", -1)); break;

        case "LangSwMenu":     // change language action
            Debug.Log("obj= " + curfocusObj);
            userLang = curfocusObj;
            StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1));
            break;

        case "GenderSwMenu":
            Debug.Log("obj= " + curfocusObj);
            userData.gender = curfocusObj;
            StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1));
            break;

        case "Back": StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", -1)); break;

        case "Repeat":     // repeat all tests
            initTestData();
            // curSnenaMotionData = new SnenaMotionData() { i = 0, act = new List<int[]>() };
            curSnenaMotionData = new SnenaMotionData()
            {
                i = 0, act = new List <UserActivity>()
            };
            curScene   = 3;
            dataSended = false;
            NextScene(0);
            break;

        case "StartGyro":
            runText.enabled = false;
            runText.text    = "";
            NextScene(1);
            break;

        default: Debug.Log("clickSelectEvent not found action for " + name); break;
        }
        OnExitTimed();
    }