Skip to content

Commit

Permalink
ModuleBDBDeployableMeshHider
Browse files Browse the repository at this point in the history
Copied from ModuleRestockDeployableMeshHider - hides skinned mesh objects on deployable part break
  • Loading branch information
Rodg88 committed Jul 17, 2024
1 parent 1eee1fd commit 3eafca4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
Binary file modified Gamedata/Bluedog_DB/Plugins/BDB.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Source/VisualStudio/BDB/BDB/BDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="EngineLife.cs" />
<Compile Include="LesController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SkinnedMeshHider.cs" />
<Compile Include="SLAHelper.cs" />
<Compile Include="SymmetricalPart.cs" />
<Compile Include="WetLab.cs" />
Expand Down
105 changes: 105 additions & 0 deletions Source/VisualStudio/BDB/BDB/SkinnedMeshHider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

//Taken from Restock https://github.com/PorktoberRevolution/ReStocked/blob/master/Source/Restock/ModuleRestockDeployableMeshHider.cs by Chris Adderley, LGPL license

namespace BDB
{
public class ModuleBDBDeployableMeshHider : PartModule
{
private ModuleDeployablePart deployable;
public List<GameObject> disableableGameObjects;
private ModuleDeployablePart.DeployState savedState;

[SerializeField]
private string serializedNode;

public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);

if (serializedNode == null)
serializedNode = node.ToString();
}


public override void OnStart(StartState state)
{
base.OnStart(state);
if (HighLogic.LoadedSceneIsFlight)
{

/*if (string.IsNullOrEmpty(serializedNode))
{
this.LogError("Serialized node is null or empty!");
return;
}*/

ConfigNode node = ConfigNode.Parse(serializedNode).nodes[0];
LoadTransforms(node);


deployable = this.GetComponent<ModuleDeployablePart>();
if (deployable == null)
{
Debug.LogError("No ModuleDeployablePart found on part");
return;
}

savedState = deployable.deployState;
SetVisibility(savedState != ModuleDeployablePart.DeployState.BROKEN);
}
}
public void LoadTransforms(ConfigNode node)
{

disableableGameObjects = new List<GameObject>();

foreach (string transformName in node.GetValues("transformName"))
{

Transform[] transforms = part.FindModelTransforms(transformName);
/*if (transforms.Length == 0)
{
this.LogError($"No transforms named '{transformName}' found in model");
continue;
}*/

foreach (Transform xform in transforms)
{
disableableGameObjects.Add(xform.gameObject);
}
}
}

private void SetVisibility(bool visible)
{
for (int i = 0; i < disableableGameObjects.Count; i++)
{
disableableGameObjects[i].SetActive(visible);
}
}
public void Update()
{
if (HighLogic.LoadedSceneIsFlight && deployable && disableableGameObjects.Count > 0)
{

if (deployable.deployState != savedState)
{
SetVisibility(deployable.deployState != ModuleDeployablePart.DeployState.BROKEN);
savedState = deployable.deployState;
}
}
}
void OnDestroy()
{

if (HighLogic.LoadedSceneIsFlight && disableableGameObjects.Count > 0)
SetVisibility(false);
}
}
}

0 comments on commit 3eafca4

Please sign in to comment.