2020-06-02 20:46:16 +00:00
|
|
|
using System.Collections.Generic;
|
2020-06-20 04:44:43 +00:00
|
|
|
using ConformalDecals.Util;
|
2020-06-02 20:46:16 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace ConformalDecals {
|
2020-06-06 04:29:57 +00:00
|
|
|
public static class DecalConfig {
|
2020-06-20 04:44:43 +00:00
|
|
|
private static Texture2D _blankNormal;
|
2020-06-02 20:46:16 +00:00
|
|
|
private static List<string> _shaderBlacklist;
|
2020-06-20 06:54:32 +00:00
|
|
|
private static int _decalLayer = 31;
|
|
|
|
private static bool _selectableInFlight = false;
|
2020-06-20 04:44:43 +00:00
|
|
|
|
2020-06-10 19:20:47 +00:00
|
|
|
public static Texture2D BlankNormal => _blankNormal;
|
2020-06-20 06:54:32 +00:00
|
|
|
|
2020-06-20 04:44:43 +00:00
|
|
|
public static int DecalLayer => _decalLayer;
|
2020-06-02 20:46:16 +00:00
|
|
|
|
2020-06-20 06:54:32 +00:00
|
|
|
public static bool SelectableInFlight => _selectableInFlight;
|
|
|
|
|
2020-06-02 20:46:16 +00:00
|
|
|
public static bool IsBlacklisted(Shader shader) {
|
|
|
|
return IsBlacklisted(shader.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsBlacklisted(string shaderName) {
|
|
|
|
return _shaderBlacklist.Contains(shaderName);
|
|
|
|
}
|
|
|
|
|
2020-06-03 00:14:52 +00:00
|
|
|
private static void ParseConfig(ConfigNode node) {
|
2020-06-02 20:46:16 +00:00
|
|
|
foreach (var blacklist in node.GetNodes("SHADERBLACKLIST")) {
|
|
|
|
foreach (var shaderName in blacklist.GetValuesList("shader")) {
|
|
|
|
_shaderBlacklist.Add(shaderName);
|
|
|
|
}
|
2020-06-20 04:44:43 +00:00
|
|
|
|
|
|
|
ParseUtil.ParseIntIndirect(ref _decalLayer, node, "decalLayer");
|
2020-06-20 06:54:32 +00:00
|
|
|
ParseUtil.ParseBoolIndirect(ref _selectableInFlight, node, "selectableInFlight");
|
2020-06-02 20:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 19:20:47 +00:00
|
|
|
private static Texture2D MakeBlankNormal() {
|
|
|
|
Debug.Log("ConformalDecals: Generating neutral normal map texture");
|
|
|
|
var width = 2;
|
|
|
|
var height = 2;
|
|
|
|
var color = new Color32(255, 128, 128, 128);
|
2020-06-20 04:44:43 +00:00
|
|
|
var colors = new[] {color, color, color, color};
|
2020-06-10 19:20:47 +00:00
|
|
|
|
|
|
|
var tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
|
|
|
|
for (var x = 0; x <= width; x++) {
|
|
|
|
for (var y = 0; y < height; y++) {
|
|
|
|
tex.SetPixels32(colors);
|
|
|
|
}
|
|
|
|
}
|
2020-06-20 04:44:43 +00:00
|
|
|
|
2020-06-10 19:20:47 +00:00
|
|
|
tex.Apply();
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2020-06-20 04:44:43 +00:00
|
|
|
// ReSharper disable once UnusedMember.Global
|
2020-06-03 00:14:52 +00:00
|
|
|
public static void ModuleManagerPostLoad() {
|
2020-06-02 20:46:16 +00:00
|
|
|
_shaderBlacklist = new List<string>();
|
|
|
|
|
|
|
|
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
|
|
|
|
|
|
|
|
if (configs.Length > 0) {
|
2020-06-03 00:14:52 +00:00
|
|
|
Debug.Log("ConformalDecals: loading config");
|
2020-06-02 20:46:16 +00:00
|
|
|
foreach (var config in configs) {
|
|
|
|
ParseConfig(config.config);
|
|
|
|
}
|
|
|
|
}
|
2020-06-10 19:20:47 +00:00
|
|
|
|
2020-06-20 04:44:43 +00:00
|
|
|
// setup physics for decals, ignore collision with everything
|
|
|
|
Physics.IgnoreLayerCollision(_decalLayer, 1, true); // default
|
|
|
|
Physics.IgnoreLayerCollision(_decalLayer, 17, true); // EVA
|
|
|
|
Physics.IgnoreLayerCollision(_decalLayer, 19, true); // PhysicalObjects
|
|
|
|
Physics.IgnoreLayerCollision(_decalLayer, 23, true); // AeroFXIgnore
|
|
|
|
Physics.IgnoreLayerCollision(_decalLayer, 26, true); // wheelCollidersIgnore
|
|
|
|
Physics.IgnoreLayerCollision(_decalLayer, 27, true); // wheelColliders
|
|
|
|
|
2020-06-10 19:20:47 +00:00
|
|
|
_blankNormal = MakeBlankNormal();
|
2020-06-02 20:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|