Skip to content

Commit

Permalink
feat: 'SoftMask.partOfParent' is now obsolete. Please use 'MaskingSha…
Browse files Browse the repository at this point in the history
…pe' component instead.

shape
  • Loading branch information
mob-sakai committed Feb 11, 2024
1 parent fe532c6 commit 380cd32
Show file tree
Hide file tree
Showing 10 changed files with 954 additions and 0 deletions.
84 changes: 84 additions & 0 deletions Editor/MaskingShapeEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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;

Utils.GetStencilDepthAndMask(current.transform, false, out var mask);
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);
// EditorGUILayout.PropertyField(_showMaskGraphic);
// EditorGUILayout.PropertyField(_alphaHitTest);

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;
}

// AntiAliasing is only available in Mask
// EditorGUI.BeginDisabledGroup(mask is SoftMask);
// {
// EditorGUILayout.PropertyField(_antiAliasing);
// EditorGUI.BeginDisabledGroup(!_antiAliasing.boolValue);
// {
// EditorGUILayout.PropertyField(_antiAliasingThreshold);
// }
// }
// EditorGUI.EndDisabledGroup();
//
// // Softness is only available in SoftMask
// EditorGUI.BeginDisabledGroup(!(mask is SoftMask));
// {
// EditorGUILayout.PropertyField(_softnessRange);
// }
// EditorGUI.EndDisabledGroup();

serializedObject.ApplyModifiedProperties();

// Draw alpha hit test warning
if (current.alphaHitTest)
{
SoftMaskEditor.DrawAlphaHitTestWarning(current.graphic);
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/MaskingShapeEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/MaskingShape.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 380cd32

Please sign in to comment.