本文整理汇总了C#中ConfigFile.GetKey_String方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigFile.GetKey_String方法的具体用法?C# ConfigFile.GetKey_String怎么用?C# ConfigFile.GetKey_String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigFile
的用法示例。
在下文中一共展示了ConfigFile.GetKey_String方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TurretBuilding
public TurretBuilding(string configName)
: base(configName)
{
ConfigFile config = new ConfigFile(configName);
m_AlertRadius = config.GetKey_Float("Turret", "AlertRadius");
m_FireRadius = config.GetKey_Float("Turret", "FireRadius");
int numGuns = config.GetKey_Int("Turret", "NumGuns");
BaseShip_Weapon currWeapon = null;
string gunGroup = "Gun";
string gunType = "";
for(int i = 0; i < numGuns; ++i)
{
gunGroup += (i+1).ToString();
gunType = config.GetKey_String(gunGroup, "Type");
currWeapon = new BaseShip_Weapon();
//currWeapon.CanRotate = ((config.GetKey_Int(gunGroup, "CanRotate") == 1) ? true : false);
currWeapon.CoolDownRate = config.GetKey_Float(gunType , "CoolDown");;
currWeapon.Position = config.GetKey_Vector2(gunGroup, "Pos");
currWeapon.WeaponSprite = new Sprite("Textures/" + config.GetKey_String(gunType, "Texture"));
currWeapon.WeaponSprite.SetSpriteSize(currWeapon.WeaponSprite.GetTextureSize());//config.GetKey_Vector2(gunGroup, "Size"));
currWeapon.WeaponSprite.SetSpritePos(Position);
currWeapon.WeaponSprite.SetGeometrySize(currWeapon.WeaponSprite.GetSpriteSize() / 2);
currWeapon.WeaponSprite.SetRotationCenter(currWeapon.WeaponSprite.GetGeometrySize() / 2.0f);
currWeapon.WeaponSprite.SetDepth(Globals.WeaponsDepth);
Globals.WorldView.SManager.AddSprite(currWeapon.WeaponSprite);
gunType.ToLower();
if(gunType == "gatling")
currWeapon.WeaponType = BaseShip_WeaponTypes.Gatling;
else if(gunType == "rail")
currWeapon.WeaponType = BaseShip_WeaponTypes.RailGun;
else if(gunType == "missile")
currWeapon.WeaponType = BaseShip_WeaponTypes.Missile;
else
currWeapon.WeaponType = BaseShip_WeaponTypes.Laser;
m_Guns.Add(currWeapon);
}
Sprite.SetDepth(Globals.BuildingDepth);
}
示例2: LevelManager
/*** Public Members ***/
// Generate a given level index
public LevelManager(int LevelIndex)
{
// Construct the level based on the seed
ConfigFile Info = new ConfigFile("Config/World/LevelsConfig");
// Get the level name
String LevelName = Info.GetKey_String("Level" + LevelIndex, "Scene");
Application.LoadLevelAdditive(LevelName);
// Level world size
int LevelSize = Info.GetKey_Int("Level" + LevelIndex, "Size");
// Get full long-text level description
Description = Info.GetKey_String("Level" + LevelIndex, "description");
WinText = Info.GetKey_String("Level" + LevelIndex, "win");
LoseText = Info.GetKey_String("Level" + LevelIndex, "lose");
}
示例3: ShipyardBuilding
public ShipyardBuilding(string configName)
: base(configName)
{
ConfigFile configFile = new ConfigFile(configName);
m_ShipCapacity = configFile.GetKey_Int("Shipyard", "ShipCapacity");
m_BuildCoolDown = configFile.GetKey_Float("Shipyard", "BuildCoolDown");
m_ShipConfig = configFile.GetKey_String("Shipyard", "ShipConfig");
}
示例4: BaseBuilding
public BaseBuilding(string configFilename)
{
ConfigFile config = new ConfigFile(configFilename);
m_Name = config.GetKey_String("General", "Name");
m_MaxHealth = m_Health = config.GetKey_Int("General", "Health");
m_Armor = config.GetKey_Int("General", "Armor");
m_ConsumptionRate = config.GetKey_Float("General", "ConsumptionRate");
m_MaxUpgradeLevels = config.GetKey_Int("General", "MaxUpgradeLevels");
m_UpgradeMagnitude = config.GetKey_Int("General", "UpgradeMagnitude");
m_MaxConnDist = config.GetKey_Float("General", "MaxConnDist");
m_MinConnDist = config.GetKey_Float("General", "MinConnDist");
Vector2 tempPrice = config.GetKey_Vector2("General", "Price");
m_MineralPrice = (int)tempPrice.x;
m_GasPrice = (int)tempPrice.y;
m_Sprite = new Sprite("Textures/" + config.GetKey_String("General", "Texture"));
m_Sprite.SetGeometrySize(config.GetKey_Vector2("General", "Size"));
m_Sprite.SetRotationCenter(m_Sprite.GetGeometrySize() / 2);
Globals.WorldView.SManager.AddSprite(m_Sprite);
}
示例5: CreateBuilding
public BaseBuilding CreateBuilding(string configName)
{
ConfigFile configFile = new ConfigFile(configName);
string buildingType = configFile.GetKey_String("General", "Type");
buildingType = buildingType.Trim().ToLower();
BaseBuilding newBuilding = null;
if(buildingType == "turret")
newBuilding = new TurretBuilding(configName);
else if(buildingType == "shipyard")
newBuilding = new ShipyardBuilding(configName);
else if(buildingType == "powernode")
newBuilding = new PowerNodeBuilding(configName);
else if(buildingType == "commandcenter")
newBuilding = new CommandCenterBuilding(configName);
else
newBuilding = new BaseBuilding(configName);
newBuilding.Sprite.SetColor(Color.grey);
m_CurrBuilding = newBuilding;
return newBuilding;
}
示例6: LoadWeapon
// Load a weapon based on the current group name (and does the internal sprite loading too)
private BaseShip_Weapon LoadWeapon(ConfigFile Info, String GroupName)
{
// Ignore if not weapon
if(GroupName.ToLower().StartsWith("weapon") == false)
return null;
// Load from config files
BaseShip_Weapon Weapon = new BaseShip_Weapon();
String Type = Info.GetKey_String(GroupName, "Type");
Weapon.Position = Info.GetKey_Vector2(GroupName, "Pos");
// Get sprite info
ConfigFile SpriteInfo = new ConfigFile("Config/Weapons/WeaponsConfig");
String TextureName = SpriteInfo.GetKey_String(Type, "Texture");
Weapon.CoolDownRate = SpriteInfo.GetKey_Float(Type, "CoolDown");
Vector2 SPos = SpriteInfo.GetKey_Vector2(Type, "Pos");
Vector2 SSize = SpriteInfo.GetKey_Vector2(Type, "Size");
//Vector2 SCenter = SpriteInfo.GetKey_Vector2(Type, "Center"); // Todo, so we rotate about a point, not center
int SCount = SpriteInfo.GetKey_Int(Type, "Count");
float STime = SpriteInfo.GetKey_Float(Type, "Time");
// Load the sprite
Weapon.WeaponSprite = new Sprite("Textures/" + TextureName);
Weapon.WeaponSprite.SetSpritePos(SPos);
Weapon.WeaponSprite.SetSpriteSize(SSize);
Weapon.WeaponSprite.SetGeometrySize(Weapon.WeaponSprite.GetSpriteSize());
Weapon.WeaponSprite.SetRotationCenter(Weapon.WeaponSprite.GetGeometrySize() / 2.0f);
// Set animation (if any)
Weapon.WeaponSprite.SetAnimation(SPos, SSize, SCount, STime);
// Right above regular ships
Weapon.WeaponSprite.SetDepth(Globals.WeaponsDepth);
// Register with renderer
Globals.WorldView.SManager.AddSprite(Weapon.WeaponSprite);
// Weapon type
String WeaponType = SpriteInfo.GetKey_String(Type, "Projectile");
if(WeaponType.ToLower().CompareTo("gatling") == 0)
Weapon.WeaponType = BaseShip_WeaponTypes.Gatling;
else if(WeaponType.ToLower().CompareTo("laser") == 0)
Weapon.WeaponType = BaseShip_WeaponTypes.Laser;
else if(WeaponType.ToLower().CompareTo("missile") == 0)
Weapon.WeaponType = BaseShip_WeaponTypes.Missile;
else if(WeaponType.ToLower().CompareTo("railgun") == 0)
Weapon.WeaponType = BaseShip_WeaponTypes.RailGun;
// All done!
return Weapon;
}
示例7: LoadDetail
// Load a detail described in the config file
private BaseShip_Detail LoadDetail(ConfigFile Info, String GroupName)
{
// Ignore if not a detail
if(GroupName.ToLower().StartsWith("detail") == false)
return null;
// Create a new detail obj to return
BaseShip_Detail Detail = new BaseShip_Detail();
// All we need is a reference to the detail's name
Detail.Position = Info.GetKey_Vector2(GroupName, "Pos");
// Load a new sprite, and default it to animation state
String DetailName = Info.GetKey_String(GroupName, "Type");
Detail.DetailSprite = new AnimatedSprite("Config/" + DetailName);
Detail.DetailSprite.SetAnimation("Animation");
Detail.DetailSprite.SetDepth(Globals.ShipDetailsDepth);
// Get the active animation, and see
if(Detail.DetailSprite.GetRotationRate() == 0.0f)
Detail.Fixed = true;
else
Detail.Fixed = false;
// Set scale and center
Detail.DetailSprite.SetGeometrySize(Detail.DetailSprite.GetSpriteSize());
Detail.DetailSprite.SetRotationCenter(Detail.DetailSprite.GetGeometrySize() / 2.0f);
// Register sprite
Globals.WorldView.SManager.AddSprite(Detail.DetailSprite);
// Load the animated sprite
return Detail;
}
示例8: BaseShip
/*** Public ***/
// Standard constructor: needs to have a paried config file name
// which should implement all of the groups and key-value pairs
// found in the ship demo config file
public BaseShip(String ConfigFileName)
{
// Load the ship's properties
this.ConfigFileName = ConfigFileName;
ConfigFile Info = new ConfigFile(ConfigFileName);
/*** General Init. ***/
// Save the health components
ShieldHealth = ShieldMaxHealth = Info.GetKey_Int("General", "Shield");
HullHealth = HullMaxHealth = Info.GetKey_Int("General", "Hull");
// Save velicity limit and default pos to center
MaxVelocity = Info.GetKey_Vector2("General", "MaxVelocity");
ShipAcceleration = new Vector2();
ShipVelocity = new Vector2();
ShipPosition = new Vector3();
// Get all group names to load up specialty geometry
String TextureName = Info.GetKey_String("General", "Texture");
String[] GroupNames = Info.GetGroupNames();
/*** Frame, Shield & Hull ***/
// For each group, look just for "Frame" and "Shield"
foreach(String GroupName in GroupNames)
{
// If shield
if(GroupName.ToLower().StartsWith("shield") == true)
{
// Get animation / frame info
ShieldAnimation = LoadHullType(Info, GroupName);
// Register the sprite with the sprite manager
ShieldSprite = new Sprite("Textures/" + TextureName);
ShieldSprite.SetAnimation(ShieldAnimation.Pos, ShieldAnimation.Size, ShieldAnimation.FrameCount, ShieldAnimation.FrameTime);
ShieldSprite.SetGeometrySize(ShieldSprite.GetSpriteSize());
ShieldSprite.SetRotationCenter(ShieldSprite.GetGeometrySize() / 2.0f);
ShieldSprite.SetDepth(Globals.ShieldDepth);
Globals.WorldView.SManager.AddSprite(ShieldSprite);
}
// Elif base frame
else if(GroupName.ToLower().StartsWith("frame") == true)
{
// Get animation / frame info
FrameAnimation = LoadHullType(Info, GroupName);
// Register the sprite with the sprite manager
FrameSprite = new Sprite("Textures/" + TextureName);
FrameSprite.SetAnimation(FrameAnimation.Pos, FrameAnimation.Size, FrameAnimation.FrameCount, FrameAnimation.FrameTime);
FrameSprite.SetGeometrySize(FrameSprite.GetSpriteSize());
FrameSprite.SetRotationCenter(FrameSprite.GetGeometrySize() / 2.0f);
FrameSprite.SetDepth(Globals.FrameDepth);
Globals.WorldView.SManager.AddSprite(FrameSprite);
}
}
// Load all the hulls
HullList = new List<BaseShip_Hull>();
foreach(String GroupName in GroupNames)
{
if(GroupName.ToLower().StartsWith("hull") == true)
{
BaseShip_Hull Hull = LoadHullType(Info, GroupName);
HullList.Add(Hull);
}
}
// Default to initial hull
HullSprite = new Sprite("Textures/" + TextureName);
HullSkinIndex = 0; // Index grows while health goes down
BaseShip_Hull HullAnimation = HullList[HullSkinIndex];
HullSprite.SetAnimation(HullAnimation.Pos, HullAnimation.Size, HullAnimation.FrameCount, HullAnimation.FrameTime);
HullSprite.SetGeometrySize(HullSprite.GetSpriteSize());
HullSprite.SetRotationCenter(HullSprite.GetGeometrySize() / 2.0f);
HullSprite.SetDepth(Globals.HullDepth);
Globals.WorldView.SManager.AddSprite(HullSprite);
/*** Contrails ***/
// Load all contrails
ContrailList = new List<BaseShip_Contrail>();
foreach(String GroupName in GroupNames)
{
BaseShip_Contrail NewContrail = LoadContrail(Info, GroupName);
if(NewContrail != null)
ContrailList.Add(NewContrail);
}
/*** Weapons ***/
// Load all weapons
WeaponsList = new List<BaseShip_Weapon>();
foreach(String GroupName in GroupNames)
{
//.........这里部分代码省略.........
示例9: AddScenery
public void AddScenery(String ConfigFileName, String GroupName, Vector3 Position, Vector3 Velocity)
{
// Load the config file name
ConfigFile Info = new ConfigFile(ConfigFileName);
String TypeString = Info.GetKey_String(GroupName, "Type");
if(TypeString == null)
TypeString = "hull"; // Force hull usage
else
TypeString = TypeString.ToLower();
// Get texture name from group, if it does not exist in the group, get it from the general:texture tag
String TextureName = Info.GetKey_String(GroupName, "Texture");
if(TextureName == null)
TextureName = Info.GetKey_String("General", "Texture");
// If no texture name, complete failure
if(TextureName == null)
Debug.LogError("Unable to load texture for given scenery item");
// Set common properties
SceneryManager_Scenery SceneryItem = new SceneryManager_Scenery();
SceneryItem.ScenerySprite = new Sprite("Textures/" + TextureName);
SceneryItem.ScenerySprite.SetSpritePos(Info.GetKey_Vector2(GroupName, "Pos"));
SceneryItem.ScenerySprite.SetSpriteSize(Info.GetKey_Vector2(GroupName, "Size"));
SceneryItem.ScenerySprite.SetGeometrySize(SceneryItem.ScenerySprite.GetSpriteSize());
SceneryItem.ScenerySprite.SetRotationCenter(SceneryItem.ScenerySprite.GetGeometrySize() / 2.0f);
SceneryItem.ScenerySprite.SetPosition(Position);
SceneryItem.ScenerySprite.SetRotation(Position.z);
SceneryItem.ScenerySprite.SetDepth(Globals.JunkDepth);
// If mineral
if(TypeString.CompareTo("mineral") == 0)
{
SceneryItem.Type = SceneryType.Mineral;
SceneryItem.Minerals = SceneryItem.MaxMinerals = Info.GetKey_Int(GroupName, "Resources");
SceneryItem.Radius = Info.GetKey_Float(GroupName, "Radius");
// No rotation for minerals
SceneryItem.Velocity = new Vector3(0, 0, Velocity.z);
}
// Else, junk
else if(TypeString.CompareTo("junk") == 0)
{
SceneryItem.Type = SceneryType.Junk;
SceneryItem.Velocity = Velocity;
}
// Else, hull
else if(TypeString.CompareTo("hull") == 0)
{
SceneryItem.Type = SceneryType.Hull;
SceneryItem.Age = 0.0f;
SceneryItem.MaxAge = 3.0f;
SceneryItem.Velocity = Velocity;
}
// Add scenery
SceneryList.Add(SceneryItem);
Globals.WorldView.SManager.AddSprite(SceneryItem.ScenerySprite);
}
示例10: LoadConfig
// Load all animations and properties from the configuration file
private void LoadConfig(string FileName)
{
// Load config
Config = new ConfigFile(FileName);
// Get the texture name
TextureName = Config.GetKey_String("General", "Texture");
// Create new animations dictionary, loosing the rest
Animations = new Dictionary<string, SpriteAnimation>();
// Get all group names for the animations set
String[] Groups = Config.GetGroupNames();
foreach(String Group in Groups)
{
// Ignore if non-animation group
if(Group == "general")
continue;
else
{
// Fill a sprite animation struct and save it as the group's name
SpriteAnimation Animation = new SpriteAnimation();
Animation.Name = Group;
Animation.Pos = Config.GetKey_Vector2(Group, "Pos");
Animation.Rotation = Config.GetKey_Float(Group, "Rotation");
Animation.Frame = Config.GetKey_Vector2(Group, "Size");
Animation.FrameCount = Config.GetKey_Int(Group, "Count");
Animation.FrameTime = Config.GetKey_Float(Group, "Time");
// Save
Animations.Add(Group, Animation);
}
}
}
示例11: GetLevelLoseText
// Return the losing text for the given level
public static String GetLevelLoseText(int LevelIndex)
{
ConfigFile Info = new ConfigFile("Config/World/LevelsConfig");
return Info.GetKey_String("Level" + LevelIndex, "lose");
}
示例12: GetLevelDescription
/*** Static Access ***/
// Return the entire description string for a given level
public static String GetLevelDescription(int LevelIndex)
{
ConfigFile Info = new ConfigFile("Config/World/LevelsConfig");
return Info.GetKey_String("Level" + LevelIndex, "description");
}