public void Find() { List <UnitCtl> buildList = War.scene.GetBuilds(); int count = buildList.Count; Dictionary <string, bool> setdict = new Dictionary <string, bool>(); for (int fromIndex = 0; fromIndex < count; fromIndex++) { UnitCtl from = buildList[fromIndex]; for (int toIndex = 0; toIndex < count; toIndex++) { UnitCtl to = buildList[toIndex]; if (from != to) { string key = StagePathData.GetKey(from.unitData.uid, to.unitData.uid); if (!setdict.ContainsKey(key)) { setdict.Add(key, true); findCount++; MoveTo(from, to); } } } } isSeted = true; }
//保存路径 public void btnSavePath() { //更新pathData数据 Vector3[] pathPos = iTweenPath.GetPath("path"); mPathData.AddPointForce(mFromId, mToId, pathPos); //保存至json文件 string str = JsonConvert.SerializeObject(mPathData, Formatting.Indented); string filesPath = Application.dataPath + "/Game/" + StagePathData.GetFilePath(mPathData.stageId) + ".json"; Debug.Log(filesPath); PathUtil.CheckPath(filesPath, true); if (File.Exists(filesPath)) { File.Delete(filesPath); } FileStream fs = new FileStream(filesPath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); sw.Write(str); sw.Close(); fs.Close(); }
public void Init() { pathData = new StagePathData(); pathData.stageId = War.sceneData.stageConfig.id; findCount = 0; findedCount = 0; isSeted = false; Find(); }
public void Save() { string str = JsonConvert.SerializeObject(pathData, Formatting.Indented); string filesPath = Application.dataPath + "/Game/" + StagePathData.GetFilePath(pathData.stageId) + ".json"; Debug.Log(filesPath); PathUtil.CheckPath(filesPath, true); if (File.Exists(filesPath)) { File.Delete(filesPath); } FileStream fs = new FileStream(filesPath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); sw.Write(str); sw.Close(); fs.Close(); Final(); }
//显示路径 public void btnShowPath() { mFromId = mFromIdxStr.ToInt32(); mToId = mToIdxStr.ToInt32(); if (War.sceneData == null) { Debug.Log("=====err cant find war===="); return; } mCurStageId = War.sceneData.stageConfig.id; //获取配置表 //object asset = WarRes.GetRes<object>(StagePathData.GetFilePath(mCurStageId)); //if (asset == null) //{ // Debug.Log("=============asset null============="); // return; //} string content = LoadFile(Application.dataPath + "/Game/Config/stage_path/path_" + mCurStageId + ".json"); Debug.Log("=================ShowPath =================: " + content.Length); mPathData = JsonConvert.DeserializeObject(content, typeof(StagePathData)) as StagePathData; Dictionary <string, PathPoint[]> pointDict = mPathData.pointDict; List <Vector3> nodes = new List <Vector3>(); //获取路径 mKey = string.Format("{0}_{1}", mFromIdxStr, mToIdxStr); PathPoint [] Pt; if (!pointDict.TryGetValue(mKey, out Pt)) { mKey = string.Format("{0}_{1}", mToIdxStr, mFromIdxStr); if (!pointDict.TryGetValue(mKey, out Pt)) { Debug.Log("cant find key: " + mKey); mKey = ""; return; } } Debug.Log("===key: " + mKey); for (int i = 0; i < Pt.Length; i++) { Vector3 vc = Vector3.zero; vc.x = Pt[i].x; vc.y = 0.0f; vc.z = Pt[i].z; nodes.Add(vc); Debug.LogFormat("===path pot:{0} {1} {2}===", vc.x, vc.y, vc.z); } //iTween.DrawPath(nodes.ToArray(), Color.red); //绘制路径 GameObject go = GameObject.Find("WarEditorScene/Path"); iTweenPath iPath = go.GetComponent <iTweenPath>(); iPath.nodeCount = 0; iPath.nodes.Clear(); for (int i = 0; i < nodes.Count; i++) { Vector3 pos = Vector3.zero; pos.x = nodes[i].x; pos.y = nodes[i].y; pos.z = nodes[i].z; iPath.nodes.Add(pos); } }