-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
Cell Spawning Feature Merge
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
using System.IO; | ||
using System; | ||
|
||
|
||
public class CelCustomEditor : MaterialEditor | ||
{ | ||
float spacing = 20; | ||
string saveName = "Preset Name"; | ||
string celOutlinePath = "Custom/CelOutline"; | ||
string celNoOutlinePath = "Custom/Cel"; | ||
|
||
void showProperty(string propertyName) | ||
{ | ||
MaterialProperty property = GetMaterialProperty(targets, propertyName); | ||
ShaderProperty(property, property.displayName); | ||
} | ||
|
||
void showPropertyAsInt(string propertyName) | ||
{ | ||
MaterialProperty property = GetMaterialProperty(targets, propertyName); | ||
ShaderProperty(property, property.displayName); | ||
property.floatValue = Mathf.Round(property.floatValue); | ||
} | ||
|
||
void showPropertyGreaterZero(string propertyName) | ||
{ | ||
MaterialProperty property = GetMaterialProperty(targets, propertyName); | ||
ShaderProperty(property, property.displayName); | ||
if (property.floatValue < 0) | ||
{ | ||
property.floatValue = 0; | ||
} | ||
} | ||
|
||
void drawPresets() | ||
{ | ||
|
||
//GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Load Existing Preset", EditorStyles.boldLabel); | ||
foreach (var path in Directory.GetFiles(FlexibleCelShader.PresetHelper.PresetDirectoryPath)) | ||
{ | ||
string fileName = Path.GetFileName(path); | ||
if (Path.GetExtension(fileName) == ".json") | ||
{ | ||
string presetName = Path.GetFileNameWithoutExtension(fileName); | ||
EditorGUILayout.BeginHorizontal(); | ||
if (GUILayout.Button(presetName)) | ||
{ | ||
MaterialProperty[] properties = GetMaterialProperties(targets); | ||
properties = FlexibleCelShader.PresetHelper.LoadPreset(presetName, properties); | ||
} | ||
Color c = GUI.backgroundColor; | ||
GUIStyle style = new GUIStyle(EditorStyles.miniButton); | ||
style.normal.textColor = Color.red; | ||
if (GUILayout.Button("Delete", style, GUILayout.Width(60))) | ||
{ | ||
if (EditorUtility.DisplayDialog("Delete " + presetName, "Are you sure you want to delete " + presetName + "? This cannot be undone.", "Delete", "Cancel")) | ||
{ | ||
FlexibleCelShader.PresetHelper.DeletePreset(presetName); | ||
} | ||
} | ||
EditorGUILayout.EndHorizontal(); | ||
} | ||
} | ||
|
||
GUILayout.Space(8); | ||
EditorGUILayout.LabelField("Save Current As New Preset", EditorStyles.boldLabel); | ||
EditorGUILayout.BeginHorizontal(); | ||
saveName = GUILayout.TextField(saveName, GUILayout.ExpandWidth(true)); | ||
if (GUILayout.Button("Save", EditorStyles.miniButton, GUILayout.Width(60))) | ||
{ | ||
FlexibleCelShader.PresetHelper.SavePreset(saveName, GetMaterialProperties(targets)); | ||
saveName = "Preset Name"; | ||
} | ||
EditorGUILayout.EndHorizontal(); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
|
||
drawPresets(); | ||
|
||
GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Base Color and Textures", EditorStyles.boldLabel); | ||
showProperty("_MainTex"); | ||
showProperty("_NormalTex"); | ||
showProperty("_EmmisTex"); | ||
showProperty("_Color"); | ||
|
||
GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Lighting Ramp", EditorStyles.boldLabel); | ||
showPropertyAsInt("_RampLevels"); | ||
showProperty("_LightScalar"); | ||
|
||
GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("High Light", EditorStyles.boldLabel); | ||
showProperty("_HighColor"); | ||
showProperty("_HighIntensity"); | ||
|
||
GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Low Light", EditorStyles.boldLabel); | ||
showProperty("_LowColor"); | ||
showProperty("_LowIntensity"); | ||
|
||
GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Outline", EditorStyles.boldLabel); | ||
showProperty("_OutlineColor"); | ||
showPropertyGreaterZero("_OutlineSize"); | ||
|
||
GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Hard Edge Light", EditorStyles.boldLabel); | ||
showProperty("_RimColor"); | ||
showProperty("_RimAlpha"); | ||
showProperty("_RimPower"); | ||
showProperty("_RimDropOff"); | ||
|
||
GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Soft Edge Light", EditorStyles.boldLabel); | ||
showProperty("_FresnelColor"); | ||
showProperty("_FresnelBrightness"); | ||
showProperty("_FresnelPower"); | ||
showProperty("_FresnelShadowDropoff"); | ||
|
||
/*GUILayout.Space(spacing); | ||
EditorGUILayout.LabelField("Vertical Gradient", EditorStyles.boldLabel); | ||
showProperty("_GradIntensity"); | ||
showProperty("_GradYCap");*/ | ||
|
||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace FlexibleCelShader | ||
{ | ||
|
||
[System.Serializable] | ||
public class PresetDataConainer : System.Object | ||
{ | ||
public float _ColorR; | ||
public float _ColorG; | ||
public float _ColorB; | ||
public float _RampLevels; | ||
public float _LightScalar; | ||
public float _HighColorR; | ||
public float _HighColorG; | ||
public float _HighColorB; | ||
public float _HighIntensity; | ||
public float _LowColorR; | ||
public float _LowColorG; | ||
public float _LowColorB; | ||
public float _LowIntensity; | ||
public float _OutlineColorR; | ||
public float _OutlineColorG; | ||
public float _OutlineColorB; | ||
public float _OutlineSize; | ||
public float _RimColorR; | ||
public float _RimColorG; | ||
public float _RimColorB; | ||
public float _RimAlpha; | ||
public float _RimPower; | ||
public float _RimDropOff; | ||
public float _FresnelColorR; | ||
public float _FresnelColorG; | ||
public float _FresnelColorB; | ||
public float _FresnelBrightness; | ||
public float _FresnelPower; | ||
public float _FresnelShadowDropoff; | ||
public float _GradYCap; | ||
public float _GradIntensity; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace FlexibleCelShader | ||
{ | ||
|
||
public static class PresetHelper | ||
{ | ||
|
||
public readonly static string PresetDirectoryPath = Application.dataPath + "/FlexibleCelShader/Presets/"; | ||
|
||
public static void SavePreset(string presetName, MaterialProperty[] properties) | ||
{ | ||
PresetDataConainer container = new PresetDataConainer(); | ||
foreach (var property in properties) | ||
{ | ||
switch (property.name) | ||
{ | ||
case ("_Color"): container._ColorR = property.colorValue.r; container._ColorG = property.colorValue.g; container._ColorB = property.colorValue.b; break; | ||
case ("_RampLevels"): container._RampLevels = property.floatValue; break; | ||
case ("_LightScalar"): container._LightScalar = property.floatValue; break; | ||
case ("_HighColor"): container._HighColorR = property.colorValue.r; container._HighColorG = property.colorValue.g; container._HighColorB = property.colorValue.b; break; | ||
case ("_HighIntensity"): container._HighIntensity = property.floatValue; break; | ||
case ("_LowColor"): container._LowColorR = property.colorValue.r; container._LowColorG = property.colorValue.g; container._LowColorB = property.colorValue.b; break; | ||
case ("_LowIntensity"): container._LowIntensity = property.floatValue; break; | ||
case ("_OutlineColor"): container._OutlineColorR = property.colorValue.r; container._OutlineColorG = property.colorValue.g; container._OutlineColorB = property.colorValue.b; break; | ||
case ("_OutlineSize"): container._OutlineSize = property.floatValue; break; | ||
case ("_RimColor"): container._RimColorR = property.colorValue.r; container._RimColorG = property.colorValue.g; container._RimColorB = property.colorValue.b; break; | ||
case ("_RimAlpha"): container._RimAlpha = property.floatValue; break; | ||
case ("_RimPower"): container._RimPower = property.floatValue; break; | ||
case ("_RimDropOff"): container._RimDropOff = property.floatValue; break; | ||
case ("_FresnelColor"): container._FresnelColorR = property.colorValue.r; container._FresnelColorG = property.colorValue.g; container._FresnelColorB = property.colorValue.b; break; | ||
case ("_FresnelBrightness"): container._FresnelBrightness = property.floatValue; break; | ||
case ("_FresnelPower"): container._FresnelPower = property.floatValue; break; | ||
case ("_FresnelShadowDropoff"): container._FresnelShadowDropoff = property.floatValue; break; | ||
case ("_GradYCap"): container._GradYCap = property.floatValue; break; | ||
case ("_GradIntensity"): container._GradIntensity = property.floatValue; break; | ||
} | ||
} | ||
|
||
// Serialize container into Json | ||
string json = JsonUtility.ToJson(container, true); | ||
|
||
// Create the preset directory if it doesn't exist | ||
if (!Directory.Exists(PresetDirectoryPath)) | ||
{ | ||
Directory.CreateDirectory(PresetDirectoryPath); | ||
} | ||
|
||
// Write to file | ||
File.WriteAllText(PresetDirectoryPath + presetName + ".json", json); | ||
} | ||
|
||
public static MaterialProperty[] LoadPreset(string presetName, MaterialProperty[] properties) | ||
{ | ||
// Check if the preset directory exists | ||
if (!Directory.Exists(PresetDirectoryPath)) | ||
{ | ||
throw new UnityException("Unable to find presets folder: " + PresetDirectoryPath); | ||
} | ||
|
||
// Try reading the file | ||
string json; | ||
try | ||
{ | ||
json = File.ReadAllText(PresetDirectoryPath + presetName + ".json"); | ||
} | ||
catch (FileNotFoundException e) | ||
{ | ||
throw new UnityException("Unable to find preset file: " + e.FileName); | ||
} | ||
|
||
// Deserialize Json into container | ||
PresetDataConainer container = JsonUtility.FromJson<PresetDataConainer>(json); | ||
|
||
// Copy values from container into material properties | ||
foreach (var property in properties) | ||
{ | ||
switch (property.name) | ||
{ | ||
case ("_Color"): property.colorValue = new Color(container._ColorR, container._ColorG, container._ColorB); break; | ||
case ("_RampLevels"): property.floatValue = container._RampLevels; break; | ||
case ("_LightScalar"): property.floatValue = container._LightScalar; break; | ||
case ("_HighColor"): property.colorValue = new Color(container._HighColorR, container._HighColorG, container._HighColorB); break; | ||
case ("_HighIntensity"): property.floatValue = container._HighIntensity; break; | ||
case ("_LowColor"): property.colorValue = new Color(container._LowColorR, container._LowColorG, container._LowColorB); break; | ||
case ("_LowIntensity"): property.floatValue = container._LowIntensity; break; | ||
case ("_OutlineColor"): property.colorValue = new Color(container._OutlineColorR, container._OutlineColorG, container._OutlineColorB); break; | ||
case ("_OutlineSize"): property.floatValue = container._OutlineSize; break; | ||
case ("_RimColor"): property.colorValue = new Color(container._RimColorR, container._RimColorG, container._RimColorB); break; | ||
case ("_RimAlpha"): property.floatValue = container._RimAlpha; break; | ||
case ("_RimPower"): property.floatValue = container._RimPower; break; | ||
case ("_RimDropOff"): property.floatValue = container._RimDropOff; break; | ||
case ("_FresnelColor"): property.colorValue = new Color(container._FresnelColorR, container._FresnelColorG, container._FresnelColorB); break; | ||
case ("_FresnelBrightness"): property.floatValue = container._FresnelBrightness; break; | ||
case ("_FresnelPower"): property.floatValue = container._FresnelPower; break; | ||
case ("_FresnelShadowDropoff"): property.floatValue = container._FresnelShadowDropoff; break; | ||
case ("_GradYCap"): property.floatValue = container._GradYCap; break; | ||
case ("_GradIntensity"): property.floatValue = container._GradIntensity; break; | ||
} | ||
} | ||
return properties; | ||
} | ||
|
||
public static void DeletePreset(string presetName) | ||
{ | ||
if (File.Exists(PresetDirectoryPath + presetName + ".json")) | ||
{ | ||
File.Delete(PresetDirectoryPath + presetName + ".json"); | ||
} | ||
if (File.Exists(PresetDirectoryPath + presetName + ".json.meta")) | ||
{ | ||
File.Delete(PresetDirectoryPath + presetName + ".json.meta"); | ||
} | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.