Skip to content

Commit

Permalink
CYF v0.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
RhenaudTheLukark committed Jul 5, 2020
1 parent e4ba280 commit 7e1bc67
Show file tree
Hide file tree
Showing 284 changed files with 25,051 additions and 12,318 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sysinfo.txt
*.apk
*.unitypackage
/bin
/Assets/Editor/Output

# External mods
/Assets/Mods/*
Expand Down
5 changes: 2 additions & 3 deletions Assets/Default/Audio/mus_battle1 fj7x.ogg.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Assets/Shader.meta → Assets/Default/Shaders.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Default/Shaders/cyfshaders.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Default/Shaders/cyfshaders/linux
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/Default/Shaders/cyfshaders/linux.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Default/Shaders/cyfshaders/mac
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/Default/Shaders/cyfshaders/mac.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Default/Shaders/cyfshaders/windows
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/Default/Shaders/cyfshaders/windows.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 153 additions & 0 deletions Assets/Editor/BundleShaders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/// Some code from https://bitbucket.org/Unity-Technologies/assetbundledemo/src/default/
#pragma warning disable 0618
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Collections.Generic;

public static class BundleShaders {
private static string assetBundleDirectory = "Assets/Editor/Output";
private static string shaderDirectory = "Assets/Editor/Shaders";

[MenuItem("Create Your Frisk/Build Shader AssetBundles...")]
static void OneBundleOption() {
if (EditorApplication.isPlaying) {
Debug.LogError("You may only build AssetBundles while not in play mode.");
return;
}

BundleShaderDialog window = (BundleShaderDialog)EditorWindow.GetWindow(typeof(BundleShaderDialog));
window.Show();
}

public static void AllBundlesOption() {
if (EditorApplication.isPlaying) {
Debug.LogError("You may only build AssetBundles while not in play mode.");
return;
}

// Gets all AssetBundles from files within the shader directory
Dictionary<string, List<Shader>> bundles = RetrieveAllBundles();
if (bundles == null)
return;

// Build AssetBundles
BuildBundles(bundles);

EditorUtility.DisplayDialog("Bundling Shaders", "All CYF Shader Bundles have been created!\n\nYou can find them in:\n" + assetBundleDirectory, "OK");
}

public static void OneBundle(string bundleName) {
if (bundleName == "") {
Debug.LogError("Please enter the name of an AssetBundle assigned in the Unity Editor.");
return;
}

// Gets all AssetBundles from files within the shader directory
Dictionary<string, List<Shader>> bundles = RetrieveAllBundles();
if (bundles == null)
return;

// Check if the given bundle name exists within this dictionary
if (!bundles.ContainsKey(bundleName)) {
Debug.LogError("The AssetBundle \"" + bundleName + "\" does not exist on any files in \"" + shaderDirectory + "\".");
return;
}

// Build all files with this bundle name into one AssetBundle
Dictionary<string, List<Shader>> bundlesToBuild = new Dictionary<string, List<Shader>>();
List<Shader> shaders = new List<Shader>();
foreach (Shader shader in bundles[bundleName])
shaders.Add(shader);
bundlesToBuild[bundleName] = shaders;

BuildBundles(bundlesToBuild);

EditorUtility.DisplayDialog("Bundling Shaders", "The CYF Shader Bundle \"" + bundleName + "\" has been created!\n\nYou can find it in:\n" + assetBundleDirectory + "/" + bundleName, "OK");
}

private static Dictionary<string, List<Shader>> RetrieveAllBundles() {
if (!Directory.Exists(shaderDirectory)) {
Debug.LogError("The shaders directory (\"" + shaderDirectory + "\") does not exist. Thus, there are no bundles to build. Aborting.");
return null;
}

// Get all assets
string[] assets = Directory.GetFiles(shaderDirectory, "*.shader");
Dictionary<string, List<Shader>> bundles = new Dictionary<string, List<Shader>>();

// Get asset bundle names from each file
foreach (string file in assets) {
ShaderImporter importer = (ShaderImporter)AssetImporter.GetAtPath(file);

if (importer == null) {
Debug.LogWarning("Could not import asset \"" + file + "\". Skipping.");
continue;
}

// Get asset bundle name
string bundleName = importer.assetBundleName;
if (bundleName != "") {
// Create a folder for each bundle if applicable
if (!Directory.Exists(assetBundleDirectory + "/" + bundleName))
Directory.CreateDirectory(assetBundleDirectory + "/" + bundleName);

// Create a bundle if applicable
if (!bundles.ContainsKey(bundleName)) {
List<Shader> list = new List<Shader>();
bundles[bundleName] = list;
}
bundles[bundleName].Add(importer.GetShader());
}
}

if (bundles.Count == 0) {
Debug.LogError("There are no AssetBundles to build. Aborting.");
return null;
}

return bundles;
}

static void BuildBundles(Dictionary<string, List<Shader>> bundles) {
if (!Directory.Exists(assetBundleDirectory))
Directory.CreateDirectory(assetBundleDirectory);

// Build AssetBundles
foreach (KeyValuePair<string, List<Shader>> pair in bundles) {
// Windows
if (!BuildPipeline.BuildAssetBundle(null, pair.Value.ToArray(), assetBundleDirectory + "/" + pair.Key + "/windows", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows))
Debug.LogError("An error occured while building the AssetBundle \"" + pair.Key + "\".");

// Linux
if (!BuildPipeline.BuildAssetBundle(null, pair.Value.ToArray(), assetBundleDirectory + "/" + pair.Key + "/linux", BuildAssetBundleOptions.None, BuildTarget.StandaloneLinuxUniversal))
Debug.LogError("An error occured while building the AssetBundle \"" + pair.Key + "\".");

// Mac
if (!BuildPipeline.BuildAssetBundle(null, pair.Value.ToArray(), assetBundleDirectory + "/" + pair.Key + "/mac", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX))
Debug.LogError("An error occured while building the AssetBundle \"" + pair.Key + "\".");

}
}
}

public class BundleShaderDialog : EditorWindow {
public string bundleName;

void OnEnable() {
this.titleContent = new GUIContent("CYF Shaders", "Utilities used to build CYF Shader AssetBundles for use with Create Your Frisk mods.");
}

void OnGUI() {
bundleName = EditorGUILayout.TextField(new GUIContent("AssetBundle to build", "The name of a CYF Shader AssetBundle within the shaders directory to build."), bundleName);

if (GUILayout.Button(new GUIContent("Build one AssetBundle", "Builds a CYF Shader AssetBundle with the name given in the text box above."))) {
BundleShaders.OneBundle(bundleName);
GUIUtility.ExitGUI();
} else if (GUILayout.Button(new GUIContent("Build all AssetBundles", "Builds all CYF Shader AssetBundles set up in the shaders directory."))) {
BundleShaders.AllBundlesOption();
GUIUtility.ExitGUI();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Editor/Shaders.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions Assets/Editor/Shaders/CYFShaderTemplate.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "CYF/Template"
{
Properties
{
_MainTex("Sprite Texture", 2D) = "white" {}

_StencilComp("Stencil Comparison", Float) = 8
_Stencil("Stencil ID", Float) = 0
_StencilOp("Stencil Operation", Float) = 0
_StencilWriteMask("Stencil Write Mask", Float) = 255
_StencilReadMask("Stencil Read Mask", Float) = 255

_ColorMask("Color Mask", Float) = 15

[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
}

SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}

Stencil
{
Ref[_Stencil]
Comp[_StencilComp]
Pass[_StencilOp]
ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask]
}

Cull Off
Lighting Off
ZWrite Off
ZTest[unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask[_ColorMask]

Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0

#include "UnityCG.cginc"
#include "UnityUI.cginc"

#pragma multi_compile __ UNITY_UI_CLIP_RECT
#pragma multi_compile __ UNITY_UI_ALPHACLIP

struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 uv : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};

sampler2D _MainTex;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
float4 _MainTex_ST;

v2f vert(appdata_t v)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = v.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);

OUT.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

OUT.color = v.color;
return OUT;
}

fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.uv) + _TextureSampleAdd) * IN.color;

#ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#endif

#ifdef UNITY_UI_ALPHACLIP
clip(color.a - 0.001);
#endif

return color;
}
ENDCG
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7e1bc67

Please sign in to comment.