-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesignerProofAttribute.cs
51 lines (40 loc) · 1.52 KB
/
DesignerProofAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* ******** Disclaimer *********
*
* Developers will have to use some means of setting the "IsUserDeveloper" bool (call EditorPrefs.SetBool("IsUserDeveloper", true); )
* from EditorPrefs to `true`, or the properties marked as [DesignerProof] will be Read Only.
*
* ********* Disclaimer *********
*/
using System;
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
using UnityEditor;
#endif
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class | AttributeTargets.Method, inherited = true)]
public class DesignerProofAttribute : Attribute { }
#if UNITY_EDITOR
namespace OdinInspector.CustomProcessors {
// Editor attribute to trigger Read Only behaviour
class DrawReadOnlyEditorAttribute : Attribute { }
class ReadOnlyEditorDrawer : OdinAttributeDrawer<DrawReadOnlyEditorAttribute> {
protected override void DrawPropertyLayout(GUIContent label) {
EditorGUI.BeginDisabledGroup(true);
{
CallNextDrawer(label);
}
EditorGUI.EndDisabledGroup();
}
}
// Adds the Editor attribute to properties marked as [DesignerProof]
class DesignerProofProcessor : OdinAttributeProcessor {
public override void ProcessSelfAttributes(InspectorProperty property, List<Attribute> attributes) {
// Don't apply for developers.
if (EditorPrefs.GetBool("IsUserDeveloper", false) == true) { return; }
if (attributes.Any(x => x is DesignerProofAttribute)) { attributes.Add(new DrawReadOnlyEditorAttribute()); }
}
}
}
#endif