Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- // Put one of these on any object you want to show up with a tint.
- // Change the assetdatabase path as needed to find the debugManager you create.
- public class EdDebug : MonoBehaviour {
- public bool showDebug = true;
- public bool useMeshColliderIfAvailable = false;
- public EdDebugManager debugManager;
- public EdDebugManager.DebugObjectType objectType;
- void OnDrawGizmos()
- {
- if (showDebug)
- {
- Gizmos.matrix = transform.localToWorldMatrix;
- if (debugManager == null)
- {
- debugManager = AssetDatabase.LoadAssetAtPath("Assets/_Tools/EdDebugManager.asset", typeof (EdDebugManager)) as EdDebugManager;
- }
- if (debugManager != null)
- {
- if (debugManager.showDebugColours)
- {
- Gizmos.color = debugManager.GetDebugObjectColour(objectType);
- Mesh drawThisMesh = null;
- if (useMeshColliderIfAvailable)
- {
- MeshCollider meshCollider = GetComponent<MeshCollider>();
- if (meshCollider != null)
- {
- drawThisMesh = meshCollider.sharedMesh;
- }
- }
- if (drawThisMesh == null)
- {
- MeshFilter meshFilter = GetComponent<MeshFilter>();
- if (meshFilter != null)
- {
- drawThisMesh = meshFilter.sharedMesh;
- }
- }
- if (drawThisMesh != null)
- {
- Gizmos.DrawMesh(drawThisMesh);
- }
- }
- }
- }
- }
- }
- // Make one of these somewhere (I'm using Assets/_Tools/) so there's a nice central place to tweak things.
- // ScriptableObjects are great! right click -> Debug -> DebugManager to create one.
- [CreateAssetMenu(fileName = "EdDebugManager", menuName = "Debug/DebugManager", order = 1)]
- public class EdDebugManager : ScriptableObject {
- public enum DebugObjectType
- {
- interactable,
- enemy,
- pickup,
- worldObject
- }
- public bool showDebugColours = false;
- [Header("Debug Colours")]
- public Color interactableColour = Color.green;
- public Color enemyColour = Color.red;
- public Color pickupColour = Color.yellow;
- public Color worldObjectColour = Color.magenta;
- public Color GetDebugObjectColour(DebugObjectType debugObjectType)
- {
- Color debugColor;
- switch (debugObjectType)
- {
- default:
- case DebugObjectType.interactable:
- debugColor = interactableColour;
- break;
- case DebugObjectType.enemy:
- debugColor = enemyColour;
- break;
- case DebugObjectType.pickup:
- debugColor = pickupColour;
- break;
- case DebugObjectType.worldObject:
- debugColor = worldObjectColour;
- break;
- }
- return new Color(debugColor.r * 2f, debugColor.g * 2f, debugColor.b * 2f, debugColor.a);
- //Gizmos always render at half brightness for some dumb reason
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment