本文整理汇总了C#中PartResourceDefinition类的典型用法代码示例。如果您正苦于以下问题:C# PartResourceDefinition类的具体用法?C# PartResourceDefinition怎么用?C# PartResourceDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PartResourceDefinition类属于命名空间,在下文中一共展示了PartResourceDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOrCreateResource
// Amount < 0 signifies use existing amount if exists, or create with max amount
public static PartResource AddOrCreateResource(this Part part, PartResourceDefinition info, float maxAmount, float amount)
{
if (amount > maxAmount)
{
part.LogWarning($"Cannot add resource '{info.name}' with amount > maxAmount, will use maxAmount (amount = {amount}, maxAmount = {maxAmount})");
amount = maxAmount;
}
PartResource resource = part.Resources[info.name];
if (resource == null)
{
if (amount < 0f)
amount = maxAmount;
resource = part.AddResource(info, maxAmount, amount);
}
else
{
resource.maxAmount = maxAmount;
if (amount >= 0f)
resource.amount = amount;
}
return resource;
}
示例2: IsResourceAvailable
public static double IsResourceAvailable(this Part part, PartResourceDefinition resource, double demand)
{
if (resource == null)
{
Debug.LogError("Tac.PartExtensions.IsResourceAvailable: resource is null");
return 0.0;
}
switch (resource.resourceFlowMode)
{
case ResourceFlowMode.NO_FLOW:
return IsResourceAvailable_NoFlow(part, resource, demand);
case ResourceFlowMode.ALL_VESSEL:
return IsResourceAvailable_AllVessel(part, resource, demand);
case ResourceFlowMode.STACK_PRIORITY_SEARCH:
return IsResourceAvailable_StackPriority(part, resource, demand);
/*case ResourceFlowMode.EVEN_FLOW:
Debug.LogWarning("Tac.PartExtensions.IsResourceAvailable: ResourceFlowMode.EVEN_FLOW is not supported yet.");
return IsResourceAvailable_AllVessel(part, resource, demand);
*/
default:
Debug.LogWarning("Tac.PartExtensions.IsResourceAvailable: Unknown ResourceFlowMode = " + resource.resourceFlowMode.ToString());
return IsResourceAvailable_AllVessel(part, resource, demand);
}
}
示例3: AggregateResourceValue
public AggregateResourceValue(PartResourceDefinition definition, SharedObjects shared)
{
name = definition.name;
density = definition.density;
this.shared = shared;
resources = new List<PartResource>();
InitializeAggregateResourceSuffixes();
}
示例4: getResourceVolume
public float getResourceVolume(String name, PartResourceDefinition def)
{
float val = 0;
if (!resourceVolumes.TryGetValue(name, out val))
{
val = def == null ? 5.0f : def.volume;
}
return val;
}
示例5: Load
public override bool Load(ConfigNode configNode)
{
// Load base class
bool valid = base.Load(configNode);
valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minRate", x => minRate = x, this, double.MinValue);
valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxRate", x => maxRate = x, this, double.MaxValue);
valid &= ConfigNodeUtil.ParseValue<PartResourceDefinition>(configNode, "resource", x => resource = x, this);
return valid;
}
示例6: ResourceTransferValue
public ResourceTransferValue(TransferManager transferManager, PartResourceDefinition resourceInfo, object transferTo, object transferFrom)
{
this.transferManager = transferManager;
this.resourceInfo = resourceInfo;
this.transferTo = transferTo;
this.transferFrom = transferFrom;
DetermineTypes();
InitializeSuffixes();
Status = TransferManager.TransferStatus.Inactive; // Last because the setter for Status prints some of the values calculated above to the log
}
示例7: ResourceTransfer
ResourceTransfer (Part fromPart, Part toPart, PartResourceDefinition resource, float amount)
{
internalFromPart = fromPart;
internalToPart = toPart;
internalResource = resource;
FromPart = new Parts.Part (fromPart);
ToPart = new Parts.Part (toPart);
Resource = resource.name;
TotalAmount = amount;
// Compute the transfer rate (in units/sec) as one tenth the size of the destination tank (determined experimentally from the KSP transfer UI)
var totalStorage = (float)toPart.Resources.Get (resource.id).maxAmount;
transferRate = 0.1f * totalStorage;
ResourceTransferAddon.AddTransfer (this);
}
示例8: ResourceConsumption
public ResourceConsumption(double minRate, double maxRate, PartResourceDefinition resource, string title = null)
: base(title)
{
if (minRate < 0 && maxRate < 0 && maxRate < minRate)
{
this.minRate = maxRate;
this.maxRate = minRate;
}
else
{
this.minRate = minRate;
this.maxRate = maxRate;
}
this.resource = resource;
}
示例9: AddResource
public static PartResource AddResource(this Part part, PartResourceDefinition info, float maxAmount, float amount)
{
PartResource resource = new PartResource(part);
resource.SetInfo(info);
resource.maxAmount = maxAmount;
resource.amount = amount;
resource.flowState = true;
resource.isTweakable = info.isTweakable;
resource.isVisible = info.isVisible;
resource.hideFlow = false;
resource.flowMode = PartResource.FlowMode.Both;
part.Resources.dict.Add(info.name.GetHashCode(), resource);
return resource;
}
示例10: ResourceQuantity
/// <summary>
/// Gets the quantity of the given resource for the vessel.
/// </summary>
/// <param name="vessel">Vessel to check</param>
/// <param name="resource">Resource to check for</param>
/// <returns></returns>
public static double ResourceQuantity(this Vessel vessel, PartResourceDefinition resource)
{
if (vessel == null)
{
return 0.0;
}
double quantity = 0.0;
foreach (Part part in vessel.Parts)
{
PartResource pr = part.Resources[resource.name];
if (pr != null)
{
quantity += pr.amount;
}
}
return quantity;
}
示例11: TransferableResource
public TransferableResource(PartResourceDefinition r)
{
resource = r;
name = resource.name;
mode = resource.resourceTransferMode;
switch (name)
{
case "LiquidFuel":
icon = EVATransfer_Startup.lfIcon;
color = XKCDColors.LightRed;
break;
case "Oxidizer":
icon = EVATransfer_Startup.loxIcon;
color = XKCDColors.OrangeyYellow;
break;
case "MonoPropellant":
icon = EVATransfer_Startup.monoIcon;
color = Color.white;
break;
case "XenonGas":
icon = EVATransfer_Startup.xenonIcon;
color = XKCDColors.AquaBlue;
break;
case "ElectricCharge":
icon = EVATransfer_Startup.ecIcon;
color = XKCDColors.SunnyYellow;
break;
case "Ore":
icon = EVATransfer_Startup.oreIcon;
color = XKCDColors.Purple_Pink;
break;
default:
icon = null;
color = Color.white;
break;
}
if (icon != null)
primary = true;
}
示例12: PersistentPropellant
// Constructor
PersistentPropellant(Propellant p)
{
propellant = p;
definition = PartResourceLibrary.Instance.GetDefinition(propellant.name);
density = definition.density;
ratio = propellant.ratio;
}
示例13: ResourceInfo
public ResourceInfo(ConfigNode node)
{
node.TryGetValue("name", ref this.name);
resource = PartResourceLibrary.Instance.GetDefinition(this.Name);
node.TryGetValue("realName", ref this.realName);
node.TryGetValue("colour", ref this.colour);
}
示例14: Load
public void Load(ConfigNode node)
{
int resourceID = node.GetValue("name").GetHashCode();
if (PartResourceLibrary.Instance.resourceDefinitions.Any(rd => rd.id == resourceID))
{
resource = PartResourceLibrary.Instance.resourceDefinitions[resourceID];
float.TryParse(node.GetValue("ratio"), out ratio);
}
}
示例15: Load
public void Load(ConfigNode node)
{
string resourceID = node.GetValue("name");
if (PartResourceLibrary.Instance.resourceDefinitions.Contains(resourceID))
{
resource = PartResourceLibrary.Instance.resourceDefinitions[resourceID];
float.TryParse(node.GetValue("ratio"), out ratio);
}
}