Exemplo n.º 1
0
    public void unselect()
    {
        ChangeMaterialOnMouseOver change = (ChangeMaterialOnMouseOver)selected.GetComponent(typeof(ChangeMaterialOnMouseOver));

        change.displayUnselected();
        selected = null;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (point == null)
        {
            trs.stopTRSGizmo();
            return;
        }

        if (selected != null && Input.GetMouseButton(0))
        {
            ChangeMaterialOnMouseOver change = (ChangeMaterialOnMouseOver)selected.GetComponent(typeof(ChangeMaterialOnMouseOver));
            change.displaySelected();
            currentMousePosition = Input.mousePosition;

            GetDimensionType dimension = (GetDimensionType)selected.GetComponent(typeof(GetDimensionType));

            //print (selected.name);


            if (dimension == null)
            {
                GyzmoTransformScript gyzmoScript = (GyzmoTransformScript)transform.parent.GetComponent(typeof(GyzmoTransformScript));


                if (selected.name == "TranslateMode")
                {
                    gyzmoScript.setActiveMode(0);
                }
                if (selected.name == "RotateMode")
                {
                    gyzmoScript.setActiveMode(1);
                }
                if (selected.name == "ScaleMode")
                {
                    gyzmoScript.setActiveMode(2);
                }

                return;
            }

            int dimensionType = dimension.returnDimension();

            //print ("current Dimension Type is "+dimensionType);

            if (dimensionType == 0)
            {
                gapValue = getXgap();
            }
            if (dimensionType == 1)
            {
                gapValue = getYgap();
            }
            if (dimensionType == 2)
            {
                gapValue = getXgap();
            }

            GetMode mode = (GetMode)selected.GetComponent(typeof(GetMode));
            modeValue = mode.returnMode();

            //TRANSLATE MODE
            if (modeValue == 0)
            {
                Vector3 rightDirection   = gyzmo.transform.right * XtranslationSpeed * gapValue;
                Vector3 upDirection      = gyzmo.transform.up * YtranslationSpeed * gapValue;
                Vector3 forwardDirection = gyzmo.transform.forward * ZtranslationSpeed * gapValue;

                if (myCamera.transform.position.z > point.transform.position.z)
                {
                    rightDirection *= -1;
                    //orwardDirection*=-1;
                }
                float distanceScale = scaleCamera.returnDistance() / 2;
                distanceScale = Mathf.Clamp(distanceScale, 1, 4);
                //distanceScale = 1;

                if (dimensionType == 0)
                {
                    TranslateObject(rightDirection * distanceScale);
                }
                if (dimensionType == 1)
                {
                    TranslateObject(upDirection * distanceScale);
                }
                if (dimensionType == 2)
                {
                    TranslateObject(-forwardDirection * distanceScale);
                }
            }

            //ROTATE MODE
            if (modeValue == 1)
            {
                currentTranslation = new Vector3(0, 0, 0);
                gapValue           = getXgap();
                Vector3 rightDirection   = gyzmo.transform.right * XrotationSpeed * gapValue;
                Vector3 upDirection      = gyzmo.transform.up * YrotationSpeed * gapValue;
                Vector3 forwardDirection = gyzmo.transform.forward * ZrotationSpeed * gapValue;

                previousEuler = currentEuler;

                if (dimensionType == 0)
                {
                    currentEuler = forwardDirection;
                }
                if (dimensionType == 1)
                {
                    currentEuler = rightDirection;
                }
                if (dimensionType == 2)
                {
                    currentEuler = upDirection;
                }

                RotateObject(currentEuler - previousEuler);
            }


            //SCALING MODE
            if (modeValue == 2)
            {
                currentTranslation = new Vector3(0, 0, 0);
                gapValue           = getXgap();
                //Vector3 rightDirection = gyzmo.transform.right * XrotationSpeed * gapValue ;
                //Vector3 upDirection = gyzmo.transform.up * YrotationSpeed * gapValue ;
                //Vector3 forwardDirection = gyzmo.transform.forward * ZrotationSpeed * gapValue ;

                previousEuler = currentEuler;

                if (dimensionType == 0)
                {
                    ScaleObject((float)gapValue / (float)10 * (float)scalingSpeed);
                }
                if (dimensionType == 1)
                {
                    ScaleObject((float)gapValue / (float)10 * (float)scalingSpeed);
                }
                if (dimensionType == 2)
                {
                    ScaleObject((float)gapValue / (float)10 * (float)scalingSpeed);
                }
            }
        }

        if (Input.GetMouseButtonUp(0) && trs.isActive())
        {
            saveRotation = point.transform.rotation;

            if (modeValue == 2)
            {
                GyzmoTransformScript gyzmo = trs.returnGyzmoTransform();
                //trs
                gyzmo.NormalizeScaling();
            }


            if (selected != null)
            {
                //myCamera.transform.Translate(currentTranslation);
                currentTranslation = new Vector3(0, 0, 0);
                //	myCamera.transform.LookAt(point.transform.position);

                unselect();
            }
        }
    }