Beispiel #1
0
        private void ShowContextMenuAtMouse(SerializedProperty property)
        {
            GenericMenu       menu = new GenericMenu();
            GraphVarAttribute attr = (GraphVarAttribute)attribute;

            object target = PropertyUtility.GetTargetObjectWithProperty(property);

            object valuesObject = GetValues(property, attr.ValuesName);

            menu.AddItem(new GUIContent(FSMTargetBehaviour.UndefinedTag), false, () => SelectMatInfo(property, FSMTargetBehaviour.UndefinedTag, target));



            if (valuesObject is IList)
            {
                IList valuesList = (IList)valuesObject;

                for (int i = 0; i < valuesList.Count; i++)
                {
                    GUIContent content = new GUIContent(valuesList[i].ToString());
                    menu.AddItem(content, valuesList[i].ToString() == property.stringValue, () => SelectMatInfo(property, content.text, target));
                }
            }

            menu.ShowAsContext();
        }
Beispiel #2
0
        private void SelectMatInfo(SerializedProperty property, string stateNode, object target)
        {
            GraphVarAttribute nodeFilter = (GraphVarAttribute)attribute;

            property.stringValue = stateNode;

            FieldInfo fieldInfo = ReflectionUtility.GetField(target, property.name);
            object    oldValue  = fieldInfo.GetValue(target);

            property.serializedObject.ApplyModifiedProperties(); // We must apply modifications so that the new value is updated in the serialized object
            object newValue = fieldInfo.GetValue(target);

            property.serializedObject.Update();



            MethodInfo callbackMethod = ReflectionUtility.GetMethod(target, nodeFilter.CallbackName);

            InvoKeCallback(callbackMethod, property, target, oldValue, newValue);
        }
Beispiel #3
0
        private void ContextPopUp(Rect position, SerializedProperty property, GUIContent label)
        {
            // Throw error on wrong type
            if (property.propertyType != SerializedPropertyType.String)
            {
                throw new ArgumentException("Parameter selected must be of type System.String");
            }
            EditorGUI.BeginChangeCheck();

            Rect buttonRect = position;
            Rect buttonGo   = position;

            string currentValue = property.stringValue;

            if (string.IsNullOrEmpty(currentValue))
            {
                property.stringValue = FSMTargetBehaviour.UndefinedTag;
                currentValue         = property.stringValue;
            }

            if (GUI.Button(buttonRect, currentValue))
            {
                GraphVarAttribute attr = (GraphVarAttribute)attribute;

                if (attr.UseNodeEnum)
                {
                    NodeEditorWindow.current.onLateGUI += () => ShowContextMenuAtMouse(property);
                }
                else
                {
                    ShowContextMenuAtMouse(property);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }