Пример #1
0
    // Update is called once per frame
    void Update()
    {
        XEnumFunctionStatus current_function_status
            = XFunctionInfor.getInstance().getCurrentFunctionStatus();

        if (current_function_status != XEnumFunctionStatus.ROTATE)
        {
            TransformRotateCanvas.SetActive(false);
            return;
        }
        else
        {
            TransformRotateCanvas.SetActive(true);
        }
        GameObject current_pointing_object
            = XRayService.getInstance().getPointingObject();

        //render canvas
        THUMBDOWN.SetActive(false);
        THUMBUP.SetActive(false);
        if (current_focusing_gameobject == null)
        {
            THUMBDOWN.SetActive(true);
            //show panel to exit focusing mode
        }
        else
        {
            THUMBUP.SetActive(true);
            //show trigger to enter focusing mode
        }
        X_SHOWTAG.SetActive(false);
        Y_SHOWTAG.SetActive(false);
        Z_SHOWTAG.SetActive(false);
        //render canvas for special axis
        LEFT.SetActive(false);
        RIGHT.SetActive(false);
        BACK.SetActive(false);
        GameObject special_axis_object_out = XSpecialAxisRayService.getInstance().getPointingObject();

        if (special_axis_object_out != null)
        {
            string current_special_axis_name = special_axis_object_out.name;
            if (current_special_axis_name.IndexOf("XLEFT") >= 0)
            {
                LEFT.GetComponent <SpriteRenderer>().color = Color.red;
                LEFT.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("XRIGHT") >= 0)
            {
                RIGHT.GetComponent <SpriteRenderer>().color = Color.red;
                RIGHT.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("XBACK") >= 0)
            {
                BACK.GetComponent <SpriteRenderer>().color = Color.red;
                BACK.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("YLEFT") >= 0)
            {
                LEFT.GetComponent <SpriteRenderer>().color = Color.green;
                LEFT.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("YRIGHT") >= 0)
            {
                RIGHT.GetComponent <SpriteRenderer>().color = Color.green;
                RIGHT.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("YBACK") >= 0)
            {
                BACK.GetComponent <SpriteRenderer>().color = Color.green;
                BACK.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("ZLEFT") >= 0)
            {
                LEFT.GetComponent <SpriteRenderer>().color = Color.blue;
                LEFT.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("ZRIGHT") >= 0)
            {
                RIGHT.GetComponent <SpriteRenderer>().color = Color.blue;
                RIGHT.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("ZBACK") >= 0)
            {
                BACK.GetComponent <SpriteRenderer>().color = Color.blue;
                BACK.SetActive(true);
            }
        }
        if (current_pointing_object == null && current_focusing_gameobject == null)
        {
            return;
        }


        if (RightControllerDriver.getInstance() != null)
        {
            //trigger
            if (RightControllerDriver.getInstance().TriggerDown())
            {
                if (current_focusing_gameobject == null)
                {
                    current_focusing_gameobject = XGroupList.getInstance().getFatherFromGroupSon(current_pointing_object);
                    if (current_focusing_gameobject == null)
                    {
                        current_focusing_gameobject = current_pointing_object;
                    }
                    //spawn axises
                    GameObject XRotateAxis_X
                        = XPreSpawnObjectManager.getInstance()
                          .getXRotateAxis_X();
                    GameObject XRotateAxis_Y
                        = XPreSpawnObjectManager.getInstance()
                          .getXRotateAxis_Y();
                    GameObject XRotateAxis_Z
                        = XPreSpawnObjectManager.getInstance()
                          .getXRotateAxis_Z();
                    //set position
                    XRotateAxis_X.transform.position
                        = current_focusing_gameobject.transform.position;
                    XRotateAxis_Y.transform.position
                        = current_focusing_gameobject.transform.position;
                    XRotateAxis_Z.transform.position
                        = current_focusing_gameobject.transform.position;
                    //set scale
                    float scale_factor_x = current_focusing_gameobject.transform.localScale.x / 0.1f;
                    float scale_factor_y = current_focusing_gameobject.transform.localScale.y / 0.1f;
                    float scale_factor_z = current_focusing_gameobject.transform.localScale.z / 0.1f;
                    if (scale_factor_x > scale_factor_y)
                    {
                        if (scale_factor_x > scale_factor_z)
                        {
                            //x
                            transform_rotate_using_v3.x = current_focusing_gameobject.transform.localScale.x / 0.1f;
                            transform_rotate_using_v3.y = transform_rotate_using_v3.x / 10.0f;
                            transform_rotate_using_v3.z = transform_rotate_using_v3.x;
                            XRotateAxis_X.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Y.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Z.transform.localScale
                                = transform_rotate_using_v3;
                        }
                        else
                        {
                            //z
                            transform_rotate_using_v3.z = current_focusing_gameobject.transform.localScale.z / 0.1f;
                            transform_rotate_using_v3.x = transform_rotate_using_v3.z;
                            transform_rotate_using_v3.y = transform_rotate_using_v3.z / 10.0f;
                            XRotateAxis_X.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Y.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Z.transform.localScale
                                = transform_rotate_using_v3;
                        }
                    }
                    else
                    {
                        if (scale_factor_y > scale_factor_z)
                        {
                            //y
                            transform_rotate_using_v3.y  = current_focusing_gameobject.transform.localScale.y / 0.1f;
                            transform_rotate_using_v3.x  = transform_rotate_using_v3.y;
                            transform_rotate_using_v3.z  = transform_rotate_using_v3.y;
                            transform_rotate_using_v3.y /= 10.0f;
                            XRotateAxis_X.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Y.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Z.transform.localScale
                                = transform_rotate_using_v3;
                        }
                        else
                        {
                            //z
                            transform_rotate_using_v3.z = current_focusing_gameobject.transform.localScale.z / 0.1f;
                            transform_rotate_using_v3.x = transform_rotate_using_v3.z;
                            transform_rotate_using_v3.y = transform_rotate_using_v3.z / 10.0f;
                            XRotateAxis_X.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Y.transform.localScale
                                = transform_rotate_using_v3;
                            XRotateAxis_Z.transform.localScale
                                = transform_rotate_using_v3;
                        }
                    }
                    XRotateAxis_X.SetActive(true);
                    XRotateAxis_Y.SetActive(true);
                    XRotateAxis_Z.SetActive(true);
                }
                else
                {
                    GameObject special_axis_object = XSpecialAxisRayService.getInstance().getPointingObject();
                    if (special_axis_object != null)
                    {
                        string current_special_axis_name = special_axis_object.name;
                        if (current_special_axis_name.IndexOf("XLEFT") >= 0)
                        {
                            transform_rotate_using_v3.x = 0;
                            transform_rotate_using_v3.z = 0;
                            transform_rotate_using_v3.y = 45;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else if (current_special_axis_name.IndexOf("XRIGHT") >= 0)
                        {
                            transform_rotate_using_v3.x = 0;
                            transform_rotate_using_v3.z = 0;
                            transform_rotate_using_v3.y = -45;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else if (current_special_axis_name.IndexOf("XBACK") >= 0)
                        {
                            transform_rotate_using_v3.x = 0;
                            transform_rotate_using_v3.y = 0;
                            transform_rotate_using_v3.z = 0;
                            current_focusing_gameobject.transform.rotation = Quaternion.Euler(transform_rotate_using_v3);
                        }
                        else if (current_special_axis_name.IndexOf("YLEFT") >= 0)
                        {
                            transform_rotate_using_v3.x = 0;
                            transform_rotate_using_v3.z = 45;
                            transform_rotate_using_v3.y = 0;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else if (current_special_axis_name.IndexOf("YRIGHT") >= 0)
                        {
                            transform_rotate_using_v3.x = 0;
                            transform_rotate_using_v3.z = -45;
                            transform_rotate_using_v3.y = 0;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else if (current_special_axis_name.IndexOf("YBACK") >= 0)
                        {
                            transform_rotate_using_v3.x = 0;
                            transform_rotate_using_v3.y = 0;
                            transform_rotate_using_v3.z = 0;
                            current_focusing_gameobject.transform.rotation = Quaternion.Euler(transform_rotate_using_v3);
                        }
                        else if (current_special_axis_name.IndexOf("ZLEFT") >= 0)
                        {
                            transform_rotate_using_v3.x = 45;
                            transform_rotate_using_v3.z = 0;
                            transform_rotate_using_v3.y = 0;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else if (current_special_axis_name.IndexOf("ZRIGHT") >= 0)
                        {
                            transform_rotate_using_v3.x = -45;
                            transform_rotate_using_v3.z = 0;
                            transform_rotate_using_v3.y = 0;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else if (current_special_axis_name.IndexOf("ZBACK") >= 0)
                        {
                            transform_rotate_using_v3.x = 0;
                            transform_rotate_using_v3.y = 0;
                            transform_rotate_using_v3.z = 0;
                            current_focusing_gameobject.transform.rotation = Quaternion.Euler(transform_rotate_using_v3);
                        }
                    }
                }
                return;
            }
            if (RightControllerDriver.getInstance().Triggering())
            {
                if (current_focusing_gameobject == null)
                {
                    return;
                }
                GameObject current_pointing_axis
                    = XAxisRayService.getInstance().getPointingAxisGameObject();
                string current_axis_way = "N";
                //render canvas
                if (current_pointing_axis != null)
                {
                    string x_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXRotateAxis_X().name;
                    string y_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXRotateAxis_Y().name;
                    string z_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXRotateAxis_Z().name;
                    string current_pointing_axis_name
                        = current_pointing_axis.name;
                    if (current_pointing_axis_name.Equals(x_name))
                    {
                        //show x
                        X_SHOWTAG.SetActive(true);
                        current_axis_way = "X";
                    }
                    else if (current_pointing_axis_name.Equals(y_name))
                    {
                        //show y
                        Y_SHOWTAG.SetActive(true);
                        current_axis_way = "Y";
                    }
                    else if (current_pointing_axis_name.Equals(z_name))
                    {
                        //show z
                        Z_SHOWTAG.SetActive(true);
                        current_axis_way = "Z";
                    }
                }
                else
                {
                    //show "no axis"
                    current_axis_way = "N";
                }
                //move object and axis
                Vector3 current_pointing_axis_point;
                XAxisRayService.getInstance()
                .getPointingPoint(out current_pointing_axis_point);
                GameObject XRotateAxis_X
                    = XPreSpawnObjectManager.getInstance()
                      .getXRotateAxis_X();
                GameObject XRotateAxis_Y
                    = XPreSpawnObjectManager.getInstance()
                      .getXRotateAxis_Y();
                GameObject XRotateAxis_Z
                    = XPreSpawnObjectManager.getInstance()
                      .getXRotateAxis_Z();
                switch (current_axis_way)
                {
                case "N":
                {
                    start_colliding_point = default_vector3;
                    break;
                }

                case "X":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float x_rotated = Vector3.Distance(current_pointing_axis_point, start_colliding_point);
                        x_rotated *= 1.1f;
                        //rotate object
                        Vector3 starter_vector = start_colliding_point - current_focusing_gameobject.transform.position;
                        Vector3 ender_vector   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                        Vector3 cross_result   = Vector3.Cross(starter_vector, ender_vector);
                        transform_rotate_using_v3.x = 0;
                        transform_rotate_using_v3.z = 0;
                        if (cross_result.y > 0)
                        {
                            transform_rotate_using_v3.y = x_rotated;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else
                        {
                            transform_rotate_using_v3.y = -x_rotated;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        //move axis

                        XRotateAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XRotateAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XRotateAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }
                    break;
                }

                case "Y":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float y_rotated = Vector3.Distance(current_pointing_axis_point, start_colliding_point);
                        y_rotated *= 1.1f;
                        //rotate object
                        Vector3 starter_vector = start_colliding_point - current_focusing_gameobject.transform.position;
                        Vector3 ender_vector   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                        Vector3 cross_result   = Vector3.Cross(starter_vector, ender_vector);
                        transform_rotate_using_v3.x = 0;
                        transform_rotate_using_v3.y = 0;
                        if (cross_result.z > 0)
                        {
                            transform_rotate_using_v3.z = y_rotated;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else
                        {
                            transform_rotate_using_v3.z = -y_rotated;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        //move axis

                        XRotateAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XRotateAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XRotateAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }

                    break;
                }

                case "Z":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float z_rotated = Vector3.Distance(current_pointing_axis_point, start_colliding_point);
                        z_rotated *= 1.1f;
                        //rotate object
                        Vector3 starter_vector = start_colliding_point - current_focusing_gameobject.transform.position;
                        Vector3 ender_vector   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                        Vector3 cross_result   = Vector3.Cross(starter_vector, ender_vector);
                        transform_rotate_using_v3.z = 0;
                        transform_rotate_using_v3.y = 0;
                        if (cross_result.x > 0)
                        {
                            transform_rotate_using_v3.x = z_rotated;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        else
                        {
                            transform_rotate_using_v3.x = -z_rotated;
                            current_focusing_gameobject.transform.Rotate(transform_rotate_using_v3, Space.World);
                        }
                        //move axis

                        XRotateAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XRotateAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XRotateAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }

                    break;
                }
                }
                return;
            }
            if (RightControllerDriver.getInstance().TriggerUp())
            {
                start_colliding_point = default_vector3;

                return;
            }
            //panel
            if (RightControllerDriver.getInstance().PanelDown())
            {
                current_focusing_gameobject = null;
                //delete axis
                GameObject XRotateAxis_X
                    = XPreSpawnObjectManager.getInstance()
                      .getXRotateAxis_X();
                GameObject XRotateAxis_Y
                    = XPreSpawnObjectManager.getInstance()
                      .getXRotateAxis_Y();
                GameObject XRotateAxis_Z
                    = XPreSpawnObjectManager.getInstance()
                      .getXRotateAxis_Z();
                XRotateAxis_X.SetActive(false);
                XRotateAxis_Y.SetActive(false);
                XRotateAxis_Z.SetActive(false);
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        XEnumFunctionStatus current_function_status
            = XFunctionInfor.getInstance().getCurrentFunctionStatus();

        if (current_function_status != XEnumFunctionStatus.SCALE)
        {
            TransformScaleCanvas.SetActive(false);
            return;
        }
        else
        {
            TransformScaleCanvas.SetActive(true);
        }
        GameObject current_pointing_object
            = XRayService.getInstance().getPointingObject();

        //render canvas
        THUMBDOWN.SetActive(false);
        THUMBUP.SetActive(false);
        if (current_focusing_gameobject == null)
        {
            THUMBDOWN.SetActive(true);
            //show panel to exit focusing mode
        }
        else
        {
            THUMBUP.SetActive(true);
            //show trigger to enter focusing mode
        }
        X_SHOWTAG.SetActive(false);
        Y_SHOWTAG.SetActive(false);
        Z_SHOWTAG.SetActive(false);
        //render canvas for special axis
        X.SetActive(false);
        Y.SetActive(false);
        Z.SetActive(false);
        GameObject special_axis_object_out = XSpecialAxisRayService.getInstance().getPointingObject();

        if (special_axis_object_out != null)
        {
            string current_special_axis_name = special_axis_object_out.name;
            if (current_special_axis_name.IndexOf("Y_Z") >= 0)
            {
                Y.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("X_Z") >= 0)
            {
                Z.SetActive(true);
            }
            else if (current_special_axis_name.IndexOf("Y_X") >= 0)
            {
                X.SetActive(true);
            }
        }
        if (current_pointing_object == null && current_focusing_gameobject == null)
        {
            return;
        }
        if (RightControllerDriver.getInstance() != null)
        {
            //trigger
            if (RightControllerDriver.getInstance().TriggerDown())
            {
                if (current_focusing_gameobject == null)
                {
                    current_focusing_gameobject = XGroupList.getInstance().getFatherFromGroupSon(current_pointing_object);
                    if (current_focusing_gameobject == null)
                    {
                        current_focusing_gameobject = current_pointing_object;
                    }
                    //spawn axises
                    GameObject XScaleAxis_X
                        = XPreSpawnObjectManager.getInstance()
                          .getXScaleAxis_X();
                    GameObject XScaleAxis_Y
                        = XPreSpawnObjectManager.getInstance()
                          .getXScaleAxis_Y();
                    GameObject XScaleAxis_Z
                        = XPreSpawnObjectManager.getInstance()
                          .getXScaleAxis_Z();
                    XScaleAxis_X.transform.position
                        = current_focusing_gameobject.transform.position;
                    XScaleAxis_Y.transform.position
                        = current_focusing_gameobject.transform.position;
                    XScaleAxis_Z.transform.position
                        = current_focusing_gameobject.transform.position;
                    Vector3 current_focusing_object_rotation = current_focusing_gameobject.transform.rotation.eulerAngles;
                    //XScaleAxis_X.transform.rotation = Quaternion.Euler(current_focusing_object_rotation.x, current_focusing_object_rotation.y+90.0f, current_focusing_object_rotation.z);
                    //XScaleAxis_Y.transform.rotation = Quaternion.Euler(current_focusing_object_rotation.x+90.0f, current_focusing_object_rotation.y, current_focusing_object_rotation.z);
                    //XScaleAxis_Z.transform.rotation = Quaternion.Euler(current_focusing_object_rotation.x, current_focusing_object_rotation.y, current_focusing_object_rotation.z);
                    XScaleAxis_X.SetActive(true);
                    XScaleAxis_Y.SetActive(true);
                    XScaleAxis_Z.SetActive(true);
                }
                else
                {
                    GameObject special_axis_object = XSpecialAxisRayService.getInstance().getPointingObject();
                    if (special_axis_object != null)
                    {
                        string current_special_axis_name = special_axis_object.name;
                        if (current_special_axis_name.IndexOf("Y_Z") >= 0)
                        {
                            transform_scale_using_v3.x = current_focusing_gameobject.transform.localScale.x;
                            transform_scale_using_v3.z = current_focusing_gameobject.transform.localScale.z;
                            transform_scale_using_v3.y = current_focusing_gameobject.transform.localScale.y;
                            if (transform_scale_using_v3.z > transform_scale_using_v3.y)
                            {
                                transform_scale_using_v3.y = transform_scale_using_v3.z;
                            }
                            else
                            {
                                transform_scale_using_v3.z = transform_scale_using_v3.y;
                            }
                            current_focusing_gameobject.transform.localScale = transform_scale_using_v3;
                        }
                        else if (current_special_axis_name.IndexOf("X_Z") >= 0)
                        {
                            transform_scale_using_v3.x = current_focusing_gameobject.transform.localScale.x;
                            transform_scale_using_v3.z = current_focusing_gameobject.transform.localScale.z;
                            transform_scale_using_v3.y = current_focusing_gameobject.transform.localScale.y;
                            if (transform_scale_using_v3.x > transform_scale_using_v3.z)
                            {
                                transform_scale_using_v3.z = transform_scale_using_v3.x;
                            }
                            else
                            {
                                transform_scale_using_v3.x = transform_scale_using_v3.z;
                            }
                            current_focusing_gameobject.transform.localScale = transform_scale_using_v3;
                        }
                        else if (current_special_axis_name.IndexOf("Y_X") >= 0)
                        {
                            transform_scale_using_v3.x = current_focusing_gameobject.transform.localScale.x;
                            transform_scale_using_v3.z = current_focusing_gameobject.transform.localScale.z;
                            transform_scale_using_v3.y = current_focusing_gameobject.transform.localScale.y;
                            if (transform_scale_using_v3.x > transform_scale_using_v3.y)
                            {
                                transform_scale_using_v3.y = transform_scale_using_v3.x;
                            }
                            else
                            {
                                transform_scale_using_v3.x = transform_scale_using_v3.y;
                            }
                            current_focusing_gameobject.transform.localScale = transform_scale_using_v3;
                        }
                    }
                    return;
                }
            }
            if (RightControllerDriver.getInstance().Triggering())
            {
                if (current_focusing_gameobject == null)
                {
                    return;
                }
                GameObject current_pointing_axis
                    = XAxisRayService.getInstance().getPointingAxisGameObject();
                string current_axis_way = "N";
                //render canvas
                if (current_pointing_axis != null)
                {
                    string x_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXScaleAxis_X().name;
                    string y_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXScaleAxis_Y().name;
                    string z_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXScaleAxis_Z().name;
                    string current_pointing_axis_name
                        = current_pointing_axis.name;
                    if (current_pointing_axis_name.Equals(x_name))
                    {
                        //show x
                        X_SHOWTAG.SetActive(true);
                        current_axis_way = "X";
                    }
                    else if (current_pointing_axis_name.Equals(y_name))
                    {
                        //show y
                        Y_SHOWTAG.SetActive(true);
                        current_axis_way = "Y";
                    }
                    else if (current_pointing_axis_name.Equals(z_name))
                    {
                        //show z
                        Z_SHOWTAG.SetActive(true);
                        current_axis_way = "Z";
                    }
                }
                else
                {
                    //show "no axis"
                    current_axis_way = "N";
                }
                //move object and axis
                Vector3 current_pointing_axis_point;
                XAxisRayService.getInstance()
                .getPointingPoint(out current_pointing_axis_point);
                switch (current_axis_way)
                {
                case "N":
                {
                    start_colliding_point = default_vector3;
                    break;
                }

                case "X":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float x_scaled = current_pointing_axis_point.x - start_colliding_point.x;
                        //move object
                        transform_scale_using_v3.x
                            = current_focusing_gameobject.transform.localScale.x
                              + x_scaled;
                        transform_scale_using_v3.y
                            = current_focusing_gameobject.transform.localScale.y;
                        transform_scale_using_v3.z
                            = current_focusing_gameobject.transform.localScale.z;
                        current_focusing_gameobject.transform.localScale
                            = transform_scale_using_v3;
                        start_colliding_point = current_pointing_axis_point;
                        //move axis
                        GameObject XScaleAxis_X
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_X();
                        GameObject XScaleAxis_Y
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_Y();
                        GameObject XScaleAxis_Z
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_Z();
                        XScaleAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XScaleAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XScaleAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }
                    break;
                }

                case "Y":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float y_scaled = current_pointing_axis_point.y - start_colliding_point.y;
                        //move object
                        transform_scale_using_v3.y
                            = current_focusing_gameobject.transform.localScale.y
                              + y_scaled;
                        transform_scale_using_v3.x
                            = current_focusing_gameobject.transform.localScale.x;
                        transform_scale_using_v3.z
                            = current_focusing_gameobject.transform.localScale.z;
                        current_focusing_gameobject.transform.localScale
                            = transform_scale_using_v3;
                        start_colliding_point = current_pointing_axis_point;
                        //move axis
                        GameObject XScaleAxis_X
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_X();
                        GameObject XScaleAxis_Y
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_Y();
                        GameObject XScaleAxis_Z
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_Z();
                        XScaleAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XScaleAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XScaleAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }
                    break;
                }

                case "Z":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float z_scaled = current_pointing_axis_point.z - start_colliding_point.z;
                        //move object
                        transform_scale_using_v3.z
                            = current_focusing_gameobject.transform.localScale.z
                              + z_scaled;
                        transform_scale_using_v3.x
                            = current_focusing_gameobject.transform.localScale.x;
                        transform_scale_using_v3.y
                            = current_focusing_gameobject.transform.localScale.y;
                        current_focusing_gameobject.transform.localScale
                            = transform_scale_using_v3;
                        start_colliding_point = current_pointing_axis_point;
                        //move axis
                        GameObject XScaleAxis_X
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_X();
                        GameObject XScaleAxis_Y
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_Y();
                        GameObject XScaleAxis_Z
                            = XPreSpawnObjectManager.getInstance()
                              .getXScaleAxis_Z();
                        XScaleAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XScaleAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XScaleAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }
                    break;
                }
                }
                return;
            }
            if (RightControllerDriver.getInstance().TriggerUp())
            {
                start_colliding_point = default_vector3;
                return;
            }
            //panel
            if (RightControllerDriver.getInstance().PanelDown())
            {
                current_focusing_gameobject = null;
                //delete axis
                GameObject XScaleAxis_X
                    = XPreSpawnObjectManager.getInstance()
                      .getXScaleAxis_X();
                GameObject XScaleAxis_Y
                    = XPreSpawnObjectManager.getInstance()
                      .getXScaleAxis_Y();
                GameObject XScaleAxis_Z
                    = XPreSpawnObjectManager.getInstance()
                      .getXScaleAxis_Z();
                XScaleAxis_X.SetActive(false);
                XScaleAxis_Y.SetActive(false);
                XScaleAxis_Z.SetActive(false);
            }
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        XEnumFunctionStatus current_function_status
            = XFunctionInfor.getInstance().getCurrentFunctionStatus();

        if (current_function_status != XEnumFunctionStatus.ARRAY)
        {
            ObjectArrayCanvas.SetActive(false);
            return;
        }
        else
        {
            ObjectArrayCanvas.SetActive(true);
        }
        //render canvas
        WANT_COUNT.GetComponent <Text>().text = "COPY COUNT\n:\n[" + array_object_want_count + "]";
        THUMBDOWN.SetActive(false);
        THUMBUP.SetActive(false);
        if (current_focusing_gameobject == null)
        {
            THUMBDOWN.SetActive(true);
            //show panel to exit focusing mode
        }
        else
        {
            THUMBUP.SetActive(true);
            //show trigger to enter focusing mode
        }
        X_SHOWTAG.SetActive(false);
        Y_SHOWTAG.SetActive(false);
        Z_SHOWTAG.SetActive(false);
        X.SetActive(false);
        Y.SetActive(false);
        Z.SetActive(false);
        GameObject current_pointing_object
            = XRayService.getInstance().getPointingObject();

        //render objects
        if (current_focusing_gameobject != null)
        {
            GameObject current_pointing_axis
                = XAxisRayService.getInstance().getPointingAxisGameObject();
            string current_axis_way = "N";
            //render canvas
            if (current_pointing_axis != null)
            {
                string x_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_X().name;
                string y_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_Y().name;
                string z_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_Z().name;
                string xy_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XY().name;
                string xz_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XZ().name;
                string yz_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_YZ().name;
                string xy1_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XY_1().name;
                string xz1_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XZ_1().name;
                string yz1_name
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_YZ_1().name;
                string current_pointing_axis_name
                    = current_pointing_axis.name;
                if (current_pointing_axis_name.Equals(x_name))
                {
                    //show x
                    X_SHOWTAG.SetActive(true);
                    current_axis_way = "X";
                }
                else if (current_pointing_axis_name.Equals(y_name))
                {
                    //show y
                    Y_SHOWTAG.SetActive(true);
                    current_axis_way = "Y";
                }
                else if (current_pointing_axis_name.Equals(z_name))
                {
                    //show z
                    Z_SHOWTAG.SetActive(true);
                    current_axis_way = "Z";
                }
                else if (current_pointing_axis_name.Equals(xy_name) || current_pointing_axis_name.Equals(xy1_name))
                {
                    //show XY
                    //Z_SHOWTAG.SetActive(true);
                    X.SetActive(true);
                    current_axis_way = "XY";
                }
                else if (current_pointing_axis_name.Equals(xz_name) || current_pointing_axis_name.Equals(xz1_name))
                {
                    //show XY
                    //Z_SHOWTAG.SetActive(true);
                    Z.SetActive(true);
                    current_axis_way = "XZ";
                }
                else if (current_pointing_axis_name.Equals(yz_name) || current_pointing_axis_name.Equals(yz1_name))
                {
                    //show XY
                    //Z_SHOWTAG.SetActive(true);
                    Y.SetActive(true);
                    current_axis_way = "YZ";
                }
            }
            else
            {
                //show "no axis"
                current_axis_way = "N";
            }
            //render clone object declaration
            Vector3 current_pointing_axis_point;
            XAxisRayService.getInstance()
            .getPointingPoint(out current_pointing_axis_point);
            switch (current_axis_way)
            {
            case "N":
            {
                //show nothing
                for (int i = 0; i != pre_spawn_declaringobject_list.Count; i++)
                {
                    pre_spawn_declaringobject_list[i].SetActive(false);
                }
                for (int i = 0; i != pre_spawn_declaringobject_list_back.Count; i++)
                {
                    pre_spawn_declaringobject_list_back[i].SetActive(false);
                }
                middle_declaringobject.SetActive(false);
                break;
            }

            case "X":
            {
                float object_point_axis_distance = Vector3.Distance(current_pointing_axis_point, current_focusing_gameobject.transform.position);
                transform_array_using_v3 = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.x < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                float internal_distance = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.x += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list[i].SetActive(true);
                }
                break;
            }

            case "Y":
            {
                float object_point_axis_distance = Vector3.Distance(current_pointing_axis_point, current_focusing_gameobject.transform.position);
                transform_array_using_v3 = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.y < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                float internal_distance = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.y += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list[i].SetActive(true);
                }
                break;
            }

            case "Z":
            {
                float object_point_axis_distance = Vector3.Distance(current_pointing_axis_point, current_focusing_gameobject.transform.position);
                transform_array_using_v3 = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.z < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                float internal_distance = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.z += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list[i].SetActive(true);
                }
                break;
            }

            case "XY":
            {
                float object_point_axis_distance;
                float internal_distance;
                //x
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.x = current_pointing_axis_point.x;
                object_point_axis_distance = Vector3.Distance(transform_array_using_v3, current_focusing_gameobject.transform.position);
                transform_array_using_v3   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.x < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                internal_distance            = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.x += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list[i].SetActive(true);
                }
                //y
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.y = current_pointing_axis_point.y;
                object_point_axis_distance = Vector3.Distance(transform_array_using_v3, current_focusing_gameobject.transform.position);
                transform_array_using_v3   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.y < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                internal_distance            = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.y += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list_back[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list_back[i].SetActive(true);
                }
                //middle
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.x = current_pointing_axis_point.x;
                transform_array_using_v3.y = current_pointing_axis_point.y;
                middle_declaringobject.transform.position = transform_array_using_v3;
                middle_declaringobject.SetActive(true);
                break;
            }

            case "XZ":
            {
                float object_point_axis_distance;
                float internal_distance;
                //x
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.x = current_pointing_axis_point.x;
                object_point_axis_distance = Vector3.Distance(transform_array_using_v3, current_focusing_gameobject.transform.position);
                transform_array_using_v3   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.x < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                internal_distance            = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.x += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list[i].SetActive(true);
                }
                //z
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.z = current_pointing_axis_point.z;
                object_point_axis_distance = Vector3.Distance(transform_array_using_v3, current_focusing_gameobject.transform.position);
                transform_array_using_v3   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.z < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                internal_distance            = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.z += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list_back[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list_back[i].SetActive(true);
                }
                //middle
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.x = current_pointing_axis_point.x;
                transform_array_using_v3.z = current_pointing_axis_point.z;
                middle_declaringobject.transform.position = transform_array_using_v3;
                middle_declaringobject.SetActive(true);
                break;
            }

            case "YZ":
            {
                float object_point_axis_distance;
                float internal_distance;
                //y
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.y = current_pointing_axis_point.y;
                object_point_axis_distance = Vector3.Distance(transform_array_using_v3, current_focusing_gameobject.transform.position);
                transform_array_using_v3   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.y < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                internal_distance            = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.y += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list[i].SetActive(true);
                }
                //z
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.z = current_pointing_axis_point.z;
                object_point_axis_distance = Vector3.Distance(transform_array_using_v3, current_focusing_gameobject.transform.position);
                transform_array_using_v3   = current_pointing_axis_point - current_focusing_gameobject.transform.position;
                if (transform_array_using_v3.z < 0)
                {
                    object_point_axis_distance = -object_point_axis_distance;
                }
                internal_distance            = (object_point_axis_distance / array_object_want_count);
                array_saving_origin_material = current_focusing_gameobject.GetComponent <Renderer>().material;
                for (int i = 0; i != array_object_want_count; i++)
                {
                    transform_array_using_v3.x  = current_focusing_gameobject.transform.position.x;
                    transform_array_using_v3.y  = current_focusing_gameobject.transform.position.y;
                    transform_array_using_v3.z  = current_focusing_gameobject.transform.position.z;
                    transform_array_using_v3.z += internal_distance * (i + 1);
                    pre_spawn_declaringobject_list_back[i].transform.position = transform_array_using_v3;
                    pre_spawn_declaringobject_list_back[i].SetActive(true);
                }
                //middle
                transform_array_using_v3.x = current_focusing_gameobject.transform.position.x;
                transform_array_using_v3.y = current_focusing_gameobject.transform.position.y;
                transform_array_using_v3.z = current_focusing_gameobject.transform.position.z;
                transform_array_using_v3.y = current_pointing_axis_point.y;
                transform_array_using_v3.z = current_pointing_axis_point.z;
                middle_declaringobject.transform.position = transform_array_using_v3;
                middle_declaringobject.SetActive(true);
                break;
            }
            }
        }
        if (current_pointing_object == null && current_focusing_gameobject == null)
        {
            return;
        }

        if (RightControllerDriver.getInstance() != null)
        {
            if (RightControllerDriver.getInstance().TriggerDown())
            {
                if (current_focusing_gameobject == null)
                {
                    current_focusing_gameobject = XGroupList.getInstance().getFatherFromGroupSon(current_pointing_object);
                    if (current_focusing_gameobject == null)
                    {
                        current_focusing_gameobject = current_pointing_object;
                    }
                    //spawn axises
                    GameObject XArrayAxis_X
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_X();
                    GameObject XArrayAxis_Y
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_Y();
                    GameObject XArrayAxis_Z
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_Z();
                    GameObject XArrayAxis_XY
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_XY();
                    GameObject XArrayAxis_YZ
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_YZ();
                    GameObject XArrayAxis_XZ
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_XZ();
                    GameObject XArrayAxis_XY_1
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_XY_1();
                    GameObject XArrayAxis_YZ_1
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_YZ_1();
                    GameObject XArrayAxis_XZ_1
                        = XPreSpawnObjectManager.getInstance()
                          .getXArrayAxis_XZ_1();
                    XArrayAxis_X.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_Y.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_Z.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_XY.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_YZ.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_XZ.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_XY_1.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_YZ_1.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_XZ_1.transform.position
                        = current_focusing_gameobject.transform.position;
                    XArrayAxis_X.SetActive(true);
                    XArrayAxis_Y.SetActive(true);
                    XArrayAxis_Z.SetActive(true);
                    XArrayAxis_XY.SetActive(true);
                    XArrayAxis_YZ.SetActive(true);
                    XArrayAxis_XZ.SetActive(true);
                    XArrayAxis_XY_1.SetActive(true);
                    XArrayAxis_YZ_1.SetActive(true);
                    XArrayAxis_XZ_1.SetActive(true);
                    //pre spawn objects
                    for (int i = 0; i != pre_spawn_declaringobject_list.Count; i++)
                    {
                        GameObject.Destroy(pre_spawn_declaringobject_list[i]);
                    }
                    pre_spawn_declaringobject_list.Clear();
                    for (int i = 0; i != array_object_want_count; i++)
                    {
                        GameObject current_prespawn = GameObject.Instantiate(current_focusing_gameobject);
                        current_prespawn.name = current_prespawn.name.Replace("(Clone)", "");
                        pre_spawn_declaringobject_list.Add(current_prespawn);
                        current_prespawn.GetComponent <Renderer>().material = DECLARATION_MATERIAL;
                        current_prespawn.SetActive(false);
                    }

                    for (int i = 0; i != pre_spawn_declaringobject_list_back.Count; i++)
                    {
                        GameObject.Destroy(pre_spawn_declaringobject_list_back[i]);
                    }
                    pre_spawn_declaringobject_list_back.Clear();
                    for (int i = 0; i != array_object_want_count; i++)
                    {
                        GameObject current_prespawn = GameObject.Instantiate(current_focusing_gameobject);
                        current_prespawn.name = current_prespawn.name.Replace("(Clone)", "");
                        pre_spawn_declaringobject_list_back.Add(current_prespawn);
                        current_prespawn.GetComponent <Renderer>().material = DECLARATION_MATERIAL;
                        current_prespawn.SetActive(false);
                    }

                    GameObject.Destroy(middle_declaringobject);
                    middle_declaringobject      = GameObject.Instantiate(current_focusing_gameobject);
                    middle_declaringobject.name = middle_declaringobject.name.Replace("(Clone)", "");
                    middle_declaringobject.GetComponent <Renderer>().material = DECLARATION_MATERIAL;
                    middle_declaringobject.SetActive(false);
                }
                else
                {
                    //instantiate objects
                    GameObject current_pointing_axis
                        = XAxisRayService.getInstance().getPointingAxisGameObject();
                    if (current_pointing_axis != null)
                    {
                        for (int i = 0; i != pre_spawn_declaringobject_list.Count; i++)
                        {
                            GameObject current_ins = GameObject.Instantiate(pre_spawn_declaringobject_list[i]);
                            current_ins.name = current_ins.name.Replace("(Clone)", "");
                            current_ins.GetComponent <Renderer>().material = array_saving_origin_material;
                        }
                        if (pre_spawn_declaringobject_list_back[0].activeSelf)
                        {
                            for (int i = 0; i != pre_spawn_declaringobject_list_back.Count; i++)
                            {
                                GameObject current_ins = GameObject.Instantiate(pre_spawn_declaringobject_list_back[i]);
                                current_ins.name = current_ins.name.Replace("(Clone)", "");
                                current_ins.GetComponent <Renderer>().material = array_saving_origin_material;
                            }
                            GameObject middle_ins = GameObject.Instantiate(middle_declaringobject);
                            middle_ins.name = middle_ins.name.Replace("(Clone)", "");
                            middle_ins.GetComponent <Renderer>().material = array_saving_origin_material;
                        }
                    }
                }
                return;
            }
            if (RightControllerDriver.getInstance().TriggerUp())
            {
                return;
            }
            //panel
            if (RightControllerDriver.getInstance().PanelDown())
            {
                //show nothing
                for (int i = 0; i != pre_spawn_declaringobject_list.Count; i++)
                {
                    pre_spawn_declaringobject_list[i].SetActive(false);
                }
                for (int i = 0; i != pre_spawn_declaringobject_list_back.Count; i++)
                {
                    pre_spawn_declaringobject_list_back[i].SetActive(false);
                }
                middle_declaringobject.SetActive(false);
                current_focusing_gameobject = null;
                //delete axis
                GameObject XArrayAxis_X
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_X();
                GameObject XArrayAxis_Y
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_Y();
                GameObject XArrayAxis_Z
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_Z();
                GameObject XArrayAxis_XY
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XY();
                GameObject XArrayAxis_YZ
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_YZ();
                GameObject XArrayAxis_XZ
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XZ();
                GameObject XArrayAxis_XY_1
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XY_1();
                GameObject XArrayAxis_YZ_1
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_YZ_1();
                GameObject XArrayAxis_XZ_1
                    = XPreSpawnObjectManager.getInstance()
                      .getXArrayAxis_XZ_1();
                XArrayAxis_X.SetActive(false);
                XArrayAxis_Y.SetActive(false);
                XArrayAxis_Z.SetActive(false);
                XArrayAxis_XY.SetActive(false);
                XArrayAxis_YZ.SetActive(false);
                XArrayAxis_XZ.SetActive(false);
                XArrayAxis_XY_1.SetActive(false);
                XArrayAxis_YZ_1.SetActive(false);
                XArrayAxis_XZ_1.SetActive(false);
                return;
            }
            if (RightControllerDriver.getInstance().GripDown())
            {
                //low array_object_want_count
                if (array_object_want_count != 1)
                {
                    array_object_want_count--;
                    if (current_focusing_gameobject != null)
                    {
                        GameObject
                        .Destroy(pre_spawn_declaringobject_list[pre_spawn_declaringobject_list.Count - 1]);
                        GameObject
                        .Destroy(pre_spawn_declaringobject_list_back[pre_spawn_declaringobject_list_back.Count - 1]);
                        pre_spawn_declaringobject_list.RemoveAt(pre_spawn_declaringobject_list.Count - 1);
                        pre_spawn_declaringobject_list_back.RemoveAt(pre_spawn_declaringobject_list_back.Count - 1);
                    }
                }
                return;
            }
            if (LeftControllerDriver.getInstance() != null)
            {
                if (LeftControllerDriver.getInstance().GripDown())
                {
                    //add array_object_want_count
                    array_object_want_count++;
                    if (current_focusing_gameobject != null)
                    {
                        //pre spawn objects
                        GameObject current_ins = Instantiate(pre_spawn_declaringobject_list[0]);
                        current_ins.name = current_ins.name.Replace("(Clone)", "");
                        pre_spawn_declaringobject_list.Add(current_ins);
                    }
                    if (current_focusing_gameobject != null)
                    {
                        //pre spawn objects
                        GameObject current_ins = Instantiate(pre_spawn_declaringobject_list_back[0]);
                        current_ins.name = current_ins.name.Replace("(Clone)", "");
                        pre_spawn_declaringobject_list_back.Add(current_ins);
                    }
                    return;
                }
            }
        }
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        XEnumFunctionStatus current_function_status
            = XFunctionInfor.getInstance().getCurrentFunctionStatus();

        if (current_function_status != XEnumFunctionStatus.MOVE)
        {
            TransformMoveCanvas.SetActive(false);
            return;
        }
        else
        {
            TransformMoveCanvas.SetActive(true);
        }
        GameObject current_pointing_object
            = XRayService.getInstance().getPointingObject();

        //render canvas
        THUMBDOWN.SetActive(false);
        THUMBUP.SetActive(false);
        if (current_focusing_gameobject == null)
        {
            THUMBDOWN.SetActive(true);
            //show panel to exit focusing mode
        }
        else
        {
            THUMBUP.SetActive(true);
            //show trigger to enter focusing mode
        }
        X_SHOWTAG.SetActive(false);
        Y_SHOWTAG.SetActive(false);
        Z_SHOWTAG.SetActive(false);
        if (current_pointing_object == null && current_focusing_gameobject == null)
        {
            return;
        }


        //htc vive handler event
        if (RightControllerDriver.getInstance() != null)
        {
            //trigger
            if (RightControllerDriver.getInstance().TriggerDown())
            {
                if (current_focusing_gameobject == null)
                {
                    current_focusing_gameobject = XGroupList.getInstance().getFatherFromGroupSon(current_pointing_object);
                    if (current_focusing_gameobject == null)
                    {
                        current_focusing_gameobject = current_pointing_object;
                    }
                    //spawn axises
                    GameObject XMovingAxis_X
                        = XPreSpawnObjectManager.getInstance()
                          .getXMovingAxis_X();
                    GameObject XMovingAxis_Y
                        = XPreSpawnObjectManager.getInstance()
                          .getXMovingAxis_Y();
                    GameObject XMovingAxis_Z
                        = XPreSpawnObjectManager.getInstance()
                          .getXMovingAxis_Z();
                    XMovingAxis_X.transform.position
                        = current_focusing_gameobject.transform.position;
                    XMovingAxis_Y.transform.position
                        = current_focusing_gameobject.transform.position;
                    XMovingAxis_Z.transform.position
                        = current_focusing_gameobject.transform.position;
                    XMovingAxis_X.SetActive(true);
                    XMovingAxis_Y.SetActive(true);
                    XMovingAxis_Z.SetActive(true);
                }
                return;
            }
            if (RightControllerDriver.getInstance().Triggering())
            {
                if (current_focusing_gameobject == null)
                {
                    return;
                }
                GameObject current_pointing_axis
                    = XAxisRayService.getInstance().getPointingAxisGameObject();
                string current_axis_way = "N";
                //render canvas
                if (current_pointing_axis != null)
                {
                    string x_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXMovingAxis_X().name;
                    string y_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXMovingAxis_Y().name;
                    string z_name
                        = XPreSpawnObjectManager.getInstance()
                          .getXMovingAxis_Z().name;
                    string current_pointing_axis_name
                        = current_pointing_axis.name;
                    if (current_pointing_axis_name.Equals(x_name))
                    {
                        //show x
                        X_SHOWTAG.SetActive(true);
                        current_axis_way = "X";
                    }
                    else if (current_pointing_axis_name.Equals(y_name))
                    {
                        //show y
                        Y_SHOWTAG.SetActive(true);
                        current_axis_way = "Y";
                    }
                    else if (current_pointing_axis_name.Equals(z_name))
                    {
                        //show z
                        Z_SHOWTAG.SetActive(true);
                        current_axis_way = "Z";
                    }
                }
                else
                {
                    //show "no axis"
                    current_axis_way = "N";
                }
                //move object and axis
                Vector3 current_pointing_axis_point;
                XAxisRayService.getInstance()
                .getPointingPoint(out current_pointing_axis_point);
                switch (current_axis_way)
                {
                case "N":
                {
                    start_colliding_point = default_vector3;
                    break;
                }

                case "X":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float x_moved = current_pointing_axis_point.x - start_colliding_point.x;
                        //move object
                        transform_move_using_v3.x
                            = current_focusing_gameobject.transform.position.x
                              + x_moved;
                        transform_move_using_v3.y
                            = current_focusing_gameobject.transform.position.y;
                        transform_move_using_v3.z
                            = current_focusing_gameobject.transform.position.z;
                        current_focusing_gameobject.transform.position
                            = transform_move_using_v3;
                        start_colliding_point = current_pointing_axis_point;
                        //move axis
                        GameObject XMovingAxis_X
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_X();
                        GameObject XMovingAxis_Y
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_Y();
                        GameObject XMovingAxis_Z
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_Z();
                        XMovingAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XMovingAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XMovingAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }
                    break;
                }

                case "Y":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float y_moved = current_pointing_axis_point.y - start_colliding_point.y;
                        //move object
                        transform_move_using_v3.y
                            = current_focusing_gameobject.transform.position.y
                              + y_moved;
                        transform_move_using_v3.x
                            = current_focusing_gameobject.transform.position.x;
                        transform_move_using_v3.z
                            = current_focusing_gameobject.transform.position.z;
                        current_focusing_gameobject.transform.position
                            = transform_move_using_v3;
                        start_colliding_point = current_pointing_axis_point;
                        //move axis
                        GameObject XMovingAxis_X
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_X();
                        GameObject XMovingAxis_Y
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_Y();
                        GameObject XMovingAxis_Z
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_Z();
                        XMovingAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XMovingAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XMovingAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }
                    break;
                }

                case "Z":
                {
                    if (start_colliding_point.Equals(default_vector3))
                    {
                        start_colliding_point = current_pointing_axis_point;
                    }
                    else
                    {
                        float z_moved = current_pointing_axis_point.z - start_colliding_point.z;
                        //move object
                        transform_move_using_v3.z
                            = current_focusing_gameobject.transform.position.z
                              + z_moved;
                        transform_move_using_v3.x
                            = current_focusing_gameobject.transform.position.x;
                        transform_move_using_v3.y
                            = current_focusing_gameobject.transform.position.y;
                        current_focusing_gameobject.transform.position
                            = transform_move_using_v3;
                        start_colliding_point = current_pointing_axis_point;
                        //move axis
                        GameObject XMovingAxis_X
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_X();
                        GameObject XMovingAxis_Y
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_Y();
                        GameObject XMovingAxis_Z
                            = XPreSpawnObjectManager.getInstance()
                              .getXMovingAxis_Z();
                        XMovingAxis_X.transform.position
                            = current_focusing_gameobject.transform.position;
                        XMovingAxis_Y.transform.position
                            = current_focusing_gameobject.transform.position;
                        XMovingAxis_Z.transform.position
                            = current_focusing_gameobject.transform.position;
                    }
                    break;
                }
                }
                return;
            }
            if (RightControllerDriver.getInstance().TriggerUp())
            {
                start_colliding_point = default_vector3;
                return;
            }
            //panel
            if (RightControllerDriver.getInstance().PanelDown())
            {
                current_focusing_gameobject = null;
                //delete axis
                GameObject XMovingAxis_X
                    = XPreSpawnObjectManager.getInstance()
                      .getXMovingAxis_X();
                GameObject XMovingAxis_Y
                    = XPreSpawnObjectManager.getInstance()
                      .getXMovingAxis_Y();
                GameObject XMovingAxis_Z
                    = XPreSpawnObjectManager.getInstance()
                      .getXMovingAxis_Z();
                XMovingAxis_X.SetActive(false);
                XMovingAxis_Y.SetActive(false);
                XMovingAxis_Z.SetActive(false);
            }
        }
    }