Edwarddv

Ed Debug Manager

Jun 6th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.53 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. // Put one of these on any object you want to show up with a tint.
  5. // Change the assetdatabase path as needed to find the debugManager you create.
  6.  
  7. public class EdDebug : MonoBehaviour {
  8.  
  9.     public bool showDebug = true;
  10.     public bool useMeshColliderIfAvailable = false;
  11.     public EdDebugManager debugManager;
  12.     public EdDebugManager.DebugObjectType objectType;
  13.  
  14.     void OnDrawGizmos()
  15.     {
  16.         if (showDebug)
  17.         {
  18.             Gizmos.matrix = transform.localToWorldMatrix;
  19.  
  20.             if (debugManager == null)
  21.             {
  22.                 debugManager = AssetDatabase.LoadAssetAtPath("Assets/_Tools/EdDebugManager.asset", typeof (EdDebugManager)) as EdDebugManager;
  23.             }
  24.  
  25.            
  26.             if (debugManager != null)
  27.             {
  28.                 if (debugManager.showDebugColours)
  29.                 {
  30.                     Gizmos.color = debugManager.GetDebugObjectColour(objectType);
  31.  
  32.                         Mesh drawThisMesh = null;
  33.                         if (useMeshColliderIfAvailable)
  34.                         {
  35.                             MeshCollider meshCollider = GetComponent<MeshCollider>();
  36.                             if (meshCollider != null)
  37.                             {
  38.                                 drawThisMesh = meshCollider.sharedMesh;
  39.                             }
  40.                         }
  41.  
  42.                         if (drawThisMesh == null)
  43.                         {
  44.                             MeshFilter meshFilter = GetComponent<MeshFilter>();
  45.                             if (meshFilter != null)
  46.                             {
  47.                                 drawThisMesh = meshFilter.sharedMesh;
  48.                             }
  49.                         }
  50.  
  51.                         if (drawThisMesh != null)
  52.                         {
  53.                             Gizmos.DrawMesh(drawThisMesh);
  54.                         }
  55.                    
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63.  
  64. // Make one of these somewhere (I'm using Assets/_Tools/) so there's a nice central place to tweak things.
  65. // ScriptableObjects are great! right click -> Debug -> DebugManager to create one.
  66.  
  67. [CreateAssetMenu(fileName = "EdDebugManager", menuName = "Debug/DebugManager", order = 1)]
  68. public class EdDebugManager : ScriptableObject {
  69.  
  70.     public enum DebugObjectType
  71.     {
  72.         interactable,
  73.         enemy,
  74.         pickup,
  75.         worldObject
  76.  
  77.     }
  78.  
  79.     public bool showDebugColours = false;
  80.  
  81.     [Header("Debug Colours")]
  82.  
  83.     public Color interactableColour = Color.green;
  84.     public Color enemyColour = Color.red;
  85.     public Color pickupColour = Color.yellow;
  86.     public Color worldObjectColour = Color.magenta;
  87.  
  88.     public Color GetDebugObjectColour(DebugObjectType debugObjectType)
  89.     {
  90.         Color debugColor;
  91.         switch (debugObjectType)
  92.         {
  93.             default:
  94.             case DebugObjectType.interactable:
  95.                 debugColor = interactableColour;
  96.                 break;
  97.             case DebugObjectType.enemy:
  98.                 debugColor = enemyColour;
  99.                 break;
  100.             case DebugObjectType.pickup:
  101.                 debugColor = pickupColour;
  102.                 break;
  103.             case DebugObjectType.worldObject:
  104.                 debugColor = worldObjectColour;
  105.                 break;
  106.         }
  107.         return new Color(debugColor.r * 2f, debugColor.g * 2f, debugColor.b * 2f, debugColor.a);
  108.         //Gizmos always render at half brightness for some dumb reason
  109.  
  110.  
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment