Add project code

master
Andrew Cassidy 5 years ago
parent de3ca7571d
commit d8419416e8
No known key found for this signature in database
GPG Key ID: 963017B38FD477A1

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{3CD2A114-2C93-4D39-95B4-214DCC386A37}") = "DepthMask", "DepthMask\DepthMask.csproj", "{AF7B4795-7A4F-4238-BF1D-F0AC763C15C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AF7B4795-7A4F-4238-BF1D-F0AC763C15C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF7B4795-7A4F-4238-BF1D-F0AC763C15C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF7B4795-7A4F-4238-BF1D-F0AC763C15C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF7B4795-7A4F-4238-BF1D-F0AC763C15C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7633F515-D77A-4A4D-998B-4EB65CD3A32C}
EndGlobalSection
EndGlobal

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AF7B4795-7A4F-4238-BF1D-F0AC763C15C8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DepthMask</RootNamespace>
<AssemblyName>DepthMask</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="UnityEngine">
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ModuleDepthMask.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,130 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace Restock
{
public class ModuleRestockDepthMask : PartModule
{
// The name of the transform that has your mask mesh. The only strictly required property
[KSPField]
public string maskTransform = "";
[KSPField]
public string bodyTransform = "";
// The name of the depth mask shader
[KSPField]
public string shaderName = "DepthMask";
// The render queue value for the mesh, should be less than maskRenderQueue
[KSPField]
public int meshRenderQueue = 1000;
// the render queue value for the mask, should be less than 2000
[KSPField]
public int maskRenderQueue = 1999;
// depth mask object transform
public Transform maskTransformObject;
// body object transform
public Transform bodyTransformObject;
// depth mask shader object
public Shader depthShader;
public override void OnStart(StartState state)
{
base.OnStart(state);
UpdatematerialQueue();
// the part variant system is implemented extremely stupidly
// so we have to make this whole module more complicated as a result
GameEvents.onVariantApplied.Add(OnVariantApplied);
}
private void OnDestroy()
{
GameEvents.onVariantApplied.Remove(OnVariantApplied);
}
public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);
if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return;
this.maskTransformObject = base.part.FindModelTransform(maskTransform);
if (this.maskTransformObject == null)
{
this.LogError($"Can't find transform {maskTransform}");
return;
}
if (bodyTransform == "")
{
this.bodyTransformObject = base.part.partTransform;
}
else
{
this.bodyTransformObject = base.part.FindModelTransform(bodyTransform);
if (this.bodyTransformObject == null)
{
this.LogError($"Can't find transform {bodyTransform}");
this.bodyTransformObject = base.part.partTransform;
}
}
this.depthShader = Shader.Find(shaderName);
if (this.depthShader == null)
{
this.LogError($"Can't find shader {shaderName}");
return;
}
}
public void OnVariantApplied(Part appliedPart, PartVariant variant)
{
// I dont know why changing part variants resets all the materials to their as-loaded state, but it does
if (appliedPart == this.part) UpdatematerialQueue();
}
private void UpdatematerialQueue()
{
var windowRenderer = maskTransformObject.GetComponent<MeshRenderer>();
windowRenderer.material.shader = depthShader;
windowRenderer.material.renderQueue = maskRenderQueue;
var meshRenderers = bodyTransformObject.GetComponentsInChildren<MeshRenderer>(true);
var skinnedMeshRenderers = bodyTransformObject.GetComponentsInChildren<SkinnedMeshRenderer>(true);
foreach (var renderer in meshRenderers)
{
if (renderer == windowRenderer) continue;
var queue = renderer.material.renderQueue;
queue = meshRenderQueue + ((queue - 2000) / 2);
renderer.material.renderQueue = queue;
}
foreach (var renderer in skinnedMeshRenderers)
{
if (renderer == windowRenderer) continue;
var queue = renderer.material.renderQueue;
queue = meshRenderQueue + ((queue - 2000) / 2);
renderer.material.renderQueue = queue;
}
}
private void LogError(string message)
{
Debug.LogError($"[{part.partInfo?.name ?? part.name} {this.GetType()}] {message}");
}
}
}

@ -0,0 +1,38 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Depth Mask")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Cineboxandrew")]
[assembly: AssemblyProduct("DepthMask")]
[assembly: AssemblyCopyright("Copyright © Andrew Cassidy 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("AF7B4795-7A4F-4238-BF1D-F0AC763C15C8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: KSPAssembly("DepthMask", 1, 0, 0)]
Loading…
Cancel
Save