mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Cleanup and fix onVariantApplied
This commit is contained in:
parent
62bdd151e1
commit
e6288942ea
Binary file not shown.
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using ConformalDecals.Text;
|
||||
using ConformalDecals.Util;
|
||||
using TMPro;
|
||||
using UniLinq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ConformalDecals {
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ConformalDecals.MaterialProperties;
|
||||
using ConformalDecals.Util;
|
||||
using UniLinq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ConformalDecals {
|
||||
@ -236,7 +237,7 @@ namespace ConformalDecals {
|
||||
opacity = defaultOpacity;
|
||||
cutoff = defaultCutoff;
|
||||
wear = defaultWear;
|
||||
|
||||
|
||||
UpdateTextures();
|
||||
UpdateScale();
|
||||
|
||||
@ -343,7 +344,10 @@ namespace ConformalDecals {
|
||||
}
|
||||
|
||||
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
|
||||
if (_isAttached && eventPart == part.parent) {
|
||||
if (_isAttached && eventPart != null) {
|
||||
if (projectMultiple && eventPart != part.parent) return;
|
||||
else if (!_targets.Select(o => o.targetPart).Contains(eventPart)) return;
|
||||
|
||||
UpdateTargets();
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ using UnityEngine.Rendering;
|
||||
namespace ConformalDecals {
|
||||
public class ProjectionTarget {
|
||||
// Target object data
|
||||
private readonly Transform _target;
|
||||
private readonly Part _targetPart;
|
||||
public readonly Transform target;
|
||||
public readonly Part targetPart;
|
||||
private readonly Mesh _targetMesh;
|
||||
private readonly Matrix4x4 _decalMatrix;
|
||||
private readonly Vector3 _decalNormal;
|
||||
@ -22,8 +22,8 @@ namespace ConformalDecals {
|
||||
public ProjectionTarget(Part targetPart, Transform target, MeshRenderer renderer, MeshFilter filter,
|
||||
Matrix4x4 orthoMatrix, Transform projector, bool useBaseNormal) {
|
||||
|
||||
_targetPart = targetPart;
|
||||
_target = target;
|
||||
this.targetPart = targetPart;
|
||||
this.target = target;
|
||||
_targetMesh = filter.sharedMesh;
|
||||
_useBaseNormal = useBaseNormal;
|
||||
_decalMPB = new MaterialPropertyBlock();
|
||||
@ -41,22 +41,22 @@ namespace ConformalDecals {
|
||||
var flightID = (uint) ParseUtil.ParseInt(node, "part");
|
||||
var targetPath = ParseUtil.ParseString(node, "targetPath");
|
||||
var targetName = ParseUtil.ParseString(node, "targetName");
|
||||
|
||||
|
||||
_decalMatrix = ParseUtil.ParseMatrix4x4(node, "decalMatrix");
|
||||
_decalNormal = ParseUtil.ParseVector3(node, "decalNormal");
|
||||
_decalTangent = ParseUtil.ParseVector3(node, "decalTangent");
|
||||
_useBaseNormal = useBaseNormal;
|
||||
_decalMPB = new MaterialPropertyBlock();
|
||||
|
||||
_targetPart = vessel[flightID];
|
||||
if (_targetPart == null) throw new IndexOutOfRangeException("Vessel returned null part");
|
||||
_target = LoadTransformPath(targetPath, _targetPart.transform);
|
||||
if (_target.name != targetName) throw new FormatException("Target name does not match");
|
||||
targetPart = vessel[flightID];
|
||||
if (targetPart == null) throw new IndexOutOfRangeException("Vessel returned null part");
|
||||
target = LoadTransformPath(targetPath, targetPart.transform);
|
||||
if (target.name != targetName) throw new FormatException("Target name does not match");
|
||||
|
||||
var renderer = _target.GetComponent<MeshRenderer>();
|
||||
var filter = _target.GetComponent<MeshFilter>();
|
||||
var renderer = target.GetComponent<MeshRenderer>();
|
||||
var filter = target.GetComponent<MeshFilter>();
|
||||
|
||||
if (!ValidateTarget(_target, renderer, filter)) throw new FormatException("Invalid target");
|
||||
if (!ValidateTarget(target, renderer, filter)) throw new FormatException("Invalid target");
|
||||
|
||||
_targetMesh = filter.sharedMesh;
|
||||
|
||||
@ -85,17 +85,17 @@ namespace ConformalDecals {
|
||||
_decalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff));
|
||||
_decalMPB.SetColor(PropertyIDs._RimColor, partMPB.GetColor(PropertyIDs._RimColor));
|
||||
|
||||
Graphics.DrawMesh(_targetMesh, _target.localToWorldMatrix, decalMaterial, 0, camera, 0, _decalMPB, ShadowCastingMode.Off, true);
|
||||
Graphics.DrawMesh(_targetMesh, target.localToWorldMatrix, decalMaterial, 0, camera, 0, _decalMPB, ShadowCastingMode.Off, true);
|
||||
}
|
||||
|
||||
public ConfigNode Save() {
|
||||
var node = new ConfigNode("TARGET");
|
||||
node.AddValue("part", _targetPart.flightID);
|
||||
node.AddValue("part", targetPart.flightID);
|
||||
node.AddValue("decalMatrix", _decalMatrix);
|
||||
node.AddValue("decalNormal", _decalNormal);
|
||||
node.AddValue("decalTangent", _decalTangent);
|
||||
node.AddValue("targetPath", SaveTransformPath(_target, _targetPart.transform)); // used to find the target transform
|
||||
node.AddValue("targetName", _target.name); // used to validate the mesh has not changed since last load
|
||||
node.AddValue("targetPath", SaveTransformPath(target, targetPart.transform)); // used to find the target transform
|
||||
node.AddValue("targetName", target.name); // used to validate the mesh has not changed since last load
|
||||
|
||||
return node;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using ConformalDecals.Util;
|
||||
using TMPro;
|
||||
using UniLinq;
|
||||
|
Loading…
Reference in New Issue
Block a user