[Add] All in one shader
This commit is contained in:
+366
@@ -0,0 +1,366 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CustomEditor(typeof(AllIn13DShaderComponent))]
|
||||
[CanEditMultipleObjects]
|
||||
public class AllIn13DShaderComponentCustomEditor : Editor
|
||||
{
|
||||
private PropertiesConfigCollection propertiesConfigCollection;
|
||||
private GlobalConfiguration globalConfiguration;
|
||||
private Texture imageInspector;
|
||||
|
||||
private void RefreshReferences()
|
||||
{
|
||||
propertiesConfigCollection = EditorUtils.FindAsset<ScriptableObject>("PropertiesConfigCollection") as PropertiesConfigCollection;
|
||||
if(propertiesConfigCollection == null)
|
||||
{
|
||||
propertiesConfigCollection = PropertiesConfigCreator.CreateConfig();
|
||||
}
|
||||
|
||||
globalConfiguration = EditorUtils.FindAssetByName<GlobalConfiguration>("GlobalConfiguration");
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
RefreshReferences();
|
||||
|
||||
bool isValidComponents = CheckSelectedComponents();
|
||||
if (!isValidComponents)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Missing Renderer", "Some of the selected game objects have no Renderer component. AllIn13DShaderComponent will be removed", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
CheckMaterialReference();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
bool saveAssets = false;
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
DrawHeaderImage();
|
||||
|
||||
EditorGUI.BeginDisabledGroup(Application.isPlaying);
|
||||
if(GUILayout.Button("Deactivate All Effects"))
|
||||
{
|
||||
ExecuteActionAfterCheck(DeactivateAllEffects);
|
||||
saveAssets = true;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("New Clean Material"))
|
||||
{
|
||||
ExecuteActionAfterCheck(NewCleanMaterial);
|
||||
}
|
||||
|
||||
if(GUILayout.Button("Create New Material With Same Properties (SEE DOC)"))
|
||||
{
|
||||
ExecuteActionAfterCheck(MakeCopyMaterial);
|
||||
}
|
||||
|
||||
if(GUILayout.Button("Save Material To Folder (SEE DOC)"))
|
||||
{
|
||||
ExecuteActionAfterCheck(SaveMaterialToFolder);
|
||||
}
|
||||
|
||||
if(GUILayout.Button("Apply Material To All Children"))
|
||||
{
|
||||
ExecuteActionAfterCheck(ApplyMaterialToAllChildren);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Render Material To Image"))
|
||||
{
|
||||
ExecuteActionAfterCheck(RenderMaterialToImage);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
|
||||
if (saveAssets)
|
||||
{
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorUtils.DrawThinLine();
|
||||
|
||||
if (GUILayout.Button("Remove Component"))
|
||||
{
|
||||
RemoveComponent();
|
||||
}
|
||||
|
||||
if(GUILayout.Button("Remove Component and Material"))
|
||||
{
|
||||
RemoveComponentAndMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHeaderImage()
|
||||
{
|
||||
if(imageInspector == null) imageInspector = AllIn13DShaderConfig.GetInspectorImage();
|
||||
Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(32));
|
||||
GUI.DrawTexture(rect, imageInspector, ScaleMode.ScaleToFit, true);
|
||||
}
|
||||
|
||||
private void CheckMaterialReference()
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
|
||||
Material currMaterial = allIn13DShaderComponent.currMaterial;
|
||||
if (currMaterial == null || !propertiesConfigCollection.IsAllIn3DShaderMaterial(currMaterial))
|
||||
{
|
||||
Shader shader = GlobalConfiguration.instance.shStandard;
|
||||
//Shader shader = propertiesConfigCollection.shaderPropertiesConfig[0].shader;
|
||||
|
||||
Material oldMaterial = allIn13DShaderComponent.currMaterial;
|
||||
allIn13DShaderComponent.NewCleanMaterial(shader, globalConfiguration.defaultPreset);
|
||||
|
||||
MaterialConverterTool.ApplyConversion(oldMaterial, allIn13DShaderComponent.currMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
EditorUtils.SetDirtyCurrentScene();
|
||||
}
|
||||
|
||||
private void DeactivateAllEffects()
|
||||
{
|
||||
bool successOperation = true;
|
||||
bool selectedComponentsAreValid = CheckSelectedComponents();
|
||||
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
successOperation = successOperation && allIn13DShaderComponent.CheckValidComponent();
|
||||
|
||||
Material mat = allIn13DShaderComponent.currMaterial;
|
||||
PropertiesConfig propertiesConfig = propertiesConfigCollection.FindPropertiesConfigByShader(mat.shader);
|
||||
|
||||
List<AllIn13DEffectConfig> effects = propertiesConfig.GetAllEffects();
|
||||
|
||||
for (int j = 0; j < effects.Count; j++)
|
||||
{
|
||||
mat.SetFloat(effects[j].keywordPropertyName, 0f);
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(allIn13DShaderComponent);
|
||||
EditorUtility.SetDirty(mat);
|
||||
}
|
||||
}
|
||||
|
||||
private void NewCleanMaterial()
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
|
||||
Shader shader = GlobalConfiguration.instance.shStandard;
|
||||
//Shader shader = propertiesConfigCollection.shaderPropertiesConfig[0].shader;
|
||||
allIn13DShaderComponent.NewCleanMaterial(shader, globalConfiguration.defaultPreset);
|
||||
}
|
||||
}
|
||||
|
||||
public void MakeCopyMaterial()
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
|
||||
Renderer currRenderer = allIn13DShaderComponent.currRenderer;
|
||||
Material currMat = currRenderer.sharedMaterial;
|
||||
|
||||
string materialName = "MAT_" + allIn13DShaderComponent.gameObject.name;
|
||||
Material copy = new Material(currMat);
|
||||
copy.name = materialName;
|
||||
|
||||
currRenderer.sharedMaterial = copy;
|
||||
|
||||
EditorUtility.SetDirty(allIn13DShaderComponent);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveMaterialToFolder()
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
SaveMaterialToFolder(allIn13DShaderComponent);
|
||||
}
|
||||
|
||||
EditorUtils.SetDirtyCurrentScene();
|
||||
}
|
||||
|
||||
private bool CheckSelectedComponents()
|
||||
{
|
||||
bool res = true;
|
||||
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
|
||||
bool isValid = allIn13DShaderComponent.CheckValidComponent();
|
||||
if (!isValid)
|
||||
{
|
||||
DestroyImmediate(allIn13DShaderComponent);
|
||||
}
|
||||
|
||||
res = res && isValid;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private void ExecuteActionAfterCheck(Action action)
|
||||
{
|
||||
bool selectedComponentsAreValid = CheckSelectedComponents();
|
||||
|
||||
if (selectedComponentsAreValid)
|
||||
{
|
||||
action();
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneView.lastActiveSceneView.ShowNotification(new GUIContent("Some of the selected components are not valid"));
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveMaterialToFolder(AllIn13DShaderComponent comp)
|
||||
{
|
||||
Material matToSave = comp.currMaterial;
|
||||
bool isAlreadySaved = AssetDatabase.Contains(matToSave);
|
||||
if (isAlreadySaved)
|
||||
{
|
||||
matToSave = comp.DuplicateCurrentMaterial();
|
||||
}
|
||||
|
||||
string folderPath = GlobalConfiguration.instance.MaterialSavePath;
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
bool ok = EditorUtility.DisplayDialog("The desired save folder doesn't exist",
|
||||
"Go to Window -> AllIn13DShaderWindow and set a valid folder", "Set default values and save material", "Cancel");
|
||||
|
||||
if (ok)
|
||||
{
|
||||
Directory.CreateDirectory(folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (Directory.Exists(folderPath))
|
||||
{
|
||||
string fullPath = Path.Combine(folderPath, matToSave.name + ".mat");
|
||||
fullPath = AssetDatabase.GenerateUniqueAssetPath(fullPath);
|
||||
|
||||
AssetDatabase.CreateAsset(matToSave, fullPath);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
EditorGUIUtility.PingObject(matToSave);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyMaterialToAllChildren()
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
allIn13DShaderComponent.ApplyMaterialToChildren();
|
||||
|
||||
EditorUtility.SetDirty(allIn13DShaderComponent);
|
||||
}
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
|
||||
private void RenderMaterialToImage()
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
RenderToImage(allIn13DShaderComponent);
|
||||
|
||||
EditorUtility.SetDirty(allIn13DShaderComponent);
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderToImage(AllIn13DShaderComponent allIn13DShaderComponent)
|
||||
{
|
||||
Texture tex = allIn13DShaderComponent.currMaterial.GetTexture("_MainTex");
|
||||
if (tex != null)
|
||||
{
|
||||
string folderPath = GlobalConfiguration.instance.RenderImageSavePath;
|
||||
string fileName = allIn13DShaderComponent.gameObject.name + ".png";
|
||||
RenderMaterialToImageTool.RenderAndSaveTexture(allIn13DShaderComponent.currMaterial, tex, 4.0f, folderPath, fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("No valid target texture found",
|
||||
"All In 1 3DShader component couldn't find a valid Main Texture in this GameObject (" +
|
||||
allIn13DShaderComponent.gameObject.name +
|
||||
"). This means that the material you are using has no Main Texture or that the texture couldn't be reached through the Renderer component you are using." +
|
||||
" Please make sure to have a valid Main Texture in the Material", "Ok");
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveComponent()
|
||||
{
|
||||
for (int i = targets.Length - 1; i >= 0; i--)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
DestroyImmediate(allIn13DShaderComponent);
|
||||
}
|
||||
|
||||
//EditorUtils.SetDirtyCurrentScene();
|
||||
|
||||
SetSceneDirty();
|
||||
EditorUtils.ShowNotification("AllIn3DShader: Component Removed");
|
||||
}
|
||||
|
||||
private void RemoveComponentAndMaterial()
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
allIn13DShaderComponent.CleanMaterial();
|
||||
}
|
||||
|
||||
for (int i = targets.Length - 1; i >= 0; i--)
|
||||
{
|
||||
AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i];
|
||||
DestroyImmediate(allIn13DShaderComponent);
|
||||
}
|
||||
|
||||
SetSceneDirty();
|
||||
}
|
||||
|
||||
public void SetSceneDirty()
|
||||
{
|
||||
if (!Application.isPlaying) EditorSceneManager.MarkAllScenesDirty();
|
||||
|
||||
//If you get an error here please delete the code block below
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||
#else
|
||||
var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
||||
#endif
|
||||
if (prefabStage != null)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(prefabStage.scene);
|
||||
}
|
||||
|
||||
//Until here
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 445b6f2ff4b09ff4993b2516859d0467
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs
|
||||
uploadId: 865720
|
||||
+416
@@ -0,0 +1,416 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
public class AllIn13DShaderMaterialInspector : ShaderGUI
|
||||
{
|
||||
private PropertiesConfigCollection propertiesConfigCollection;
|
||||
|
||||
private PropertiesConfig currentPropertiesConfig;
|
||||
|
||||
private AllIn13DShaderInspectorReferences inspectorReferences;
|
||||
private AbstractEffectDrawer[] drawers;
|
||||
private GlobalPropertiesDrawer globalPropertiesDrawer;
|
||||
private AdvancedPropertiesDrawer advancedPropertiesDrawer;
|
||||
|
||||
private MaterialPresetCollection blendingModeCollection;
|
||||
|
||||
private MaterialProperty matPropertyRenderPreset;
|
||||
private MaterialProperty matPropertyBlendSrc;
|
||||
private MaterialProperty matPropertyBlendDst;
|
||||
private MaterialProperty matPropertyZWrite;
|
||||
|
||||
private int lastRenderQueue;
|
||||
|
||||
private static CommonStyles commonStyles;
|
||||
|
||||
private void RefreshReferences(MaterialEditor materialEditor, MaterialProperty[] properties)
|
||||
{
|
||||
if (inspectorReferences == null)
|
||||
{
|
||||
inspectorReferences = new AllIn13DShaderInspectorReferences();
|
||||
inspectorReferences.Setup(materialEditor, properties);
|
||||
|
||||
if (lastRenderQueue > 0)
|
||||
{
|
||||
for(int i = 0; i < inspectorReferences.targetMatInfos.Length; i++)
|
||||
{
|
||||
inspectorReferences.targetMatInfos[i].mat.renderQueue = lastRenderQueue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (propertiesConfigCollection == null)
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets("PropertiesConfigCollection t:PropertiesConfigCollection");
|
||||
if(guids.Length == 0)
|
||||
{
|
||||
Debug.LogWarning("PropertiesConfigCollection not found in the project. Configuring...");
|
||||
this.propertiesConfigCollection = PropertiesConfigCreator.CreateConfig();
|
||||
Debug.LogWarning("AllIn13DShader configured");
|
||||
}
|
||||
else
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
propertiesConfigCollection = AssetDatabase.LoadAssetAtPath<PropertiesConfigCollection>(path);
|
||||
}
|
||||
|
||||
RefreshPropertiesConfig();
|
||||
}
|
||||
|
||||
if (blendingModeCollection == null)
|
||||
{
|
||||
blendingModeCollection = (MaterialPresetCollection)EditorUtils.FindAsset<ScriptableObject>("BlendingModeCollection");
|
||||
}
|
||||
|
||||
CreateDrawers();
|
||||
|
||||
matPropertyRenderPreset = inspectorReferences.matProperties[currentPropertiesConfig.renderPreset];
|
||||
matPropertyBlendSrc = inspectorReferences.matProperties[currentPropertiesConfig.blendSrcIdx];
|
||||
matPropertyBlendDst = inspectorReferences.matProperties[currentPropertiesConfig.blendDstIdx];
|
||||
matPropertyZWrite = inspectorReferences.matProperties[currentPropertiesConfig.zWriteIndex];
|
||||
|
||||
//We ensure that data is refreshed. Sometimes objects are not null but we need to refresh the references
|
||||
inspectorReferences.Setup(materialEditor, properties);
|
||||
|
||||
if(commonStyles == null)
|
||||
{
|
||||
commonStyles = new CommonStyles();
|
||||
}
|
||||
|
||||
RefreshDrawers();
|
||||
}
|
||||
|
||||
private void ResetReferences()
|
||||
{
|
||||
this.propertiesConfigCollection = null;
|
||||
this.currentPropertiesConfig = null;
|
||||
|
||||
inspectorReferences = null;
|
||||
drawers = null;
|
||||
|
||||
globalPropertiesDrawer = null;
|
||||
advancedPropertiesDrawer = null;
|
||||
}
|
||||
|
||||
private void CreateDrawers()
|
||||
{
|
||||
if (propertiesConfigCollection == null ||
|
||||
currentPropertiesConfig == null ||
|
||||
inspectorReferences == null ||
|
||||
drawers == null ||
|
||||
globalPropertiesDrawer == null ||
|
||||
advancedPropertiesDrawer == null)
|
||||
{
|
||||
drawers = new AbstractEffectDrawer[0];
|
||||
|
||||
GeneralEffectDrawer generalEffectDrawer = new GeneralEffectDrawer(inspectorReferences, currentPropertiesConfig);
|
||||
|
||||
EffectProperty mainNormalMapProperty = currentPropertiesConfig.FindEffectProperty("NORMAL_MAP", "_NormalMap");
|
||||
|
||||
TriplanarEffectDrawer triplanarEffectDrawer = new TriplanarEffectDrawer(mainNormalMapProperty, inspectorReferences, currentPropertiesConfig);
|
||||
ColorRampEffectDrawer colorRampEffectDrawer = new ColorRampEffectDrawer(inspectorReferences, currentPropertiesConfig);
|
||||
OutlineEffectDrawer outlineEffectDrawer = new OutlineEffectDrawer(inspectorReferences, currentPropertiesConfig);
|
||||
TextureBlendingEffectDrawer vertexColorEffectDrawer = new TextureBlendingEffectDrawer(mainNormalMapProperty, inspectorReferences, currentPropertiesConfig);
|
||||
NormalMapEffectDrawer normalMapEffectDrawer = new NormalMapEffectDrawer(inspectorReferences, currentPropertiesConfig);
|
||||
|
||||
drawers = new AbstractEffectDrawer[]
|
||||
{
|
||||
generalEffectDrawer,
|
||||
triplanarEffectDrawer,
|
||||
colorRampEffectDrawer,
|
||||
outlineEffectDrawer,
|
||||
vertexColorEffectDrawer,
|
||||
normalMapEffectDrawer
|
||||
};
|
||||
|
||||
advancedPropertiesDrawer = new AdvancedPropertiesDrawer(currentPropertiesConfig.advancedProperties, currentPropertiesConfig.blendSrcIdx, currentPropertiesConfig.blendDstIdx, inspectorReferences);
|
||||
}
|
||||
|
||||
if (globalPropertiesDrawer == null)
|
||||
{
|
||||
globalPropertiesDrawer = new GlobalPropertiesDrawer();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshDrawers()
|
||||
{
|
||||
for(int i = 0; i < drawers.Length; i++)
|
||||
{
|
||||
drawers[i].Refresh(inspectorReferences);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractEffectDrawer FindEffectDrawerByID(string drawerID)
|
||||
{
|
||||
AbstractEffectDrawer res = null;
|
||||
|
||||
for (int i = 0; i < drawers.Length; i++)
|
||||
{
|
||||
if (drawers[i].ID == drawerID)
|
||||
{
|
||||
res = drawers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
|
||||
{
|
||||
base.AssignNewShaderToMaterial(material, oldShader, newShader);
|
||||
}
|
||||
|
||||
private void RefreshPropertiesConfig()
|
||||
{
|
||||
Shader shader = inspectorReferences.GetShader();
|
||||
currentPropertiesConfig = propertiesConfigCollection.FindPropertiesConfigByShader(shader);
|
||||
|
||||
inspectorReferences.SetOutlineEffect(currentPropertiesConfig);
|
||||
inspectorReferences.SetCastShadowsEffect(currentPropertiesConfig);
|
||||
}
|
||||
|
||||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
|
||||
{
|
||||
if (inspectorReferences != null && drawers != null)
|
||||
{
|
||||
inspectorReferences.Setup(materialEditor, properties);
|
||||
}
|
||||
|
||||
RefreshReferences(materialEditor, properties);
|
||||
|
||||
commonStyles.InitStyles();
|
||||
|
||||
#if ALLIN13DSHADER_URP
|
||||
bool urpCorrectlyConfigured = URPConfigurator.IsURPCorrectlyConfigured();
|
||||
if (!urpCorrectlyConfigured)
|
||||
{
|
||||
EditorGUILayout.LabelField(CommonMessages.URP_PIPELINE_NOT_ASSIGNED, commonStyles.warningLabel);
|
||||
EditorUtils.DrawButtonLink(CommonMessages.URP_PIPELINE_NOT_ASSIGNED_DOC_LINK);
|
||||
|
||||
GUILayout.Space(50f);
|
||||
}
|
||||
|
||||
EditorGUI.BeginDisabledGroup(!urpCorrectlyConfigured);
|
||||
#endif
|
||||
|
||||
DrawPresetsTabs();
|
||||
DrawAdvancedProperties();
|
||||
DrawGlobalProperties();
|
||||
DrawEffects();
|
||||
|
||||
#if ALLIN13DSHADER_URP
|
||||
EditorGUI.EndDisabledGroup();
|
||||
#endif
|
||||
|
||||
CheckLightmapFlags();
|
||||
bool shaderChanged = false;
|
||||
for (int i = 0; i < inspectorReferences.targetMatInfos.Length; i++)
|
||||
{
|
||||
Material targetMat = inspectorReferences.targetMatInfos[i].mat;
|
||||
|
||||
lastRenderQueue = targetMat.renderQueue;
|
||||
|
||||
if (!inspectorReferences.targetMatInfos[i].IsShaderVariant())
|
||||
{
|
||||
shaderChanged = shaderChanged || MaterialUtils.CheckMaterialShader(targetMat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
EditorUtils.DrawLine(Color.grey, 1, 3);
|
||||
|
||||
if (inspectorReferences.AreAllMaterialsShaderGeneric())
|
||||
{
|
||||
if (GUILayout.Button("Bake Shader Keywords"))
|
||||
{
|
||||
for (int i = 0; i < inspectorReferences.targetMatInfos.Length; i++)
|
||||
{
|
||||
string variantName = Selection.objects[i].name;
|
||||
Shader newShader = ShaderVariantCreator.CreateVariantByMaterialInfo(currentPropertiesConfig, inspectorReferences.targetMatInfos[i], variantName);
|
||||
inspectorReferences.targetMatInfos[i].mat.shader = newShader;
|
||||
}
|
||||
//Shader newShader = ShaderVariantCreator.CreateVariantByMaterialInfo(currentPropertiesConfig, inspectorReferences.targetMatInfos[0], variantName);
|
||||
//materialEditor.SetShader(newShader);
|
||||
|
||||
shaderChanged = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Revert To Generic Shader"))
|
||||
{
|
||||
Shader currentShader = inspectorReferences.GetShader();
|
||||
GlobalConfiguration.instance.effectsProfileCollection.RemoveEffectsProfileByShader(currentShader);
|
||||
|
||||
Shader newShader = Shader.Find(Constants.SHADER_FULL_NAME_ALLIN13D);
|
||||
materialEditor.SetShader(newShader);
|
||||
|
||||
shaderChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shaderChanged)
|
||||
{
|
||||
ResetReferences();
|
||||
}
|
||||
}
|
||||
|
||||
//private void CheckPasses(Material targetMat)
|
||||
//{
|
||||
// if (targetMat.IsKeywordEnabled("_LIGHTMODEL_FASTLIGHTING") || targetMat.IsKeywordEnabled("_LIGHTMODEL_NONE"))
|
||||
// {
|
||||
// targetMat.SetShaderPassEnabled("ForwardAdd", false);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// targetMat.SetShaderPassEnabled("ForwardAdd", true);
|
||||
// }
|
||||
//}
|
||||
|
||||
private void DrawPresetsTabs()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
string[] texts = blendingModeCollection.CreateStringsArray();
|
||||
|
||||
|
||||
int presetIndex = (int)matPropertyRenderPreset.floatValue;
|
||||
if (presetIndex >= blendingModeCollection.presets.Length)
|
||||
{
|
||||
presetIndex = 1;
|
||||
matPropertyRenderPreset.floatValue = presetIndex;
|
||||
}
|
||||
|
||||
BlendingMode previousPreset = blendingModeCollection[presetIndex];
|
||||
if(previousPreset == null)
|
||||
{
|
||||
previousPreset = blendingModeCollection[0];
|
||||
}
|
||||
|
||||
int newIndex = (int)matPropertyRenderPreset.floatValue;
|
||||
newIndex = GUILayout.SelectionGrid(newIndex, texts, 3, inspectorReferences.tabButtonStyle);
|
||||
matPropertyRenderPreset.floatValue = newIndex;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
BlendingMode selectedPreset = blendingModeCollection[newIndex];
|
||||
for(int i = 0; i < inspectorReferences.targetMatInfos.Length; i++)
|
||||
{
|
||||
Material targetMat = inspectorReferences.targetMatInfos[i].mat;
|
||||
ApplyMaterialPreset(targetMat, previousPreset, selectedPreset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawAdvancedProperties()
|
||||
{
|
||||
//Security check
|
||||
if (advancedPropertiesDrawer != null)
|
||||
{
|
||||
advancedPropertiesDrawer.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGlobalProperties()
|
||||
{
|
||||
globalPropertiesDrawer.Draw(currentPropertiesConfig.singleProperties, inspectorReferences);
|
||||
}
|
||||
|
||||
private void DrawEffects()
|
||||
{
|
||||
int globalEffectIndex = 0;
|
||||
for (int groupIdx = 0; groupIdx < currentPropertiesConfig.effectsGroups.Length; groupIdx++)
|
||||
{
|
||||
EffectGroup effectGroup = currentPropertiesConfig.effectsGroups[groupIdx];
|
||||
if (effectGroup.effects.Length <= 0) { continue; }
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
EditorUtils.DrawLine(Color.grey, 1, 3);
|
||||
GUILayout.Label(effectGroup.DisplayName, inspectorReferences.bigLabelStyle);
|
||||
|
||||
for (int effectIdx = 0; effectIdx < effectGroup.effects.Length; effectIdx++)
|
||||
{
|
||||
AllIn13DEffectConfig effectConfig = effectGroup.effects[effectIdx];
|
||||
|
||||
globalEffectIndex++;
|
||||
|
||||
AbstractEffectDrawer drawer = FindEffectDrawerByID(effectConfig.effectDrawerID);
|
||||
drawer.Draw(currentPropertiesConfig, effectConfig, globalEffectIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckLightmapFlags()
|
||||
{
|
||||
for (int i = 0; i < inspectorReferences.targetMatInfos.Length; i++)
|
||||
{
|
||||
AbstractMaterialInfo matInfo = inspectorReferences.targetMatInfos[i];
|
||||
AllIn13DEffectConfig emissionEffectConfig = propertiesConfigCollection.propertiesConfig.FindEffectConfigByID(Constants.EFFECT_ID_EMISSION);
|
||||
bool emissionEnabled = AllIn13DEffectConfig.IsEffectEnabled(emissionEffectConfig, matInfo);
|
||||
if (emissionEnabled)
|
||||
{
|
||||
matInfo.mat.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
|
||||
}
|
||||
else
|
||||
{
|
||||
matInfo.mat.globalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyMaterialPreset(Material targetMat, BlendingMode previousPresset, BlendingMode newPreset)
|
||||
{
|
||||
matPropertyBlendSrc.floatValue = (float)newPreset.blendSrc;
|
||||
matPropertyBlendDst.floatValue = (float)newPreset.blendDst;
|
||||
matPropertyZWrite.floatValue = newPreset.depthWrite ? 1.0f : 0.0f;
|
||||
|
||||
|
||||
lastRenderQueue = (int)newPreset.renderQueue;
|
||||
targetMat.renderQueue = lastRenderQueue;
|
||||
|
||||
if (previousPresset != newPreset && previousPresset.defaultEnabledEffects != null)
|
||||
{
|
||||
for (int i = 0; i < previousPresset.defaultEnabledEffects.Length; i++)
|
||||
{
|
||||
string effectID = previousPresset.defaultEnabledEffects[i];
|
||||
AllIn13DEffectConfig effectConfig = currentPropertiesConfig.FindEffectConfigByID(effectID);
|
||||
|
||||
for(int matIdx = 0; matIdx < inspectorReferences.targetMatInfos.Length; matIdx++)
|
||||
{
|
||||
AbstractMaterialInfo matInfo = inspectorReferences.targetMatInfos[matIdx];
|
||||
AllIn13DEffectConfig.DisableEffectToggle(effectConfig, inspectorReferences, matInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newPreset.defaultEnabledEffects != null)
|
||||
{
|
||||
for (int matIdx = 0; matIdx < inspectorReferences.targetMatInfos.Length; matIdx++)
|
||||
{
|
||||
AbstractMaterialInfo matInfo = inspectorReferences.targetMatInfos[matIdx];
|
||||
|
||||
if (newPreset.isTransparent)
|
||||
{
|
||||
matInfo.EnableKeyword(Constants.KEYWORD_ALLIN13D_SURFACE_TRANSPARENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
matInfo.DisableKeyword(Constants.KEYWORD_ALLIN13D_SURFACE_TRANSPARENT);
|
||||
}
|
||||
|
||||
for (int i = 0; i < newPreset.defaultEnabledEffects.Length; i++)
|
||||
{
|
||||
string effectID = newPreset.defaultEnabledEffects[i];
|
||||
AllIn13DEffectConfig effectConfig = currentPropertiesConfig.FindEffectConfigByID(effectID);
|
||||
AllIn13DEffectConfig.EnableEffectToggle(effectConfig, inspectorReferences, matInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57331ffe54816494c92e6b25562e4ed5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs
|
||||
uploadId: 865720
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CustomEditor(typeof(AllIn1DepthColoringProperties))]
|
||||
public class AllIn1DepthColoringPropertiesCustomEditor : Editor
|
||||
{
|
||||
private AllIn1DepthColoringProperties depthColoringProperties;
|
||||
|
||||
private DepthColoringPropertiesDrawer drawer;
|
||||
|
||||
private void RefreshDrawer()
|
||||
{
|
||||
depthColoringProperties = (AllIn1DepthColoringProperties)target;
|
||||
|
||||
if (drawer == null)
|
||||
{
|
||||
drawer = new DepthColoringPropertiesDrawer(depthColoringProperties);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
RefreshDrawer();
|
||||
|
||||
drawer.Draw(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40a4840e946197045b8663f3d968727f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs
|
||||
uploadId: 865720
|
||||
@@ -0,0 +1,71 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CustomEditor(typeof(DepthColoringCamera))]
|
||||
public class DepthColoringCameraCustomEditor : Editor
|
||||
{
|
||||
private SerializedProperty spCam;
|
||||
private SerializedProperty spDepthColoringProperties;
|
||||
|
||||
private AllIn1DepthColoringProperties depthColoringProperties;
|
||||
private DepthColoringPropertiesDrawer depthColoringPropertiesDrawer;
|
||||
|
||||
private DepthColoringCamera depthColoringCamera;
|
||||
|
||||
private bool depthColoringFoldout;
|
||||
|
||||
private void RefreshReferences()
|
||||
{
|
||||
if(spCam == null)
|
||||
{
|
||||
spCam = serializedObject.FindProperty("cam");
|
||||
}
|
||||
|
||||
if(spDepthColoringProperties == null)
|
||||
{
|
||||
spDepthColoringProperties = serializedObject.FindProperty("depthColoringProperties");
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshDepthColoringPropertiesDrawer()
|
||||
{
|
||||
if(depthColoringPropertiesDrawer == null && depthColoringProperties != null)
|
||||
{
|
||||
depthColoringPropertiesDrawer = new DepthColoringPropertiesDrawer(depthColoringProperties);
|
||||
}
|
||||
else if(depthColoringPropertiesDrawer != null && depthColoringProperties != null)
|
||||
{
|
||||
depthColoringPropertiesDrawer.SetDepthColoringProperties(depthColoringProperties);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
RefreshReferences();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(spCam);
|
||||
EditorGUILayout.PropertyField(spDepthColoringProperties);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if(spDepthColoringProperties.objectReferenceValue != null)
|
||||
{
|
||||
GUILayout.Space(25f);
|
||||
|
||||
depthColoringProperties = (AllIn1DepthColoringProperties)spDepthColoringProperties.objectReferenceValue;
|
||||
|
||||
RefreshDepthColoringPropertiesDrawer();
|
||||
|
||||
if(depthColoringPropertiesDrawer != null)
|
||||
{
|
||||
depthColoringPropertiesDrawer.Draw(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f455792fcb55c34d97cd0b478de36ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs
|
||||
uploadId: 865720
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CustomEditor(typeof(EffectsProfileCollection))]
|
||||
public class EffectsProfileCollectionCustomEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df521890445440245b75e88c4fb4bd73
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs
|
||||
uploadId: 865720
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CustomEditor(typeof(GlobalConfiguration))]
|
||||
public class GlobalConfigurationCustomEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c57330f81e2eed441862d8a92a0e63cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs
|
||||
uploadId: 865720
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CustomEditor(typeof(PropertiesConfigCollection))]
|
||||
public class PropertiesConfigCollectionCustomEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 436434178bc9cbf449485b83a639cdbb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs
|
||||
uploadId: 865720
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AllIn13DShader
|
||||
{
|
||||
[CustomEditor(typeof(URPSettingsUserPref))]
|
||||
public class URPSettingsUserPrefCustomEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ff9df7e6f241e844821ae6d61fb8b20
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316173
|
||||
packageName: All In 1 3D-Shader
|
||||
packageVersion: 2.72
|
||||
assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs
|
||||
uploadId: 865720
|
||||
Reference in New Issue
Block a user