Пример #1
0
    IEnumerator ChangeTool()
    {
        //换刀器旋转90度抓住所需刀具
        selfRotateTrans.Clear();
        selfRotateTrans.Add(twistGrip);
        selfRotateTrans.Add(twistAxis);
        startTime        = 0;
        rotate_speed     = 270f;
        endTime          = 90 / rotate_speed;
        centre_point     = twistAxis.position;
        rotate_direction = twistAxis.TransformDirection(Vector3.up);
        cw = 1;
        reviseInfo_Revolution.Clear();
        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            toolRef.position    = selfRotateTrans[i].position;
            toolRef.eulerAngles = selfRotateTrans[i].eulerAngles;
            toolRef.RotateAround(centre_point, -cw * rotate_direction, 90f);
            reviseInfo_Revolution.Add(toolRef.position);
            reviseInfo_Revolution.Add(toolRef.eulerAngles);
        }
        selfRotation_on = true;
        yield return(StartCoroutine(Timer()));

        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            selfRotateTrans[i].position    = reviseInfo_Revolution[i * 2];
            selfRotateTrans[i].eulerAngles = reviseInfo_Revolution[i * 2 + 1];
        }
        yield return(StartCoroutine(PauseTimer(0.3f)));

//		pause_on = true;
        //换刀器和刀具向下移动,准备换刀
        selfRotateTrans.Clear();
        if (cutter[20] != null)
        {
//			selfRotateTrans.Add(cutter[20]);
            selfRotateTrans.Add(cutterApron[20]);
            cutter[21]         = cutter[20];
            cutterApron[21]    = cutterApron[20];
            cutterIndex[21]    = cutterIndex[20];
            cutterName[21]     = cutterName[20];
            cutterLength[21]   = cutterLength[20];
            cutterDiamater[21] = cutterDiamater[20];
        }
        else
        {
            cutter[21]         = null;
            cutterApron[21]    = null;
            cutterIndex[21]    = 0;
            cutterName[21]     = "null";
            cutterLength[21]   = 0;
            cutterDiamater[21] = 0;
        }
        if (cutter[buttomApronNo - 1] != null)
        {
//			selfRotateTrans.Add(cutter[buttomApronNo - 1]);
            selfRotateTrans.Add(cutterApron[buttomApronNo - 1]);
            cutter[22]         = cutter[buttomApronNo - 1];
            cutterApron[22]    = cutterApron[buttomApronNo - 1];
            cutterName[22]     = cutterName[buttomApronNo - 1];
            cutterLength[22]   = cutterLength[buttomApronNo - 1];
            cutterDiamater[22] = cutterDiamater[buttomApronNo - 1];
        }
        else
        {
            cutter[22]         = null;
            cutterApron[22]    = null;
            cutterName[22]     = "null";
            cutterLength[22]   = 0;
            cutterDiamater[22] = 0;
        }
        cutterIndex[22] = cutterIndex[buttomApronNo - 1];
        selfRotateTrans.Add(twistGrip);
        selfRotateTrans.Add(twistAxis);
        startTime = 0;
        endTime   = move_distance / move_speed;
        cw        = -1;
        reviseInfo_Revolution.Clear();
        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            toolRef.position    = selfRotateTrans[i].position;
            toolRef.eulerAngles = selfRotateTrans[i].eulerAngles;
            toolRef.Translate(new Vector3(0, -move_distance, 0), Space.World);
            reviseInfo_Revolution.Add(toolRef.position);
            reviseInfo_Revolution.Add(toolRef.eulerAngles);
        }
        move_on = true;
        yield return(StartCoroutine(Timer()));

        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            selfRotateTrans[i].position    = reviseInfo_Revolution[i * 2];
            selfRotateTrans[i].eulerAngles = reviseInfo_Revolution[i * 2 + 1];
        }
        yield return(StartCoroutine(PauseTimer(0.3f)));

        //旋转180度换刀
        startTime        = 0;
        rotate_speed     = 270f;
        endTime          = 180 / rotate_speed;
        centre_point     = twistAxis.position;
        rotate_direction = twistAxis.TransformDirection(Vector3.up);
        cw = 1;
        reviseInfo_Revolution.Clear();
        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            toolRef.position    = selfRotateTrans[i].position;
            toolRef.eulerAngles = selfRotateTrans[i].eulerAngles;
            toolRef.RotateAround(centre_point, -cw * rotate_direction, 180f);
            reviseInfo_Revolution.Add(toolRef.position);
            reviseInfo_Revolution.Add(toolRef.eulerAngles);
        }
        selfRotation_on = true;
        yield return(StartCoroutine(Timer()));

        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            selfRotateTrans[i].position    = reviseInfo_Revolution[i * 2];
            selfRotateTrans[i].eulerAngles = reviseInfo_Revolution[i * 2 + 1];
        }
        yield return(StartCoroutine(PauseTimer(0.3f)));

        //安装刀具入刀位
        startTime = 0;
        endTime   = move_distance / move_speed;
        cw        = 1;
        reviseInfo_Revolution.Clear();
        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            toolRef.position    = selfRotateTrans[i].position;
            toolRef.eulerAngles = selfRotateTrans[i].eulerAngles;
            toolRef.Translate(new Vector3(0, move_distance, 0), Space.World);
            reviseInfo_Revolution.Add(toolRef.position);
            reviseInfo_Revolution.Add(toolRef.eulerAngles);
        }
        move_on = true;
        yield return(StartCoroutine(Timer()));

        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            selfRotateTrans[i].position    = reviseInfo_Revolution[i * 2];
            selfRotateTrans[i].eulerAngles = reviseInfo_Revolution[i * 2 + 1];
        }
        currentToolNo                     = buttomToolNo;
        buttomToolNo                      = cutterIndex[21];
        cutter[buttomApronNo - 1]         = cutter[21];
        cutterApron[buttomApronNo - 1]    = cutterApron[21];
        cutterIndex[buttomApronNo - 1]    = cutterIndex[21];
        cutterName[buttomApronNo - 1]     = cutterName[21];
        cutterLength[buttomApronNo - 1]   = cutterLength[21];
        cutterDiamater[buttomApronNo - 1] = cutterDiamater[21];
        cutter[20]         = cutter[22];
        cutterApron[20]    = cutterApron[22];
        cutterIndex[20]    = cutterIndex[22];
        cutterName[20]     = cutterName[22];
        cutterLength[20]   = cutterLength[22];
        cutterDiamater[20] = cutterDiamater[22];
        Main.toolLength    = cutterLength[20];
        Main.toolDiameter  = cutterDiamater[20];
        Main.ToolNo        = currentToolNo;
        LightControl_Script.SetNumber(Main.ToolNo);
        //刀具显示控制
        if (DisplayMode_Script.AllPartsHide())
        {
            if (cutter[buttomApronNo - 1] != null)
            {
                cutter[buttomApronNo - 1].renderer.enabled      = false;
                cutterApron[buttomApronNo - 1].renderer.enabled = false;
            }
            if (cutter[20] != null)
            {
                cutter[20].renderer.enabled      = true;
                cutterApron[20].renderer.enabled = true;
            }
        }
        cutterIndex[21]    = -1;
        cutterIndex[22]    = -1;
        cutterLength[21]   = 0;
        cutterLength[22]   = 0;
        cutterDiamater[21] = 0;
        cutterDiamater[22] = 0;
        if (cutter[20] != null)
        {
//			cutter[20].parent = MainAxis;
            cutterApron[20].parent           = MainAxis;
            cutterApron[20].localPosition    = new Vector3(0, -0.1908453f, 0);
            cutterApron[20].localEulerAngles = new Vector3(270f, 109.2f, 0);
//			cutter[20].localPosition = new Vector3(0, cutter[20].localPosition.y, 0);
        }
        if (cutter[buttomApronNo - 1] != null)
        {
//			cutter[buttomApronNo - 1].parent = Tool_Changer;
            cutterApron[buttomApronNo - 1].parent           = apron[buttomApronNo - 1];
            cutterApron[buttomApronNo - 1].localPosition    = new Vector3(0, 0, -0.04730511f);
            cutterApron[buttomApronNo - 1].localEulerAngles = new Vector3(0, 0, 0);
            cutterApron[buttomApronNo - 1].parent           = Tool_Changer;
        }

        yield return(StartCoroutine(PauseTimer(0.3f)));

        //换刀器旋转90度回到原位
        selfRotateTrans.Clear();
        selfRotateTrans.Add(twistGrip);
        selfRotateTrans.Add(twistAxis);
        startTime        = 0;
        rotate_speed     = 270f;
        endTime          = 90 / rotate_speed;
        centre_point     = twistAxis.position;
        rotate_direction = twistAxis.TransformDirection(Vector3.up);
        cw = -1;
        reviseInfo_Revolution.Clear();
        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            toolRef.position    = selfRotateTrans[i].position;
            toolRef.eulerAngles = selfRotateTrans[i].eulerAngles;
            toolRef.RotateAround(centre_point, -cw * rotate_direction, 90f);
            reviseInfo_Revolution.Add(toolRef.position);
            reviseInfo_Revolution.Add(toolRef.eulerAngles);
        }
        selfRotation_on = true;
        yield return(StartCoroutine(Timer()));

        for (int i = 0; i < selfRotateTrans.Count; i++)
        {
            selfRotateTrans[i].position    = reviseInfo_Revolution[i * 2];
            selfRotateTrans[i].eulerAngles = reviseInfo_Revolution[i * 2 + 1];
        }
        yield return(StartCoroutine(PauseTimer(0.3f)));
    }