//Tips表格信提取 public TipsMotion TipsInfoGet(DataRow tips_row, string id, ref bool is_right) { _tipsMotion.TipsString = (string)tips_row[1].ToString(); if (_tipsMotion.TipsString == "") { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("TIPS", "CONTENT", id) + ",Tips文本信息为空!"); } return(_tipsMotion); } //处理文本播放时长 _tipsMotion.StandardTime = GetPlayTime(_tipsMotion.TipsString); //TODO:语音播放时长要与播放速率匹配,调节起来与一般调速不一样,还需要再调节 _tipsMotion.TipsTimeControl(); //显示位置处理 DisplayPos((string)tips_row[2].ToString(), id, ref is_right); //是否为标题判断 _tipsMotion.IsTitle = BoolenJudge((string)tips_row[3].ToString(), id, "TITLE", ref is_right); //是否可移动判断 _tipsMotion.IsMoveable = BoolenJudge((string)tips_row[4].ToString(), id, "MOVE", ref is_right); //是否同步运动判断,暂时取消,同步运动放到Motion选项中 //_tipsMotion.IsSynchronized = BoolenJudge((string)tips_row[5].ToString(), id, "SYNCHRONIZE", ref is_right); return(_tipsMotion); }
//PROGRAM表格信息提取 public bool ProgramInfoGet(DataRow program_row, string id, DataTable group_table, IList <IMotion> _motionList, IList <IList <IMotion> > _complexMotionList) { //提取Program ID string programID = ((string)program_row[2].ToString()).ToUpper(); //检验ID是否正确 if (MotionPara.programMotionID.Contains(programID)) { if (programID == "TONGBANG") { //铜棒敲击 return(CopperHit(program_row, id, group_table, _motionList, _complexMotionList)); } else if (programID == "BAIFANG") { //物体摆放 return(ObjPut(program_row, id, group_table, _motionList, _complexMotionList)); } else if (programID == "NINGSONG") { //螺钉拧松拧紧 return(NingSong(program_row, id, group_table, _motionList, _complexMotionList)); } else if (programID == "NINGCHU") { //螺钉拧进拧出 return(NingChu(program_row, id, group_table, _motionList, _complexMotionList)); } else { //Program ID错误 if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "PROGRAMID", id) + "," + programID + ":此ProgramID暂未定义,请联系相关程序猿,请确认!"); } return(false); } } else { //Program ID错误 if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "PROGRAMID", id) + "," + programID + ":此ProgramID不存在,请确认!"); } return(false); } }
//标题和移动标志位判断 private bool BoolenJudge(string bool_str, string id, string grid_type, ref bool is_right) { if (bool_str == "") { return(false); } else { bool_str = bool_str.ToUpper(); if (bool_str == "TRUE") { return(true); } else if (bool_str == "FALSE") { return(false); } else { is_right = false; if (grid_type.ToUpper() == "TITLE") { Debug.LogWarning(ErrorLocation.Locate("TIPS", "TITLE", id) + ", 标题填写错误,默认为非标题"); return(false); } else if (grid_type.ToUpper() == "MOVE") { Debug.LogWarning(ErrorLocation.Locate("TIPS", "MOVE", id) + ", 移动选项填写错误,默认为非移动"); return(false); } else { Debug.LogWarning(ErrorLocation.Locate("TIPS", "SYNCHRONIZE", id) + ", 同步运动选项填写错误,默认为同步"); return(true); } } } }
//Excel表格信息提取总入口 public bool ExcelAdd(DataRow excel_row, string id, DataTable group_table) { bool isRight = true; //Motion Type int motionInt = IntConversion(excel_row[3].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "MOTIONTYPE", id) + ",运动方式填写错误!"); } return(false); } ExcelInfoManager excelMana = new ExcelInfoManager(); if (motionInt == 1 || motionInt == 2 || motionInt == 3 || motionInt == 4 || motionInt == 5 || motionInt == 6) { //运动符合要求 BasicMotion excelMotion = excelMana.SimpleMotion(excel_row, id, group_table, ref isRight, motionInt); if (!isRight) { return(false); } _motionList.Add(excelMotion); } else { //报错 if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "MOTIONTYPE", id) + ",运动方式填写错误,暂时未包含该种运动方式!"); } return(false); } simpleID.Add(simpleID.Count, id); return(true); }
//3DMAX表格信提取 public MaxMotion MaxInfoGet(DataRow max_row, string id, ref bool is_right) { string objName = (string)max_row[2].ToString(); _maxMotion.AnimationParent = GameObject.Find(objName); if (_maxMotion.AnimationParent == null) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "OBJNAME", id) + ",动画所在物体名称错误!"); } return(_maxMotion); } _maxMotion.AnimationName = (string)max_row[3].ToString(); //时间确定 try{ _maxMotion.StandardTime = _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].length; _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].speed = 1.0f; }catch { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "ANINAME", id) + ",动画名字错误!"); } return(_maxMotion); } string customTimeStr = (string)max_row[4].ToString(); if (customTimeStr != "") { _maxMotion.StandardTime = FloatConversion(customTimeStr, ref is_right); if (!is_right || _maxMotion.StandardTime == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "Time", id) + ",自定义动画播放时长设置错误!"); } return(_maxMotion); } _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].speed = _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].length / _maxMotion.StandardTime; } //根据速率改变终止时间和播放速度 _maxMotion.EndTime = _maxMotion.StandardTime / _maxMotion.SpeedRate; _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].speed = _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].speed * _maxMotion.SpeedRate; _maxMotion.RecordSpeed = _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].speed; //记录当前播放速度 _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].speed = 0f; //当前播放速度设置为0 if ((string)max_row[5].ToString() == "") { return(_maxMotion); } //PC2动画 string[] pc2_1 = max_row[5].ToString().Split('|'); string[] pc2_2 = max_row[6].ToString().Split('|'); string[] pc2_3 = max_row[7].ToString().Split('|'); _maxMotion.PC2_Animation_Name.Clear(); _maxMotion.PC2_Animation_StartFrame.Clear(); _maxMotion.PC2_Animation_EndFrame.Clear(); for (int i = 0; i < pc2_1.Length; i++) { //Debug.Log(i+","+pc2_1[i]+","+pc2_2[i]+","+pc2_3[i]); if (GameObject.Find(pc2_1[i]) == null) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "PC2OBJNAME", id) + ",PC2动画所在物体名称错误!"); } return(_maxMotion); } int num = 0; if (!int.TryParse(pc2_2[i], out num)) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "PC2STARTFRAME", id) + ",PC2动画所在起始帧填写错误!"); } return(_maxMotion); } else { if (int.Parse(pc2_2[i]) < 0) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "PC2STARTFRAME", id) + ",PC2动画所在起始帧必须大于或等于0!"); } return(_maxMotion); } } if (!int.TryParse(pc2_3[i], out num)) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "PC2EndFRAME", id) + ",PC2动画所在结束帧填写错误!"); } return(_maxMotion); } if (int.Parse(pc2_2[i]) >= int.Parse(pc2_3[i])) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "PC2STARTFRAME", id) + ",PC2动画所在起始帧必须小于结束帧!"); } return(_maxMotion); } int pc2_frames = int.Parse(pc2_3[i]) - int.Parse(pc2_2[i]); float pc2_time = pc2_frames / _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].clip.frameRate; GameObject obj = GameObject.Find(pc2_1[i]); if (Mathf.Abs(pc2_time - obj.GetComponent <MegaPointCache>().maxtime) > 0.01f) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "PC2STARTFRAME", id) + ",PC2动画所在起始帧结束帧差值不能刚好播完PC2动画!"); } return(_maxMotion); } float pc2_endtime = int.Parse(pc2_3[i]) / _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].clip.frameRate; if (pc2_endtime > _maxMotion.AnimationParent.animation[_maxMotion.AnimationName].length) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("3DMAX", "PC2EndFRAME", id) + ",PC2动画所在起始帧结束帧不能在父物体的动画内播完PC2动画!"); } return(_maxMotion); } _maxMotion.PC2_Animation_Name.Add(pc2_1[i]); _maxMotion.PC2_Animation_StartFrame.Add(int.Parse(pc2_2[i])); _maxMotion.PC2_Animation_EndFrame.Add(int.Parse(pc2_3[i])); } return(_maxMotion); }
//Tips显示位置处理 private void DisplayPos(string pos_str, string id, ref bool is_right) { if (pos_str == "") { _tipsMotion.PosString = "down_left"; _tipsMotion.IsString = true; } else { if (pos_str.ToLower() == "down_left") { _tipsMotion.PosString = "down_left"; _tipsMotion.IsString = true; } else if (pos_str.ToLower() == "down_right") { _tipsMotion.PosString = "down_right"; _tipsMotion.IsString = true; } else if (pos_str.ToLower() == "top_left") { _tipsMotion.PosString = "top_left"; _tipsMotion.IsString = true; } else if (pos_str.ToLower() == "top_right") { _tipsMotion.PosString = "top_right"; _tipsMotion.IsString = true; } else if (pos_str.ToLower() == "center" || pos_str.ToLower() == "centre") { _tipsMotion.PosString = "center"; _tipsMotion.IsString = true; } else { string[] strArray = pos_str.Split(',', ','); if (strArray.Length != 2) { _tipsMotion.PosString = "down_left"; _tipsMotion.IsString = true; Debug.LogWarning(ErrorLocation.Locate("TIPS", "POS", id) + ", 位置填写错误,默认为down_left"); is_right = false; } else { try{ _tipsMotion.PosVec2.x = float.Parse(strArray[0]); _tipsMotion.PosVec2.y = float.Parse(strArray[1]); }catch { _tipsMotion.PosString = "down_left"; _tipsMotion.IsString = true; Debug.LogWarning(ErrorLocation.Locate("TIPS", "POS", id) + ", 位置填写错误,默认为down_left"); is_right = false; return; } _tipsMotion.IsString = false; } } } }
//直接设定位置 private bool SetPos(DataRow excel_row, string id, DataTable group_table) { bool isRight = true; //运动类型 _simpleMotion.CurrentMotion = MotionType.SetPos; //Group Column int groupColumn = IntConversion(excel_row[2].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); _simpleMotion.ParentTrans = GameObject.Find(objName).transform; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; _simpleMotion.ChildList.Add(tempTrans); _simpleMotion.ParentList.Add(tempTrans.parent); } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //起始信息记录 _simpleMotion.StartPos = _simpleMotion.ParentTrans.position; _simpleMotion.StartEurler = _simpleMotion.ParentTrans.eulerAngles; //终止位置获取 _simpleMotion.EndPos = Vector3Conversion((string)excel_row[12].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "POSITION", id) + ",参考位置填写错误!"); } return(false); } _simpleMotion.EndEurler = Vector3Conversion((string)excel_row[13].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "EURLER", id) + ",参考角度填写错误!"); } return(false); } //参考物体 string refStr = ((string)excel_row[11].ToString()).ToUpper(); if (refStr != "" && refStr != "WORLD") { GameObject empty = new GameObject(); empty.name = "random_move_empty-" + id; Transform finalTrans; try{ finalTrans = GameObject.Find((string)excel_row[11].ToString()).transform; }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "REFER", id) + ",参考物体填写错误!"); } return(false); } empty.transform.parent = finalTrans; empty.transform.localPosition = _simpleMotion.EndPos; empty.transform.localEulerAngles = _simpleMotion.EndEurler; _simpleMotion.EndPos = empty.transform.position; _simpleMotion.EndEurler = empty.transform.eulerAngles; GameObject.DestroyImmediate(empty); } _simpleMotion.StandardTime = 0.05f; _simpleMotion.EndTime = 0.05f; return(true); }
//螺钉拧进拧出 private bool NingChu(DataRow program_row, string id, DataTable group_table, IList <IMotion> _motionList, IList <IList <IMotion> > _complexMotionList) { Transform firstObj = null; Transform firstObjParent = null; List <Transform> parentList = new List <Transform>(); List <Transform> childList = new List <Transform>(); Transform screwTrans = null; Transform screwTransParent = null; bool isRight = true; //Group Column int groupColumn = IntConversion((string)program_row[3].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCGROUP", id) + ",螺钉拧出运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); firstObj = GameObject.Find(objName).transform; firstObjParent = firstObj.parent; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; childList.Add(tempTrans); parentList.Add(tempTrans.parent); } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCGROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //被拧物体 try{ screwTrans = GameObject.Find((string)program_row[4].ToString()).transform; screwTransParent = screwTrans.parent; }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCREFER", id) + ",被拧物体填写有错误!"); } return(false); } //扳手到螺钉距离 Vector3 disNCVec = Vector3Conversion((string)program_row[5].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCDIS", id) + ",拧的距离填写有错误!"); } return(false); } float disNC = disNCVec.magnitude; //旋转轴 Vector3 rotateAxis = Vector3Conversion((string)program_row[6].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCAXIS", id) + ",拧的旋转轴填写有错误!"); } return(false); } //螺钉拧出的距离 Vector3 disNCLVec = Vector3Conversion((string)program_row[7].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCLDIS", id) + ",拧出来的距离填写有错误!"); } return(false); } float disNCL = disNCLVec.magnitude; //移动速度 float moveSpeed = MotionPara.toolMoveSpeed; if (program_row.Table.Columns.Count > 8) { if ((string)program_row[8].ToString() != "") { moveSpeed = FloatConversion((string)program_row[8].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCSPEED", id) + ",自定义速度填写有错误!"); } return(false); } } } //扳手移进时的坐标轴,如果要通用化,请修改这里 Vector3 moveVecUnit = new Vector3(0f, -1.0f, 0f); if (program_row.Table.Columns.Count > 9) { if ((string)program_row[9].ToString() != "") { moveVecUnit = Vector3Conversion((string)program_row[9].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCBANSHOU", id) + ",自定义扳手坐标轴填写有错误!"); } return(false); } } } //参考空物体 GameObject emptyRefer = new GameObject(); emptyRefer.name = "NingChu_empty-" + id; //开始生成类数据 IList <IMotion> tempMotionList = new List <IMotion>(); //首次移进 New---Class BasicMotion _simpleMotion = new BasicMotion(); _simpleMotion.State = CurrentState.Active; _simpleMotion.CurrentMotion = MotionType.MoveOnly; _simpleMotion.StartPos = firstObj.position; _simpleMotion.StartEurler = firstObj.eulerAngles; emptyRefer.transform.position = firstObj.position; emptyRefer.transform.eulerAngles = firstObj.eulerAngles; _simpleMotion.ParentTrans = firstObj; _simpleMotion.ListCopy(childList, parentList); Vector3 motionVec = moveVecUnit * disNC; emptyRefer.transform.Translate(motionVec, Space.Self); _simpleMotion.EndPos = emptyRefer.transform.position; _simpleMotion.EndEurler = emptyRefer.transform.eulerAngles; _simpleMotion.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime; _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; tempMotionList.Add(_simpleMotion); //拧出 New---Class BasicMotion _simpleMotion2 = new BasicMotion(); _simpleMotion2.State = CurrentState.Future; _simpleMotion2.CurrentMotion = MotionType.MoveRotateSingle; _simpleMotion2.ParentTrans = screwTrans; _simpleMotion2.ListCopy(childList, parentList); _simpleMotion2.ChildList.Add(firstObj); _simpleMotion2.ParentList.Add(firstObjParent); _simpleMotion2.ChildList.Add(screwTrans); _simpleMotion2.ParentList.Add(screwTransParent); GameObject emptyObj = new GameObject(); emptyObj.name = "move-rotate_empty-" + id + "-ningchu"; emptyObj.transform.position = screwTrans.position; emptyObj.transform.eulerAngles = screwTrans.eulerAngles; //将emptyRefer当做扳手用于后面过程定位 emptyRefer.transform.parent = emptyObj.transform; _simpleMotion2.StartPos = screwTrans.position; _simpleMotion2.StartEurler = screwTrans.eulerAngles; _simpleMotion2.RotateAxis = rotateAxis; float rotateDegree = disNCL / MotionPara.rotateDegreeRate * 360f; _simpleMotion2.RotateSpeed = MotionPara.wrenchSpeed * 7; _simpleMotion2.StandardTime = rotateDegree / _simpleMotion2.RotateSpeed; motionVec = -rotateAxis * disNCL; emptyObj.transform.Translate(motionVec, Space.Self); motionVec = _simpleMotion2.ParentTrans.TransformDirection(motionVec).normalized *disNCL; _simpleMotion2.SpeedVector = motionVec / _simpleMotion2.StandardTime; _simpleMotion2.EndPos = emptyObj.transform.position; emptyObj.transform.Rotate(rotateAxis * rotateDegree, Space.Self); _simpleMotion2.EndEurler = emptyObj.transform.eulerAngles; emptyRefer.transform.parent = null; emptyObj.transform.position = _simpleMotion2.StartPos; emptyObj.transform.eulerAngles = _simpleMotion2.StartEurler; _simpleMotion2.EmptyObj = emptyObj; _simpleMotion2.EndTime = _simpleMotion2.StandardTime / _simpleMotion2.SpeedRate; tempMotionList.Add(_simpleMotion2); //最后退出 New---Class BasicMotion _simpleMotion6 = new BasicMotion(); _simpleMotion6.State = CurrentState.Future; _simpleMotion6.CurrentMotion = MotionType.MoveOnly; _simpleMotion6.StartPos = emptyRefer.transform.position; _simpleMotion6.StartEurler = emptyRefer.transform.eulerAngles; _simpleMotion6.ParentTrans = firstObj; _simpleMotion6.ListCopy(childList, parentList); motionVec = -moveVecUnit * disNC; emptyRefer.transform.Translate(motionVec, Space.Self); _simpleMotion6.EndPos = emptyRefer.transform.position; _simpleMotion6.EndEurler = emptyRefer.transform.eulerAngles; _simpleMotion6.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion6.SpeedVector = motionVec / _simpleMotion6.StandardTime; _simpleMotion6.EndTime = _simpleMotion6.StandardTime / _simpleMotion6.SpeedRate; tempMotionList.Add(_simpleMotion6); _complexMotionList.Add(tempMotionList); emptyRefer.transform.parent = null; GameObject.DestroyImmediate(emptyRefer); return(true); }
//部件摆放处理 private bool ObjPut(DataRow program_row, string id, DataTable group_table, IList <IMotion> _motionList, IList <IList <IMotion> > _complexMotionList) { Transform firstObj = null; List <Transform> parentList = new List <Transform>(); List <Transform> childList = new List <Transform>(); bool isRight = true; //Group Column int groupColumn = IntConversion((string)program_row[3].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", id) + ",任意摆放运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); firstObj = GameObject.Find(objName).transform; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; childList.Add(tempTrans); parentList.Add(tempTrans.parent); } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //参考物体 Transform referTrans = null; try{ referTrans = GameObject.Find((string)program_row[4].ToString()).transform; }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFREFER", id) + ",任意摆放运动参考物体填写错误!"); } return(false); } //判断是工具移出还是任意部件移动,默认为任意部件 bool isTool = false; if (program_row.Table.Columns.Count >= 5) { if ((string)program_row[5].ToString() == "") { isTool = true; } } //任意部件移动信息提取 Vector3 finalPos = new Vector3(0f, 0f, 0f); Vector3 finalEuler = new Vector3(0f, 0f, 0f); if (!isTool) { if (program_row.Table.Columns.Count >= 7) { //提取相对位置 finalPos = Vector3Conversion((string)program_row[5].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFPOS", id) + ",相对位置信息填写有错误!"); } return(false); } //提取相对角度 finalEuler = Vector3Conversion((string)program_row[6].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFEULER", id) + ",相对角度信息填写有错误!"); } return(false); } GameObject emptyRefer = new GameObject(); emptyRefer.name = "ObjPut_empty_Refer-" + id; emptyRefer.transform.parent = referTrans; emptyRefer.transform.localPosition = finalPos; emptyRefer.transform.localEulerAngles = finalEuler; finalPos = emptyRefer.transform.position; finalEuler = emptyRefer.transform.eulerAngles; emptyRefer.transform.parent = null; GameObject.DestroyImmediate(emptyRefer); } else { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFEULER", id) + ",相对位置或角度信息填写有错误!"); } return(false); } } else { int toolIndex = MotionPara.toolsName.IndexOf(objName); if (toolIndex == -1) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", id) + ",Group号对应的Group表第一个物体在Tool.xls工具信息中找不到,请确认!"); } return(false); } else { finalPos = MotionPara.toolsInitPos[toolIndex]; finalEuler = MotionPara.toolsInitEuler[toolIndex]; } } //自定义速度提取 float moveSpeed = MotionPara.toolMoveSpeed; if (program_row.Table.Columns.Count > 7) { if ((string)program_row[7].ToString() != "") { moveSpeed = FloatConversion((string)program_row[7].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFSPEED", id) + ",自定义速度填写有错误!"); } return(false); } } } //自定义安全高度 float safeHeight = MotionPara.safeHeight; if (program_row.Table.Columns.Count > 8) { if ((string)program_row[8].ToString() != "") { safeHeight = FloatConversion((string)program_row[8].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFHEIGHT", id) + ",自定义安全高度填写有错误!"); } return(false); } } } //开始生成类数据 IList <IMotion> tempMotionList = new List <IMotion>(); //首先上升到安全高度 //New Class,世界坐标移动 BasicMotion _simpleMotion = new BasicMotion(); _simpleMotion.State = CurrentState.Active; _simpleMotion.CurrentMotion = MotionType.WorldMove; _simpleMotion.StartPos = firstObj.position; _simpleMotion.StartEurler = firstObj.eulerAngles; _simpleMotion.ParentTrans = firstObj; _simpleMotion.ListCopy(childList, parentList); //如果部件摆放的safeHeight对应的轴要改,修改这个参数 Vector3 motionVec = new Vector3(0f, safeHeight - _simpleMotion.StartPos.y, 0f); _simpleMotion.EndPos = new Vector3(_simpleMotion.StartPos.x, safeHeight, _simpleMotion.StartPos.z); _simpleMotion.EndEurler = _simpleMotion.StartEurler; if (motionVec.magnitude == 0f) { _simpleMotion.StandardTime = 0.05f; _simpleMotion.SpeedVector = new Vector3(0f, 0f, 0f); } else { _simpleMotion.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime; } _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; tempMotionList.Add(_simpleMotion); //New Class---任意移动过度到目标位置上方 BasicMotion _simpleMotion2 = new BasicMotion(); _simpleMotion2.State = CurrentState.Future; _simpleMotion2.CurrentMotion = MotionType.RandomMotion; _simpleMotion2.StartPos = _simpleMotion.EndPos; _simpleMotion2.StartEurler = _simpleMotion.EndEurler; _simpleMotion2.ParentTrans = firstObj; _simpleMotion2.ListCopy(childList, parentList); _simpleMotion2.EndPos = new Vector3(finalPos.x, safeHeight, finalPos.z); _simpleMotion2.EndEurler = finalEuler; motionVec = _simpleMotion2.EndPos - _simpleMotion2.StartPos; float moveTime = 0; float rotateTime = 0; moveTime = motionVec.magnitude / moveSpeed; Vector3 angleDiff = GetAngleDiff(_simpleMotion2.StartEurler, ref _simpleMotion2.EndEurler); rotateTime = Vector3.Angle(_simpleMotion2.StartEurler, _simpleMotion2.EndEurler) / MotionPara.toolRotateSpeed; if (moveTime == 0 && rotateTime == 0) { _simpleMotion2.StandardTime = 0.05f; _simpleMotion2.SpeedVector = Vector3.zero; _simpleMotion2.AngleVector = Vector3.zero; } else if (moveTime > rotateTime) { _simpleMotion2.StandardTime = moveTime; _simpleMotion2.SpeedVector = motionVec / moveTime; _simpleMotion2.AngleVector = angleDiff / moveTime; } else { _simpleMotion2.StandardTime = rotateTime; _simpleMotion2.SpeedVector = motionVec / rotateTime; _simpleMotion2.AngleVector = angleDiff / rotateTime; } _simpleMotion2.EndTime = _simpleMotion2.StandardTime / _simpleMotion2.SpeedRate; tempMotionList.Add(_simpleMotion2); //New Class,下移到目标位置 BasicMotion _simpleMotion3 = new BasicMotion(); _simpleMotion3.State = CurrentState.Future; _simpleMotion3.CurrentMotion = MotionType.WorldMove; _simpleMotion3.StartPos = _simpleMotion2.EndPos; _simpleMotion3.StartEurler = _simpleMotion2.EndEurler; _simpleMotion3.ParentTrans = firstObj; _simpleMotion3.ListCopy(childList, parentList); _simpleMotion3.EndPos = finalPos; _simpleMotion3.EndEurler = finalEuler; motionVec = _simpleMotion3.EndPos - _simpleMotion3.StartPos; if (motionVec.magnitude == 0f) { _simpleMotion3.StandardTime = 0.05f; _simpleMotion3.SpeedVector = new Vector3(0f, 0f, 0f); } else { _simpleMotion3.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion3.SpeedVector = motionVec / _simpleMotion3.StandardTime; } _simpleMotion3.EndTime = _simpleMotion3.StandardTime / _simpleMotion3.SpeedRate; tempMotionList.Add(_simpleMotion3); _complexMotionList.Add(tempMotionList); return(true); }
//螺钉拧松拧紧 private bool NingSong(DataRow program_row, string id, DataTable group_table, IList <IMotion> _motionList, IList <IList <IMotion> > _complexMotionList) { Transform firstObj = null; Transform firstObjParent = null; List <Transform> parentList = new List <Transform>(); List <Transform> childList = new List <Transform>(); Transform screwTrans = null; Transform screwTransParent = null; bool isRight = true; //Group Column int groupColumn = IntConversion((string)program_row[3].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSGROUP", id) + ",螺钉拧松运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); firstObj = GameObject.Find(objName).transform; firstObjParent = firstObj.parent; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; childList.Add(tempTrans); parentList.Add(tempTrans.parent); } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSGROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //被拧物体 try{ screwTrans = GameObject.Find((string)program_row[4].ToString()).transform; screwTransParent = screwTrans.parent; }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSREFER", id) + ",被拧物体填写有错误!"); } return(false); } //拧的次数 int twistTimes = IntConversion((string)program_row[5].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSTIMES", id) + ",拧的次数填写有错误!"); } return(false); } //扳手到螺钉距离 Vector3 disNSVec = Vector3Conversion((string)program_row[6].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSDIS", id) + ",拧的距离填写有错误!"); } return(false); } float disNS = disNSVec.magnitude; //旋转轴 Vector3 rotateAxis = Vector3Conversion((string)program_row[7].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSAXIS", id) + ",拧的旋转轴填写有错误!"); } return(false); } //拧的角度大小 float twistDegree = FloatConversion((string)program_row[8].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSDEGREE", id) + ",拧的旋转轴填写有错误!"); } return(false); } //移动速度 float moveSpeed = MotionPara.toolMoveSpeed; if (program_row.Table.Columns.Count > 9) { if ((string)program_row[9].ToString() != "") { moveSpeed = FloatConversion((string)program_row[9].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSSPEED", id) + ",自定义速度填写有错误!"); } return(false); } } } //扳手移出的微小距离 float wrenchBackDis = MotionPara.wrenchBackDis; if (program_row.Table.Columns.Count > 10) { if ((string)program_row[10].ToString() != "") { wrenchBackDis = FloatConversion((string)program_row[10].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSWREHCHDIS", id) + ",自定义扳手回退距离填写有错误!"); } return(false); } } } //扳手移进时的坐标轴,如果要通用化,请修改这里 Vector3 moveVecUnit = new Vector3(-1.0f, 0f, 0f); if (program_row.Table.Columns.Count > 11) { if ((string)program_row[11].ToString() != "") { moveVecUnit = Vector3Conversion((string)program_row[11].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSBANSHOU", id) + ",自定义扳手坐标轴填写有错误!"); } return(false); } } } //参考空物体 GameObject emptyRefer = new GameObject(); emptyRefer.name = "NingSong_empty-" + id; //开始生成类数据 IList <IMotion> tempMotionList = new List <IMotion>(); //首次移进 New---Class BasicMotion _simpleMotion = new BasicMotion(); _simpleMotion.State = CurrentState.Active; _simpleMotion.CurrentMotion = MotionType.MoveOnly; _simpleMotion.StartPos = firstObj.position; _simpleMotion.StartEurler = firstObj.eulerAngles; emptyRefer.transform.position = firstObj.position; emptyRefer.transform.eulerAngles = firstObj.eulerAngles; _simpleMotion.ParentTrans = firstObj; _simpleMotion.ListCopy(childList, parentList); //扳手拧一圈时移动的距离 float screwBack = (twistDegree / 30f) * MotionPara.screwBackRate; Vector3 motionVec = moveVecUnit * disNS; emptyRefer.transform.Translate(motionVec, Space.Self); _simpleMotion.EndPos = emptyRefer.transform.position; _simpleMotion.EndEurler = emptyRefer.transform.eulerAngles; _simpleMotion.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime; _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; tempMotionList.Add(_simpleMotion); for (int i = 0; i < twistTimes; i++) { //拧 New---Class BasicMotion _simpleMotion2 = new BasicMotion(); _simpleMotion2.State = CurrentState.Future; _simpleMotion2.CurrentMotion = MotionType.MoveRotateSingle; _simpleMotion2.ParentTrans = screwTrans; _simpleMotion2.ListCopy(childList, parentList); _simpleMotion2.ChildList.Add(firstObj); _simpleMotion2.ParentList.Add(firstObjParent); _simpleMotion2.ChildList.Add(screwTrans); _simpleMotion2.ParentList.Add(screwTransParent); GameObject emptyObj = new GameObject(); emptyObj.name = "move-rotate_empty-" + id + "-" + i.ToString(); emptyObj.transform.position = screwTrans.position; emptyObj.transform.eulerAngles = screwTrans.eulerAngles; //将emptyRefer当做扳手用于后面过程定位 emptyRefer.transform.parent = emptyObj.transform; _simpleMotion2.StartPos = screwTrans.position; _simpleMotion2.StartEurler = screwTrans.eulerAngles; _simpleMotion2.RotateAxis = rotateAxis; _simpleMotion2.RotateSpeed = MotionPara.wrenchSpeed; _simpleMotion2.StandardTime = twistDegree / _simpleMotion2.RotateSpeed; motionVec = -rotateAxis * screwBack; emptyObj.transform.Translate(motionVec, Space.Self); motionVec = _simpleMotion2.ParentTrans.TransformDirection(motionVec).normalized *screwBack; _simpleMotion2.SpeedVector = motionVec / _simpleMotion2.StandardTime; _simpleMotion2.EndPos = emptyObj.transform.position; emptyObj.transform.Rotate(rotateAxis * twistDegree, Space.Self); _simpleMotion2.EndEurler = emptyObj.transform.eulerAngles; emptyRefer.transform.parent = null; emptyObj.transform.position = _simpleMotion2.StartPos; emptyObj.transform.eulerAngles = _simpleMotion2.StartEurler; _simpleMotion2.EmptyObj = emptyObj; _simpleMotion2.EndTime = _simpleMotion2.StandardTime / _simpleMotion2.SpeedRate; tempMotionList.Add(_simpleMotion2); //中间循环动作 if (twistTimes - i > 1) { //扳手退出很小的距离 New---Class BasicMotion _simpleMotion3 = new BasicMotion(); _simpleMotion3.State = CurrentState.Future; _simpleMotion3.CurrentMotion = MotionType.MoveOnly; _simpleMotion3.ParentTrans = firstObj; _simpleMotion3.ListCopy(childList, parentList); _simpleMotion3.StartPos = emptyRefer.transform.position; _simpleMotion3.StartEurler = emptyRefer.transform.eulerAngles; motionVec = new Vector3(1f, 0f, 0f) * wrenchBackDis / 3; emptyRefer.transform.Translate(motionVec, Space.Self); _simpleMotion3.EndPos = emptyRefer.transform.position; _simpleMotion3.EndEurler = emptyRefer.transform.eulerAngles; _simpleMotion3.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion3.SpeedVector = motionVec / _simpleMotion3.StandardTime; _simpleMotion3.EndTime = _simpleMotion3.StandardTime / _simpleMotion3.SpeedRate; tempMotionList.Add(_simpleMotion3); //扳手回转 New---Class BasicMotion _simpleMotion4 = new BasicMotion(); _simpleMotion4.State = CurrentState.Future; _simpleMotion4.CurrentMotion = MotionType.RotateOnly; _simpleMotion4.ParentTrans = firstObj; _simpleMotion4.ListCopy(childList, parentList); _simpleMotion4.StartPos = emptyRefer.transform.position; _simpleMotion4.StartEurler = emptyRefer.transform.eulerAngles; _simpleMotion4.RotateCenter = _simpleMotion4.ParentTrans.position; _simpleMotion4.RotateAxis = new Vector3(rotateAxis.z, 0f, 0f); _simpleMotion4.RotateAxis = _simpleMotion4.ParentTrans.TransformDirection(_simpleMotion4.RotateAxis); _simpleMotion4.RotateSpeed = MotionPara.wrenchSpeed * 4f; _simpleMotion4.StandardTime = twistDegree / _simpleMotion4.RotateSpeed; emptyRefer.transform.RotateAround(_simpleMotion4.RotateCenter, _simpleMotion4.RotateAxis, twistDegree); _simpleMotion4.EndPos = emptyRefer.transform.position; _simpleMotion4.EndEurler = emptyRefer.transform.eulerAngles; _simpleMotion4.EndTime = _simpleMotion4.StandardTime / _simpleMotion4.SpeedRate; tempMotionList.Add(_simpleMotion4); //扳手再次进入 New---Class BasicMotion _simpleMotion5 = new BasicMotion(); _simpleMotion5.State = CurrentState.Future; _simpleMotion5.CurrentMotion = MotionType.MoveOnly; _simpleMotion5.ParentTrans = firstObj; _simpleMotion5.ListCopy(childList, parentList); _simpleMotion5.StartPos = emptyRefer.transform.position; _simpleMotion5.StartEurler = emptyRefer.transform.eulerAngles; motionVec = new Vector3(-1f, 0f, 0f) * wrenchBackDis / 3; emptyRefer.transform.Translate(motionVec, Space.Self); _simpleMotion5.EndPos = emptyRefer.transform.position; _simpleMotion5.EndEurler = emptyRefer.transform.eulerAngles; _simpleMotion5.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion5.SpeedVector = motionVec / _simpleMotion5.StandardTime; _simpleMotion5.EndTime = _simpleMotion5.StandardTime / _simpleMotion5.SpeedRate; tempMotionList.Add(_simpleMotion5); } } //最后退出 New---Class BasicMotion _simpleMotion6 = new BasicMotion(); _simpleMotion6.State = CurrentState.Future; _simpleMotion6.CurrentMotion = MotionType.MoveOnly; _simpleMotion6.StartPos = emptyRefer.transform.position; _simpleMotion6.StartEurler = emptyRefer.transform.eulerAngles; _simpleMotion6.ParentTrans = firstObj; _simpleMotion6.ListCopy(childList, parentList); motionVec = -moveVecUnit * disNS; emptyRefer.transform.Translate(motionVec, Space.Self); _simpleMotion6.EndPos = emptyRefer.transform.position; _simpleMotion6.EndEurler = emptyRefer.transform.eulerAngles; _simpleMotion6.StandardTime = motionVec.magnitude / moveSpeed; _simpleMotion6.SpeedVector = motionVec / _simpleMotion6.StandardTime; _simpleMotion6.EndTime = _simpleMotion6.StandardTime / _simpleMotion6.SpeedRate; tempMotionList.Add(_simpleMotion6); _complexMotionList.Add(tempMotionList); emptyRefer.transform.parent = null; GameObject.DestroyImmediate(emptyRefer); return(true); }
//Camera表格信提取 public CameraMotion CameraInfoGet(DataRow camera_row, string id, ref bool is_right) { //摄像机名称检查 string cameraName = (string)camera_row[2].ToString(); is_right = Check(cameraName); if (!is_right) { //摄像机名称出错 if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "NAME", id) + ",摄像机名称错误!"); } return(_cameraMotion); } //圆弧运动、直线和路径运动确定,圆弧优先级高于其他,根据【旋转参考物体:9】是否有填来确定 string rotateRefStr = (string)camera_row[9].ToString(); string pathName = ""; if (rotateRefStr == "") { pathName = (string)camera_row[14].ToString(); if (pathName == "") { _cameraMotion.CurrentMotion = CameraMotionType.Line; //直线运动 } else { _cameraMotion.CurrentMotion = CameraMotionType.VisualPath; //可视化路径运动 } } else //圆弧运动 { _cameraMotion.CurrentMotion = CameraMotionType.Circular; try{ _cameraMotion.RotateCenter = GameObject.Find(rotateRefStr).transform.position; }catch { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "ROTATEREF", id) + ",旋转参考物体填写错误!"); } return(_cameraMotion); } } //观察中心物体处理 string targetTransStr = (string)camera_row[3].ToString(); if (targetTransStr != "") { try { CameraMotion.TargetTrans = GameObject.Find(targetTransStr).transform; } catch { is_right = false; //摄像机名称出错 if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "OBSERVER", id) + ",观察物体填写错误!"); } return(_cameraMotion); } } else { if (_cameraMotion.CurrentMotion != CameraMotionType.VisualPath) { is_right = false; //摄像机名称出错 if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "OBSERVER", id) + ",直线和圆弧模式下必须有观察物体!"); } return(_cameraMotion); } } //起始位置确定 bool isRelativePos = false; //用于目标位置确定 string relativeRefStr = (string)camera_row[4].ToString(); string startPosStr = (string)camera_row[5].ToString(); string endPosStr = (string)camera_row[6].ToString(); GameObject empty = new GameObject(); empty.name = "camera_motion_empty-" + id; Transform relativeTrans = null; if (startPosStr == "") { _cameraMotion.StartPos = CameraMotion.CurrentCamera.transform.position; _cameraMotion.needSetPos = false; } else { //默认为世界坐标位置 _cameraMotion.StartPos = Vector3Conversion(startPosStr, ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "SPOSITION", id) + ",摄像机初始位置错误!"); } return(_cameraMotion); } if (relativeRefStr != "") //相对坐标位置 { isRelativePos = true; try{ relativeTrans = GameObject.Find(relativeRefStr).transform; }catch { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "RELATIVE", id) + ",相对位置参考物体填写错误!"); } return(_cameraMotion); } empty.transform.parent = relativeTrans; empty.transform.localPosition = _cameraMotion.StartPos; _cameraMotion.StartPos = empty.transform.position; empty.transform.parent = null; } if ((_cameraMotion.StartPos - CameraMotion.CurrentCamera.transform.position).magnitude > 0.01f) { _cameraMotion.needSetPos = true; } else { _cameraMotion.needSetPos = false; } } //视域缩放参数确定 string endSizeStr = (string)camera_row[8].ToString(); if (endSizeStr == "") { _cameraMotion.HasSizeChange = false; } else { _cameraMotion.HasSizeChange = true; _cameraMotion.EndSize = FloatConversion(endSizeStr, ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "APORT", id) + ",摄像机视域变化终值错误!"); } return(_cameraMotion); } string startSizeStr = (string)camera_row[7].ToString(); if (startSizeStr == "") { _cameraMotion.StartSize = _cameraMotion.GetCameraPortValue(); } else { _cameraMotion.StartSize = FloatConversion(startSizeStr, ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "SPORT", id) + ",摄像机视域变化初值错误!"); } return(_cameraMotion); } } } //直线、可视化路径、旋转运动分别处理 if (_cameraMotion.CurrentMotion == CameraMotionType.Circular) //圆弧过程 //旋转速度获取 { _cameraMotion.RotateSpeed = MotionPara.cameraAngleSpeed; string customRotStr = (string)camera_row[13].ToString(); if (customRotStr != "") { _cameraMotion.RotateSpeed = FloatConversion(customRotStr, ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "ROTATESPEED", id) + ",自定义角速度错误!"); } return(_cameraMotion); } } //旋转角度 float rotateDegree = FloatConversion((string)camera_row[11].ToString(), ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "DEGREE", id) + ",旋转角度错误!"); } return(_cameraMotion); } //旋转轴 _cameraMotion.RotateAxis = Vector3Conversion((string)camera_row[10].ToString(), ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "AXIS", id) + ",旋转轴错误!"); } return(_cameraMotion); } _cameraMotion.RotateAxis = GameObject.Find(rotateRefStr).transform.TransformDirection(_cameraMotion.RotateAxis); //终止信息记录 GameObject emptyCamera = new GameObject(); emptyCamera.name = "camera_empty-" + id; emptyCamera.transform.position = _cameraMotion.StartPos; emptyCamera.transform.eulerAngles = CameraMotion.CurrentCamera.transform.eulerAngles; emptyCamera.transform.RotateAround(_cameraMotion.RotateCenter, _cameraMotion.RotateAxis, rotateDegree); _cameraMotion.EndPos = emptyCamera.transform.position; GameObject.DestroyImmediate(emptyCamera); //时间 _cameraMotion.StandardTime = rotateDegree / _cameraMotion.RotateSpeed; } else { //直线速度获取 float moveSpeed = MotionPara.cameraLineSpeed; string customMoveStr = (string)camera_row[12].ToString(); if (customMoveStr != "") { moveSpeed = FloatConversion(customMoveStr, ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "MOVESPEED", id) + ",自定义直线速度错误!"); } return(_cameraMotion); } } if (endPosStr == "" && _cameraMotion.CurrentMotion == CameraMotionType.VisualPath) { //Do nothing } else { //默认为世界坐标位置 _cameraMotion.EndPos = Vector3Conversion(endPosStr, ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "APOSITION", id) + ",摄像机目标位置错误,直线时必须填!"); } return(_cameraMotion); } //是相对位置 if (isRelativePos) { empty.transform.parent = relativeTrans; empty.transform.localPosition = _cameraMotion.EndPos; _cameraMotion.EndPos = empty.transform.position; empty.transform.parent = null; } } if (_cameraMotion.CurrentMotion == CameraMotionType.VisualPath) //可视化路径运动 { JsonLoad(pathName, _cameraMotion.crSpline, ref is_right); if (!is_right) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "PATHNAME", id) + ",摄像机可视化路径名称填写错误!"); } return(_cameraMotion); } if (startPosStr != "") { _cameraMotion.crSpline.controlPoints[0] = _cameraMotion.StartPos; } if (endPosStr != "") { _cameraMotion.crSpline.controlPoints[_cameraMotion.crSpline.controlPoints.Count - 1] = _cameraMotion.EndPos; } AngleOptimization(_cameraMotion.crSpline.rotationList); _cameraMotion.crSpline.pts = _cameraMotion.crSpline.PathControlPointGenerator(_cameraMotion.crSpline.controlPoints.ToArray()); _cameraMotion.StandardTime = _cameraMotion.crSpline.TimeGet(_cameraMotion.crSpline.pts, moveSpeed); _cameraMotion.crSpline.TimeRateGenerator(_cameraMotion.crSpline.rotationList.Count); } else //直线运动过程 { //运动向量 Vector3 motionVec = _cameraMotion.EndPos - _cameraMotion.StartPos; //时间 _cameraMotion.StandardTime = motionVec.magnitude / moveSpeed; //线速度 _cameraMotion.SpeedVector = motionVec / _cameraMotion.StandardTime; } } if (_cameraMotion.StandardTime == 0) { is_right = false; if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("CAMERA", "ID", id) + ",计算出的移动时间为0,请检查信息填写是否正确!"); } return(_cameraMotion); } if (_cameraMotion.HasSizeChange) { _cameraMotion.SizeSpeed = (_cameraMotion.EndSize - _cameraMotion.StartSize) / _cameraMotion.StandardTime; } _cameraMotion.EndTime = _cameraMotion.StandardTime / _cameraMotion.SpeedRate; //判断摄像机是否需要过渡 if (CameraMotion.TargetTrans != null && _cameraMotion.CurrentMotion != CameraMotionType.Circular && !_cameraMotion.needSetPos) { _cameraMotion.diffVector[0] = CameraMotion.CurrentCamera.transform.eulerAngles; if (_cameraMotion.CurrentMotion == CameraMotionType.Line) { empty.transform.position = _cameraMotion.LineInterp(0.1f); } else { empty.transform.position = _cameraMotion.crSpline.Interp(0.1f); } empty.transform.LookAt(CameraMotion.TargetTrans); _cameraMotion.diffVector[1] = empty.transform.eulerAngles; _cameraMotion.diffVector[1] = new Vector3(AngleClerp(_cameraMotion.diffVector[0].x, _cameraMotion.diffVector[1].x, 1f), AngleClerp(_cameraMotion.diffVector[0].y, _cameraMotion.diffVector[1].y, 1f), AngleClerp(_cameraMotion.diffVector[0].z, _cameraMotion.diffVector[1].z, 1f)); if ((_cameraMotion.diffVector[1] - _cameraMotion.diffVector[0]).magnitude > 0.1f) { _cameraMotion.needExcess = true; } else { _cameraMotion.needExcess = false; } } else { _cameraMotion.needExcess = false; } GameObject.DestroyImmediate(empty); return(_cameraMotion); }
//铜棒敲击处理 private bool CopperHit(DataRow program_row, string id, DataTable group_table, IList <IMotion> _motionList, IList <IList <IMotion> > _complexMotionList) { //铜棒运动时的父亲 GameObject empty = new GameObject(); empty.name = "copper_empty-" + id; Transform copperTrans = null; Transform firstObj = null; // Transform firstObjParent = null; List <Transform> parentList = new List <Transform>(); List <Transform> childList = new List <Transform>(); try{ //铜棒 copperTrans = GameObject.Find(MotionPara.copperName).transform; }catch { if (MotionPara.isEditor) { Debug.LogError(MotionPara.copperName + ":在此场景中未能找到铜棒!"); } return(false); } bool isRight = true; //Group Column int groupColumn = IntConversion(program_row[3].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "TBGROUP", id) + ",铜棒运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); firstObj = GameObject.Find(objName).transform; // firstObjParent = firstObj.parent; empty.transform.position = firstObj.position; empty.transform.eulerAngles = firstObj.eulerAngles; // firstObj.parent = empty.transform; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; childList.Add(tempTrans); parentList.Add(tempTrans.parent); // tempTrans.parent = empty.transform; } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("PROGRAM", "TBGROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //敲击次数 int copperTimes = IntConversion((string)program_row[4].ToString(), ref isRight); if (!isRight || copperTimes == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "TBTIMES", id) + ",铜棒敲击次数填写有错误!"); } return(false); } //铜棒离敲击点距离 Vector3 disTBVec = Vector3Conversion((string)program_row[5].ToString(), ref isRight); if (!isRight || disTBVec.magnitude == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "TBDIS", id) + ",铜棒敲击距离填写有错误!"); } return(false); } float disTB = disTBVec.magnitude; //铜棒移动距离 //物体移动方向 Vector3 dirTBVec = Vector3Conversion((string)program_row[6].ToString(), ref isRight); if (!isRight || dirTBVec.magnitude == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "TBDIR", id) + ",铜棒敲击物体移动方向填写有错误!"); } return(false); } //移动速度确定 float copperHitSpeed = MotionPara.copperHitSpeed; //检测是否有自定义速度 if (program_row.Table.Columns.Count > 7) { if ((string)program_row[7].ToString() != "") { copperHitSpeed = FloatConversion((string)program_row[7].ToString(), ref isRight); if (!isRight || copperHitSpeed == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "TBSPEED", id) + ",铜棒自定义速度填写有错误!"); } return(false); } } } float copperBackSpeed = copperHitSpeed / 3f; //铜棒敲击一次移动距离 float copperForwardDis = MotionPara.copperForwardDis; //检测是否有自定义距离 if (program_row.Table.Columns.Count > 8) { if ((string)program_row[8].ToString() != "") { copperForwardDis = FloatConversion((string)program_row[8].ToString(), ref isRight); if (!isRight || copperForwardDis == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "TBFORWARDDIS", id) + ",铜棒自定义敲击移动距离填写有错误!"); } return(false); } } } GameObject emptyPos = new GameObject(); emptyPos.name = "copper_empty_position--" + id; //敲击类创建 IList <IMotion> tempMotionList = new List <IMotion>(); for (int i = 0; i < copperTimes; i++) { //铜棒敲击---New Class BasicMotion _simpleMotion = new BasicMotion(); Vector3 motionVec = MotionPara.copperVector * (disTB + i * copperForwardDis); _simpleMotion.CurrentMotion = MotionType.MoveOnly; _simpleMotion.ParentTrans = copperTrans; _simpleMotion.MoveSpeed = copperHitSpeed; _simpleMotion.StandardTime = motionVec.magnitude / copperHitSpeed; _simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime; //起始信息记录 _simpleMotion.StartPos = copperTrans.position; _simpleMotion.StartEurler = copperTrans.eulerAngles; emptyPos.transform.position = _simpleMotion.StartPos; emptyPos.transform.eulerAngles = _simpleMotion.StartEurler; emptyPos.transform.Translate(motionVec, Space.Self); //终止信息记录 _simpleMotion.EndPos = emptyPos.transform.position; _simpleMotion.EndEurler = emptyPos.transform.eulerAngles; _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; if (i == 0) { _simpleMotion.State = CurrentState.Active; } else { _simpleMotion.State = CurrentState.Future; } tempMotionList.Add(_simpleMotion); //被敲击物体瞬移---New Class BasicMotion _simpleMotion2 = new BasicMotion(); _simpleMotion2.State = CurrentState.Future; _simpleMotion2.CurrentMotion = MotionType.SetPos; _simpleMotion2.ParentTrans = firstObj; _simpleMotion2.ListCopy(childList, parentList); //起始信息记录 emptyPos.transform.position = empty.transform.position; emptyPos.transform.eulerAngles = empty.transform.eulerAngles; _simpleMotion2.StartPos = emptyPos.transform.position; _simpleMotion2.StartEurler = emptyPos.transform.eulerAngles; emptyPos.transform.Translate(dirTBVec.normalized * (i + 1) * copperForwardDis, Space.Self); //终止信息记录 _simpleMotion2.EndPos = emptyPos.transform.position; _simpleMotion2.EndEurler = emptyPos.transform.eulerAngles; //时间记录 _simpleMotion2.StandardTime = 0.05f; _simpleMotion2.EndTime = 0.05f; tempMotionList.Add(_simpleMotion2); //铜棒返回---New Class BasicMotion _simpleMotion3 = new BasicMotion(); _simpleMotion3.State = CurrentState.Future; _simpleMotion3.CurrentMotion = MotionType.MoveOnly; _simpleMotion3.ParentTrans = copperTrans; _simpleMotion3.MoveSpeed = copperBackSpeed; _simpleMotion3.StandardTime = motionVec.magnitude / copperBackSpeed; _simpleMotion3.SpeedVector = -motionVec / _simpleMotion3.StandardTime; //起始信息记录 _simpleMotion3.StartPos = _simpleMotion.EndPos; _simpleMotion3.StartEurler = _simpleMotion.EndEurler; //终止信息记录 _simpleMotion3.EndPos = _simpleMotion.StartPos; _simpleMotion3.EndEurler = _simpleMotion.StartEurler; _simpleMotion3.EndTime = _simpleMotion3.StandardTime / _simpleMotion3.SpeedRate; tempMotionList.Add(_simpleMotion3); } _complexMotionList.Add(tempMotionList); GameObject.DestroyImmediate(emptyPos); GameObject.DestroyImmediate(empty); return(true); }
//任意移动 private bool RandomMove(DataRow excel_row, string id, DataTable group_table) { bool isRight = true; //运动类型 _simpleMotion.CurrentMotion = MotionType.RandomMotion; //Group Column int groupColumn = IntConversion(excel_row[2].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); _simpleMotion.ParentTrans = GameObject.Find(objName).transform; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; _simpleMotion.ChildList.Add(tempTrans); _simpleMotion.ParentList.Add(tempTrans.parent); } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //起始信息记录 _simpleMotion.StartPos = _simpleMotion.ParentTrans.position; _simpleMotion.StartEurler = _simpleMotion.ParentTrans.eulerAngles; //移动速度确定,如果有自定义移动速度 float customMoveSpeed = MotionPara.toolMoveSpeed; string speedStr = (string)excel_row[5].ToString(); if (speedStr != "") { customMoveSpeed = FloatConversion(speedStr, ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "MOVESPEED", id) + ",移动速度格式填写错误!"); } return(false); } } //旋转速度确定,如果有自定义旋转速度 float customRotateSpeed = MotionPara.toolRotateSpeed; string rotateSpeedStr = (string)excel_row[9].ToString(); if (rotateSpeedStr != "") { customRotateSpeed = FloatConversion(rotateSpeedStr, ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "ANGLEVECTOR", id) + ",旋转速度格式填写错误!"); } return(false); } } //终止位置获取 GameObject empty = new GameObject(); empty.name = "random_move_empty-" + id; Transform finalTrans; try{ finalTrans = GameObject.Find((string)excel_row[11].ToString()).transform; }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "REFER", id) + ",参考物体填写错误!"); } return(false); } _simpleMotion.EndPos = Vector3Conversion((string)excel_row[12].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "POSITION", id) + ",参考位置填写错误!"); } return(false); } _simpleMotion.EndEurler = Vector3Conversion((string)excel_row[13].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "EURLER", id) + ",参考角度填写错误!"); } return(false); } empty.transform.parent = finalTrans; empty.transform.localPosition = _simpleMotion.EndPos; empty.transform.localEulerAngles = _simpleMotion.EndEurler; _simpleMotion.EndPos = empty.transform.position; _simpleMotion.EndEurler = empty.transform.eulerAngles; GameObject.DestroyImmediate(empty); //时间计算 Vector3 motionVec = _simpleMotion.EndPos - _simpleMotion.StartPos; Vector3 angleVec = GetAngleDiff(_simpleMotion.StartEurler, ref _simpleMotion.EndEurler); float moveTime = 0; float rotateTime = 0; if (motionVec.magnitude != 0) { moveTime = motionVec.magnitude / customMoveSpeed; } if (angleVec.magnitude != 0) { rotateTime = Vector3.Angle(_simpleMotion.StartEurler, _simpleMotion.EndEurler) / customRotateSpeed; } if (moveTime == 0 && rotateTime == 0) { Debug.LogError(ErrorLocation.Locate("EXCEL", "REFER", id) + ",参考物体所计算出的位移和角度都为0,没有移动!"); return(false); } if (moveTime > rotateTime) { _simpleMotion.StandardTime = moveTime; _simpleMotion.SpeedVector = motionVec / moveTime; _simpleMotion.RotateSpeed = Vector3.Angle(_simpleMotion.StartEurler, _simpleMotion.EndEurler) / moveTime; _simpleMotion.AngleVector = angleVec / moveTime; } else { _simpleMotion.StandardTime = rotateTime; _simpleMotion.SpeedVector = motionVec / rotateTime; _simpleMotion.MoveSpeed = motionVec.magnitude / rotateTime; _simpleMotion.AngleVector = angleVec / rotateTime; } _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; return(true); }
//平移+旋转运动 private bool MoveAndRotate(DataRow excel_row, string id, DataTable group_table) { bool isRight = true; //运动类型 if (excel_row[11].ToString() == "") //绕同一中心旋转 { _simpleMotion.CurrentMotion = MotionType.MoveRotateSingle; } else //绕各自中心旋转 { _simpleMotion.CurrentMotion = MotionType.MoveRotateEvery; } //Group Column int groupColumn = IntConversion(excel_row[2].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; GameObject emptyObj = new GameObject(); try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); _simpleMotion.ParentTrans = GameObject.Find(objName).transform; _simpleMotion.ChildList.Add(_simpleMotion.ParentTrans); _simpleMotion.ParentList.Add(_simpleMotion.ParentTrans.parent); emptyObj.name = "move-rotate_empty-" + id; emptyObj.transform.position = _simpleMotion.ParentTrans.position; emptyObj.transform.eulerAngles = _simpleMotion.ParentTrans.eulerAngles; _simpleMotion.EmptyObj = emptyObj; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; _simpleMotion.ChildList.Add(tempTrans); _simpleMotion.ParentList.Add(tempTrans.parent); } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //起始信息记录 _simpleMotion.StartPos = _simpleMotion.ParentTrans.position; _simpleMotion.StartEurler = _simpleMotion.ParentTrans.eulerAngles; //平移和旋转动作判断,当【MoveVector:5】有信息时,平移有动作,否则无; //当【RotateDegree:9】有时要考虑两个动作谁快谁慢,以慢的时间为标准,没有旋转就报错 bool _hasMove = true; float moveTime = 0; float rotateTime = 0; string moveStr = (string)excel_row[6].ToString(); Vector3 motionVec = new Vector3(0f, 0f, 0f); if (moveStr == "") { _hasMove = false; } else { _hasMove = true; //运动向量提取 motionVec = Vector3Conversion(excel_row[6].ToString(), ref isRight); if (!isRight || motionVec.magnitude == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "SPEEDVECTOR", id) + ",移动向量格式填写错误!"); } return(false); } //速度提取 _simpleMotion.MoveSpeed = FloatConversion(excel_row[5].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "MOVESPEED", id) + ",移动速度格式填写错误!"); } return(false); } moveTime = motionVec.magnitude / _simpleMotion.MoveSpeed; } //旋转轴 _simpleMotion.RotateAxis = Vector3Conversion(excel_row[7].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "ROTATEAXIS", id) + ",旋转轴格式填写错误!"); } return(false); } //旋转速度 _simpleMotion.RotateSpeed = FloatConversion(excel_row[9].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "ANGLEVECTOR", id) + ",旋转速度格式填写错误!"); } return(false); } string rotateStr = (string)excel_row[10].ToString(); if (rotateStr == "") { if (!_hasMove) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "SPEEDVECTOR", id) + ",移动数据填写不全或者应增加旋转角度!"); } return(false); } //以移动的时间为标准,只修正位置 _simpleMotion.StandardTime = moveTime; _simpleMotion.SpeedVector = motionVec / moveTime; } else { //旋转角度 float rotateDegree = FloatConversion(excel_row[10].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "DEGREE", id) + ",旋转速度格式填写错误!"); } return(false); } rotateTime = rotateDegree / _simpleMotion.RotateSpeed; if (_hasMove) //对比时间,哪一个长用哪个,修正位置和角度 { if (moveTime > rotateTime) { _simpleMotion.StandardTime = moveTime; _simpleMotion.SpeedVector = motionVec / moveTime; _simpleMotion.RotateSpeed = rotateDegree / moveTime; } else { _simpleMotion.StandardTime = rotateTime; _simpleMotion.MoveSpeed = motionVec.magnitude / rotateTime; _simpleMotion.SpeedVector = motionVec / rotateTime; } } else //以旋转的时间为标准,修正角度 { _simpleMotion.StandardTime = rotateTime; } } //终止信息记录,只修正位置 //平移改成记录相对位移已经,转换成绝对位置之差 if (_hasMove) { emptyObj.transform.Translate(motionVec, Space.Self); _simpleMotion.EndPos = emptyObj.transform.position; _simpleMotion.SpeedVector = _simpleMotion.ParentTrans.TransformDirection(motionVec).normalized * _simpleMotion.MoveSpeed; } emptyObj.transform.Rotate(_simpleMotion.RotateSpeed * _simpleMotion.StandardTime * _simpleMotion.RotateAxis, Space.Self); _simpleMotion.EndEurler = emptyObj.transform.eulerAngles; emptyObj.transform.position = _simpleMotion.StartPos; emptyObj.transform.eulerAngles = _simpleMotion.StartEurler; _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; return(true); }
//旋转运动 private bool SimpleRotate(DataRow excel_row, string id, DataTable group_table) { bool isRight = true; //运动类型 _simpleMotion.CurrentMotion = MotionType.RotateOnly; //Group Column int groupColumn = IntConversion(excel_row[2].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); _simpleMotion.ParentTrans = GameObject.Find(objName).transform; _simpleMotion.RotateCenter = _simpleMotion.ParentTrans.position; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; _simpleMotion.ChildList.Add(tempTrans); _simpleMotion.ParentList.Add(tempTrans.parent); _simpleMotion.RotateCenter = (_simpleMotion.RotateCenter + tempTrans.position) / 2; } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //起始信息记录 _simpleMotion.StartPos = _simpleMotion.ParentTrans.position; _simpleMotion.StartEurler = _simpleMotion.ParentTrans.eulerAngles; if ((string)excel_row[8].ToString() != "") { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "ACCELERATEROTATE", id) + ",暂不支持匀加速旋转!"); } } //旋转轴 _simpleMotion.RotateAxis = Vector3Conversion(excel_row[7].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "ROTATEAXIS", id) + ",旋转轴格式填写错误!"); } return(false); } //旋转速度 _simpleMotion.RotateSpeed = FloatConversion(excel_row[9].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "ANGLEVECTOR", id) + ",旋转速度格式填写错误!"); } return(false); } //旋转角度 float rotateDegree = FloatConversion(excel_row[10].ToString(), ref isRight); if (rotateDegree <= 0) { isRight = false; Debug.LogError("旋转角度不能为负数!"); } if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "DEGREE", id) + ",旋转角度格式填写错误!"); } return(false); } //旋转模式 string rotateType = (string)excel_row[11].ToString(); if (rotateType == "") { //普通旋转 _simpleMotion.RotateAxis = _simpleMotion.ParentTrans.TransformDirection(_simpleMotion.RotateAxis); } else if (rotateType.ToUpper() == "WORLD") { //绕世界坐标轴旋转 //Do Nothing } else { //绕某一物体旋转 Transform tempTrans; try{ tempTrans = GameObject.Find(rotateType).transform; }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "REFER", id) + ",参照物体填写错误!"); } return(false); } _simpleMotion.RotateAxis = tempTrans.TransformDirection(_simpleMotion.RotateAxis); _simpleMotion.RotateCenter = tempTrans.position; } _simpleMotion.StandardTime = rotateDegree / _simpleMotion.RotateSpeed; //终止信息记录 GameObject empty = new GameObject(); empty.name = "rotate_empty-" + id; empty.transform.position = _simpleMotion.StartPos; empty.transform.eulerAngles = _simpleMotion.StartEurler; empty.transform.RotateAround(_simpleMotion.RotateCenter, _simpleMotion.RotateAxis, rotateDegree); _simpleMotion.EndPos = empty.transform.position; _simpleMotion.EndEurler = empty.transform.eulerAngles; GameObject.DestroyImmediate(empty); _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; return(true); }
//直线运动 private bool SimpleMove(DataRow excel_row, string id, DataTable group_table) { bool isRight = true; //运动类型 if (excel_row[4].ToString() == "") //匀速直线 { _simpleMotion.CurrentMotion = MotionType.MoveOnly; } else //匀加速直线运动 { _simpleMotion.CurrentMotion = MotionType.AccelerateMove; } //Group Column int groupColumn = IntConversion(excel_row[2].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try{ objName = (string)group_table.Rows[0][groupColumn].ToString(); _simpleMotion.ParentTrans = GameObject.Find(objName).transform; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; _simpleMotion.ChildList.Add(tempTrans); _simpleMotion.ParentList.Add(tempTrans.parent); } }catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //起始信息记录 _simpleMotion.StartPos = _simpleMotion.ParentTrans.position; _simpleMotion.StartEurler = _simpleMotion.ParentTrans.eulerAngles; //运动向量提取 Vector3 motionVec = Vector3Conversion(excel_row[6].ToString(), ref isRight); if (!isRight || motionVec.magnitude == 0) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "SPEEDVECTOR", id) + ",移动向量格式填写错误!"); } return(false); } //终止信息记录 GameObject empty = new GameObject(); empty.name = "move_empty-" + id; empty.transform.position = _simpleMotion.StartPos; empty.transform.eulerAngles = _simpleMotion.StartEurler; empty.transform.Translate(motionVec, Space.Self); _simpleMotion.EndPos = empty.transform.position; _simpleMotion.EndEurler = empty.transform.eulerAngles; GameObject.DestroyImmediate(empty); //速度提取 _simpleMotion.MoveSpeed = FloatConversion(excel_row[5].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "MOVESPEED", id) + ",移动速度格式填写错误!"); } return(false); } if (_simpleMotion.CurrentMotion == MotionType.AccelerateMove) //加速直线运动 { float finalSpeed = FloatConversion(excel_row[4].ToString(), ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "ACCELERATEMOVE", id) + ",移动加速度格式填写错误!"); } return(false); } _simpleMotion.AccelerateVec = motionVec.normalized; _simpleMotion.StandardTime = motionVec.magnitude / (_simpleMotion.MoveSpeed + 0.5f * (finalSpeed - _simpleMotion.MoveSpeed)); _simpleMotion.AccelerateVec = (finalSpeed * _simpleMotion.AccelerateVec - _simpleMotion.MoveSpeed * _simpleMotion.AccelerateVec) / _simpleMotion.StandardTime; _simpleMotion.SpeedVector = motionVec.normalized * _simpleMotion.MoveSpeed; } else //匀速直线运动 //运动信息获取 { _simpleMotion.StandardTime = motionVec.magnitude / _simpleMotion.MoveSpeed; _simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime; } _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; return(true); }
//直接设定位置 private bool VisualPathInfo(DataRow excel_row, string id, DataTable group_table) { bool isRight = true; //运动类型 _simpleMotion.CurrentMotion = MotionType.VisualPath; //Group Column int groupColumn = IntConversion((string)excel_row[2].ToString(), ref isRight) + 1; if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",运动Group填写错误!"); } return(false); } //运动物体信息 string objName = ""; try { objName = (string)group_table.Rows[0][groupColumn].ToString(); _simpleMotion.ParentTrans = GameObject.Find(objName).transform; for (int i = 1; i < group_table.Rows.Count; i++) { objName = (string)group_table.Rows[i][groupColumn].ToString(); if (objName == "") { break; } Transform tempTrans = GameObject.Find(objName).transform; _simpleMotion.ChildList.Add(tempTrans); _simpleMotion.ParentList.Add(tempTrans.parent); } } catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", id) + ",Group号对应的Group表填写有错误!"); } return(false); } //移动速度确定,如果有自定义移动速度 float customMoveSpeed = MotionPara.toolMoveSpeed; string speedStr = (string)excel_row[5].ToString(); if (speedStr != "") { customMoveSpeed = FloatConversion(speedStr, ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "MOVESPEED", id) + ",移动速度格式填写错误!"); } return(false); } } //路径信息加载 string pathName = (string)excel_row[4].ToString(); JsonLoad(pathName, _simpleMotion.crSpline, ref isRight, _simpleMotion.ParentTrans); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "PATHNAME", id) + ",可视化路径名称填写错误!"); } return(false); } //起始信息记录 _simpleMotion.StartPos = _simpleMotion.crSpline.controlPoints[0]; _simpleMotion.StartEurler = _simpleMotion.crSpline.rotationList[0]; //终止位置获取 string endPosStr = (string)excel_row[12].ToString(); if (endPosStr == "") { _simpleMotion.EndPos = _simpleMotion.crSpline.controlPoints[_simpleMotion.crSpline.controlPoints.Count - 1]; } else { _simpleMotion.EndPos = Vector3Conversion(endPosStr, ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "POSITION", id) + ",参考位置填写错误!"); } return(false); } } //终止角度获取 string endEulerStr = (string)excel_row[13].ToString(); if (endEulerStr == "") { _simpleMotion.EndEurler = _simpleMotion.crSpline.rotationList[_simpleMotion.crSpline.rotationList.Count - 1]; } else { _simpleMotion.EndEurler = Vector3Conversion(endEulerStr, ref isRight); if (!isRight) { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "EURLER", id) + ",参考角度填写错误!"); } return(false); } } //参考物体 string refStr = ((string)excel_row[11].ToString()).ToUpper(); if (refStr != "" && refStr != "WORLD" && (endEulerStr != "" || endPosStr != "")) { GameObject empty = new GameObject(); empty.name = "random_move_empty-" + id; Transform finalTrans; try { finalTrans = GameObject.Find((string)excel_row[11].ToString()).transform; } catch { if (MotionPara.isEditor) { Debug.LogError(ErrorLocation.Locate("EXCEL", "REFER", id) + ",参考物体填写错误!"); } return(false); } empty.transform.parent = finalTrans; empty.transform.localPosition = _simpleMotion.EndPos; empty.transform.localEulerAngles = _simpleMotion.EndEurler; if (endPosStr != "") { _simpleMotion.EndPos = empty.transform.position; _simpleMotion.crSpline.controlPoints[_simpleMotion.crSpline.controlPoints.Count - 1] = empty.transform.position; } if (endEulerStr != "") { _simpleMotion.EndEurler = empty.transform.eulerAngles; _simpleMotion.crSpline.rotationList[_simpleMotion.crSpline.rotationList.Count - 1] = empty.transform.eulerAngles; } GameObject.DestroyImmediate(empty); } AngleOptimization(_simpleMotion.crSpline.rotationList); _simpleMotion.crSpline.pts = _simpleMotion.crSpline.PathControlPointGenerator(_simpleMotion.crSpline.controlPoints.ToArray()); _simpleMotion.StandardTime = _simpleMotion.crSpline.TimeGet(_simpleMotion.crSpline.pts, customMoveSpeed); _simpleMotion.crSpline.TimeRateGenerator(_simpleMotion.crSpline.rotationList.Count); _simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate; return(true); }