Add enable/disable logic to ModuleConformingDecal

feature-multiSDF
Andrew Cassidy 4 years ago
parent d5038e19bc
commit 995c9120e5

@ -39,8 +39,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls/UnityEngine.dll</HintPath>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

@ -108,7 +108,5 @@ namespace ConformalDecals.MaterialModifiers {
textureProperty.UpdateScale(ParsedMaterial, scale);
}
}
}
}

@ -5,13 +5,13 @@ namespace ConformalDecals.MaterialModifiers {
public class TextureMaterialProperty : MaterialProperty {
public string TextureUrl { get; }
public Texture2D TextureRef { get; }
public bool IsNormal { get; }
public bool IsMain { get; }
public bool AutoScale { get; }
public Rect TileRect { get; }
public float AspectRatio => TileRect.height / TileRect.width;
private readonly Vector2 _textureOffset;

@ -1,5 +1,61 @@
using System;
using UnityEngine;
namespace ConformalDecals {
public class ModuleConformalDecal : PartModule {
[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);
}
public bool Render(Material decalMaterial) {
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
if (_projectionEnabled) {
foreach (var camera in Camera.allCameras) {
Graphics.DrawMesh(_targetMesh, Target.worldToLocalMatrix, decalMaterial, 0, camera, 0, DecalMPB, ShadowCastingMode.Off, true);
}
DecalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff));
DecalMPB.SetColor(PropertyIDs._RimFalloff, partMPB.GetColor(PropertyIDs._RimFalloff));
Graphics.DrawMesh(_targetMesh, Target.localToWorldMatrix, decalMaterial, 0, camera, 0, DecalMPB, ShadowCastingMode.Off, true);
return true;
}

Loading…
Cancel
Save