public override bool MovePosition(Vector3 destination) { // Debug.LogError("===================自动寻路=============" + destination); isSlide = false; actorObj.AutoPathFind = false; List <Vector3> points = pathFinder.FindPath(transform.position, destination); if (points == null || points.Count == 0) { LogMgr.DebugLog(string.Format("目标点{0}不可达,寻路失败", destination)); return(false); } pointList.Clear(); for (int i = 0; i < points.Count; i++) { Vector3 p = points[i]; pointList.Enqueue(p); } currentDestination = pointList.Dequeue(); moveDirection = (currentDestination - transform.position).normalized; FaceTo(currentDestination); SendMoveTo(transform.position, currentDestination); Status = MoveStatus.Running; actorObj.AutoPathFind = true; return(true); }
void playAction(string actionName) { if (m_anim != null) { try { m_anim.CrossFade(actionName, 0.5f); } catch (Exception e) { LogMgr.DebugLog("陷阱没有找到动作名:{0} msg:{1}", actionName, e.Message); } } }
//add by lzp 14:43 2016/10/11 开始重连检测在这个函数里 private bool ConnectIfNeeded() { if (!m_isConnectted && m_reconnect != null && MapMgr.Instance.CurMapType != MapMgr.MapType.Map_Login && MapMgr.Instance.CurMapType != MapMgr.MapType.Map_None) { LogMgr.DebugLog("ConnectIfNeeded : StartReconnect"); m_reconnect.StartReconnect(); } if (!IsTcpClientConnected() && (null == m_currentTry)) { #if (NETMGR_USE_IP_FOR_CON) ConnectAsyncWithIp(); #else ConnectAsyncWithUrl(); #endif return(true); } return(false); }
public static void Log(string logString, string stackTrace, LogType type) { if (!m_isDebug) { return; } switch (type) { case LogType.Log: LogMgr.DebugLog(logString); break; case LogType.Warning: LogMgr.WarningLog(logString); break; case LogType.Error: LogMgr.ErrorLog(logString); break; } }
//给定终点移动 public bool MoveToPos(string strClipName, Vector3 dstPos, bool bHitBack = false) { m_needMove = true; //重新获取下radius,防止init函数获取失败 m_curRadius = m_actor.GetColliderRadius(); //给定动画是否有位移曲线 if (null == m_animationCurveData) { return(false); } CurveData curveData = m_animationCurveData.GetCurveData(strClipName); if (curveData == null) { LogMgr.DebugLog("can't find {0} curve data", strClipName); return(false); } //是否是击退 m_bHitBack = bHitBack; m_DeltaPos = Vector3.zero; m_LastPos = m_transform.position; List <float> listValueX = new List <float>(); List <float> listValueY = new List <float>(); List <float> listValueZ = new List <float>(); List <float> listTime = new List <float>(); List <Keyframe> listKeyFrameX = new List <Keyframe>(); List <Keyframe> listKeyFrameY = new List <Keyframe>(); List <Keyframe> listKeyFrameZ = new List <Keyframe>(); //这里必须帧数一样 for (int i = 0; i < curveData.curve.Length; ++i) { if (curveData.curve[i].propertyName.Contains("m_LocalPosition.x")) { AnimationCurve tempX = curveData.curve[i].curve; //LogMgr.UnityLog("curveX length=" + tempX.length); for (int j = 0; j < tempX.length; ++j) { listTime.Add(tempX.keys[j].time); listValueX.Add(tempX.keys[j].value); listKeyFrameX.Add(tempX.keys[j]); } } else if (curveData.curve[i].propertyName.Contains("m_LocalPosition.y")) { AnimationCurve tempY = curveData.curve[i].curve; //LogMgr.UnityLog("curveY length=" + tempY.length); for (int j = 0; j < tempY.length; ++j) { listValueY.Add(tempY.keys[j].value); listKeyFrameY.Add(tempY.keys[j]); } } else if (curveData.curve[i].propertyName.Contains("m_LocalPosition.z")) { AnimationCurve tempZ = curveData.curve[i].curve; //LogMgr.UnityLog("curveZ length=" + tempZ.length); for (int j = 0; j < tempZ.length; ++j) { listValueZ.Add(tempZ.keys[j].value); listKeyFrameZ.Add(tempZ.keys[j]); } } } //帧数不一致,不处理 if (listValueX.Count != listValueY.Count || listValueX.Count != listValueZ.Count || listValueY.Count != listValueZ.Count) { LogMgr.LogError(strClipName + " have diffent key count"); return(false); } bool needCutKey = false; //缩放系数 float distanceA = Vector3.Distance(dstPos, m_transform.position); Vector3 pos1 = new Vector3(listValueX[0], listValueY[0], listValueZ[0]); Vector3 pos2 = new Vector3(listValueX[listValueX.Count - 1], listValueY[listValueX.Count - 1], listValueZ[listValueX.Count - 1]); float distanceB = Vector3.Distance(pos1, pos2); //是否有卡帧系数 if (curveData.keyIndex > 0 & curveData.keyIndex < listValueX.Count - 1) { //卡帧前面的位移 Vector3 pos3 = new Vector3(listValueX[curveData.keyIndex], listValueY[0], listValueZ[curveData.keyIndex]); float distanceC = Vector3.Distance(pos1, pos3); //LogMgr.UnityLog("distanceC=" + distanceC); if (distanceA > distanceC) { distanceA -= distanceC; distanceB -= distanceC; needCutKey = true; } } float fscale = distanceA / distanceB; if (Mathf.Approximately(distanceB, 0) || fscale <= 0) { fscale = 1f; } //LogMgr.UnityLog("distanceA=" + distanceA + ", distanceB=" + distanceB + ", fscale=" + fscale); //使用点的旋转 List <Vector3> listCurvePos = new List <Vector3>(); for (int i = 0; i < listValueX.Count; ++i) { Vector3 pos = new Vector3(listValueX[i], listValueY[i], listValueZ[i]); //缩放 if (needCutKey && curveData.keyIndex > 0 && curveData.keyIndex < listValueX.Count - 1) { //后面的缩放 if (i > curveData.keyIndex) { pos.Scale(new Vector3(fscale, 1, fscale)); pos += new Vector3(listValueX[curveData.keyIndex], pos.y, listValueZ[curveData.keyIndex]); } } else { pos.Scale(new Vector3(fscale, 1f, fscale)); } //自身旋转 pos = m_transform.rotation * pos; listCurvePos.Add(pos); } //终点旋转 Vector3 curveDstPos = listCurvePos[listCurvePos.Count - 1] + m_transform.position; Vector3 fromDir = curveDstPos - m_transform.position; Vector3 toDir = dstPos - m_transform.position; Quaternion rot = Quaternion.FromToRotation(fromDir, toDir); //旋转到指定点方向 for (int i = 0; i < listCurvePos.Count; ++i) { listCurvePos[i] = rot * listCurvePos[i]; } //找到对应的值 AnimationCurve curveX = new AnimationCurve(); AnimationCurve curveY = new AnimationCurve(); AnimationCurve curveZ = new AnimationCurve(); //动画曲线 for (int i = 0; i < listCurvePos.Count; ++i) { Vector3 pos = listCurvePos[i] + m_transform.position; //LogMgr.UnityLog("pos=" + pos.ToString("f4") + ", time=" + listTime[i]); Keyframe keyX = new Keyframe(listTime[i], pos.x, listKeyFrameX[i].inTangent, listKeyFrameX[i].outTangent); keyX.tangentMode = listKeyFrameX[i].tangentMode; Keyframe keyY = new Keyframe(listTime[i], pos.y, listKeyFrameY[i].inTangent, listKeyFrameY[i].outTangent); keyY.tangentMode = listKeyFrameY[i].tangentMode; Keyframe keyZ = new Keyframe(listTime[i], pos.z, listKeyFrameZ[i].inTangent, listKeyFrameZ[i].outTangent); keyZ.tangentMode = listKeyFrameZ[i].tangentMode; curveX.AddKey(keyX); curveY.AddKey(keyY); curveZ.AddKey(keyZ); } // 平滑处理 if (curveX.length > 3) { for (int i = 1; i < curveX.length - 1; i++) { // 小的颤动平滑掉 if (Mathf.Abs((curveX.keys[i].value - curveX.keys[i - 1].value) + (curveX.keys[i].value - curveX.keys[i + 1].value)) > 0.3f) { continue; } if (Mathf.Abs((curveY.keys[i].value - curveY.keys[i - 1].value) + (curveY.keys[i].value - curveY.keys[i + 1].value)) > 0.3f) { continue; } if (Mathf.Abs((curveZ.keys[i].value - curveZ.keys[i - 1].value) + (curveZ.keys[i].value - curveZ.keys[i + 1].value)) > 0.3f) { continue; } curveX.SmoothTangents(i, 0.5f); curveY.SmoothTangents(i, 0.5f); curveZ.SmoothTangents(i, 0.5f); } } m_curveX = curveX; m_curveY = curveY; m_curveZ = curveZ; m_beginTime = Time.time; return(true); }
/// <summary> /// 获取武器模型。 /// </summary> /// <param name="fashion">时装。</param> /// <param name="sb">神兵。</param> /// <param name="equip">武器。</param> /// <param name="job">职业。</param> /// <returns>按优先级获取的模型ID。</returns> public static int GetWeaponModelID(int fashion, int magicweapon, int equip, int job) { //武器显示优先级 时装>神兵>装备>模型默认 if (fashion != 0) { return(ConfigManager.Instance.BagItem.GetFashionModelID(fashion, job, 0)); } //神兵外观读取 if (magicweapon != 0) { int configId = job * 100 + magicweapon; int mid = ShenBingMgr.Instance.GetShenBingModelId(configId); if (mid > 0) { return(mid); } else { LogMgr.DebugLog("模型配置表有误,找不到神兵模型id " + configId); } } //读取装备武器,没有则读取角色默认武器 int weapon = equip; if (weapon == 0) { LuaTable cfg = ConfigManager.Instance.Actor.GetPlayerInfoConfig(job); if (cfg != null) { weapon = cfg.Get <int>("arm"); } } if (weapon == 0) { LogMgr.ErrorLog("角色职业默认武器配置错误,武器编号为0"); return(0); } LuaTable equipCfg = ConfigManager.Instance.BagItem.GetItemConfig(weapon); if (null == equipCfg) { LogMgr.ErrorLog("没有找到编号为{0}的武器", weapon); return(0); } int modelid = 0; switch (job) { case 1: modelid = equipCfg.Get <int>("vmesh1"); break; case 2: modelid = equipCfg.Get <int>("vmesh2"); break; case 3: modelid = equipCfg.Get <int>("vmesh3"); break; case 4: modelid = equipCfg.Get <int>("vmesh4"); break; default: break; } return(modelid); }