Skip to content

Commit

Permalink
added mesh switch
Browse files Browse the repository at this point in the history
  • Loading branch information
snjo committed May 6, 2014
1 parent 210d8fe commit 702be45
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions Firespitter/Firespitter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Compile Include="engine\FSgroundParticles.cs" />
<Compile Include="engine\FSheliLiftEngine.cs" />
<Compile Include="engine\FSengine.cs" />
<Compile Include="gui\FSmeshSwitch.cs" />
<Compile Include="tools\MeshCreator.cs" />
<Compile Include="tools\CompatabilityChecker.cs" />
<Compile Include="tools\FSversionCheck.cs" />
Expand Down
86 changes: 86 additions & 0 deletions Firespitter/gui/FSmeshSwitch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Firespitter.gui
{
public class FSmeshSwitch : PartModule
{
[KSPField]
public string buttonName = "Next part variant";

[KSPField]
public string objects = string.Empty;

// in case of multiple instances of this module, on will be the master, the rest slaves.
[KSPField]
public bool isController = true;

// in case of multiple sets of master/slaves, only affect ones on the same channel.
[KSPField]
public int channel = 0;

[KSPField(isPersistant = true)]
public int selectedObject = 0;

private string[] objectNames;
private List<Transform> objectTransforms = new List<Transform>();

[KSPEvent(guiActive = false, guiActiveEditor = true, guiActiveUnfocused = false, guiName = "Next part variant")]
public void nextObjectEvent()
{
selectedObject++;
if (selectedObject >= objectTransforms.Count)
{
selectedObject = 0;
}
switchToObject(selectedObject);
}

private void parseObjectNames()
{
objectNames = objects.Split(';');
if (objectNames.Length < 1)
Debug.Log("FSmeshSwitch: Found no object names in the object list");
else
{
objectTransforms.Clear();
for (int i = 0; i < objectNames.Length; i++)
{
Transform newTransform = part.FindModelTransform(objectNames[i]);
if (newTransform != null)
{
objectTransforms.Add(newTransform);
//Debug.Log("FSmeshSwitch: added object to list: " + objectNames[i]);
}
else
{
Debug.Log("FSmeshSwitch: could not find object " + objectNames[i]);
}
}
}
}

private void switchToObject(int objectNumber)
{
if (objectNumber >= objectTransforms.Count) return;

for (int i = 0; i < objectTransforms.Count; i++)
{
objectTransforms[i].gameObject.renderer.enabled = false;
}

// 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.
objectTransforms[objectNumber].gameObject.renderer.enabled = true;
}

public override void OnStart(PartModule.StartState state)
{
parseObjectNames();
switchToObject(selectedObject);
Events["nextObjectEvent"].guiName = buttonName;
}
}
}
2 changes: 1 addition & 1 deletion For release/Firespitter/Firespitter.version
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"NAME": "Firespitter",
"URL": "https://raw.githubusercontent.com/snjo/Firespitter/master/For\ release/Firespitter/Firespitter.version",
"URL": "https://raw.githubusercontent.com/snjo/Firespitter/master/For%20release/Firespitter/Firespitter.version",
"VERSION": {
"MAJOR": 6,
"MINOR": 3,
Expand Down

0 comments on commit 702be45

Please sign in to comment.