private void RefreshUnitCahce( Unit unit ) { lock ( _unitSync ) { HashSet<Unit> set; if ( _playerUnits.TryGetValue( unit.Owner, out set ) == false ) _playerUnits[unit.Owner] = set = new HashSet<Unit>(); set.Add( unit ); if ( _placeUnits.TryGetValue( unit.Coordinate, out set ) == false ) _placeUnits[unit.Coordinate] = set = new HashSet<Unit>(); set.Add( unit ); } }
/// <summary> /// 保存游戏单位对象 /// </summary> /// <param name="unit"></param> private void Save( Unit unit ) { RefreshUnitCahce( unit ); var filepath = Path.Combine( unitsDirectory, unit.Guid + ".json" ); File.WriteAllText( filepath, unit.SaveAsJson() ); }
/// <summary> /// 获取单位可以执行的操作列表 /// </summary> /// <param name="unit"></param> /// <returns></returns> public virtual ActionDescriptor[] GetActions( Unit unit ) { return new ActionDescriptor[0]; }