public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    {
        InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)this.attribute;
        Rect buttonRect = new Rect(position.x, position.y, position.width, UnityEditor.EditorGUIUtility.singleLineHeight);

        if (GUI.Button(buttonRect, !string.IsNullOrEmpty(inspectorButtonAttribute.ButtonLabel) ? inspectorButtonAttribute.ButtonLabel : label.text))
        {
            System.Type eventOwnerType = prop.serializedObject.targetObject.GetType();
            string      eventName      = inspectorButtonAttribute.MethodName;

            if (eventMethodInfo == null)
            {
                eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            }

            if (eventMethodInfo != null)
            {
                eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
            }
            else
            {
                Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
            }
        }

        position = new Rect(position.x, position.y + UnityEditor.EditorGUIUtility.singleLineHeight + UnityEditor.EditorGUIUtility.standardVerticalSpacing, position.width, UnityEditor.EditorGUIUtility.singleLineHeight);
        EditorGUI.PropertyField(position, prop, label);
    }
    public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    {
        InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;

        GUI.color = inspectorButtonAttribute.btnColor;

        Rect buttonRect = new Rect(position.x + (position.width - inspectorButtonAttribute.ButtonWidth) * 0.5f, position.y, inspectorButtonAttribute.ButtonWidth, position.height + 5);

        if (GUI.Button(buttonRect, label.text))
        {
            System.Type eventOwnerType = prop.serializedObject.targetObject.GetType();
            string      eventName      = inspectorButtonAttribute.MethodName;

            if (_eventMethodInfo == null)
            {
                _eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            }

            if (_eventMethodInfo != null)
            {
                _eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
            }
            else
            {
                Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
            }
        }
        GUI.color = Color.white;
    }
Exemplo n.º 3
0
    public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    {
        InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;
        Rect buttonRect = new Rect(position.x, position.y, position.width, position.height);

        if (GUI.Button(buttonRect, label.text))
        {
            Type   eventOwnerType = prop.serializedObject.targetObject.GetType();
            string eventName      = inspectorButtonAttribute.MethodName;

            do
            {
                eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                eventOwnerType  = eventOwnerType.BaseType;
            } while (eventMethodInfo == null);

            if (eventMethodInfo != null)
            {
                eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
            }
            else
            {
                Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
            }
        }
    }
Exemplo n.º 4
0
    public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    {
        InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;

        int num = 1 + (!string.IsNullOrEmpty(inspectorButtonAttribute.MethodName2) ? 1 : 0) + (!string.IsNullOrEmpty(inspectorButtonAttribute.MethodName3) ? 1 : 0);
        //Rect buttonRect = new Rect(position.x + (position.width - inspectorButtonAttribute.ButtonWidth) * 0.5f, position.y, inspectorButtonAttribute.ButtonWidth, position.height);
        float buttonWidth = position.width / num;

        {
            Rect buttonRect = new Rect(position.x + buttonWidth * 0, position.y, buttonWidth, position.height);
            if (GUI.Button(buttonRect, inspectorButtonAttribute.MethodName))
            {
                Execute(prop, inspectorButtonAttribute.MethodName);
            }
        }

        if (!string.IsNullOrEmpty(inspectorButtonAttribute.MethodName2))
        {
            Rect buttonRect = new Rect(position.x + buttonWidth * 1, position.y, buttonWidth, position.height);
            if (GUI.Button(buttonRect, inspectorButtonAttribute.MethodName2))
            {
                Execute(prop, inspectorButtonAttribute.MethodName2);
            }
        }

        if (!string.IsNullOrEmpty(inspectorButtonAttribute.MethodName3))
        {
            Rect buttonRect = new Rect(position.x + buttonWidth * 2, position.y, buttonWidth, position.height);
            if (GUI.Button(buttonRect, inspectorButtonAttribute.MethodName3))
            {
                Execute(prop, inspectorButtonAttribute.MethodName3);
            }
        }
    }
