Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thunderkit Utilities #558

Merged
merged 23 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7f73102
Added asset bundles guide
Indigocoder1 Feb 28, 2024
2d9cd12
Grammar changes and formatting
Indigocoder1 Feb 28, 2024
2f03104
Grammar & readability improvements. Added prefab guide
Indigocoder1 Feb 29, 2024
612d98d
Fix a couple grammar issues
LeeTwentyThree Feb 29, 2024
c8d44e8
Fixed names and comment spaces
Indigocoder1 Mar 1, 2024
c41b416
Merge branch 'master' of https://github.com/Indigocoder1/Nautilus
Indigocoder1 Mar 1, 2024
699d92e
Replace constant classID with PrefabInfo one
Indigocoder1 Mar 1, 2024
56a92bc
Changed TechType to PascalCase
Indigocoder1 Mar 1, 2024
19bda17
Fix duplicate usage of "on"
LeeTwentyThree Mar 1, 2024
d4616b4
Add Nautilus.Utility using statement
LeeTwentyThree Mar 1, 2024
3bc5d8a
Since the prefab has a recipe, must be pickupable
LeeTwentyThree Mar 1, 2024
12d6124
Merge branch 'master' of https://github.com/Indigocoder1/Nautilus
Indigocoder1 Sep 14, 2024
f0e3d6f
Added thunderkit utilites
Indigocoder1 Sep 14, 2024
ad6de78
Added SN/BZ checking
Indigocoder1 Sep 14, 2024
cbd18cb
Added separate enums for the layers in SN & BZ
Indigocoder1 Sep 14, 2024
a6cd36c
Changed name of application modes
Indigocoder1 Sep 14, 2024
600639d
Moved material getters to MaterialUtils
Indigocoder1 Sep 14, 2024
0e5f48d
Changed layer application to use switch expression
Indigocoder1 Sep 14, 2024
50efec8
Removed unnecessary comment
Indigocoder1 Sep 14, 2024
8b2ddd0
Changed property names to respect their type name
Indigocoder1 Sep 14, 2024
a86deef
Added default index of 0 to material indices
Indigocoder1 Sep 14, 2024
1c2a2d5
Added graphic setting and reverted default build config
Indigocoder1 Sep 14, 2024
3a31553
Added graphic option to layer applier & removed outdated comment
Indigocoder1 Sep 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Nautilus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{418502DD-372D-4EF9-8021-B262552DFEDE}.BZ.STABLE|Any CPU.ActiveCfg = BZ.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.BZ.STABLE|Any CPU.Build.0 = BZ.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.Debug|Any CPU.ActiveCfg = SN.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.Debug|Any CPU.Build.0 = SN.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.Debug|Any CPU.ActiveCfg = BZ.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.Debug|Any CPU.Build.0 = BZ.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.Release|Any CPU.ActiveCfg = SN.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.Release|Any CPU.Build.0 = SN.STABLE|Any CPU
{418502DD-372D-4EF9-8021-B262552DFEDE}.SN.STABLE|Any CPU.ActiveCfg = SN.STABLE|Any CPU
Expand Down
23 changes: 21 additions & 2 deletions Nautilus/Utility/MaterialUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ internal static void Patch()

