当前位置: 首页>>代码示例>>C#>>正文


C# Part.GetConnectedResources方法代码示例

本文整理汇总了C#中Part.GetConnectedResources方法的典型用法代码示例。如果您正苦于以下问题:C# Part.GetConnectedResources方法的具体用法?C# Part.GetConnectedResources怎么用?C# Part.GetConnectedResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Part的用法示例。


在下文中一共展示了Part.GetConnectedResources方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetConnectedResources

 public static List<PartResource> GetConnectedResources(Part part, String resourceName)
 {
     var resourceDef = PartResourceLibrary.Instance.GetDefinition(resourceName);
     var resources = new List<PartResource>();
     part.GetConnectedResources(resourceDef.id, resourceDef.resourceFlowMode, resources);
     return resources;
 }
开发者ID:MartinLyne,项目名称:BioMass,代码行数:7,代码来源:GreenHouse.cs

示例2: fixedRequestResource

        public static double fixedRequestResource(Part part, string resourcename, double resource_amount) 
        {
            List<PartResource> prl = part.GetConnectedResources(resourcename).ToList();
            List<Part> parts = new List<Part>();
            ResourceFlowMode flow = PartResourceLibrary.Instance.GetDefinition(resourcename).resourceFlowMode;

            prl = prl.Where(p => p.flowState == true).ToList();
            double max_available = 0;
            double spare_capacity = 0;

            foreach (PartResource partresource in prl) 
            {
                parts.Add(partresource.part);
                max_available += partresource.amount;
                spare_capacity += partresource.maxAmount - partresource.amount;
            }

            if (flow == ResourceFlowMode.ALL_VESSEL) 
            { // use our code
                double resource_left_to_draw = 0;
                double total_resource_change = 0;
                double res_ratio = 0;
                
                if (resource_amount > 0) 
                {
                    resource_left_to_draw = Math.Min(resource_amount, max_available);
                    res_ratio = Math.Min(resource_amount / max_available,1);
                } 
                else 
                {
                    resource_left_to_draw = Math.Max(-spare_capacity, resource_amount);
                    res_ratio = Math.Min(-resource_amount / spare_capacity,1);
                }

                if (double.IsNaN(res_ratio) || double.IsInfinity(res_ratio) || res_ratio == 0) 
                {
                    return 0;
                } 
                else 
                {
                    foreach (PartResource local_part_resource in prl) {
                        if (resource_amount > 0) {
                            local_part_resource.amount = local_part_resource.amount - local_part_resource.amount * res_ratio;
                            total_resource_change += local_part_resource.amount * res_ratio;
                        }else{
                            local_part_resource.amount = local_part_resource.amount + (local_part_resource.maxAmount - local_part_resource.amount) * res_ratio;
                            total_resource_change -= (local_part_resource.maxAmount - local_part_resource.amount) * res_ratio;
                        }
                    }
                }
                return total_resource_change;
            } else {
                if (resource_amount > 0) {
                    return part.RequestResource(resourcename, Math.Min(resource_amount, max_available));
                } else {
                    return part.RequestResource(resourcename, Math.Max(-spare_capacity, resource_amount));
                }
            }
        }
开发者ID:Yitscar,项目名称:KSPInterstellar,代码行数:59,代码来源:ORSHelper.cs

示例3: getDemand

 public static double getDemand(Part part, string name)
 {
     var res_set = new List<PartResource>();
     var res_def = PartResourceLibrary.Instance.GetDefinition(name);
     if (res_def == null) return 0;
     part.GetConnectedResources(res_def.id, res_def.resourceFlowMode, res_set);
     if (res_set == null) return 0;
     return sumDemand(res_set);
 }
开发者ID:N3h3miah,项目名称:OrbitalMaterialScience,代码行数:9,代码来源:ResourceHelper.cs

示例4: GetSnackResource

        public double GetSnackResource(Part p, double demand)
        {
            List<PartResource> resources = new List<PartResource>();
            p.GetConnectedResources(snacksResource.id, ResourceFlowMode.ALL_VESSEL, resources);

            double supplied = 0;
            foreach (PartResource res in resources)
            {
                if (res.amount >= demand)
                {
                    res.amount -= demand;
                    supplied += demand;
                    return supplied;
                }
                else
                {
                    supplied += res.amount;
                    demand -= res.amount;
                    res.amount = 0;
                }

            }
            return supplied;
        }
开发者ID:Murdabenne,项目名称:Snacks,代码行数:24,代码来源:SnackConsumer.cs

示例5: fixedRequestResourceSpareCapacity

 public static double fixedRequestResourceSpareCapacity(Part part, string resourcename)
 {
     return part.GetConnectedResources(resourcename).Sum(r => r.maxAmount - r.amount);
 }
开发者ID:Profit0004,项目名称:KSPInterstellar,代码行数:4,代码来源:ORSHelper.cs

示例6: GetConnectedResources

 // =====================================================================================================================================================
 // Build Helper Functions
 // Gets connected resources to a part. Note fuel lines are NOT reversible! Add flow going TO the constructing part!
 private static List<PartResource> GetConnectedResources(Part part, String resourceName)
 {
     var resources = new List<PartResource>();
     part.GetConnectedResources(PartResourceLibrary.Instance.GetDefinition(resourceName).id, resources);
     return resources;
 }
开发者ID:evilC,项目名称:Extraplanetary-Launchpads,代码行数:9,代码来源:ExLaunchPad.cs

示例7: GetBattery

 //tr.name.StartsWith(rotatorsName, StringComparison.Ordinal
 /// <summary>Gets a battery.  Names it "Jennifer" and gives it a good home.</summary>
 /// <remarks>My father once played a game where he had to choose a mascot.  He grabbed a dead battery and named it "Jennifer."  That story never gets old. - Gaalidas</remarks>
 public static float GetBattery(Part part)
 {
     PartResourceDefinition resourceDefinitions = PartResourceLibrary.Instance.GetDefinition("ElectricCharge");
     var resources = new List<PartResource>();
     //List<PartResource> resources = new List<PartResource>();
     part.GetConnectedResources(resourceDefinitions.id, resourceDefinitions.resourceFlowMode, resources);
     var ratio = (float)resources.Sum(r => r.amount) / (float)resources.Sum(r => r.maxAmount);
     return ratio;
 }
开发者ID:Kerbas-ad-astra,项目名称:KF_plugin,代码行数:12,代码来源:Utils.cs

示例8: updateAvailableResourceCapacity

 public void updateAvailableResourceCapacity(Part p)
 {
     p.GetConnectedResources(resourceDefID, ResourceFlowMode.ALL_VESSEL, cacheList);
     emptyCapacity = Enumerable.Sum<PartResource>(cacheList, emptyFunc);
     cacheList.Clear();
 }
开发者ID:SixDasher,项目名称:SSTULabs,代码行数:6,代码来源:ConverterRecipe.cs

示例9: updateAvailableResource

 public void updateAvailableResource(Part p)
 {
     p.GetConnectedResources(resourceDefID, ResourceFlowMode.ALL_VESSEL, cacheList);
     foundAmount = Enumerable.Sum<PartResource>(cacheList, sumFunc);
     cacheList.Clear();
 }
开发者ID:SixDasher,项目名称:SSTULabs,代码行数:6,代码来源:ConverterRecipe.cs


注:本文中的Part.GetConnectedResources方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。