Project

General

Profile

ScaledSpaceDumper.cs

[email protected] - BloodyRain2k, 08/08/2013 10:54 PM

 
1
/*
2
 * Created by SharpDevelop.
3
 * User: Bernhard
4
 * Date: 28.07.2013
5
 * Time: 01:47
6
 */
7

8
using System;
9
using System.IO;
10
using System.Collections.Generic;
11
using System.Linq;
12
using UnityEngine;
13

14
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
15
public class ScaledSpaceDumper : MonoBehaviour
16
{
17
	public void Start()
18
	{
19
		string data = "Scene: " + HighLogic.LoadedScene.ToString() + "\nTime: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n";
20
		
21
		foreach (var sst in ScaledSpace.Instance.scaledSpaceTransforms)
22
		{
23
			try {
24
				data += sst.name + "\n"; //" - Parent: " + (sst.parent != null ? sst.parent.name : "none") + " - Children:\n";
25
//				for (int c = 0; c < sst.childCount; c++)
26
//				{
27
//					data += "    " + sst.GetChild(c).name + "\n";
28
//				}
29
			}
30
			catch (Exception ex)
31
			{
32
				data += "Error: " + ex.Message + "\n";
33
			}
34
		}
35
		data += "\n";
36
		
37
		File.AppendAllText(KSPUtil.ApplicationRootPath + @"\ScaledSpaceDump.txt", data);
38
		Debug.Log("SSD: dumped");
39
		
40
		ScaledSpace.Instance.scaledSpaceTransforms.RemoveAll(ss => ss == null);
41
		if (HighLogic.LoadedScene == GameScenes.MAINMENU) {
42
			foreach (var sst in ScaledSpace.Instance.scaledSpaceTransforms)
43
			{
44
				ScaledSpace.Instance.scaledSpaceTransforms.RemoveAll(ss => !FlightGlobals.Bodies.Find(cb => cb.name == ss.name));
45
			}
46
		}
47
	}
48
}