Skip to content

Commit 702be45

Browse files
committed
added mesh switch
1 parent 210d8fe commit 702be45

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

Firespitter/Firespitter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Compile Include="engine\FSgroundParticles.cs" />
6969
<Compile Include="engine\FSheliLiftEngine.cs" />
7070
<Compile Include="engine\FSengine.cs" />
71+
<Compile Include="gui\FSmeshSwitch.cs" />
7172
<Compile Include="tools\MeshCreator.cs" />
7273
<Compile Include="tools\CompatabilityChecker.cs" />
7374
<Compile Include="tools\FSversionCheck.cs" />

Firespitter/gui/FSmeshSwitch.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnityEngine;
6+
7+
namespace Firespitter.gui
8+
{
9+
public class FSmeshSwitch : PartModule
10+
{
11+
[KSPField]
12+
public string buttonName = "Next part variant";
13+
14+
[KSPField]
15+
public string objects = string.Empty;
16+
17+
// in case of multiple instances of this module, on will be the master, the rest slaves.
18+
[KSPField]
19+
public bool isController = true;
20+
21+
// in case of multiple sets of master/slaves, only affect ones on the same channel.
22+
[KSPField]
23+
public int channel = 0;
24+
25+
[KSPField(isPersistant = true)]
26+
public int selectedObject = 0;
27+
28+
private string[] objectNames;
29+
private List<Transform> objectTransforms = new List<Transform>();
30+
31+
[KSPEvent(guiActive = false, guiActiveEditor = true, guiActiveUnfocused = false, guiName = "Next part variant")]
32+
public void nextObjectEvent()
33+
{
34+
selectedObject++;
35+
if (selectedObject >= objectTransforms.Count)
36+
{
37+
selectedObject = 0;
38+
}
39+
switchToObject(selectedObject);
40+
}
41+
42+
private void parseObjectNames()
43+
{
44+
objectNames = objects.Split(';');
45+
if (objectNames.Length < 1)
46+
Debug.Log("FSmeshSwitch: Found no object names in the object list");
47+
else
48+
{
49+
objectTransforms.Clear();
50+
for (int i = 0; i < objectNames.Length; i++)
51+
{
52+
Transform newTransform = part.FindModelTransform(objectNames[i]);
53+
if (newTransform != null)
54+
{
55+
objectTransforms.Add(newTransform);
56+
//Debug.Log("FSmeshSwitch: added object to list: " + objectNames[i]);
57+
}
58+
else
59+
{
60+
Debug.Log("FSmeshSwitch: could not find object " + objectNames[i]);
61+
}
62+
}
63+
}
64+
}
65+
66+
private void switchToObject(int objectNumber)
67+
{
68+
if (objectNumber >= objectTransforms.Count) return;
69+
70+
for (int i = 0; i < objectTransforms.Count; i++)
71+
{
72+
objectTransforms[i].gameObject.renderer.enabled = false;
73+
}
74+
75+
// enable the selected one last because there might be several entries with the same object, and we don't want to disable it after it's been enabled.
76+
objectTransforms[objectNumber].gameObject.renderer.enabled = true;
77+
}
78+
79+
public override void OnStart(PartModule.StartState state)
80+
{
81+
parseObjectNames();
82+
switchToObject(selectedObject);
83+
Events["nextObjectEvent"].guiName = buttonName;
84+
}
85+
}
86+
}

For release/Firespitter/Firespitter.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"NAME": "Firespitter",
3-
"URL": "https://raw.githubusercontent.com/snjo/Firespitter/master/For\ release/Firespitter/Firespitter.version",
3+
"URL": "https://raw.githubusercontent.com/snjo/Firespitter/master/For%20release/Firespitter/Firespitter.version",
44
"VERSION": {
55
"MAJOR": 6,
66
"MINOR": 3,

0 commit comments

Comments
 (0)