Пример #1
0
 public void moveAndRotate(GameObject pointOfCollision, Selection controller)
 {
     connectedModelingObject.StartMoving(controller, connectedModelingObject);
     //Rotate (pointOfCollision, controller, false);
 }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0) && movingHandle)
        {
            currentFocus.GetComponent <handle> ().FinishUsingHandle(this);
            movingHandle   = false;
            triggerPressed = false;
        }

        RaycastHit hit;

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (pointOfCollisionGO != null)
        {
            float distance;
            if (dragPlane.Raycast(ray, out distance))
            {
                pointOfCollisionGO.transform.position = ray.GetPoint(distance);
                //Debug.Log ("point of coll at" + pointOfCollisionGO.transform.position);
            }
        }

        // only change focus is the object is not moved at the moment

        // adjust this for touch

        if (!movingObject && !movingHandle && !scalingObject && !triggerPressed &&
            ((!TouchManager.Instance.touchActive && !Input.GetMouseButton(0) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2)) ||
             (TouchManager.Instance.touchActive)))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (Physics.Raycast(ray, out hit))
                {
                    if (currentSelectionMode == selectionMode.laserpointer)
                    {
                        pointOfCollision = hit.point;
                    }

                    if (currentSelectionMode == selectionMode.laserpointer)
                    {
                        if (hit.rigidbody != null && hit.rigidbody.transform.parent != null)
                        {
                            collisionObject = hit.rigidbody.transform.parent.gameObject;
                        }
                        else
                        {
                            collisionObject = null;
                        }
                    }

                    if (collisionObject != null)
                    {
                        if (currentFocus != collisionObject || recheckFocus)
                        {
                            count++;

                            recheckFocus = false;

                            if (collisionObject.CompareTag("ModelingObject"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <ModelingObject> ().Focus(this);
                            }
                            else if (collisionObject.CompareTag("Handle"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <handle> ().Focus(this);
                            }
                            else if (collisionObject.CompareTag("UiElement") && UiCanvasGroup.Instance.visible)
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <UiElement> ().Focus(this);
                            }
                            else if (!UiCanvasGroup.Instance.visible && collisionObject.CompareTag("TeleportTrigger"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <TeleportationTrigger> ().Focus(this);
                            }
                            else if (collisionObject.CompareTag("SelectionButton"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <ObjectSelecter> ().Focus(this);
                                if (currentFocus.GetComponent <ObjectSelecter> ().connectedObject != null)
                                {
                                    currentFocus.GetComponent <ObjectSelecter> ().connectedObject.Focus(this);
                                }
                            }
                            else if (!UiCanvasGroup.Instance.visible && collisionObject.CompareTag("TeleportPosition"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <TeleportationPosition> ().Focus(this);
                            }
                            else if (!UiCanvasGroup.Instance.visible && collisionObject.CompareTag("Library"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                library.Instance.Focus(this);
                            }
                            else if (collisionObject.CompareTag("HeightControl"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <StageHeightController> ().Focus(this);
                            }
                            else if (collisionObject.CompareTag("DistanceControl"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <StageDistanceController> ().Focus(this);
                            }
                            else if (collisionObject.CompareTag("Stage") && typeOfController == controllerType.mainController)
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <StageFreeMovement> ().Focus(this);
                            }
                            else if (collisionObject.CompareTag("InfoPanel"))
                            {
                                DeFocusCurrent(collisionObject);
                                currentFocus = collisionObject;
                                currentFocus.GetComponent <Infopanel> ().Focus(this);
                            }
                            else
                            {
                                DeFocusCurrent(null);
                            }
                        }
                    }
                    else
                    {
                        if (currentFocus != null && collisionObject == null)
                        {
                            DeFocusCurrent(null);
                            temps = Time.time;
                        }
                    }
                }
                else
                {
                    if (currentFocus != null || (currentSelectionMode == selectionMode.directTouch && collisionObject == null))
                    {
                        DeFocusCurrent(null);
                        temps = Time.time;
                    }
                }
            }
            else
            {
                if (currentFocus != null)
                {
                    DeFocusCurrent(null);
                    temps = Time.time;
                }
            }


            if (currentlyFocusedUiElement != null && currentSelection != null)
            {
                // check which element is hovered and focus right 3d handle
                if (currentlyFocusedUiElement.typeOfThis == NewUielement.typeOfUiElement.YMovement)
                {
                    GameObject chosenHandle = currentSelection.GetComponent <ModelingObject> ().handles.YMovement;
                    DeFocusCurrent(chosenHandle);
                    currentFocus = chosenHandle;
                    currentFocus.GetComponent <handle> ().Focus(this);
                    pointOfCollision = chosenHandle.transform.position;
                }
                else if (currentlyFocusedUiElement.typeOfThis == NewUielement.typeOfUiElement.UniformScale)
                {
                    GameObject chosenHandle = currentSelection.GetComponent <ModelingObject> ().handles.UniformScale.transform.GetChild(0).gameObject;
                    DeFocusCurrent(chosenHandle);
                    currentFocus = chosenHandle;
                    currentFocus.GetComponent <handle> ().Focus(this);
                    pointOfCollision = chosenHandle.transform.position;
                }
                else if (currentlyFocusedUiElement.typeOfThis == NewUielement.typeOfUiElement.ToggleRotation)
                {
                    GameObject chosenHandle = currentSelection.GetComponent <ModelingObject> ().handles.ToggleRotateOnOff;
                    DeFocusCurrent(chosenHandle);
                    currentFocus = chosenHandle;
                    currentFocus.GetComponent <handle> ().Focus(this);
                    pointOfCollision = chosenHandle.transform.position;
                }
                else if (currentlyFocusedUiElement.typeOfThis == NewUielement.typeOfUiElement.RotateX)
                {
                    GameObject chosenHandle = currentSelection.GetComponent <ModelingObject> ().handles.RotateX;
                    DeFocusCurrent(chosenHandle);
                    currentFocus = chosenHandle;
                    currentFocus.GetComponent <handle> ().Focus(this);
                    pointOfCollision = chosenHandle.transform.position;
                }
                else if (currentlyFocusedUiElement.typeOfThis == NewUielement.typeOfUiElement.RotateY)
                {
                    GameObject chosenHandle = currentSelection.GetComponent <ModelingObject> ().handles.RotateY;
                    DeFocusCurrent(chosenHandle);
                    currentFocus = chosenHandle;
                    currentFocus.GetComponent <handle> ().Focus(this);
                    pointOfCollision = chosenHandle.transform.position;
                }
                else if (currentlyFocusedUiElement.typeOfThis == NewUielement.typeOfUiElement.RotateZ)
                {
                    GameObject chosenHandle = currentSelection.GetComponent <ModelingObject> ().handles.RotateZ;
                    DeFocusCurrent(chosenHandle);
                    currentFocus = chosenHandle;
                    currentFocus.GetComponent <handle> ().Focus(this);
                    pointOfCollision = chosenHandle.transform.position;
                }
            }
        }


        if (currentFocus != null)
        {
            if (Input.GetMouseButtonDown(0))
            {
                triggerPressed = true;
                temps          = Time.time;
            }

            if (triggerPressed && (currentFocus.CompareTag("ModelingObject") || currentFocus.CompareTag("TeleportPosition") || currentFocus.CompareTag("Stage") || currentFocus.CompareTag("Library") || currentFocus.CompareTag("DistanceControl") || currentFocus.CompareTag("HeightControl")) && typeOfController == controllerType.mainController)
            {
                if (!movingObject && !groupItemSelection)
                {
                    CreatePointOfCollisionPrefab(Vector3.up);
                    //CreatePointOfCollisionPrefab (Camera.main.transform.forward * (-1f));
                    movingObject = true;

                    if (currentFocus.CompareTag("ModelingObject"))
                    {
                        Logger.Instance.AddLine(Logger.typeOfLog.triggerOnObject);

                        if (currentSelection != null && currentFocus != currentSelection)
                        {
                            //WorldLocalToggle.Instance.Hide ();
                            currentSelection.GetComponent <ModelingObject> ().DeSelect(this);
                        }

                        if (!duplicateMode)
                        {
                            currentFocus.GetComponent <ModelingObject> ().StartMoving(this, currentFocus.GetComponent <ModelingObject> ());

                            if (typeOfController == controllerType.mainController)
                            {
                                //settingsButtonHelp.HideCompletely (false);
                            }
                        }
                        else
                        {
                            if (currentFocus.GetComponent <ModelingObject> ().group == null)
                            {
                                // needs to be local position
                                ObjectCreator.Instance.DuplicateObject(currentFocus.GetComponent <ModelingObject> (), null, currentFocus.transform.localPosition);
                            }
                            else
                            {
                                ObjectCreator.Instance.DuplicateGroup(currentFocus.GetComponent <ModelingObject> ().group, Vector3.zero);
                            }

                            ModelingObject duplicatedObject = ObjectCreator.Instance.latestModelingObject;

                            DeFocusCurrent(duplicatedObject.gameObject);

                            if (currentSelection != null)
                            {
                                currentSelection.GetComponent <ModelingObject> ().DeSelect(this);
                            }

                            currentFocus = duplicatedObject.gameObject;
                            duplicatedObject.Focus(this);
                            duplicatedObject.StartMoving(this, duplicatedObject);
                        }
                    }
                    else if (currentFocus.CompareTag("Library"))
                    {
                        library.Instance.StartMoving(this);
                    }
                    else if (currentFocus.CompareTag("HeightControl"))
                    {
                        currentFocus.GetComponent <StageHeightController> ().StartMoving(this);
                    }
                    else if (currentFocus.CompareTag("DistanceControl"))
                    {
                        currentFocus.GetComponent <StageDistanceController> ().StartMoving(this);
                    }
                }
                else if (currentFocus.CompareTag("Stage"))
                {
                    currentFocus.GetComponent <StageFreeMovement> ().StartMoving(this);
                }
            }
            else if (triggerPressed && (movingHandle || currentFocus.CompareTag("Handle")))
            {
                handle currentHandle = currentFocus.GetComponent <handle> ();

                if (!movingHandle)
                {
                    CreatePointOfCollisionPrefab(Camera.main.transform.forward * (-1f));

                    if (currentHandle.typeOfHandle == handle.handleType.Rotation)
                    {
                        movingHandle = currentHandle.ApplyChanges(pointOfCollisionGO, movingHandle, this);
                    }
                    movingHandle = true;
                }
                else
                {
                    movingHandle = currentHandle.ApplyChanges(pointOfCollisionGO, movingHandle, this);
                }

                //Debug.Log ("point of collisionpos " + pointOfCollisionGO.transform.position);
                //currentHandle.connectedObject.GetComponent<ModelingObject> ().HideBoundingBox ();
                // movingHandle = true;
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            triggerPressed    = false;
            grabbedIconOffset = Vector3.zero;

            if (movingHandle)
            {
                currentFocus.GetComponent <handle> ().FinishUsingHandle(this);
                movingHandle = false;
            }


            if (movingObject && typeOfController == controllerType.mainController)
            {
                //otherController.triggerPressed = false;
                //otherController.movingHandle = false;

                recheckFocus = true;

                if (currentFocus.CompareTag("ModelingObject"))
                {
                    currentFocus.GetComponent <ModelingObject> ().StopMoving(this, currentFocus.GetComponent <ModelingObject> ());

                    if (currentFocus.GetComponent <ModelingObject> ().inTrashArea)
                    {
                        UiCanvasGroup.Instance.CloseMenu(this);
                        currentFocus.GetComponent <ModelingObject> ().TrashObject(true);
                        trashInfopanel.CloseInfoPanel();
                    }
                    else
                    {
                        if (currentSelection != null)
                        {
                            if (currentSelection != currentFocus)
                            {
                                //currentSelection.GetComponent<ModelingObject> ().DeSelect (this);

                                if (currentSettingSelectionMode == settingSelectionMode.alwaysOpen)
                                {
                                    currentFocus.GetComponent <ModelingObject> ().Select(this, uiPositon.position);
                                }
                            }
                            else
                            {
                                UiCanvasGroup.Instance.ShowAgain(uiPositon.position);
                            }
                        }
                        else
                        {
                            if (currentSettingSelectionMode == settingSelectionMode.alwaysOpen)
                            {
                                currentFocus.GetComponent <ModelingObject> ().Select(this, uiPositon.position);
                            }
                        }
                    }
                }
                else if (currentFocus.CompareTag("TeleportPosition"))
                {
                    currentFocus.GetComponent <TeleportationPosition> ().StopMoving(this);
                    Teleportation.Instance.JumpToPos(5);
                }
                else if (currentFocus.CompareTag("Library"))
                {
                    library.Instance.StopMoving(this);
                }
                else if (currentFocus.CompareTag("HeightControl"))
                {
                    currentFocus.GetComponent <StageHeightController> ().StopMoving(this);
                }
                else if (currentFocus.CompareTag("DistanceControl"))
                {
                    currentFocus.GetComponent <StageDistanceController> ().StopMoving(this);
                }
                else if (currentFocus.CompareTag("Stage"))
                {
                    currentFocus.GetComponent <StageFreeMovement> ().StopMoving(this);
                }
            }

            ///Destroy (pointOfCollisionGO);
            if (pointOfCollisionGO != null)
            {
                pointOfCollisionGO.SetActive(false);
            }

            movingObject = false;

            if (currentFocus != null)
            {
                if (currentFocus.CompareTag("ModelingObject"))
                {
                    if (groupItemSelection)
                    {
                        if (currentFocus.GetComponent <ModelingObject> ().group == null)
                        {
                            ObjectsManager.Instance.AddObjectToGroup(ObjectsManager.Instance.currentGroup, currentFocus.GetComponent <ModelingObject> ());
                        }
                        else
                        {
                            if (currentFocus.GetComponent <ModelingObject> ().group != ObjectsManager.Instance.currentGroup)
                            {
                                ObjectsManager.Instance.AddAllObjectsOfGroupToGroup(ObjectsManager.Instance.currentGroup, currentFocus.GetComponent <ModelingObject> ().group);
                            }
                        }
                    }
                }
                else if (currentFocus.CompareTag("SelectionButton"))
                {
                    UiCanvasGroup.Instance.Show();
                    currentFocus.GetComponent <ObjectSelecter> ().Select(this, uiPositon.position);
                }
                else if (currentFocus.CompareTag("Handle"))
                {
                    handle currentHandle = currentFocus.GetComponent <handle> ();
                    currentHandle.ResetLastPosition();
                    currentHandle.UnLock();
                    currentHandle.UnFocus(this);
                    currentHandle.connectedObject.GetComponent <ModelingObject> ().ShowBoundingBox(true);
                }
                else if (currentFocus.CompareTag("UiElement") && UiCanvasGroup.Instance.visible && !movingObject && !movingHandle)
                {
                    if (Time.time - tempsUI > 0.1f)
                    {
                        tempsUI = Time.time;
                        currentFocus.GetComponent <UiElement> ().PerformAction(this);

                        if (currentFocus.GetComponent <UiElement> ().goal != null)
                        {
                            currentFocus.GetComponent <UiElement> ().goal.ActivateMenu();
                        }

                        Logger.Instance.AddLine(Logger.typeOfLog.uiElement);
                    }
                }
                else if (currentFocus.CompareTag("InfoPanel"))
                {
                    currentFocus.GetComponent <Infopanel> ().CloseInfoPanel();
                }
                else if (currentFocus.CompareTag("TeleportTrigger"))
                {
                    Teleportation.Instance.JumpToPos(currentFocus.GetComponent <TeleportationTrigger> ().triggerPos);
                }
            }

            temps = 0;
        }

        if (Input.GetKeyDown(KeyCode.LeftAlt))
        {
            duplicateMode = true;
        }

        if (Input.GetKeyUp(KeyCode.LeftAlt))
        {
            duplicateMode = false;
        }
    }