mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Merge pull request #147 from blowfishpro/fairings-plugin
Add plugin code for fairing material modifier
This commit is contained in:
commit
a2400d6e65
Binary file not shown.
80
Source/Restock/ModuleRestockModifyFairingMaterials.cs
Normal file
80
Source/Restock/ModuleRestockModifyFairingMaterials.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Restock
|
||||
{
|
||||
public class ModuleRestockModifyFairingMaterials : PartModule
|
||||
{
|
||||
[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);
|
||||
|
||||
StartCoroutine(WaitAndUpdateMaterials());
|
||||
}
|
||||
|
||||
private IEnumerator WaitAndUpdateMaterials()
|
||||
{
|
||||
yield return null;
|
||||
|
||||
if (string.IsNullOrEmpty(serializedNode))
|
||||
{
|
||||
Debug.LogError("Serialized node is null or empty!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
ConfigNode node = ConfigNode.Parse(serializedNode).nodes[0];
|
||||
|
||||
ModuleProceduralFairing fairingModule = part.FindModuleImplementing<ModuleProceduralFairing>();
|
||||
|
||||
if (fairingModule == null)
|
||||
{
|
||||
Debug.LogError("No fairing module found on part!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
UpdateMaterial(fairingModule.FairingMaterial, node);
|
||||
UpdateMaterial(fairingModule.FairingConeMaterial, node);
|
||||
UpdateMaterial(fairingModule.FairingFlightMaterial, node);
|
||||
UpdateMaterial(fairingModule.FairingFlightConeMaterial, node);
|
||||
|
||||
foreach (ProceduralFairings.FairingPanel fairingPanel in fairingModule.Panels)
|
||||
{
|
||||
MeshRenderer renderer = fairingPanel.go.GetComponent<MeshRenderer>();
|
||||
UpdateMaterial(renderer.material, node);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateMaterial(Material material, ConfigNode node)
|
||||
{
|
||||
foreach (ConfigNode node2 in node.nodes)
|
||||
{
|
||||
if (node2.name == "COLOR_PROPERTY")
|
||||
{
|
||||
string name = node2.GetValue("name");
|
||||
Color color = ConfigNode.ParseColor(node2.GetValue("color"));
|
||||
|
||||
material.SetColor(name, color);
|
||||
}
|
||||
else if (node2.name == "FLOAT_PROPERTY")
|
||||
{
|
||||
string name = node2.GetValue("name");
|
||||
float value = float.Parse(node2.GetValue("value"));
|
||||
|
||||
material.SetFloat(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -41,6 +41,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ModuleRestockModifyFairingMaterials.cs" />
|
||||
<Compile Include="ModuleRestockModifyMaterials.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user