/// <summary> /// This function display the custom fields for each component in the inspector /// </summary> public void OnInspectorGUI() { #if UNITY_EDITOR // This try catch is in place to fix an issue which happens when deleting a component. This essentially refreshes the draw sequence. try { GUILayout.BeginHorizontal(); } catch { return; } // Draw the foldout header hideShowSection = RenderHeader(EnhancedTriggerBox.AddSpacesToSentence(GetType().Name.Replace("(", "").Replace(")", ""), true), hideShowSection, true); hideFlags = HideFlags.HideInInspector; // Draw the delete button if (GUILayout.Button(new GUIContent("X", "Remove component"), GUILayout.Width(25))) { deleted = true; } GUILayout.EndHorizontal(); EditorGUI.indentLevel = 1; // Draw the specific components fields (only if the section is folded out). This function should be overriden by each inheirited component. if (hideShowSection) { UnityEditor.Undo.RecordObject(this, "Value Change"); DrawInspectorGUI(); } // Check and draw warnings for the fields. This function should be overriden by each inheirited component. if (showWarnings) { Validation(); } #endif }
/// <summary> /// Draws each generic variable in the component. Not all types can be drawn. Enums or structs are the most prominent that cannot be drawn. /// </summary> /// <param name="o">The field that will be drawn</param> protected void RenderGeneric(System.Reflection.FieldInfo o) { #if UNITY_EDITOR if (o.FieldType == typeof(GameObject)) { o.SetValue(this, (GameObject)EditorGUILayout.ObjectField(new GUIContent(EnhancedTriggerBox.AddSpacesToSentence(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(o.Name), true) , "No description provided"), (GameObject)o.GetValue(this), typeof(GameObject), true)); } else if (o.FieldType == typeof(Camera)) { o.SetValue(this, (Camera)EditorGUILayout.ObjectField(new GUIContent(EnhancedTriggerBox.AddSpacesToSentence(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(o.Name), true) , "No description provided"), (Camera)o.GetValue(this), typeof(Camera), true)); } else if (o.FieldType == typeof(Material)) { o.SetValue(this, (Material)EditorGUILayout.ObjectField(new GUIContent(EnhancedTriggerBox.AddSpacesToSentence(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(o.Name), true) , "No description provided"), (Material)o.GetValue(this), typeof(Material), true)); } else if (o.FieldType == typeof(bool)) { o.SetValue(this, EditorGUILayout.Toggle(new GUIContent(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(EnhancedTriggerBox.AddSpacesToSentence(o.Name, true)), "No description provided"), (bool)o.GetValue(this))); } else if (o.FieldType == typeof(float)) { o.SetValue(this, EditorGUILayout.FloatField(new GUIContent(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(EnhancedTriggerBox.AddSpacesToSentence(o.Name, true)), "No description provided"), (float)o.GetValue(this))); } else if (o.FieldType == typeof(int)) { o.SetValue(this, EditorGUILayout.IntField(new GUIContent(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(EnhancedTriggerBox.AddSpacesToSentence(o.Name, true)), "No description provided"), (int)o.GetValue(this))); } else if (o.FieldType == typeof(string)) { o.SetValue(this, EditorGUILayout.TextField(new GUIContent(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(EnhancedTriggerBox.AddSpacesToSentence(o.Name, true)), "No description provided"), (string)o.GetValue(this))); } // TODO: Add more generic types #endif }