Ejemplo n.º 1
0
        public static void TagDropdown(SerializedProperty tagProperty, SerializedProperty tagValueProperty, ImpactTagNameList tagNames, Rect controlRect)
        {
            string selectedTagName = "";
            int    tagValue        = tagValueProperty.intValue;

            if (tagValue >= 0 && tagValue < tagNames.Length)
            {
                selectedTagName = tagNames[tagValue];
            }

            if (GUI.Button(controlRect, selectedTagName, EditorStyles.layerMaskField))
            {
                ImpactTagSelectionDropdown tagMaskPopup = ScriptableObject.CreateInstance <ImpactTagSelectionDropdown>();

                tagMaskPopup.Initialize(tagValueProperty, tagNames, false, (int pos, bool selected) =>
                {
                    tagValueProperty.intValue = pos;
                    tagProperty.serializedObject.ApplyModifiedProperties();
                });

                Rect    buttonRect       = controlRect;
                Vector2 adjustedPosition = EditorGUIUtility.GUIToScreenPoint(buttonRect.position);
                buttonRect.position = adjustedPosition;

                tagMaskPopup.ShowAsDropDown(buttonRect, tagMaskPopup.GetWindowSize(controlRect));
            }
        }
Ejemplo n.º 2
0
        public static void TagMaskDropdown(SerializedProperty tagMaskProperty, SerializedProperty tagMaskValueProperty, ImpactTagNameList tagNames, Rect controlRect)
        {
            string selectedTags        = GetSelectedTags(tagMaskValueProperty.intValue, tagNames, false);
            string selectedTagsTooltip = GetSelectedTags(tagMaskValueProperty.intValue, tagNames, true);

            if (GUI.Button(controlRect, new GUIContent(selectedTags, selectedTagsTooltip), EditorStyles.layerMaskField))
            {
                ImpactTagSelectionDropdown tagMaskPopup = ScriptableObject.CreateInstance <ImpactTagSelectionDropdown>();

                tagMaskPopup.Initialize(tagMaskValueProperty, tagNames, true, (int pos, bool selected) =>
                {
                    if (selected)
                    {
                        tagMaskValueProperty.intValue = tagMaskValueProperty.intValue.SetBit(pos);
                    }
                    else
                    {
                        tagMaskValueProperty.intValue = tagMaskValueProperty.intValue.UnsetBit(pos);
                    }

                    tagMaskProperty.serializedObject.ApplyModifiedProperties();
                });

                Rect    buttonRect       = controlRect;
                Vector2 adjustedPosition = EditorGUIUtility.GUIToScreenPoint(buttonRect.position);
                buttonRect.position = adjustedPosition;

                tagMaskPopup.ShowAsDropDown(buttonRect, tagMaskPopup.GetWindowSize(controlRect));
            }
        }