#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
namespace SpriteShadersUltimate
{
[CustomEditor(typeof(ImageSSU))]
[CanEditMultipleObjects]
public class ImageSSUEditor : Editor
{
public override void OnInspectorGUI()
{
SerializedProperty updateChanges = serializedObject.FindProperty("updateChanges");
EditorGUILayout.PropertyField(updateChanges);
GUI.enabled = false;
EditorGUILayout.PropertyField(serializedObject.FindProperty("runtimeMaterial"));
GUI.enabled = true;
serializedObject.ApplyModifiedProperties();
GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
labelStyle.richText = true;
EditorGUILayout.Space();
EditorGUILayout.BeginVertical("Helpbox");
GUI.color = new Color(1, 1, 1, 0.7f);
EditorGUILayout.LabelField("Requires the UI_Graphic shader space.", labelStyle);
EditorGUILayout.LabelField("Sets the material's Rect Width and Rect Height.", labelStyle);
EditorGUILayout.LabelField("Will also instantiate the material at runtime.", labelStyle);
GUI.color = Color.white;
EditorGUILayout.EndVertical();
//Check:
ImageSSU image = (ImageSSU) target;
if(image.GetComponent() == null)
{
EditorGUILayout.Space();
GUI.color = Color.red;
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Requires a RectTransform.", labelStyle);
EditorGUILayout.EndVertical();
GUI.color = Color.white;
}
if (image.GetComponent() == null)
{
EditorGUILayout.Space();
GUI.color = Color.red;
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Requires an Image.", labelStyle);
EditorGUILayout.EndVertical();
GUI.color = Color.white;
}
else if(Application.isPlaying == false)
{
Material mat = image.GetComponent().material;
if (mat.shader.name.StartsWith("Sprite Shaders Ultimate") == false)
{
EditorGUILayout.Space();
GUI.color = Color.red;
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Requires a Sprite Shaders Ultimate shader.", labelStyle);
EditorGUILayout.EndVertical();
GUI.color = Color.white;
}
else if (Mathf.RoundToInt(mat.GetFloat("_ShaderSpace")) != 5)
{
EditorGUILayout.Space();
GUI.color = Color.red;
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Requires UI_Graphic shader space.", labelStyle);
EditorGUILayout.EndVertical();
GUI.color = Color.white;
}
else
{
EditorGUILayout.Space();
GUI.color = Color.green;
EditorGUILayout.BeginVertical("Helpbox");
if (updateChanges.hasMultipleDifferentValues)
{
EditorGUILayout.LabelField("Rect Width and Rect Height will be updated on Awake() or Update().", labelStyle);
}
else if (updateChanges.boolValue)
{
EditorGUILayout.LabelField("Rect Width and Rect Height will be updated on Awake() and Update().", labelStyle);
EditorGUILayout.LabelField("Material is only updated if the RectTransform's Width or Height is changed.", labelStyle);
}
else
{
EditorGUILayout.LabelField("Rect Width and Rect Height will be updated on Awake().", labelStyle);
}
EditorGUILayout.EndVertical();
GUI.color = Color.white;
}
}
}
}
}
#endif