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 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…
Reference in New Issue
Block a user