Exemplo n.º 5
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;
        Rect buttonRect = new Rect(position.x + (position.width - (Screen.width / 1.2f)) * 0.5f, position.y + 5, (Screen.width / 1.2f), position.height - 10);

        if (GUI.Button(buttonRect, label.text))
        {
            Object      eventOwner     = property.serializedObject.targetObject;
            System.Type eventOwnerType = eventOwner.GetType();
            string      eventName      = inspectorButtonAttribute.MethodName;

            Undo.RecordObject(eventOwner, eventName);

            if (_eventMethodInfo == null)
            {
                _eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            }

            if (_eventMethodInfo != null)
            {
                _eventMethodInfo.Invoke(property.serializedObject.targetObject, null);
            }
            else
            {
                Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
            }
        }
    }
Exemplo n.º 6
0
        public InspectorButtonMethod(InspectorButtonAttribute attribute, object target)
        {
            this.attribute  = attribute;
            declaringObject = target;
            method          = ReflectionUtils.GetCachedMethod(target.GetType(), attribute.MethodName);
            if (method == null)
            {
                errorMessage = $"{nameof(InspectorButtonAttribute)} refers to a missing method '{attribute.MethodName}' in '{target.GetType()}' class";
                return;
            }

            checkIfShouldBeDrawed = ReflectionUtils.GetCachedMethod(target.GetType(), $"__{attribute.MethodName}__");

            HasFontAwesomeTitile = DrawerHelper.ContainsFontAwesomeString(attribute.Label);
            IsCoroutine          = method.ReturnType == typeof(IEnumerator);
            paramsInfos          = method.GetParameters();

            arguments = new object[paramsInfos.Length];

            var title = ObjectNames.NicifyVariableName(attribute.MethodName);

            accordion = new SimpleAccordion($"{title} Function Arguments", DrawArguments);
            accordion.drawHeaderCallback = () => SimpleAccordion.DrawDefaultAccordionHeader(accordion, 14, 8);

            var index = 0;

            foreach (var param in paramsInfos)
            {
                arguments[index] = ReflectionUtils.DefaultValue(param.ParameterType);
                index++;
            }
        }
Exemplo n.º 7
0
    private static Rect GetButtonRect(Rect position, InspectorButtonAttribute inspectorButtonAttribute)
    {
        float x = position.x;

        if (inspectorButtonAttribute.CenterAlign)
        {
            x = position.x + (position.width - inspectorButtonAttribute.ButtonWidth) * 0.5f;
        }
        return(new Rect(x, position.y, inspectorButtonAttribute.ButtonWidth, position.height));
    }
Exemplo n.º 8
0
        private void OnEnable()
        {
            if (Target == null)
            {
                return;
            }
            var methodsList = new List <InspectorMethodButton>();

            MethodInfo[] allMethods = Target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            int          length     = allMethods.Length;

            for (int i = 0; i < length; i++)
            {
                InspectorButtonAttribute buttonAtt = allMethods[i].GetSingleCustomAttribute <InspectorButtonAttribute>(true);
                if (buttonAtt != null)
                {
                    methodsList.Add(new InspectorMethodButton(buttonAtt, allMethods[i]));
                }
            }
            kvpMethods = methodsList.ToArray();
        }
Exemplo n.º 9
0
    public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    {
        InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;

        if (GUI.Button(position, label.text))
        {
            System.Type eventOwnerType = prop.serializedObject.targetObject.GetType();
            string      eventName      = inspectorButtonAttribute.MethodName;

            if (_eventMethodInfo == null)
            {
                _eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            }

            if (_eventMethodInfo != null)
            {
                _eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
            }
            else
            {
                Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
            }
        }
    }
Exemplo n.º 10
0
 public InspectorMethodButton(InspectorButtonAttribute att, MethodInfo method)
 {
     Att    = att;
     Method = method;
 }
    public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
    {
        InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;

        return(base.GetPropertyHeight(prop, label) * inspectorButtonAttribute.ButtonHeight * 0.075f);
    }