You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/MPUIKit/Editor/Scripts/Integrations/SoftMaskIntegration.cs

59 lines
2.1 KiB
C#

using System.IO;
using UnityEditor;
using UnityEngine;
namespace MPUIKIT.Editor
{
public class SoftMaskIntegration
{
public static void SetupMPUIKitForSoftMask(bool toggle, string softMaskCgincLocation)
{
SetupShaderForSoftMask(Shader.Find("MPUI/Procedural Image"), toggle, softMaskCgincLocation);
SetupShaderForSoftMask(Shader.Find("MPUI/Basic Procedural Image"), toggle, softMaskCgincLocation);
}
private static void SetupShaderForSoftMask(Shader shader, bool toggle, string softMaskLocation = null)
{
string shaderPath = AssetDatabase.GetAssetPath(shader);
string[] lines = File.ReadAllLines(shaderPath);
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].Contains("SOFTMASK_HANDLE_START"))
{
if (toggle)
{
if(lines[i].Contains("/*"))
lines[i] = lines[i].Replace("/*", string.Empty);
}
else
{
if(lines[i].Contains("/* //")) return;
lines[i] = lines[i].Replace("//", "/* //");
}
}else if (lines[i].Contains("SOFTMASK_HANDLE_END"))
{
if (toggle)
{
if(lines[i].Contains("*/"))
lines[i] = lines[i].Replace("*/", string.Empty);
}
else
{
if(lines[i].Contains("*/ //")) return;
lines[i] = lines[i].Replace("//", "*/ //");
}
}
else if (lines[i].Contains("SOFTMASK_INCLUDE_HANDLE"))
{
lines[i] = "\t\t\t#include \"" + softMaskLocation + "\" //SOFTMASK_INCLUDE_HANDLE";
}
}
File.WriteAllLines(shaderPath, lines);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
}