Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- namespace ksp_test
- {
- [KSPAddon(KSPAddon.Startup.Instantly, false)]
- public class ksp_test : MonoBehaviour
- {
- public void Start()
- {
- // Plugin started as scene
- var game = HighLogic.CurrentGame;
- ProtoScenarioModule psm = game.scenarios.Find(s => s.moduleName == typeof(ksp_career).Name);
- if (psm == null)
- {
- psm = game.AddProtoScenarioModule(typeof(ksp_career), GameScenes.SPACECENTER, GameScenes.FLIGHT);
- }
- }
- }
- // Scenario for R&D
- public class ksp_career : ScenarioModule
- {
- //All your plug in code here. Start, Update, FixedUpdate, OnSave, OnLoad, etc. all work as they do in a partmodule.
- ConfigNode DB;
- private string RootNodeName { get { return "RnDCareer"; } }
- public override void OnAwake()
- {
- // Make all parts to unavailable status
- foreach (AvailablePart p in PartLoader.LoadedPartsList)
- {
- // orz
- p.amountAvailable = 0;
- }
- // Load career config
- // LoadCareer();
- // Create start node if no career loaded
- }
- public void Start()
- {
- GameEvents.onGUIRnDComplexSpawn.Add(new EventVoid.OnEvent(OnGUIRnDComplexSpawn));
- GameEvents.OnPartPurchased.Add(new EventData<AvailablePart>.OnEvent(OnPartPurchased));
- if (ResearchAndDevelopment.Instance != null)
- {
- var techNode = ResearchAndDevelopment.Instance.GetTechState("start");
- if (techNode != null)
- {
- techNode.partsPurchased = new List<AvailablePart>();
- ResearchAndDevelopment.Instance.SetTechState("start", techNode);
- }
- }
- }
- void onDestroy()
- {
- GameEvents.onGUIRnDComplexSpawn.Remove(new EventVoid.OnEvent(OnGUIRnDComplexSpawn));
- }
- void OnGUIRnDComplexSpawn()
- {
- print("=====================");
- print("RD complex spawned");
- print("=====================");
- }
- void OnPartPurchased(AvailablePart p)
- {
- print("=====================");
- print("= Part " + p.name + " purchased = ");
- print("=====================");
- }
- public override void OnSave(ConfigNode node)
- {
- if (node.HasNode(RootNodeName))
- node.SetNode(RootNodeName, this.DB);
- else
- {
- node.AddNode(this.DB);
- }
- }
- public override void OnLoad(ConfigNode node)
- {
- if (node.HasNode(RootNodeName))
- this.DB = node.GetNode(RootNodeName);
- else
- {
- this.DB = NewDatabase();
- }
- }
- private ConfigNode NewDatabase()
- {
- ConfigNode db = new ConfigNode(RootNodeName);
- return db;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement