Browse Source

Commented Code

feature/Minesweeper
Joshua Reason 6 years ago
parent
commit
4e9bb9c71f
3 changed files with 25 additions and 9 deletions
  1. +4
    -1
      Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs
  2. +21
    -0
      Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs
  3. +0
    -8
      Assets/Editor.meta

+ 4
- 1
Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs View File

@ -2,11 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// Example of a script using [HideInPrfab]
/// </summary>
public class HideInPrefabExample : MonoBehaviour { public class HideInPrefabExample : MonoBehaviour {
[Header ("Drag Me into scene to show hidden properties.")] [Header ("Drag Me into scene to show hidden properties.")]
[HideInPrefab] [HideInPrefab]
public float HiddenFloat = 5; //Hidden in prefab inspector public float HiddenFloat = 5; //Hidden in prefab inspector
public float ShownFloat = 6; //Not hidden in prefab inspector public float ShownFloat = 6; //Not hidden in prefab inspector

+ 21
- 0
Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs View File

@ -4,29 +4,50 @@
using UnityEditor; using UnityEditor;
#endif #endif
/// <summary>
/// Class for the Hide in Prefab Attribute
/// </summary>
/// <remarks>
/// Class is empty because we have no parameters needed for this attribute
/// </remarks>
public class HideInPrefabAttribute : PropertyAttribute public class HideInPrefabAttribute : PropertyAttribute
{ {
} }
#if UNITY_EDITOR
/// <summary>
/// Override for the Property Drawer which draws the GUI
/// </summary>
[CustomPropertyDrawer(typeof(HideInPrefabAttribute))] [CustomPropertyDrawer(typeof(HideInPrefabAttribute))]
public class HideInPrefabDrawer : PropertyDrawer public class HideInPrefabDrawer : PropertyDrawer
{ {
//On GUI override
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{ {
//get the type of the object this property is attched to
PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject); PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
//if the type isn't a perfab then draw the property
if (type != PrefabType.Prefab) if (type != PrefabType.Prefab)
EditorGUI.PropertyField(position, property, label); EditorGUI.PropertyField(position, property, label);
} }
//Override GetPropertyHeight
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{ {
//get the type of the object this property is attched to
PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject); PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
//if type prefab return zero height (because it won't be drawn)
if (type == PrefabType.Prefab) if (type == PrefabType.Prefab)
return 0; return 0;
//else return normal height
return base.GetPropertyHeight(property, label); return base.GetPropertyHeight(property, label);
} }
} }
#endif

+ 0
- 8
Assets/Editor.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: d2ef7c61cf0a63a439bf63d461541ce3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save