private static IEnumerator LoadReferences()
{
#if SUBNAUTICA
yield return PatchInternal();
#endif

IsReady = true;

yield break;
Expand All @@ -32,6 +31,26 @@ private static IEnumerator LoadReferences()
/// </summary>
public static bool IsReady { get; private set; }

/// <summary>
/// Gets the basic glass material
/// </summary>
public static Material GlassMaterial { get; private set; }

/// <summary>
/// Gets the material for the outside of glass, such as for base windows
/// </summary>
public static Material ExteriorGlassMaterial { get; private set; }

/// <summary>
/// Gets the material for the inside of glass, such as the inside of the Cyclops windshield
/// </summary>
public static Material InteriorGlassMaterial { get; private set; }

/// <summary>
/// Gets a shiny glass material
/// </summary>
public static Material ShinyGlassMaterial { get; private set; }

/// <summary>
/// Contains references to various Shaders.
/// </summary>
Expand Down
47 changes: 47 additions & 0 deletions Nautilus/Utility/MaterialUtils_BelowZero.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections;
using UnityEngine;

#if BELOWZERO
namespace Nautilus.Utility;

public static partial class MaterialUtils
{
private static IEnumerator PatchInternal()
{
yield return LoadGlassMaterials();
}

private static IEnumerator LoadGlassMaterials()
{
var seamothTask = CraftData.GetPrefabForTechTypeAsync(TechType.SeaTruck);

yield return seamothTask;

var glassMaterial = seamothTask.GetResult()
.transform.Find("model/seatruck_anim/Seatruck_cabin_exterior_glass_geo")
.GetComponent<Renderer>().material;

GlassMaterial = new Material(glassMaterial);

ExteriorGlassMaterial = new Material(glassMaterial);
ExteriorGlassMaterial.SetFloat("_SpecInt", 100);
ExteriorGlassMaterial.SetFloat("_Shininess", 6.3f);
ExteriorGlassMaterial.SetFloat("_Fresnel", 0.85f);
ExteriorGlassMaterial.SetColor("_Color", new Color(0.33f, 0.58f, 0.71f, 0.1f));
ExteriorGlassMaterial.SetColor("_SpecColor", new Color(0.5f, 0.76f, 1f, 1f));

ShinyGlassMaterial = new Material(glassMaterial);
ShinyGlassMaterial.SetColor("_Color", new Color(1, 1, 1, 0.2f));
ShinyGlassMaterial.SetFloat("_SpecInt", 3);
ShinyGlassMaterial.SetFloat("_Shininess", 8);
ShinyGlassMaterial.SetFloat("_Fresnel", 0.78f);

InteriorGlassMaterial = new Material(glassMaterial);
InteriorGlassMaterial.SetColor("_Color", new Color(0.67f, 0.71f, 0.76f, 0.56f));
InteriorGlassMaterial.SetFloat("_SpecInt", 2);
InteriorGlassMaterial.SetFloat("_Shininess", 6f);
InteriorGlassMaterial.SetFloat("_Fresnel", 0.88f);
}
}

#endif
59 changes: 59 additions & 0 deletions Nautilus/Utility/MaterialUtils_Subnautica.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ private static IEnumerator PatchInternal()
yield return LoadAirWaterBarrierMaterial();
yield return LoadForcefieldMaterial();
yield return LoadGhostMaterial();
yield return LoadGlassMaterials();
yield return LoadUIMaterial();
}

/// <summary>
Expand Down Expand Up @@ -47,6 +49,11 @@ private static IEnumerator PatchInternal()
/// </summary>
public static Material GhostMaterial { get; private set; }

/// <summary>
/// Gets the material used by the UI in the Cyclops
/// </summary>
public static Material HolographicUIMaterial { get; private set; }

private static IEnumerator LoadIonCubeMaterial()
{
if (IonCubeMaterial)
Expand Down Expand Up @@ -128,5 +135,57 @@ private static IEnumerator LoadGhostMaterial()
GhostMaterial = wallShelf.GetComponentInChildren<Constructable>().ghostMaterial;
}
}

private static IEnumerator LoadGlassMaterials()
{
var seamothTask = CraftData.GetPrefabForTechTypeAsync(TechType.Seamoth);

yield return seamothTask;

var glassMaterial = seamothTask.GetResult()
.transform.Find("Model/Submersible_SeaMoth/Submersible_seaMoth_geo/Submersible_SeaMoth_glass_geo")
.GetComponent<Renderer>().material;

GlassMaterial = new Material(glassMaterial);

ExteriorGlassMaterial = new Material(glassMaterial);
ExteriorGlassMaterial.SetFloat("_SpecInt", 100);
ExteriorGlassMaterial.SetFloat("_Shininess", 6.3f);
ExteriorGlassMaterial.SetFloat("_Fresnel", 0.85f);
ExteriorGlassMaterial.SetColor("_Color", new Color(0.33f, 0.58f, 0.71f, 0.1f));
ExteriorGlassMaterial.SetColor("_SpecColor", new Color(0.5f, 0.76f, 1f, 1f));

ShinyGlassMaterial = new Material(glassMaterial);
ShinyGlassMaterial.SetColor("_Color", new Color(1, 1, 1, 0.2f));
ShinyGlassMaterial.SetFloat("_SpecInt", 3);
ShinyGlassMaterial.SetFloat("_Shininess", 8);
ShinyGlassMaterial.SetFloat("_Fresnel", 0.78f);

InteriorGlassMaterial = new Material(glassMaterial);
InteriorGlassMaterial.SetColor("_Color", new Color(0.67f, 0.71f, 0.76f, 0.56f));
InteriorGlassMaterial.SetFloat("_SpecInt", 2);
InteriorGlassMaterial.SetFloat("_Shininess", 6f);
InteriorGlassMaterial.SetFloat("_Fresnel", 0.88f);
}

private static bool _cyclopsLoaded;

private static IEnumerator LoadUIMaterial()
{
yield return new WaitUntil(() => LightmappedPrefabs.main);

LightmappedPrefabs.main.RequestScenePrefab("Cyclops", new LightmappedPrefabs.OnPrefabLoaded(OnCyclopsLoaded));

yield return new WaitUntil(() => _cyclopsLoaded);
}

private static void OnCyclopsLoaded(GameObject cyclops)
{
var holoMat = cyclops.transform.Find("HelmHUD/HelmHUDVisuals/Canvas_LeftHUD/EngineOnUI/EngineOff_Button")
.GetComponent<UnityEngine.UI.Image>().material;

HolographicUIMaterial = new Material(holoMat);
_cyclopsLoaded = true;
}
}
#endif
27 changes: 27 additions & 0 deletions Nautilus/Utility/ThunderkitUtilities/ApplySNFont.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using UnityEngine;
using TMPro;

namespace Nautilus.Utility.ThunderkitUtilities;

internal class ApplySNFont : MonoBehaviour
{
[Tooltip("How to apply the font")]
public GeneralSetMode fontSetMode;

private void Start()
{
switch (fontSetMode)
{
case GeneralSetMode.SingleObject:
GetComponent<TextMeshProUGUI>().font = FontUtils.Aller_Rg;
break;
case GeneralSetMode.AllChildObjects:
GetComponentsInChildren<TextMeshProUGUI>().ForEach(t => t.font = FontUtils.Aller_Rg);
break;
case GeneralSetMode.AllChildObjectsIncludeInactive:
GetComponentsInChildren<TextMeshProUGUI>(true).ForEach(t => t.font = FontUtils.Aller_Rg);
break;
}

}
}
75 changes: 75 additions & 0 deletions Nautilus/Utility/ThunderkitUtilities/ApplySNLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Reflection;
using UnityEngine;

namespace Nautilus.Utility.ThunderkitUtilities;

