public static void Add(long sn, CMapObject mo) { if (dict_.ContainsKey(sn)) { CMapObject old = dict_[sn]; old.Dispose(); dict_.Remove(sn); LOG.Erro("MapObjectDict Contains same MapObject SN = " + sn); } dict_[sn] = mo; }
public static void Clear() { if (dict_.Count > 0) { var moList = new CMapObject[dict_.Count]; dict_.Values.CopyTo(moList, 0); dict_.Clear(); foreach (CMapObject mo in moList) { mo.Dispose(); } } }
protected override void Initialize() { if (this.BindObject is CMapObject) { mapobj = this.BindObject as CMapObject; } /* if (mapobj.reference.ClickEffect == MapObjetType.Obstacle) * { * NavMeshObstacle Obstacle = this.gameObject.AddComponent<NavMeshObstacle>(); * Obstacle.carving = true; * Obstacle.shape = NavMeshObstacleShape.Box; * }*/ }
void LoadMapObjects(ref BinaryReader binaryReader) { int ObjectCount = binaryReader.ReadInt32(); byte[] ObjectCountBuffer = binaryReader.ReadBytes(ObjectCount); for (int j = 0; j < ObjectCount; ++j) { string ObjectName = binaryReader.ReadString(); for (int i = 0; i < ObjectCountBuffer[j]; ++i) { GameObject instance = Instantiate <GameObject>(CResourceMgr.LoadMapObject(ObjectName)); CMapObject component = instance.GetComponent <CMapObject>(); component.Read(ref binaryReader); component.UpdatePos(); } } }
void SaveMapObject(ref BinaryWriter binaryWriter) { CTimeCheck.Start(); Dictionary <string, CMapObject[]> SortMapObjects = new Dictionary <string, CMapObject[]>(); CMapObject[] MapObjects = FindObjectsOfType <CMapObject>(); foreach (var MapObject in MapObjects) { CMapObject[] FindMapObjects; string FixName = MapObject.name; int FindIndex = FixName.IndexOf('('); if (-1 != FindIndex) { FixName = FixName.Remove(FindIndex); } FixName = FixName.Trim(); if (SortMapObjects.TryGetValue(FixName, out FindMapObjects)) { for (int i = 0; i < FindMapObjects.Length; ++i) { if (FindMapObjects[i] == null) { FindMapObjects[i] = MapObject; break; } } } else { CMapObject[] AddMapObjects = new CMapObject[100]; AddMapObjects[0] = MapObject; SortMapObjects.Add(FixName, AddMapObjects); } } binaryWriter.Write(SortMapObjects.Keys.Count); byte[] ObjectCountBuffer = new byte[SortMapObjects.Keys.Count]; int Index = 0; foreach (var kv in SortMapObjects) { CMapObject[] Values = kv.Value; for (int i = 0; i < Values.Length; ++i) { if (Values[i] == null) { ObjectCountBuffer[Index] = (byte)i; break; } } ++Index; } binaryWriter.Write(ObjectCountBuffer); foreach (var kv in SortMapObjects) { binaryWriter.Write(kv.Key); CMapObject[] Values = kv.Value; for (int i = 0; i < Values.Length; ++i) { if (Values[i] != null) { Values[i].Write(ref binaryWriter); } else { break; } } } CTimeCheck.End(ELogType.MapGenerator, "map generator save map object"); }