using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace SpriteShadersUltimate
{
[CustomEditor(typeof(InteractiveWindSSU)), CanEditMultipleObjects]
public class InteractiveWindSSUEditor : Editor
{
bool displaySetup;
bool displayTroubleshooting;
bool displayInformation;
public override void OnInspectorGUI()
{
//References:
GUIStyle style = new GUIStyle(GUI.skin.label);
style.richText = true;
InteractiveWindSSU wind = (InteractiveWindSSU)target;
//Header:
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Interactive Wind", style);
EditorGUILayout.LabelField(" ", GUILayout.Height(1));
DisplayHints(ref displaySetup, "Setup",
"- Attach this to a SpriteRenderer with the Wind shader.",
"- Set Mesh Type to Full Rect in the sprite's settings.",
"- Attach a BoxCollider2D to this gameobject.",
"- Set Is Trigger to true in the BoxCollider2D.",
"- Have a single active WindManager component in your scene.",
" ",
"- You can flip the shader for hanging objects.",
"- You can combine the shader with UV Distort."
);
EditorGUILayout.LabelField(" ", GUILayout.Height(1));
DisplayHints(ref displayTroubleshooting, "Troubleshooting",
" ",
"Pixels are clipping out:",
"- Make sure the sprite's Mesh Type is Full Rect.",
"- Sprite Sheets need the Sprite Sheet Fix option.",
"- Expand the sprite's texture horizontally with empty pixels.",
" ",
"Wind is not visible:",
"- Make sure the SpriteRenderer is using the Wind shader.",
"- If using a Uber Shader you need to enable Wind.",
"- Make sure you have a single active WindManager component.",
"- Check your WindManager's and material's settings.",
" ",
"Physical interaction is not happening:",
"- Check this component's and the material's settings.",
"- Make sure the BoxCollider2D is positioned properly.",
"- Set the BoxCollider2D to a trigger.",
"- Make sure a collision with the BoxCollider2D is happening.",
" "
);
EditorGUILayout.LabelField(" ", GUILayout.Height(1));
DisplayHints(ref displayInformation, "Information",
" ",
"Summary:",
"- Interaction will bend and squish the sprite.",
"- Can be used for Grass, Trees, Chains, Vines and more.",
" ",
"Temporary Interaction:",
"- Disable Stay Bent to have a temporary interaction.",
"- Only objects moving faster than " + Mathf.RoundToInt(wind.minBendSpeed) + " unit/s will interact.",
" "
);
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
//Rotation:
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Rotation:", style);
EditorGUILayout.PropertyField(serializedObject.FindProperty("rotationFactor"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("bendInSpeed"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("bendOutSpeed"));
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
//Temporary:
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Method:", style);
EditorGUILayout.PropertyField(serializedObject.FindProperty("stayBent"));
if(!wind.stayBent)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("minBendSpeed"));
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
//Hyper Performance:
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Hyper Performance:", style);
EditorGUILayout.PropertyField(serializedObject.FindProperty("hyperPerformanceMode"));
if (wind.hyperPerformanceMode)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("randomOffsetZ"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("customMaterial"));
if (wind.customMaterial)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("inactiveMaterial"));
}
else
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("inactiveShader"));
}
//Hint:
GUI.color = new Color(1, 1, 1, 0.7f);
EditorGUILayout.LabelField("- GPU performance boost for lowest-end mobile phones.", style);
if(!wind.customMaterial)
{
EditorGUILayout.LabelField("- Sets the shader to " + wind.inactiveShader + " while inactive.", style);
}
else
{
if(wind.inactiveMaterial != null)
{
EditorGUILayout.LabelField("- Sets the material to " + wind.inactiveMaterial.name + " while inactive.", style);
}
else
{
GUIStyle warningStyle = new GUIStyle(GUI.skin.label);
warningStyle.richText = true;
if (EditorGUIUtility.isProSkin)
{
warningStyle.normal.textColor = new Color(1, 0.7f, 0.7f, 1);
}
else
{
warningStyle.normal.textColor = new Color(0.3f, 0f, 0f, 1);
}
EditorGUILayout.LabelField("- Please reference a material in Inactive Material.", warningStyle);
}
}
EditorGUILayout.LabelField("- Use this if you want physical interaction but don't need Wind.", style);
EditorGUILayout.LabelField("- You must set Rotation Wind Factor to 0 in the material.", style);
EditorGUILayout.Space();
EditorGUILayout.LabelField("- Enabling Random Offset Z will prevent resorting of render order.", style);
GUI.color = Color.white;
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
//Other:
EditorGUILayout.BeginVertical("Helpbox");
EditorGUILayout.LabelField("Other:", style);
EditorGUILayout.PropertyField(serializedObject.FindProperty("randomizeWiggle"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("allowCustomLayer"));
EditorGUILayout.EndVertical();
serializedObject.ApplyModifiedProperties();
//Fix Layer:
if(wind.gameObject.layer != 2 && !wind.allowCustomLayer)
{
wind.gameObject.layer = 2;
}
//Fix BoxCollider2D:
BoxCollider2D boxCollider = wind.gameObject.GetComponent();
if(boxCollider == null)
{
//Create new BoxCollider2D:
boxCollider = wind.gameObject.AddComponent();
boxCollider.isTrigger = true;
}
//Fix Variables:
if(wind.bendInSpeed < 0)
{
wind.bendInSpeed = 0;
}
if (wind.bendOutSpeed < 0)
{
wind.bendOutSpeed = 0;
}
if (wind.minBendSpeed < 0)
{
wind.minBendSpeed = 0;
}
}
void DisplayHints(ref bool toggleVariable, string title,params string[] lines)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.richText = true;
GUIStyle button = new GUIStyle(GUI.skin.button);
button.richText = true;
if (toggleVariable)
{
GUI.color = new Color(1, 1, 1, 0.7f);
}
else
{
GUI.color = new Color(1, 1, 1, 0.5f);
}
title = "" + title + "";
EditorGUILayout.BeginVertical(GUI.skin.box);
EditorGUILayout.BeginHorizontal();
GUI.color = Color.white;
EditorGUILayout.LabelField(title, style);
if (GUILayout.Button("" + (toggleVariable ? "▼" : "▲") + "", button, GUILayout.Width(20)))
{
toggleVariable = !toggleVariable;
}
EditorGUILayout.EndHorizontal();
if (toggleVariable == true)
{
GUI.color = new Color(1, 1, 1, 0.7f);
for(int l = 0; l < lines.Length; l++)
{
if(lines[l] == " ")
{
EditorGUILayout.LabelField(lines[l], style,GUILayout.Height(6));
}
else
{
EditorGUILayout.LabelField(lines[l], style);
}
}
}
GUI.color = Color.white;
EditorGUILayout.EndVertical();
}
}
}