private static void SaveMesh(CAIBakedNavmesh targ, string filePath) { if (filePath.Length == 0 || !targ.HasNavmesh) { return; } FileStream fs = null; BinaryFormatter formatter = new BinaryFormatter(); try { fs = new FileStream(filePath, FileMode.Create); formatter.Serialize(fs, targ.GetNavmesh().GetSerializedMesh()); } catch (System.Exception ex) { Debug.LogError(targ.name + ": BakedNavmesh: Save bytes failed: " + ex.Message); } finally { if (fs != null) { fs.Close(); } } }
public static void Init(BattleParams param) { _init = true; _shouldSendActions = false; string model = ModelFactory.GetBattleData(Utils.GetIDFromRID(param.id)).model; CAIBakedNavmesh navmeshData = AssetsManager.LoadAsset <CAIBakedNavmesh>("scene/" + model + "_navmesh", "CAIBakedNavmesh"); _framesPerKeyFrame = param.framesPerKeyFrame; _frameRate = param.frameRate; _nextKeyFrame = param.framesPerKeyFrame; cBattle = new VBattle(param); lBattle = new Battle(param, navmeshData.GetNavmesh(), Env.LUA_ENV); _logicThread = new Thread(LogicWorker); _logicThread.IsBackground = true; _logicThread.Start(); NetModule.instance.AddACMDListener(Module.BATTLE, Command.ACMD_BATTLE_START, HandleBattleStart); NetModule.instance.AddACMDListener(Module.BATTLE, Command.ACMD_FRAME, HandleFrame); NetModule.instance.AddACMDListener(Module.BATTLE, Command.ACMD_BATTLE_END, HandleBattleEnd); NetModule.instance.Send(ProtocolManager.PACKET_BATTLE_QCMD_BATTLE_CREATED()); }
static void CreateAsset() { CAIBakedNavmesh item = EditorUtil.CreateAsset <CAIBakedNavmesh>(NavEditorUtil.AssetLabel); EditorUtility.FocusProjectWindow(); Selection.activeObject = item; }
private static void SaveMesh(CAIBakedNavmesh targ, string filePath) { if (filePath.Length == 0 || !targ.HasNavmesh) { return; } FileStream fs = null; BinaryFormatter formatter = new BinaryFormatter(); try { fs = new FileStream(filePath, FileMode.Create); formatter.Serialize(fs, targ.GetNavmesh().GetSerializedMesh()); } catch (System.Exception ex) { Debug.LogError(targ.name + ": BakedNavmesh: Save bytes failed: " + ex.Message); } finally { if (fs != null) { fs.Close(); } } FileStream pFileStream = null; try { byte[] meshData = targ.GetNavmesh().GetSerializedMesh(); pFileStream = new FileStream(filePath + ".byte", FileMode.OpenOrCreate); pFileStream.Write(meshData, 0, meshData.Length); } catch { //return false; } finally { if (pFileStream != null) { pFileStream.Close(); } } //return true; }
private static bool LoadMesh(CAIBakedNavmesh targ, string filePath) { string msg = null; if (filePath.Length == 0) { return(false); } FileStream fs = null; BinaryFormatter formatter = new BinaryFormatter(); try { fs = new FileStream(filePath, FileMode.Open); System.Object obj = formatter.Deserialize(fs); NavStatus status = targ.Load((byte[])obj, null); if ((status & NavStatus.Sucess) == 0) { msg = status.ToString(); } } catch (System.Exception ex) { msg = ex.Message; } finally { if (fs != null) { fs.Close(); } } if (msg != null) { Debug.LogError(targ.name + ": BakedNavmesh: Load bytes failed: " + msg); return(false); } return(true); }
static void CreateLoadedAsset() { NavmeshBuild item = EditorUtil.CreateAsset <NavmeshBuild>(NMBEditorUtil.AssetLabel); ScriptableObject child; child = EditorUtil.CreateAsset <MeshCompiler>(item, NMBEditorUtil.AssetLabel); item.inputProcessors.Add(child); CAIBakedNavmesh nm = EditorUtil.CreateAsset <CAIBakedNavmesh>(item, NMBEditorUtil.AssetLabel); item.BuildTarget = nm; EditorUtility.SetDirty(item); EditorUtility.FocusProjectWindow(); Selection.activeObject = item; }
private static void SaveMesh(CAIBakedNavmesh targ, string filePath) { if (filePath.Length == 0 || !targ.HasNavmesh) { return; } FileStream fs = null; BinaryFormatter formatter = new BinaryFormatter(); try { fs = new FileStream(filePath, FileMode.Create); formatter.Serialize(fs, targ.GetNavmesh().GetSerializedMesh()); } catch (System.Exception ex) { Debug.LogError(targ.name + ": BakedNavmesh: Save bytes failed: " + ex.Message); } finally { if (fs != null) { fs.Close(); } } fs = new FileStream(filePath, FileMode.Open); System.Object obj = formatter.Deserialize(fs); byte[] datas = (byte[])obj; string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(filePath); filePath = filePath.Replace(fileNameWithoutExtension + ".", "NFServer_" + fileNameWithoutExtension + "."); FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write); fs1.Write(datas, 0, datas.Length); fs1.Close(); fs.Close(); }
private static bool LoadMesh(CAIBakedNavmesh targ, string filePath) { string msg = null; if (filePath.Length == 0) return false; FileStream fs = null; BinaryFormatter formatter = new BinaryFormatter(); try { fs = new FileStream(filePath, FileMode.Open); System.Object obj = formatter.Deserialize(fs); NavStatus status = targ.Load((byte[])obj, null); if ((status & NavStatus.Sucess) == 0) msg = status.ToString(); } catch (System.Exception ex) { msg = ex.Message; } finally { if (fs != null) fs.Close(); } if (msg != null) { Debug.LogError(targ.name + ": BakedNavmesh: Load bytes failed: " + msg); return false; } return true; }
private static void SaveMesh(CAIBakedNavmesh targ, string filePath) { if (filePath.Length == 0 || !targ.HasNavmesh) return; FileStream fs = null; BinaryFormatter formatter = new BinaryFormatter(); try { fs = new FileStream(filePath, FileMode.Create); formatter.Serialize(fs, targ.GetNavmesh().GetSerializedMesh()); } catch (System.Exception ex) { Debug.LogError(targ.name + ": BakedNavmesh: Save bytes failed: " + ex.Message); } finally { if (fs != null) fs.Close(); } fs = new FileStream(filePath, FileMode.Open); System.Object obj = formatter.Deserialize(fs); byte[] datas = (byte[])obj; string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(filePath); filePath = filePath.Replace(fileNameWithoutExtension + ".", "srv_" + fileNameWithoutExtension + "."); FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write); fs1.Write(datas, 0, datas.Length); fs1.Close(); fs.Close(); }
/// <summary> /// Controls behavior of the inspector. /// </summary> public override void OnInspectorGUI() { CAIBakedNavmesh targ = (CAIBakedNavmesh)target; EditorGUILayout.Separator(); EditorGUILayout.LabelField("Status", (targ.HasNavmesh ? "Has mesh" : "Empty")); EditorGUILayout.LabelField("Version", targ.Version.ToString()); EditorGUILayout.LabelField("Input Scene", NavEditorUtil.SceneDisplayName(targ.BuildInfo)); EditorGUILayout.Separator(); NavmeshSceneDraw.Instance.OnGUI(targ, "Show Mesh", true, true); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); GUI.enabled = targ.HasNavmesh; if (GUILayout.Button("Save")) { string filePath = EditorUtility.SaveFilePanel( "Save Navigation Mesh" , "" , targ.name , "navmesh"); SaveMesh(targ, filePath); } GUI.enabled = true; if (GUILayout.Button("Load")) { string filePath = EditorUtility.OpenFilePanel( "Select Serialized Navmesh" , "" , "navmesh"); if (LoadMesh(targ, filePath)) { GUI.changed = true; } } EditorGUILayout.EndHorizontal(); if (targ.HasNavmesh) { EditorGUILayout.Separator(); if (GUILayout.Button("Log Mesh State")) { Debug.Log(targ.GetMeshReport()); } } EditorGUILayout.Separator(); if (GUI.changed) { EditorUtility.SetDirty(target); } }
private static void SaveMesh(CAIBakedNavmesh targ, string szFilePath) { /* if (!string.IsNullOrEmpty(szFilePath) && targ.HasNavmesh) { string szFileName = EditorSupport.GetFileName(szFilePath, true); if (szFileName.Length > 0) { FileStream stream = new FileStream( szFilePath, FileMode.Create ); // serialize the file stream BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize( stream, targ.GetNavmesh().GetSerializedMesh() ); stream.Close(); int nStart = szFilePath.LastIndexOf("/"); int nEnd = szFilePath.LastIndexOf("."); string szServerFilePath = szFilePath.Substring (0, nStart + 1); if (!string.IsNullOrEmpty(szServerFilePath)) { // save to server file FileStream hStream = new FileStream( szFilePath, FileMode.Open ); System.Object bytes = formatter.Deserialize(hStream); byte[] datas = (byte[])bytes; FileStream hServer = new FileStream(szServerFilePath + szFileName + ".snav", FileMode.Create, FileAccess.Write); hServer.Write(datas, 0, datas.Length); hServer.Close(); hStream.Close(); // export obj file if (bExportObj) { CAIObjFileExport.ExportObj (szServerFilePath); } if (bSaveToAssetbundle) { nStart = Application.dataPath.LastIndexOf("/"); string szReplace = Application.dataPath.Substring(0, nStart + 1); string szAssetPath = szFilePath.Replace(szReplace, string.Empty); if (!string.IsNullOrEmpty(szAssetPath)) { string szDirectory = EditorSupport.URL + "/NavMesh"; if (!Directory.Exists(szDirectory)) Directory.CreateDirectory(szDirectory); UnityEngine.Object prefab = AssetDatabase.LoadMainAssetAtPath(szAssetPath); if (prefab) { EditorSupport.Build(prefab, szDirectory + "/" + szFileName + ".navscene"); } } } } } } */ }
private static bool LoadMesh(CAIBakedNavmesh targ, string filePath) { if (string.IsNullOrEmpty (filePath)) return false; string szErrorMessage = string.Empty; try{ FileStream fs = new FileStream ( filePath, FileMode.Open ); BinaryFormatter formatter = new BinaryFormatter(); System.Object bytes = formatter.Deserialize(fs); NavStatus status = targ.Load((byte[])bytes, null); if ((status & NavStatus.Sucess) == 0) szErrorMessage = status.ToString(); fs.Close(); } catch(System.Exception e) { FileStream fs = new FileStream (filePath, FileMode.Open); byte[] buffer = new byte[fs.Length]; fs.Read (buffer, 0, (int)fs.Length); NavStatus status = targ.Load(buffer, null); if ((status & NavStatus.Sucess) == 0) szErrorMessage = status.ToString(); fs.Close(); } return !string.IsNullOrEmpty(szErrorMessage); }
private static void SaveMesh(CAIBakedNavmesh targ, string szFilePath) { if (!string.IsNullOrEmpty(szFilePath) && targ.HasNavmesh) { string szFileName = GetFileName(szFilePath, true); if (szFileName.Length > 0) { FileStream stream = new FileStream( szFilePath, FileMode.Create ); // serialize the file stream BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize( stream, targ.GetNavmesh().GetSerializedMesh() ); stream.Close(); int nStart = szFilePath.LastIndexOf("/"); int nEnd = szFilePath.LastIndexOf("."); string szServerFilePath = szFilePath.Substring (0, nStart + 1); if (!string.IsNullOrEmpty(szServerFilePath)) { // save to server file FileStream hStream = new FileStream( szFilePath, FileMode.Open ); System.Object bytes = formatter.Deserialize(hStream); byte[] datas = (byte[])bytes; FileStream hServer = new FileStream(szServerFilePath + szFileName + ".snav", FileMode.Create, FileAccess.Write); hServer.Write(datas, 0, datas.Length); hServer.Close(); hStream.Close(); // export obj file if (bExportObj) { CAIObjFileExport.ExportObj (szServerFilePath); } } } } }
private static void SaveMesh(CAIBakedNavmesh targ, string filePath) { if (filePath.Length == 0 || !targ.HasNavmesh) return; FileStream fs = null; BinaryFormatter formatter = new BinaryFormatter(); try { fs = new FileStream(filePath, FileMode.Create); formatter.Serialize(fs, targ.GetNavmesh().GetSerializedMesh()); } catch (System.Exception ex) { Debug.LogError(targ.name + ": BakedNavmesh: Save bytes failed: " + ex.Message); } finally { if (fs != null) fs.Close(); } }