From b0e7e1f753b798a8d359ab3bf13bd8ea8b326ced Mon Sep 17 00:00:00 2001 From: "DESKTOP-B4ME9GF\\Joshua Reason" Date: Thu, 14 Jun 2018 15:01:56 +1000 Subject: [PATCH 1/2] Implemented feature, but needs commenting before finishing --- .../Editor AddOn.meta => Editor Add On.meta} | 2 +- Assets/Editor Add On/Custom Attributes.meta | 8 +++ .../Custom Attributes/Hide in Prefab.meta | 8 +++ .../Hide in Prefab/Examples.meta | 8 +++ .../Examples/HideInPrefabExample.cs | 19 ++++++ .../Examples/HideInPrefabExample.cs.meta | 11 ++++ .../Examples/HideInPrefabExample.prefab | 58 +++++++++++++++++++ .../Examples/HideInPrefabExample.prefab.meta | 8 +++ .../Hide in Prefab/Scripts.meta | 8 +++ .../Scripts/HideInPrefabAttribute.cs | 32 ++++++++++ .../Scripts/HideInPrefabAttribute.cs.meta | 11 ++++ 11 files changed, 172 insertions(+), 1 deletion(-) rename Assets/{Editor/Editor AddOn.meta => Editor Add On.meta} (77%) create mode 100644 Assets/Editor Add On/Custom Attributes.meta create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab.meta create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples.meta create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs.meta create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab.meta create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts.meta create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs create mode 100644 Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs.meta diff --git a/Assets/Editor/Editor AddOn.meta b/Assets/Editor Add On.meta similarity index 77% rename from Assets/Editor/Editor AddOn.meta rename to Assets/Editor Add On.meta index c80949d..03841ef 100644 --- a/Assets/Editor/Editor AddOn.meta +++ b/Assets/Editor Add On.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1eba5231ebd032b4db5d58d699e0f0de +guid: 7a8bfbd0555f21048abd1415f2c47893 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Editor Add On/Custom Attributes.meta b/Assets/Editor Add On/Custom Attributes.meta new file mode 100644 index 0000000..6b84961 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 040e0c0ec80bb52409744b03671df838 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab.meta b/Assets/Editor Add On/Custom Attributes/Hide in Prefab.meta new file mode 100644 index 0000000..1356328 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f134e8ccabae44c45b14bad67978a30b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples.meta b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples.meta new file mode 100644 index 0000000..c3283e5 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: affc4046c2a5111479cf285e82bedb4f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs new file mode 100644 index 0000000..7cb6a64 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class HideInPrefabExample : MonoBehaviour { + + [Header ("Drag Me into scene to show hidden properties.")] + + + [HideInPrefab] + public float HiddenFloat = 5; //Hidden in prefab inspector + public float ShownFloat = 6; //Not hidden in prefab inspector + [HideInInspector] + public float AlwaysHiddenFloat = 7; //Always hidden (Unity's default implementation) + + [HideInPrefab] + public GameObject HiddenGameObject; //Hidden in Prefab inspector + public GameObject ShownGameObject; //NotHidden in Prefab inspector +} diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs.meta b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs.meta new file mode 100644 index 0000000..cffa6cf --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3a8b00c985891a448737258d9b09ede +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab new file mode 100644 index 0000000..a84f9e0 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab @@ -0,0 +1,58 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1839211675386134} + m_IsPrefabParent: 1 +--- !u!1 &1839211675386134 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4904693562653106} + - component: {fileID: 114800799608557334} + m_Layer: 0 + m_Name: HideInPrefabExample + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4904693562653106 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1839211675386134} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &114800799608557334 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1839211675386134} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b3a8b00c985891a448737258d9b09ede, type: 3} + m_Name: + m_EditorClassIdentifier: + HiddenFloat: 5 + ShownFloat: 6 + AlwaysHiddenFloat: 7 + HiddenGameObject: {fileID: 0} + ShownGameObject: {fileID: 0} diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab.meta b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab.meta new file mode 100644 index 0000000..5b6c5df --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3e4c28a2ff8a30f4da1d96c254a14fc5 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts.meta b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts.meta new file mode 100644 index 0000000..2cbbcb7 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5629afcda35004c4d99c76bde4f4eeb7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs new file mode 100644 index 0000000..17ee791 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +#if UNITY_EDITOR +using UnityEditor; +#endif + +public class HideInPrefabAttribute : PropertyAttribute +{ + +} + +[CustomPropertyDrawer(typeof(HideInPrefabAttribute))] +public class HideInPrefabDrawer : PropertyDrawer +{ + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject); + + if (type != PrefabType.Prefab) + EditorGUI.PropertyField(position, property, label); + } + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject); + if (type == PrefabType.Prefab) + return 0; + + return base.GetPropertyHeight(property, label); + } +} diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs.meta b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs.meta new file mode 100644 index 0000000..29b0fd7 --- /dev/null +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7ffee7f5af11da344ae52c6c92cce67c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 4e9bb9c71f68146b2304dc6a33c883e5d30275f8 Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Sun, 17 Jun 2018 15:40:00 +1000 Subject: [PATCH 2/2] Commented Code --- .../Examples/HideInPrefabExample.cs | 5 ++++- .../Scripts/HideInPrefabAttribute.cs | 21 +++++++++++++++++++ Assets/Editor.meta | 8 ------- 3 files changed, 25 insertions(+), 9 deletions(-) delete mode 100644 Assets/Editor.meta diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs index 7cb6a64..c29d318 100644 --- a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Examples/HideInPrefabExample.cs @@ -2,11 +2,14 @@ using System.Collections.Generic; using UnityEngine; + +/// +/// Example of a script using [HideInPrfab] +/// public class HideInPrefabExample : MonoBehaviour { [Header ("Drag Me into scene to show hidden properties.")] - [HideInPrefab] public float HiddenFloat = 5; //Hidden in prefab inspector public float ShownFloat = 6; //Not hidden in prefab inspector diff --git a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs index 17ee791..02b924a 100644 --- a/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs +++ b/Assets/Editor Add On/Custom Attributes/Hide in Prefab/Scripts/HideInPrefabAttribute.cs @@ -4,29 +4,50 @@ using UnityEditor; #endif +/// +/// Class for the Hide in Prefab Attribute +/// +/// +/// Class is empty because we have no parameters needed for this attribute +/// public class HideInPrefabAttribute : PropertyAttribute { } + + +#if UNITY_EDITOR +/// +/// Override for the Property Drawer which draws the GUI +/// [CustomPropertyDrawer(typeof(HideInPrefabAttribute))] public class HideInPrefabDrawer : PropertyDrawer { + //On GUI override 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); + //if the type isn't a perfab then draw the property if (type != PrefabType.Prefab) EditorGUI.PropertyField(position, property, label); } + //Override GetPropertyHeight 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); + + //if type prefab return zero height (because it won't be drawn) if (type == PrefabType.Prefab) return 0; + //else return normal height return base.GetPropertyHeight(property, label); } } +#endif diff --git a/Assets/Editor.meta b/Assets/Editor.meta deleted file mode 100644 index 178ee3f..0000000 --- a/Assets/Editor.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d2ef7c61cf0a63a439bf63d461541ce3 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: