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 15 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
16 changes: 16 additions & 0 deletions Nautilus/Utility/ThunderkitUtilities/ApplicationModes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Nautilus.Utility.ThunderkitUtilities;

internal enum GeneralApplicationMode
Metious marked this conversation as resolved.
Show resolved Hide resolved
{
SingleObject,
AllChildObjects,
AllChildObjectsIncludeInactive,
}

internal enum MaterialApplicationMode
Metious marked this conversation as resolved.
Show resolved Hide resolved
{
SingleObject,
AllChildObjects,
AllChildObjectsIncludeInactive,
AllChildGraphics
}
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 GeneralApplicationMode applicationMode;

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

}
}
56 changes: 56 additions & 0 deletions Nautilus/Utility/ThunderkitUtilities/ApplySNLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 GeneralApplicationMode applicationMode;

private void Start()
{
FieldInfo field = typeof(LayerID).GetField(layerName.ToString(), BindingFlags.Static | BindingFlags.Public);
Metious marked this conversation as resolved.
Show resolved Hide resolved
int layer = (int) field.GetValue(null);

switch(applicationMode)
{
case GeneralApplicationMode.SingleObject:
gameObject.layer = layer;
break;
case GeneralApplicationMode.AllChildObjects:
GetComponentsInChildren<GameObject>().ForEach(g => g.layer = layer);
break;
case GeneralApplicationMode.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 SN_STABLE
DefaultCollisionMask,
SubRigidbodyExclude,
#elif BZ_STABLE
Interior,
AllowPlayerAndVehicle
#endif
}
}
192 changes: 192 additions & 0 deletions Nautilus/Utility/ThunderkitUtilities/ApplySNMaterial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;

namespace Nautilus.Utility.ThunderkitUtilities;

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

[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 static Material _glassMaterial;
private static Material _exteriorGlassMaterial;
private static Material _shinyGlassMaterial;
private static Material _interiorWindowGlassMaterial;
private static Material _holographicUIMaterial;
private static bool _cyclopsLoaded;

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

private IEnumerator Start()
{
yield return LoadMaterialsAsync();

if (!runAtStart) yield break;

yield return AssignMaterials();
}

/// <summary>
/// Applies the set material using the specified <see cref="MaterialApplicationMode"/>
/// A coroutine is required to ensure all material references are retrieved before being applied
/// </summary>
public IEnumerator AssignMaterials()
{
if (!_cyclopsLoaded)
{
yield return LoadMaterialsAsync();
}

switch(applicationMode)
{
case MaterialApplicationMode.SingleObject:
ApplyMaterialsOnSingleRend();
break;
case MaterialApplicationMode.AllChildObjects:
ApplyMaterialsOnChildren(false);
break;
case MaterialApplicationMode.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 => _holographicUIMaterial,
#endif
MaterialType.Glass => _glassMaterial,
MaterialType.ExteriorGlass => _exteriorGlassMaterial,
MaterialType.ShinyGlass => _shinyGlassMaterial,
MaterialType.InteriorWindowGlass => _interiorWindowGlassMaterial,
_ => null
};

return mat;
}

private IEnumerator LoadMaterialsAsync()
Metious marked this conversation as resolved.
Show resolved Hide resolved
{
CoroutineTask<GameObject> task = null;
#if BZ_STABLE
task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaTruck);
#elif SN_STABLE
task = CraftData.GetPrefabForTechTypeAsync(TechType.Seamoth);
#endif

yield return task;

string path = "";
#if BZ_STABLE
path = "model/seatruck_anim/Seatruck_cabin_exterior_glass_geo";
#elif SN_STABLE
path = "Model/Submersible_SeaMoth/Submersible_seaMoth_geo/Submersible_SeaMoth_glass_geo";
#endif

var glassMaterial = task.GetResult()
.transform.Find("Model/Submersible_SeaMoth/Submersible_seaMoth_geo/Submersible_SeaMoth_glass_geo")
EldritchCarMaker marked this conversation as resolved.
Show resolved Hide resolved
.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);

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

#if SN_STABLE
yield return new WaitUntil(() => LightmappedPrefabs.main);

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

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

private void OnCyclopsLoaded(GameObject cyclops)
{
_cyclopsLoaded = true;

var holoMat = cyclops.transform.Find("HelmHUD/HelmHUDVisuals/Canvas_LeftHUD/EngineOnUI/EngineOff_Button")
.GetComponent<Image>().material;

_holographicUIMaterial = new Material(holoMat);
}

internal enum MaterialType
{
Glass,
ExteriorGlass,
ShinyGlass,
InteriorWindowGlass,
// Kinda icky but these underlying values shouldn't change between versions
#if SN_STABLE
WaterBarrier,
ForceField,
StasisField,
HolographicUI
#endif
}
}
19 changes: 19 additions & 0 deletions Nautilus/Utility/ThunderkitUtilities/ApplySNShaders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEngine;

namespace Nautilus.Utility.ThunderkitUtilities;

internal class ApplySNShaders : MonoBehaviour
{
[Tooltip("Which GameObject to apply the shaders to (All children will also be affected)")]
public GameObject applyTo;

private void OnValidate()
{
if (applyTo == null) applyTo = gameObject;
}

private void Start()
{
MaterialUtils.ApplySNShaders(applyTo);
}
}
Loading