mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add enable/disable logic to ModuleConformingDecal
This commit is contained in:
parent
d5038e19bc
commit
995c9120e5
@ -39,8 +39,8 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||||
<HintPath>dlls/UnityEngine.dll</HintPath>
|
<HintPath>dlls\UnityEngine.CoreModule.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -108,7 +108,5 @@ namespace ConformalDecals.MaterialModifiers {
|
|||||||
textureProperty.UpdateScale(ParsedMaterial, scale);
|
textureProperty.UpdateScale(ParsedMaterial, scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
public class ModuleConformalDecal : PartModule {
|
public class ModuleConformalDecal : PartModule {
|
||||||
[KSPField] public string decalPreviewTransform = "";
|
[KSPField] public string decalPreviewTransform = "";
|
||||||
|
|
||||||
|
public void OnStart(StartState state) {
|
||||||
|
if ((state & StartState.Editor) != 0) {
|
||||||
|
GameEvents.onEditorPartEvent.Add(OnEditorEvent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Attach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnEditorEvent(ConstructionEventType eventType, Part eventPart) {
|
||||||
|
if (eventPart != this.part) return;
|
||||||
|
switch (eventType) {
|
||||||
|
case ConstructionEventType.PartAttached:
|
||||||
|
Attach();
|
||||||
|
break;
|
||||||
|
case ConstructionEventType.PartDetached:
|
||||||
|
Detach();
|
||||||
|
break;
|
||||||
|
case ConstructionEventType.PartOffsetting:
|
||||||
|
case ConstructionEventType.PartRotated:
|
||||||
|
case ConstructionEventType.PartDragging:
|
||||||
|
Project();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Attach() {
|
||||||
|
if (part.parent == null) {
|
||||||
|
this.LogError("Attach function called but part has no parent!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera.onPreCull += Render;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Detach() {
|
||||||
|
if (part.parent != null) {
|
||||||
|
this.LogError("Detach function called but part still has parent!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera.onPreCull -= Render;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDisable() {
|
||||||
|
Camera.onPreCull -= Render;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Project() { }
|
||||||
|
|
||||||
|
public void Render(Camera camera) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -63,11 +63,12 @@ namespace ConformalDecals {
|
|||||||
_projectionEnabled = projectorBounds.Intersects(targetBounds);
|
_projectionEnabled = projectorBounds.Intersects(targetBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Render(Material decalMaterial) {
|
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
|
||||||
if (_projectionEnabled) {
|
if (_projectionEnabled) {
|
||||||
foreach (var camera in Camera.allCameras) {
|
DecalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff));
|
||||||
Graphics.DrawMesh(_targetMesh, Target.worldToLocalMatrix, decalMaterial, 0, camera, 0, DecalMPB, ShadowCastingMode.Off, true);
|
DecalMPB.SetColor(PropertyIDs._RimFalloff, partMPB.GetColor(PropertyIDs._RimFalloff));
|
||||||
}
|
|
||||||
|
Graphics.DrawMesh(_targetMesh, Target.localToWorldMatrix, decalMaterial, 0, camera, 0, DecalMPB, ShadowCastingMode.Off, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user