forked from mob-sakai/SoftMaskForUGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaskingShapeEditor.cs
64 lines (56 loc) · 2.52 KB
/
MaskingShapeEditor.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using UnityEditor;
using UnityEngine;
namespace Coffee.UISoftMask
{
[CustomEditor(typeof(MaskingShape), true)]
[CanEditMultipleObjects]
public class MaskingShapeEditor : Editor
{
private SerializedProperty _alphaHitTest;
private SerializedProperty _antiAliasingThreshold;
private SerializedProperty _maskingMethod;
private SerializedProperty _showMaskGraphic;
private SerializedProperty _softnessRange;
protected void OnEnable()
{
_maskingMethod = serializedObject.FindProperty("m_MaskingMethod");
_showMaskGraphic = serializedObject.FindProperty("m_ShowMaskGraphic");
_alphaHitTest = serializedObject.FindProperty("m_AlphaHitTest");
_antiAliasingThreshold = serializedObject.FindProperty("m_AntiAliasingThreshold");
_softnessRange = serializedObject.FindProperty("m_SoftnessRange");
}
public override void OnInspectorGUI()
{
var current = target as MaskingShape;
if (!current) return;
var useStencil = UISoftMaskProjectSettings.useStencilOutsideScreen;
Utils.GetStencilBits(current.transform, false, useStencil, out var mask, out var _);
var maskingMode = mask is SoftMask softMask ? softMask.GetActualMaskingMode() : SoftMask.MaskingMode.Normal;
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.EnumPopup(new GUIContent("Masking Mode"), maskingMode);
EditorGUI.EndDisabledGroup();
EditorGUILayout.PropertyField(_maskingMethod);
switch (maskingMode)
{
case SoftMask.MaskingMode.SoftMasking:
EditorGUILayout.PropertyField(_showMaskGraphic);
EditorGUILayout.PropertyField(_alphaHitTest);
EditorGUILayout.PropertyField(_softnessRange);
break;
case SoftMask.MaskingMode.AntiAliasing:
EditorGUILayout.PropertyField(_alphaHitTest);
EditorGUILayout.PropertyField(_antiAliasingThreshold);
break;
case SoftMask.MaskingMode.Normal:
EditorGUILayout.PropertyField(_showMaskGraphic);
break;
}
serializedObject.ApplyModifiedProperties();
// Draw alpha hit test warning
if (current.alphaHitTest)
{
SoftMaskEditor.DrawAlphaHitTestWarning(current.graphic);
}
}
}
}