private static JsonEnemyEnvironmentStructure GetEnemyData(Enemy enemy) { Vector2 position = enemy.getActualPosition(); Weapon weapon = enemy.Weapon; JsonEnemyEnvironmentStructure structure = new JsonEnemyEnvironmentStructure { ID = enemy.ID, Type = GetEnemyType(enemy), Health = enemy.health, MaxVelocity = enemy.maxVelocity, TurnVelocity = enemy.turnVelocity, PatrolVelocity = enemy.patrolVelocity, CurrentVelocity = enemy.navAgent.velocity, Acceleration = enemy.acceleration, VisionAngle = enemy.visionAngle, VisionRange = enemy.visionRange, Position = new JsonFloatPositionStructure(position.x, position.y), Rotation = enemy.transform.rotation.z, Awareness = enemy.awarenessSystem.Awareness, InciteEnemiesRange = enemy.inciteEnemiesRange, VisibleElements = GetVisibleElementsData(enemy) }; if (weapon) { structure.WeaponType = GetWeaponType(weapon); structure.Ammunition = weapon.GetAmmo(); structure.ProjectileDamage = weapon.GetProjectileDamage(); structure.ProjectileSpeed = weapon.GetProjectileVelocity(); } return(structure); }
/// <summary> /// Serialize environment data for an enemy as json using Json.NET /// </summary> /// <param name="enemy"></param> public static string SerializeEnemyEnvironmentData(Enemy enemy) { JsonEnemyEnvironmentStructure enemyNode = GetEnemyData(enemy); return(JsonConvert.SerializeObject(enemyNode)); }