예제 #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            SerializedProperty valueProperty      = property.FindPropertyRelative("_value");
            SerializedProperty tagLibraryProperty = property.FindPropertyRelative("_tagLibrary");

            position.height = 16;
            tagLibraryProperty.objectReferenceValue = EditorGUI.ObjectField(position, tagLibraryProperty.objectReferenceValue, typeof(ImpactTagLibraryBase), false);

            position.y     += 18;
            position.height = 16;

            ImpactTagLibraryBase tagLibrary = tagLibraryProperty.objectReferenceValue as ImpactTagLibraryBase;

            if (tagLibrary != null)
            {
                ImpactTagNameList tagNames = new ImpactTagNameList(ImpactTagLibraryConstants.TagCount);
                ImpactEditorUtilities.GetTagNames(tagLibrary, ref tagNames);

                ImpactEditorUtilities.TagDropdown(property, valueProperty, tagNames, position);
            }
            else
            {
                valueProperty.intValue = EditorGUI.IntField(position, valueProperty.intValue);
            }

            EditorGUI.EndProperty();
        }
예제 #2
0
        public static string GetSelectedTags(int tagMaskValue, ImpactTagNameList tagNames, bool newline)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < tagNames.Length; i++)
            {
                if (tagMaskValue.IsBitSet(i))
                {
                    sb.Append(tagNames[i]);

                    if (newline)
                    {
                        sb.Append("\n");
                    }
                    else
                    {
                        sb.Append(", ");
                    }
                }
            }

            if (sb.Length == 0)
            {
                sb.Append("Nothing");
            }
            else
            {
                sb.Remove(sb.Length - (newline ? 1 : 2), newline ? 1 : 2);
            }


            return(sb.ToString());
        }
예제 #3
0
        public void Initialize(SerializedProperty tagMaskValueProperty, ImpactTagNameList tagNames, bool isMask, Action <int, bool> tagSelectedChangedCallback)
        {
            this.isMask                     = isMask;
            this.tagValueProperty           = tagMaskValueProperty;
            this.tagNames                   = tagNames;
            this.tagSelectedChangedCallback = tagSelectedChangedCallback;

            search      = "";
            searchField = new SearchField();
        }
예제 #4
0
        public static void GetTagNames(IImpactTagLibrary tagLibrary, ref ImpactTagNameList tagNames)
        {
            tagNames.ActiveTagCount = 0;

            for (int i = 0; i < ImpactTagLibraryConstants.TagCount; i++)
            {
                if (tagLibrary != null && !string.IsNullOrEmpty(tagLibrary[i]))
                {
                    tagNames.ActiveTagCount++;
                    tagNames[i] = i + ": " + tagLibrary[i];
                }
                else
                {
                    tagNames[i] = "";
                }
            }
        }
        private void OnEnable()
        {
            material = target as ImpactMaterial;

            tagLibraryProperty       = serializedObject.FindProperty("_tagLibrary");
            materialTagsMaskProperty = serializedObject.FindProperty("_materialTagsMask");

            interactionSetsProperty = serializedObject.FindProperty("_interactionSets");

            fallbackTagsMaskProperty = serializedObject.FindProperty("_fallbackTagMask");

            tagNames = new ImpactTagNameList(ImpactTagLibraryConstants.TagCount);
            updateTagNames();

            for (int i = 0; i < material.InteractionSetCount; i++)
            {
                interactionFoldouts.Add(false);
            }
        }
예제 #6
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));
            }
        }
예제 #7
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));
            }
        }
예제 #8
0
        public static void TagMaskPropertyEditor(SerializedProperty tagMaskProperty, GUIContent label, ImpactTagNameList tagNames)
        {
            SerializedProperty tagMaskValueProperty = tagMaskProperty.FindPropertyRelative("_value");

            //Fallback for if no tags are given
            if (tagNames.ActiveTagCount == 0)
            {
                EditorGUILayout.PropertyField(tagMaskValueProperty, label);
                tagMaskProperty.serializedObject.ApplyModifiedProperties();
            }
            else
            {
                Rect totalRect   = GUILayoutUtility.GetRect(new GUIContent(), EditorStyles.layerMaskField);
                Rect controlRect = EditorGUI.PrefixLabel(totalRect, label);

                TagMaskDropdown(tagMaskProperty, tagMaskValueProperty, tagNames, controlRect);
            }
        }