mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 08:11:47 -05:00
Automatically ship shaders on build
This commit is contained in:
parent
5cfa4de5c6
commit
4c4a365faf
2 changed files with 50 additions and 0 deletions
39
Assets/Editor/OpenTS2/BuildPreProcessor.cs
Normal file
39
Assets/Editor/OpenTS2/BuildPreProcessor.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class BuildPreProcessor : IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
var allshaders = Directory.GetFiles("Assets/Shaders", "*.shader", SearchOption.AllDirectories);
|
||||
var graphicsSettings = AssetDatabase.LoadAssetAtPath<GraphicsSettings>("ProjectSettings/GraphicsSettings.asset");
|
||||
var serializedObject = new SerializedObject(graphicsSettings);
|
||||
var alwaysIncludedShadersProp = serializedObject.FindProperty("m_AlwaysIncludedShaders");
|
||||
|
||||
foreach(var shaderPath in allshaders)
|
||||
{
|
||||
var shader = AssetDatabase.LoadAssetAtPath<Shader>(shaderPath);
|
||||
if (shader == null) continue;
|
||||
for(var i=0;i<alwaysIncludedShadersProp.arraySize;i++)
|
||||
{
|
||||
var elem = alwaysIncludedShadersProp.GetArrayElementAtIndex(i);
|
||||
if (elem.objectReferenceValue == shader)
|
||||
continue;
|
||||
}
|
||||
alwaysIncludedShadersProp.InsertArrayElementAtIndex(0);
|
||||
var arrayElem = alwaysIncludedShadersProp.GetArrayElementAtIndex(0);
|
||||
arrayElem.objectReferenceValue = shader;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
11
Assets/Editor/OpenTS2/BuildPreProcessor.cs.meta
generated
Normal file
11
Assets/Editor/OpenTS2/BuildPreProcessor.cs.meta
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4caf04b0595c5c4f8e91b22f501b249
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue