コード例 #1
0
        private void LogResource(PartResource resource)
        {
            var spacing = "     ";

            Log(spacing + "ResourceName: " + resource.resourceName);
            Log(spacing + spacing + "Resource Amount: " + resource.amount + " / " + resource.maxAmount);

            Log(spacing + spacing + "info?.resourceFlowMode: " + resource.info?.resourceFlowMode.ToString());
            Log(spacing + spacing + "info?.resourceTransferMode: " + resource.info?.resourceTransferMode.ToString());

            Log(spacing + spacing + "GetInfo: " + resource.GetInfo());
        }
コード例 #2
0
        public static void ModifyPart(AvailablePart partData, ConfigNode node)
        {
            //Step 1: load the Fields
            partData.partPrefab.Fields.Load(node);

            //Step 2A: clear the old Resources
            partData.partPrefab.Resources.list.Clear();
            partData.resourceInfo = "";
            //Step 2B: load the new Resources
            foreach (ConfigNode rNode in node.GetNodes("RESOURCE"))
            {
                PartResource resource = partData.partPrefab.AddResource(rNode);
                if (partData.resourceInfo.Length > 0)
                {
                    partData.resourceInfo += "\n";
                }
                partData.resourceInfo += resource.GetInfo();
            }
            if (partData.resourceInfo.Length > 0)
            {
                partData.resourceInfo += "\nDry Mass: " + partData.partPrefab.mass.ToString("F3");
            }
            //Step 3A: clear the old Modules
            while (partData.partPrefab.Modules.Count > 0)
            {
                partData.partPrefab.RemoveModule(partData.partPrefab.Modules [0]);
            }
            partData.moduleInfo = "";
            //Step 3B: load the new Modules
            foreach (ConfigNode mNode in node.GetNodes("MODULE"))
            {
                PartModule module = partData.partPrefab.AddModule(mNode.GetValue("name"));
                if (module)
                {
                    // really? REALLY? It appears the only way to make this work, is to molest KSP's privates.
                    if (Awaken(module))                       // uses reflection to find and call the PartModule.Awake() private method
                    {
                        module.Load(mNode);
                    }
                    else
                    {
                        print("Awaken failed for new module.");
                    }
                    if (module.part == null)
                    {
                        print("new module has null part.");
                    }
                    else
                    {
                                                #if DEBUG
                        print("Created module for " + module.part.name);
                                                #endif
                    }
                }
                if (partData.moduleInfo.Length > 0)
                {
                    partData.moduleInfo += "\n";
                }
                partData.moduleInfo += module.GetInfo();
            }
        }