Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (doFinalizeLoad)
        {
            if (!doFinalizeLoad2)
            {
                doFinalizeLoad2 = true;
            }
            else
            {
                int count = 0;
                for (int ii = 0; ii < OnlineMapsControlBase3D.instance.markers3D.Length; ii++)
                {
                    var isAsset    = false;
                    var prefabType = OnlineMapsControlBase3D.instance.markers3D[ii].prefab;

                    foreach (var assetP in assetPrefab)
                    {
                        if (prefabType.name == assetP.name)
                        {
                            isAsset = true;
                        }
                    }
                    if (!isAsset)
                    {
                        //Appropriately rename for running the study
                        if (SceneManager.GetActiveScene().name.Contains("Study") && StudyFlowControl.visualizationType.Contains("line"))
                        {
                            switch (types[count])
                            {
                            case "FanLowComponentLowUncertainty":
                                types[count] = "LineCloudLow";
                                break;

                            case "FanLowComponentMidUncertainty":
                                types[count] = "LineCloudMid";
                                break;

                            case "FanLowComponentHighUncertainty":
                                types[count] = "LineCloudHigh";
                                break;
                            }
                        }

                        var temp = OnlineMapsControlBase3D.instance.markers3D[ii].transform.gameObject.GetComponent <ConeHelper>().ChangePrefabToType(types[count], scales[count], zooms[count]);
                        temp.transform.rotation = rotations[count];
                        count++;
                    }

                    /*
                     * foreach (Transform child in OnlineMapsControlBase3D.instance.markers3D[ii].transform)
                     * {
                     *  print(child.name);
                     *  if (!child.name.Contains("Cylinder"))
                     *  {
                     *      child.rotation = rotations[ii];
                     *      OnlineMapsControlBase3D.instance.markers3D[ii].transform.gameObject.GetComponent<ConeHelper>().ChangePrefabToType(types[ii]);
                     *      break;
                     *  }
                     * }*/
                }
                rotations.Clear();
                types.Clear();

                doFinalizeLoad  = false;
                doFinalizeLoad2 = false;
            }
        }

        if (isAnimating)
        {
            GameObject.Find("TimeSlider").GetComponent <Slider>().value += 2 * Time.deltaTime;
            if (GameObject.Find("TimeSlider").GetComponent <Slider>().value >= GameObject.Find("TimeSlider").GetComponent <Slider>().maxValue)
            {
                ResetTimeInformation();
                LogHelper.AnimationLooped(StudyFlowControl.TrueQuestionID);
            }
            else
            {
                TimeStepChangedLerp();
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            //SceneManager.LoadScene("Menu", LoadSceneMode.Single);
        }

        if (!manipulationEnabled)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Home))
        {
            SaveScreenshot();
        }

        if (isDragging)
        {
            if (Input.GetMouseButtonUp(0))
            {
                isDragging = false;
                dragged    = null;
            }
            else
            {
                OnMarkerDrag(dragged);
            }
        }

        if (isRotating)
        {
            if (Input.GetMouseButtonUp(0) || rotated == null)
            {
                isRotating = false;
                rotated    = null;
            }
            else
            {
                OnRotateCone(rotated);
            }
        }
        if (Input.GetMouseButtonDown(0) && !isDragging && !isRotating && !isFileWindowOpen)
        {
            RaycastHit[] hits;
            var          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            hits = Physics.RaycastAll(ray).OrderBy(h => h.distance).ToArray();
            var bestDistance = float.MaxValue;
            OnlineMapsMarker3D bestMarker = null;
            if (hits.Length > 0)
            {
                foreach (OnlineMapsMarker3D marker in OnlineMapsControlBase3D.instance.markers3D)
                {
                    var distance = CheckHitMarker(hits, marker.instance.gameObject);
                    if (distance >= 0 && distance < bestDistance)
                    {
                        bestDistance = distance;
                        bestMarker   = marker;
                    }
                }
                if (bestMarker != null)
                {
                    OnlineMapsControlBase3D.instance.allowUserControl = false;
                    isDragging = true;
                    dragged    = bestMarker;
                    OnMarkerDrag(dragged);
                }
                if (!isDragging)
                {
                    foreach (GameObject cone in GameObject.FindGameObjectsWithTag("Uncertainty"))
                    {
                        if (CheckHit(hits, cone))
                        {
                            OnlineMapsControlBase3D.instance.allowUserControl = false;
                            isRotating = true;
                            rotated    = cone;
                            OnRotateCone(rotated);
                            break;
                        }
                    }
                }
            }
        }
        if (!isDragging && !isRotating && !isFileWindowOpen)
        {
            OnlineMapsControlBase3D.instance.allowUserControl = true;
        }
    }