internal class ApplySNLayer : MonoBehaviour
{
[Tooltip("The name of the layer you want to apply")]
public LayerName layerName;

[Tooltip("How to apply the layer")]
public GeneralSetMode layerSetMode;
EldritchCarMaker marked this conversation as resolved.
Show resolved Hide resolved

private void Start()
{
int layer = layerName switch
{
LayerName.Default => LayerID.Default,
LayerName.Useable => LayerID.Useable,
LayerName.NotUseable => LayerID.NotUseable,
LayerName.Player => LayerID.Player,
LayerName.TerrainCollider => LayerID.TerrainCollider,
LayerName.UI => LayerID.UI,
LayerName.Trigger => LayerID.Trigger,
LayerName.BaseClipProxy => LayerID.BaseClipProxy,
LayerName.OnlyVehicle => LayerID.OnlyVehicle,
LayerName.Vehicle => LayerID.Vehicle,
#if SUBNAUTICA
LayerName.DefaultCollisionMask => LayerID.DefaultCollisionMask,
LayerName.SubRigidbodyExclude => LayerID.SubRigidbodyExclude,
#elif BELOWZERO
LayerName.Interior => LayerID.Interior,
LayerName.AllowPlayerAndVehicle => LayerID.AllowPlayerAndVehicle,
#endif
_ => 0
};

switch(layerSetMode)
{
case GeneralSetMode.SingleObject:
gameObject.layer = layer;
break;
case GeneralSetMode.AllChildObjects:
GetComponentsInChildren<GameObject>().ForEach(g => g.layer = layer);
break;
case GeneralSetMode.AllChildObjectsIncludeInactive:
GetComponentsInChildren<GameObject>(true).ForEach(g => g.layer = layer);
break;
}
}

/// <summary>
/// These are taken from <see cref="LayerID"/>, and are retrieved using reflection
EldritchCarMaker marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public enum LayerName
{
Default,
Useable,
NotUseable,
Player,
TerrainCollider,
UI,
Trigger,
BaseClipProxy,
OnlyVehicle,
Vehicle,
#if SUBNAUTICA
DefaultCollisionMask,
SubRigidbodyExclude,
#elif BELOWZERO
Interior,
AllowPlayerAndVehicle
#endif
}
}
114 changes: 114 additions & 0 deletions Nautilus/Utility/ThunderkitUtilities/ApplySNMaterial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;

namespace Nautilus.Utility.ThunderkitUtilities;

internal class ApplySNMaterial : MonoBehaviour
{
[Tooltip("How to apply the material")]
public MaterialSetMode materialSetMode;

[Tooltip("What material to apply")]
public MaterialType materialType;

[Tooltip("Run at start, or be manually called?")]
public bool runAtStart = true;

[Header("Single Object Settings:")]
public Renderer renderer;
public int[] materialIndices;

private void OnValidate()
{
if (!renderer) TryGetComponent(out renderer);
}

private void Start()
{
if (!runAtStart) return;

AssignMaterials();
}

/// <summary>
/// Applies the set material using the specified <see cref="MaterialSetMode"/>
/// </summary>
public void AssignMaterials()
{
switch(materialSetMode)
{
case MaterialSetMode.SingleObject:
ApplyMaterialsOnSingleRend();
break;
case MaterialSetMode.AllChildObjects:
ApplyMaterialsOnChildren(false);
break;
case MaterialSetMode.AllChildObjectsIncludeInactive:
ApplyMaterialsOnChildren(true);
break;
}
}

private void ApplyMaterialsOnSingleRend()
{
if (renderer == null) throw new System.Exception($"The renderer is null on {gameObject} when SN materials were trying to be applied");

var mats = renderer.materials;
foreach (var index in materialIndices)
{
mats[index] = GetMaterial(materialType);
}

renderer.materials = mats;
}

private void ApplyMaterialsOnChildren(bool includeInactive)
{
var rends = GetComponentsInChildren<Renderer>(includeInactive);
foreach (var rend in rends)
{
var materials = rend.materials;
for (int i = 0; i < materials.Length; i++)
{
materials[i] = GetMaterial(materialType);
}

rend.materials = materials;
}
}

private Material GetMaterial(MaterialType type)
{
Material mat = type switch
{
#if SN_STABLE
MaterialType.WaterBarrier => MaterialUtils.AirWaterBarrierMaterial,
MaterialType.ForceField => MaterialUtils.ForceFieldMaterial,
MaterialType.StasisField => MaterialUtils.StasisFieldMaterial,
MaterialType.HolographicUI => MaterialUtils.HolographicUIMaterial,
#endif
MaterialType.Glass => MaterialUtils.GlassMaterial,
MaterialType.ExteriorGlass => MaterialUtils.ExteriorGlassMaterial,
MaterialType.ShinyGlass => MaterialUtils.ShinyGlassMaterial,
MaterialType.InteriorWindowGlass => MaterialUtils.InteriorGlassMaterial,
_ => null
};

return mat;
}

internal enum MaterialType
{
Glass,
ExteriorGlass,
ShinyGlass,
InteriorWindowGlass,
#if SN_STABLE
WaterBarrier,
ForceField,
StasisField,
HolographicUI
#endif
}
}
Loading
Loading