Advertisement
Guest User

ksp_ksp

a guest
Jul 24th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6.  
  7. namespace ksp_test
  8. {
  9.     [KSPAddon(KSPAddon.Startup.Instantly, false)]
  10.     public class ksp_test : MonoBehaviour
  11.     {
  12.         public void Start()
  13.         {
  14.             // Plugin started as scene
  15.             var game = HighLogic.CurrentGame;
  16.             ProtoScenarioModule psm = game.scenarios.Find(s => s.moduleName == typeof(ksp_career).Name);
  17.             if (psm == null)
  18.             {
  19.                 psm = game.AddProtoScenarioModule(typeof(ksp_career), GameScenes.SPACECENTER, GameScenes.FLIGHT);
  20.             }
  21.         }
  22.     }
  23.  
  24.     // Scenario for R&D
  25.     public class ksp_career : ScenarioModule
  26.     {
  27.         //All your plug in code here. Start, Update, FixedUpdate, OnSave, OnLoad, etc. all work as they do in a partmodule.
  28.  
  29.         ConfigNode DB;
  30.         private string RootNodeName { get { return "RnDCareer"; } }
  31.  
  32.         public override void OnAwake()
  33.         {
  34.             // Make all parts to unavailable status
  35.             foreach (AvailablePart p in PartLoader.LoadedPartsList)
  36.             {
  37.                 // orz
  38.                 p.amountAvailable = 0;
  39.             }
  40.             // Load career config
  41.             // LoadCareer();
  42.             // Create start node if no career loaded
  43.         }
  44.  
  45.         public void Start()
  46.         {
  47.             GameEvents.onGUIRnDComplexSpawn.Add(new EventVoid.OnEvent(OnGUIRnDComplexSpawn));
  48.             GameEvents.OnPartPurchased.Add(new EventData<AvailablePart>.OnEvent(OnPartPurchased));
  49.  
  50.             if (ResearchAndDevelopment.Instance != null)
  51.             {
  52.                 var techNode = ResearchAndDevelopment.Instance.GetTechState("start");
  53.                 if (techNode != null)
  54.                 {
  55.                     techNode.partsPurchased = new List<AvailablePart>();
  56.                     ResearchAndDevelopment.Instance.SetTechState("start", techNode);
  57.                 }
  58.             }
  59.         }
  60.  
  61.         void onDestroy()
  62.         {
  63.             GameEvents.onGUIRnDComplexSpawn.Remove(new EventVoid.OnEvent(OnGUIRnDComplexSpawn));
  64.         }
  65.  
  66.         void OnGUIRnDComplexSpawn()
  67.         {
  68.             print("=====================");
  69.             print("RD complex spawned");
  70.             print("=====================");
  71.         }
  72.  
  73.         void OnPartPurchased(AvailablePart p)
  74.         {
  75.             print("=====================");
  76.             print("= Part " + p.name + " purchased = ");
  77.             print("=====================");
  78.         }
  79.  
  80.         public override void OnSave(ConfigNode node)
  81.         {
  82.             if (node.HasNode(RootNodeName))
  83.                 node.SetNode(RootNodeName, this.DB);
  84.             else
  85.             {
  86.                 node.AddNode(this.DB);
  87.             }
  88.         }
  89.  
  90.         public override void OnLoad(ConfigNode node)
  91.         {
  92.             if (node.HasNode(RootNodeName))
  93.                 this.DB = node.GetNode(RootNodeName);
  94.             else
  95.             {
  96.                 this.DB = NewDatabase();
  97.             }
  98.         }
  99.  
  100.  
  101.  
  102.         private ConfigNode NewDatabase()
  103.         {
  104.             ConfigNode db = new ConfigNode(RootNodeName);
  105.             return db;
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement