Cozy Wather + buld systeme

This commit is contained in:
2026-07-07 16:43:51 +02:00
parent 031ac42e5d
commit 6b26ae3376
2140 changed files with 3482825 additions and 2252 deletions
@@ -0,0 +1,99 @@
// Distant Lands 2025
// COZY: Stylized Weather 3
// All code included in this file is protected under the Unity Asset Store Eula
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.AssetImporters;
using System.IO;
using UnityEditor;
namespace DistantLands.Cozy.ShaderUtility
{
[ScriptedImporter(1, "cozyshader")]
public class CozyShaderImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
string fileContent = File.ReadAllText(ctx.assetPath);
var package = ObjectFactory.CreateInstance<CozyShaderPackage>();
bool overwriteFileWithShaderText = false;
bool isJSON = IsJson(fileContent);
if (!isJSON)
{
Shader shader = ShaderUtil.CreateShaderAsset(ctx, fileContent, false);
ctx.AddObjectToAsset("MainAsset", shader);
ctx.SetMainObject(shader);
return;
}
if (!string.IsNullOrEmpty(fileContent))
{
EditorJsonUtility.FromJsonOverwrite(fileContent, package);
}
if (package.entries == null)
{
package.entries = new List<CozyShaderPackage.Entry>();
}
package.PackageShaderVariants();
foreach (var e in package.entries)
{
if (e.shader != null)
{
ctx.DependsOnSourceAsset(AssetDatabase.GetAssetPath(e.shader));
}
else
overwriteFileWithShaderText = true;
}
string shaderSrc = package.GetShaderSource();
if (shaderSrc == null)
{
Debug.LogWarning($"{name} has no shader for this SRP provided");
return;
}
if (overwriteFileWithShaderText)
{
File.WriteAllText(ctx.assetPath, shaderSrc);
Shader shader = ShaderUtil.CreateShaderAsset(ctx, shaderSrc, false);
ctx.AddObjectToAsset("MainAsset", shader);
ctx.SetMainObject(shader);
return;
}
else
{
Shader shader = ShaderUtil.CreateShaderAsset(ctx, shaderSrc, false);
ctx.AddObjectToAsset("MainAsset", shader);
ctx.SetMainObject(shader);
}
}
bool IsJson(string content)
{
// Try parsing the content as JSON
try
{
// JsonUtility.FromJson will throw an exception if the content is not valid JSON
JsonUtility.FromJson<object>(content);
return true;
}
catch (System.Exception)
{
return false;
}
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b3d2a8b1e6bffe94ab9f6fdff27fcf4f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 271742
packageName: 'COZY: Stylized Weather 3'
packageVersion: 3.6.20
assetPath: Packages/com.distantlands.cozy.core/Runtime/Shaders/Compiler Scripts/CozyShaderImporter.cs
uploadId: 939148
@@ -0,0 +1,113 @@
// Distant Lands 2025
// COZY: Stylized Weather 3
// All code included in this file is protected under the Unity Asset Store Eula
// Code derived from https://github.com/slipster216/ShaderPackager with permission from Jason Booth
using System.Collections.Generic;
using UnityEngine;
#if UnityEditor
using UnityEditor;
#endif
namespace DistantLands.Cozy.ShaderUtility
{
public class CozyShaderPackage : ScriptableObject
{
public enum SRPTarget
{
BIRP,
URP,
HDRP
}
public enum UnityVersion
{
Min = 0,
Unity2021_2 = 20212,
Unity2021_3 = 20213,
Unity2022_1 = 20221,
Unity2022_2 = 20222,
Unity2022_3 = 20223,
Unity2023_2 = 20232,
Unity2023_3 = 20233,
Max = 30000
}
[System.Serializable]
public class Entry
{
public SRPTarget srpTarget = SRPTarget.BIRP;
public UnityVersion min = UnityVersion.Min;
public UnityVersion max = UnityVersion.Max;
public Shader shader;
[HideInInspector] public string shaderSource;
}
public List<Entry> entries = new List<Entry>();
public void PackageShaderVariants()
{
foreach (var e in entries)
{
if (!e.shader)
{
break;
}
if (e.shader != null)
{
#if UnityEditor
var path = AssetDatabase.GetAssetPath(e.shader);
e.shaderSource = System.IO.File.ReadAllText(path);
#endif
}
}
}
public static SRPTarget GetCurrentSRP()
{
#if COZY_URP
return SRPTarget.URP;
#elif COZY_HDRP
return SRPTarget.HDRP;
#else
return SRPTarget.BIRP;
#endif
}
public string GetShaderSource()
{
UnityVersion curVersion = UnityVersion.Min;
#if UNITY_2021_2_OR_NEWER
curVersion = UnityVersion.Unity2021_2;
#endif
#if UNITY_2021_3_OR_NEWER
curVersion = UnityVersion.Unity2021_3;
#endif
#if UNITY_2022_1_OR_NEWER
curVersion = UnityVersion.Unity2022_1;
#endif
#if UNITY_2022_2_OR_NEWER
curVersion = UnityVersion.Unity2022_2;
#endif
#if UNITY_2022_3_OR_NEWER
curVersion = UnityVersion.Unity2022_3;
#endif
SRPTarget target = GetCurrentSRP();
string source = null;
foreach (var entry in entries)
{
if (target != entry.srpTarget)
continue;
if (curVersion >= entry.min && curVersion <= entry.max)
{
if (source != null)
{
Debug.LogWarning("Found multiple possible entries for unity version of shader");
}
source = entry.shaderSource;
}
}
return source;
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 3428998b03ad59743a4c9a881527e20a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 271742
packageName: 'COZY: Stylized Weather 3'
packageVersion: 3.6.20
assetPath: Packages/com.distantlands.cozy.core/Runtime/Shaders/Compiler Scripts/CozyShaderPackage.cs
uploadId: 939148
@@ -0,0 +1,54 @@
// Distant Lands 2025
// COZY: Stylized Weather 3
// All code included in this file is protected under the Unity Asset Store Eula
#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEngine;
namespace DistantLands.Cozy.ShaderUtility
{
public class CozyShaderPostProcessor : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
RegisterShaders(importedAssets);
}
static void RegisterShaders(string[] paths)
{
foreach (var assetPath in paths)
{
if (!assetPath.EndsWith("cozyshader", StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
var mainObj = AssetDatabase.LoadMainAssetAtPath(assetPath) as Shader;
if (mainObj != null)
{
ShaderUtil.ClearShaderMessages(mainObj);
if (!ShaderUtil.ShaderHasError(mainObj))
{
ShaderUtil.RegisterShader(mainObj);
}
}
foreach (var obj in AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))
{
if (obj is Shader)
{
Shader s = obj as Shader;
ShaderUtil.ClearShaderMessages(s);
if (!ShaderUtil.ShaderHasError(s))
{
ShaderUtil.RegisterShader((Shader)obj);
}
}
}
}
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b37f3f41845f06b4ca068ed3303c259f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 271742
packageName: 'COZY: Stylized Weather 3'
packageVersion: 3.6.20
assetPath: Packages/com.distantlands.cozy.core/Runtime/Shaders/Compiler Scripts/CozyShaderPostProcessor.cs
uploadId: 939148
@@ -0,0 +1,19 @@
// Distant Lands 2025
// COZY: Stylized Weather 3
// All code included in this file is protected under the Unity Asset Store Eula
#if UNITY_EDITOR
using UnityEditor;
namespace DistantLands.Cozy.EditorScripts
{
public class EmptyShaderGUI : MaterialEditor
{
public override void OnInspectorGUI()
{
EditorGUILayout.HelpBox("Material generated at runtime by COZY: Stylized Weather 3. Edit material properties within COZY's editor", MessageType.Info);
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: a41234a844420fc4ebcf7895228986c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 271742
packageName: 'COZY: Stylized Weather 3'
packageVersion: 3.6.20
assetPath: Packages/com.distantlands.cozy.core/Runtime/Shaders/Compiler Scripts/EmptyShaderGUI.cs
uploadId: 939148