本文整理汇总了C#中PartResourceDefinition类的典型用法代码示例。如果您正苦于以下问题:C# PartResourceDefinition类的具体用法?C# PartResourceDefinition怎么用?C# PartResourceDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PartResourceDefinition类属于命名空间,在下文中一共展示了PartResourceDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:blowfishpro,项目名称:B9PartSwitch,代码行数:28,代码来源:PartExtensions.cs
示例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);
}
}
开发者ID:MartinLyne,项目名称:BioMass,代码行数:25,代码来源:PartExtensions.cs
示例3: AggregateResourceValue
public AggregateResourceValue(PartResourceDefinition definition, SharedObjects shared)
{
name = definition.name;
density = definition.density;
this.shared = shared;
resources = new List<PartResource>();
InitializeAggregateResourceSuffixes();
}
开发者ID:CalebJ2,项目名称:KOS,代码行数:8,代码来源:AggregateResourceValue.cs
示例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;
}
开发者ID:shadowmage45,项目名称:SSTULabs,代码行数:9,代码来源:FuelType.cs
示例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;
}
开发者ID:Kerbas-ad-astra,项目名称:ContractConfigurator,代码行数:11,代码来源:ResourceConsumptionFactory.cs
示例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
}
开发者ID:KSP-KOS,项目名称:KOS,代码行数:12,代码来源:ResourceTransferValue.cs
示例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);
}
开发者ID:paperclip,项目名称:krpc,代码行数:14,代码来源:ResourceTransfer.cs
示例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;
}
开发者ID:Kerbas-ad-astra,项目名称:ContractConfigurator,代码行数:15,代码来源:ResourceConsuption.cs
示例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;
}
开发者ID:blowfishpro,项目名称:B9PartSwitch,代码行数:15,代码来源:PartExtensions.cs
示例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;
}
开发者ID:linuxgurugamer,项目名称:ContractConfigurator,代码行数:24,代码来源:Extensions.cs
示例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;
}
开发者ID:kfsone,项目名称:KSP-EVA-Transfer,代码行数:41,代码来源:TransferableResource.cs
示例12: IsResourceAvailable
public static double IsResourceAvailable(this Part part, PartResourceDefinition resource, double demand)
{
if (resource == null)
{
Debug.LogError("USI.PartExtensions.IsResourceAvailable: resource is null");
return 0.0;
}
switch (resource.resourceFlowMode)
{
case ResourceFlowMode.NO_FLOW:
return IsResourceAvailable_NoFlow(part, resource, demand);
default:
return IsResourceAvailable_AllVessel(part, resource, demand);
//case ResourceFlowMode.STACK_PRIORITY_SEARCH:
// return IsResourceAvailable_StackPriority(part, resource, demand);
//default:
// Debug.LogWarning("USI.PartExtensions.IsResourceAvailable: Unknown ResourceFlowMode = " + resource.resourceFlowMode.ToString());
// return IsResourceAvailable_AllVessel(part, resource, demand);
}
}
开发者ID:nanathan,项目名称:UmbraSpaceIndustries,代码行数:21,代码来源:PartExtensions.cs
示例13: TakeResource_StackPriority
private static double TakeResource_StackPriority(Part part, PartResourceDefinition resource, double demand)
{
// FIXME finish implementing
return part.RequestResource(resource.id, demand);
}
开发者ID:NathanKell,项目名称:TacLib,代码行数:5,代码来源:PartExtensions.cs
示例14: TakeResource_AllVessel
private static double TakeResource_AllVessel(Part part, PartResourceDefinition resource, double demand)
{
if (demand >= 0.0)
{
double leftOver = demand;
// Takes an equal percentage from each part (rather than an equal amount from each part)
List<PartResource> partResources = GetAllPartResources(part.vessel, resource, true);
double totalAmount = 0.0;
foreach (PartResource partResource in partResources)
{
totalAmount += partResource.amount;
}
if (totalAmount > 0.0)
{
double percentage = Math.Min(leftOver / totalAmount, 1.0);
foreach (PartResource partResource in partResources)
{
double taken = partResource.amount * percentage;
partResource.amount -= taken;
leftOver -= taken;
}
}
return demand - leftOver;
}
else
{
double leftOver = -demand;
List<PartResource> partResources = GetAllPartResources(part.vessel, resource, false);
double totalSpace = 0.0;
foreach (PartResource partResource in partResources)
{
totalSpace += partResource.maxAmount - partResource.amount;
}
if (totalSpace > 0.0)
{
double percentage = Math.Min(leftOver / totalSpace, 1.0);
foreach (PartResource partResource in partResources)
{
double space = partResource.maxAmount - partResource.amount;
double given = space * percentage;
partResource.amount += given;
leftOver -= given;
}
}
return demand + leftOver;
}
}
开发者ID:NathanKell,项目名称:TacLib,代码行数:55,代码来源:PartExtensions.cs
示例15: TakeResource_NoFlow
private static double TakeResource_NoFlow(Part part, PartResourceDefinition resource, double demand)
{
// ignoring PartResourceDefinition.ResourceTransferMode
PartResource partResource = part.Resources.Get(resource.id);
if (partResource != null)
{
if (partResource.flowMode == PartResource.FlowMode.None)
{
Debug.LogWarning("Tac.PartExtensions.TakeResource_NoFlow: cannot take resource from a part where FlowMode is None.");
return 0.0;
}
else if (!partResource.flowState)
{
// Resource flow was shut off -- no warning needed
return 0.0;
}
else if (demand >= 0.0)
{
if (partResource.flowMode == PartResource.FlowMode.In)
{
Debug.LogWarning("Tac.PartExtensions.TakeResource_NoFlow: cannot take resource from a part where FlowMode is In.");
return 0.0;
}
double taken = Math.Min(partResource.amount, demand);
partResource.amount -= taken;
return taken;
}
else
{
if (partResource.flowMode == PartResource.FlowMode.Out)
{
Debug.LogWarning("Tac.PartExtensions.TakeResource_NoFlow: cannot give resource to a part where FlowMode is Out.");
return 0.0;
}
double given = Math.Min(partResource.maxAmount - partResource.amount, -demand);
partResource.amount += given;
return -given;
}
}
else
{
return 0.0;
}
}
开发者ID:NathanKell,项目名称:TacLib,代码行数:47,代码来源:PartExtensions.cs
示例16: IsResourceAvailable_StackPriority
private static double IsResourceAvailable_StackPriority(Part part, PartResourceDefinition resource, double demand)
{
// FIXME finish implementing
return IsResourceAvailable_AllVessel(part, resource, demand);
}
开发者ID:NathanKell,项目名称:TacLib,代码行数:5,代码来源:PartExtensions.cs
示例17: IsResourceAvailable_NoFlow
private static double IsResourceAvailable_NoFlow(Part part, PartResourceDefinition resource, double demand)
{
PartResource partResource = part.Resources.Get(resource.id);
if (partResource != null)
{
if (partResource.flowMode == PartResource.FlowMode.None || partResource.flowState == false)
{
return 0.0;
}
else if (demand > 0.0)
{
if (partResource.flowMode != PartResource.FlowMode.In)
{
return Math.Min(partResource.amount, demand);
}
}
else
{
if (partResource.flowMode != PartResource.FlowMode.Out)
{
return -Math.Min((partResource.maxAmount - partResource.amount), -demand);
}
}
}
return 0.0;
}
开发者ID:NathanKell,项目名称:TacLib,代码行数:27,代码来源:PartExtensions.cs
示例18: IsResourceAvailable_AllVessel
private static double IsResourceAvailable_AllVessel(Part part, PartResourceDefinition resource, double demand)
{
if (demand >= 0.0)
{
double amountAvailable = 0.0;
foreach (Part p in part.vessel.parts)
{
PartResource partResource = p.Resources.Get(resource.id);
if (partResource != null)
{
if (partResource.flowState && partResource.flowMode != PartResource.FlowMode.None && partResource.flowMode != PartResource.FlowMode.In)
{
amountAvailable += partResource.amount;
if (amountAvailable >= demand)
{
return demand;
}
}
}
}
return amountAvailable;
}
else
{
double availableSpace = 0.0;
double demandedSpace = -demand;
foreach (Part p in part.vessel.parts)
{
PartResource partResource = p.Resources.Get(resource.id);
if (partResource != null)
{
if (partResource.flowState && partResource.flowMode != PartResource.FlowMode.None && partResource.flowMode != PartResource.FlowMode.Out)
{
availableSpace += (partResource.maxAmount - partResource.amount);
if (availableSpace >= demandedSpace)
{
return demand;
}
}
}
}
return -availableSpace;
}
}
开发者ID:NathanKell,项目名称:TacLib,代码行数:50,代码来源:PartExtensions.cs
示例19: GetAllPartResources
private static List<PartResource> GetAllPartResources(Vessel vessel, PartResourceDefinition resource, bool consuming)
{
// ignoring PartResourceDefinition.ResourceTransferMode
List<PartResource> resources = new List<PartResource>();
foreach (Part p in vessel.parts)
{
PartResource partResource = p.Resources.Get(resource.id);
if (partResource != null)
{
if (partResource.flowState && partResource.flowMode != PartResource.FlowMode.None)
{
if (consuming)
{
if (partResource.flowMode != PartResource.FlowMode.In && partResource.amount > 0.0)
{
resources.Add(partResource);
}
}
else
{
if (partResource.flowMode != PartResource.FlowMode.Out && partResource.amount < partResource.maxAmount)
{
resources.Add(partResource);
}
}
}
}
}
return resources;
}
开发者ID:NathanKell,项目名称:TacLib,代码行数:32,代码来源:PartExtensions.cs
示例20: PersistentPropellant
// Constructor
PersistentPropellant(Propellant p)
{
propellant = p;
definition = PartResourceLibrary.Instance.GetDefinition(propellant.name);
density = definition.density;
ratio = propellant.ratio;
}
开发者ID:Kerbas-ad-astra,项目名称:PersistentThrust,代码行数:8,代码来源:Propellant.cs
注:本文中的PartResourceDefinition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论