Fishing_Fish[] CreatFish(byte fishTypeId, FishingPathData pd, Transform parent, PathManager pm, uint fishId, int count, float passTime, byte group, byte index) { if (!Fishing_Data.GetInstance().m_FishData.ContainsKey(fishTypeId)) { DebugLog.LogError("fish:" + fishTypeId + " data is error!!"); return(null); } FishingFishData fd = Fishing_Data.GetInstance().m_FishData[fishTypeId]; GameObject prefab = (GameObject)m_GameBase.FishingAssetBundle.LoadAsset(fd.m_szFish); int arrayCount = pd.m_Offsets.Count > 0 ? pd.m_Offsets.Count : 1; Debug.Assert(count != 0 && count <= arrayCount, "create fish count wrong!!"); Fishing_Fish[] fishs = new Fishing_Fish[count]; for (uint j = 0; j < count; j++) { GameObject go = (GameObject)GameMain.instantiate(prefab); go.transform.SetParent(parent, false); splineMove sm = go.AddComponent <splineMove>(); sm.local = true; sm.lookAhead = 0.01f; sm.forwardDir = Vector3.right; sm.pathMode = PathMode.Ignore; sm.offset = index < pd.m_Offsets.Count ? pd.m_Offsets[index] : Vector3.zero; sm.waypointRotation = (fd.m_nRotType == 1) ? splineMove.RotationType.all : splineMove.RotationType.none; if (m_GameBase.IsMirror()) { sm.eulerAngles = (fd.m_nRotType == 1) ? new Vector3(180f, 0f, 0f) : new Vector3(0f, 0f, 180f); } else { sm.eulerAngles = Vector3.zero; } sm.speed = fd.m_GroupSpeed[group]; sm.loopType = pd.m_bLoop ? splineMove.LoopType.loop : splineMove.LoopType.none; sm.SetPath(pm); sm.GoTo(GetPathPassTime(passTime, sm, pd)); if (FishPause) { sm.Pause(); } Fishing_Fish fish = go.transform.Find("skin").gameObject.AddComponent <Fishing_Fish>(); fish.Init(m_GameBase, sm, fishId + j, fishTypeId); fish.OnDeath += RemoveFish; fishs[j] = fish; m_FishDict.Add(fish.m_nOnlyId, fish); } return(fishs); }
void ReadFishingData() { List <string[]> strList; int j; byte id; ushort pathId; byte temp; CReadCsvBase.ReaderCsvDataFromAB(GameDefine.CsvAssetbundleName, "Fishing_Cannon.txt", out strList); int columnCount = strList.Count; for (int i = 2; i < columnCount; i++) { j = 0; FishingCannonData gamedata = new FishingCannonData(); byte.TryParse(strList[i][j++], out id); gamedata.m_szCannon = strList[i][j++]; gamedata.m_szBullet = strList[i][j++]; float.TryParse(strList[i][j++], out gamedata.m_fBulletSpeed); float.TryParse(strList[i][j++], out gamedata.m_fBulletCD); float.TryParse(strList[i][j++], out gamedata.m_fBulletLifeTime); byte.TryParse(strList[i][j++], out gamedata.m_nBounceTimes); //float.TryParse(strList[i][j++], out gamedata.m_fExplosinRange); j++; gamedata.m_szNet = strList[i][j++]; //int.TryParse(strList[i][j++], out gamedata.m_nBulletCost); j++; //level not read j++; gamedata.m_szBulletPoint = strList[i][j++].Split('|'); gamedata.m_szLvPoint = strList[i][j++]; //gamedata.m_szIcon = strList[i][j++]; j++; int.TryParse(strList[i][j++], out gamedata.m_nAudio); j += 2; gamedata.m_szName = strList[i][j++]; gamedata.m_szDetail = strList[i][j++]; m_CannonData[id] = gamedata; } strList.Clear(); CReadCsvBase.ReaderCsvDataFromAB(GameDefine.CsvAssetbundleName, "Fishing_Path.txt", out strList); columnCount = strList.Count; for (int i = 2; i < columnCount; i++) { j = 0; FishingPathData gamedata = new FishingPathData(); ushort.TryParse(strList[i][j++], out pathId); gamedata.m_szPath = strList[i][j++]; float.TryParse(strList[i][j++], out gamedata.m_fSpeed); float.TryParse(strList[i][j++], out gamedata.m_fTime); byte.TryParse(strList[i][j++], out temp); gamedata.m_bLoop = temp == 0 ? false : true; string str = strList[i][j++]; if (!string.IsNullOrEmpty(str)) { string[] offsets = str.Split('@'); string[] point; foreach (string oft in offsets) { point = oft.Split('|'); Debug.Assert(point.Length == 3, "offset point coordinate wrong(not 3)!!"); Vector3 pos = new Vector3(); float.TryParse(point[0], out pos.x); float.TryParse(point[1], out pos.y); float.TryParse(point[2], out pos.z); gamedata.m_Offsets.Add(pos); } } str = strList[i][j++]; if (!string.IsNullOrEmpty(str)) { string[] speedChange = str.Split('@'); string[] info; foreach (string sc in speedChange) { info = sc.Split('|'); Debug.Assert(info.Length == 3, "point change speed info is wrong(not 3)!!"); byte pointIndex, endIndex; float speed, time; byte.TryParse(info[0], out pointIndex); float.TryParse(info[1], out speed); if (speed == 0f)//pause { float.TryParse(info[2], out time); gamedata.m_ChangePoints[pointIndex] = -time; } else//change speed { byte.TryParse(info[2], out endIndex); gamedata.m_ChangePoints[pointIndex] = speed; gamedata.m_ChangePoints[endIndex] = 1f;//change back } } } m_PathData[pathId] = gamedata; } strList.Clear(); CReadCsvBase.ReaderCsvDataFromAB(GameDefine.CsvAssetbundleName, "Fishing_Fish.txt", out strList); columnCount = strList.Count; for (int i = 2; i < columnCount; i++) { j = 0; FishingFishData gamedata = new FishingFishData(); byte.TryParse(strList[i][j++], out id); gamedata.m_szFish = strList[i][j++]; string[] groupspeed = strList[i][j++].Split('@'); string[] speedStr; foreach (string speed in groupspeed) { speedStr = speed.Split('|'); Debug.Assert(speedStr.Length == 2, "group speed data is wrong(not 2)!!"); gamedata.m_GroupSpeed[byte.Parse(speedStr[0])] = float.Parse(speedStr[1]); } //float.TryParse(strList[i][j++], out gamedata.m_fHitRate); j++; int.TryParse(strList[i][j++], out gamedata.m_nMultiple); j += 5; int.TryParse(strList[i][j++], out gamedata.m_nHitAudio); int.TryParse(strList[i][j++], out gamedata.m_nDeadAudio); string[] strs = strList[i][j++].Split('|'); if (strs.Length == 3) { byte.TryParse(strs[0], out gamedata.m_nTalkInterval); byte.TryParse(strs[1], out gamedata.m_nTalkShowTime); gamedata.m_szTalk = strs[2]; } j += 3; byte.TryParse(strList[i][j++], out temp); gamedata.m_eFishType = (FishType)temp; gamedata.m_szName = strList[i][j++]; gamedata.m_szIcon = strList[i][j++]; byte.TryParse(strList[i][j++], out gamedata.m_nRotType); m_FishData[id] = gamedata; } }
public void CreatePathFish(ushort pathId, uint fishId, byte typeId, float pathPassTime, byte group, byte index) { if (pathPassTime < 0f) { return; } if (!Fishing_Data.GetInstance().m_PathData.ContainsKey(pathId)) { DebugLog.LogWarning("Error: reate path id(" + pathId + ") no path data!"); return; } FishingPathData pd = Fishing_Data.GetInstance().m_PathData[pathId]; PathManager pm; PathInfo pi = null; List <Fishing_Fish> fishList = null; if (m_PathDict.ContainsKey(pathId)) { pm = m_PathDict[pathId]; if (m_PathFishList.ContainsKey(pm)) { pi = m_PathFishList[pm]; fishList = pi.fishList; } else { DebugLog.LogError("fishMgr pathFishList not contain dict's pm!"); } } else { //create path GameObject prefab = (GameObject)m_GameBase.FishingAssetBundle.LoadAsset(pd.m_szPath); if (prefab == null) { DebugLog.LogWarning("Fail to preload path:" + pd.m_szPath); return; } GameObject path = (GameObject)GameMain.instantiate(prefab); path.transform.SetParent(m_WaypointMgr.transform); pm = path.GetComponent <PathManager>(); fishList = new List <Fishing_Fish>(); pi = new PathInfo(); pi.speed = pd.m_fSpeed; pi.time = pd.m_fTime; m_PathDict[pathId] = pm; } Fishing_Fish[] fish = CreatFish(typeId, pd, pm.transform, pm, fishId, 1, pathPassTime, group, index); fishList.AddRange(fish); pi.fishList = fishList; m_PathFishList[pm] = pi; if (pd.m_fSpeed != 0f) { float endX = pm.transform.localPosition.x + pd.m_fSpeed * pd.m_fTime; pm.transform.Translate(pd.m_fSpeed * pathPassTime, 0f, 0f); Tweener t = pm.transform.DOLocalMoveX(endX, pd.m_fTime - pathPassTime); if (pd.m_bLoop) { t.OnComplete(() => RemovePath(pm)); } } }
float GetPathPassTime(float passTime, splineMove sm, FishingPathData pd) { if (pd.m_ChangePoints.Count == 0) { return(passTime); } float value; float speed = sm.speed; float countTime = passTime; List <byte> changeList = new List <byte>(pd.m_ChangePoints.Keys); if (passTime > 0f) { sm.tween.ForceInit(); TweenerCore <Vector3, Path, PathOptions> tweenPath = sm.tween as TweenerCore <Vector3, Path, PathOptions>; float time = 0f; countTime = 0f; float curSpeed = speed; for (byte i = 0; i < sm.pathContainer.GetWaypointCount(); i++) { value = tweenPath.changeValue.wpLengths[i] / curSpeed; time += value; countTime += value; if (passTime <= time) { countTime -= (time - passTime); break; } if (pd.m_ChangePoints.ContainsKey(i)) { changeList.Remove(i); if (i >= sm.events.Count) { DebugLog.LogWarning("Error: fish point count(" + sm.events.Count + ") out path(" + pd.m_szPath + ") change config!!"); break; } value = pd.m_ChangePoints[i]; if (value > 0f) { sm.events[i].AddListener(() => sm.ChangeSpeed(value * speed)); curSpeed = speed * value; } else { time -= value; if (passTime <= time) { sm.events[i].AddListener(() => sm.Pause(time - passTime)); break; } } } } } foreach (byte i in changeList) { if (i >= sm.events.Count) { DebugLog.LogWarning("Error: fish point count(" + sm.events.Count + ") out path(" + pd.m_szPath + ") change config!!"); break; } value = pd.m_ChangePoints[i]; if (value > 0f) { sm.events[i].AddListener(() => sm.ChangeSpeed(value * speed)); } else { sm.events[i].AddListener(() => sm.Pause(-value)); } } return(countTime); }