Revamped collision system
This commit is contained in:
94
Editor/PSXTriggerBoxEditor.cs
Normal file
94
Editor/PSXTriggerBoxEditor.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using SplashEdit.RuntimeCode;
|
||||
|
||||
namespace SplashEdit.EditorCode
|
||||
{
|
||||
[CustomEditor(typeof(PSXTriggerBox))]
|
||||
public class PSXTriggerBoxEditor : UnityEditor.Editor
|
||||
{
|
||||
private SerializedProperty sizeProp;
|
||||
private SerializedProperty luaFileProp;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
sizeProp = serializedObject.FindProperty("size");
|
||||
luaFileProp = serializedObject.FindProperty("luaFile");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.LabelField("PSX Trigger Box", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space(4);
|
||||
|
||||
EditorGUILayout.PropertyField(sizeProp, new GUIContent("Size"));
|
||||
EditorGUILayout.PropertyField(luaFileProp, new GUIContent("Lua Script"));
|
||||
|
||||
if (luaFileProp.objectReferenceValue != null)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUI.indentLevel * 15);
|
||||
if (GUILayout.Button("Edit", EditorStyles.miniButtonLeft, GUILayout.Width(50)))
|
||||
AssetDatabase.OpenAsset(luaFileProp.objectReferenceValue);
|
||||
if (GUILayout.Button("Clear", EditorStyles.miniButtonRight, GUILayout.Width(50)))
|
||||
luaFileProp.objectReferenceValue = null;
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUI.indentLevel * 15);
|
||||
if (GUILayout.Button("Create Lua Script", EditorStyles.miniButton, GUILayout.Width(130)))
|
||||
CreateNewLuaScript();
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private void CreateNewLuaScript()
|
||||
{
|
||||
var trigger = target as PSXTriggerBox;
|
||||
string defaultName = trigger.gameObject.name.ToLower().Replace(" ", "_");
|
||||
string path = EditorUtility.SaveFilePanelInProject(
|
||||
"Create Lua Script", defaultName + ".lua", "lua",
|
||||
"Create a new Lua script for this trigger box");
|
||||
|
||||
if (string.IsNullOrEmpty(path)) return;
|
||||
|
||||
string template =
|
||||
"function onTriggerEnter(triggerIndex)\nend\n\nfunction onTriggerExit(triggerIndex)\nend\n";
|
||||
System.IO.File.WriteAllText(path, template);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
var luaFile = AssetDatabase.LoadAssetAtPath<LuaFile>(path);
|
||||
if (luaFile != null)
|
||||
{
|
||||
luaFileProp.objectReferenceValue = luaFile;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
[DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)]
|
||||
private static void DrawTriggerGizmo(PSXTriggerBox trigger, GizmoType gizmoType)
|
||||
{
|
||||
bool selected = (gizmoType & GizmoType.Selected) != 0;
|
||||
|
||||
Gizmos.color = selected ? new Color(0.2f, 1f, 0.3f, 0.8f) : new Color(0.2f, 1f, 0.3f, 0.25f);
|
||||
Gizmos.matrix = trigger.transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(Vector3.zero, trigger.Size);
|
||||
|
||||
if (selected)
|
||||
{
|
||||
Gizmos.color = new Color(0.2f, 1f, 0.3f, 0.08f);
|
||||
Gizmos.DrawCube(Vector3.zero, trigger.Size);
|
||||
}
|
||||
|
||||
Gizmos.matrix = Matrix4x4.identity;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user