コード例 #1
0
        private void LoadAdditionalResources(ConfigNode[] resourceNodes, OperationContext context)
        {
            OperationContext newContext = new OperationContext(context, this);

            foreach (ConfigNode resourceNode in resourceNodes)
            {
                string name = resourceNode.GetValue("name");

                if (name.IsNullOrEmpty())
                {
                    LogError("Cannot load a RESOURCE node without a name");
                    continue;
                }

                TankResource resource = tankType[name];

                if (resource.IsNull())
                {
                    resource = new TankResource();
                    tankType.resources.Add(resource);
                }

                resource.Load(resourceNode, newContext);
            }
        }
コード例 #2
0
        private void UpdateTankSetup(bool forceFull)
        {
            List <PartResource> partResources = part.Resources.list;

            int[] resourceIndices = Enumerable.Repeat <int>(-1, CurrentTankType.resources.Count).ToArray();
            bool  tmp             = false;

            for (int i = 0; i < partResources.Count; i++)
            {
                string resourceName = partResources[i].resourceName;
                tmp = false;

                for (int j = 0; j < CurrentTankType.resources.Count; j++)
                {
                    if (resourceName == CurrentTankType.resources[j].ResourceName)
                    {
                        resourceIndices[j] = i;
                        tmp = true;
                        break;
                    }
                }

                if (tmp)
                {
                    continue;
                }

                if (IsManagedResource(resourceName))
                {
                    DestroyImmediate(partResources[i]);
                    partResources.RemoveAt(i);
                    i--;
                }
            }

            for (int i = 0; i < CurrentTankType.resources.Count; i++)
            {
                TankResource resource       = CurrentTankType[i];
                float        resourceAmount = resource.unitsPerVolume * TankVolume;
                PartResource partResource   = null;
                if (resourceIndices[i] < 0)
                {
                    partResource = part.gameObject.AddComponent <PartResource>();
                    partResource.SetInfo(resource.resourceDefinition);
                    partResource.maxAmount   = resourceAmount;
                    partResource.amount      = resourceAmount;
                    partResource.flowState   = true;
                    partResource.isTweakable = resource.resourceDefinition.isTweakable;
                    partResource.hideFlow    = false;
                    partResource.flowMode    = PartResource.FlowMode.Both;
                    partResources.Add(partResource);
                }
                else
                {
                    partResource           = part.Resources[resourceIndices[i]];
                    partResource.maxAmount = resourceAmount;
                    if (forceFull)
                    {
                        partResource.amount = resourceAmount;
                    }
                    else
                    {
                        if (partResource.amount > resourceAmount)
                        {
                            partResource.amount = resourceAmount;
                        }
                    }
                }
            }

            part.Resources.UpdateList();
        }