Пример #1
0
        /// <inheritdoc cref="IDrawer.OnMouseUpAfterDownOverControl" />
        public override void OnMouseUpAfterDownOverControl(Event inputEvent, bool isClick)
        {
                        #if DEV_MODE && DEBUG_ON_CLICK
            Debug.Log(StringUtils.ToColorizedString(GetType(), ".OnMouseUpAfterDownOverControl(isClick=", isClick, ") with mouseOverHeaderPart=", MouseoveredHeaderPart, ", HeaderMouseovered=", HeaderMouseovered, ", Selectable=", Selectable, ", event=", StringUtils.ToString(inputEvent), ", mousePos=", inputEvent.mousePosition));
                        #endif

            if (isClick && HasEnabledFlag && MouseoveredHeaderPart == HeaderPart.EnabledFlag)
            {
                SelectHeaderPart(MouseoveredHeaderPart);

                if (!Selected)
                {
                    Select(HeaderMouseovered ? ReasonSelectionChanged.PrefixClicked : ReasonSelectionChanged.ControlClicked);
                }

                if (createCustomEnabledFlag)
                {
                    ComponentDrawerUtility.OnCustomEnabledControlClicked(this, inputEvent);

                    OnValidateHandler.CallForTargets(UnityObjects);

                    if (OnValueChanged != null)
                    {
                        OnValueChanged(this, Target);
                    }

                    if (parent != null)
                    {
                        parent.OnMemberValueChanged(Array.IndexOf(parent.Members, this), Target, null);
                    }
                }
                else
                {
                    OnNextLayout(() =>
                    {
                        OnValidateHandler.CallForTargets(UnityObjects);

                        if (OnValueChanged != null)
                        {
                            OnValueChanged(this, Target);
                        }

                        if (parent != null)
                        {
                            parent.OnMemberValueChanged(Array.IndexOf(parent.Members, this), Target, null);
                        }
                    });
                }

                //if using built in enabled flag
                //don't consume click event so that it will cause
                //the enabled state of the component to change
                return;
            }

            base.OnMouseUpAfterDownOverControl(inputEvent, isClick);
        }
        /// <summary>
        /// called when the left mouse button is released
        /// if it was pressed down while being over this
        /// </summary>
        public override void OnMouseUpAfterDownOverControl(Event inputEvent, bool isClick)
        {
            if (isClick && HasEnabledFlag && MouseoveredHeaderPart == HeaderPart.EnabledFlag)
            {
                SelectHeaderPart(MouseoveredHeaderPart);

                if (!Selected)
                {
                    Select(HeaderMouseovered ? ReasonSelectionChanged.PrefixClicked : ReasonSelectionChanged.ControlClicked);
                }

                if (createCustomEnabledFlag)
                {
                    ComponentDrawerUtility.OnCustomEnabledControlClicked(this, inputEvent);

                    OnValidateHandler.CallForTargets(UnityObjects);

                    if (OnValueChanged != null)
                    {
                        OnValueChanged(this, Target);
                    }

                    if (parent != null)
                    {
                        parent.OnMemberValueChanged(Array.IndexOf(parent.Members, this), Target, null);
                    }
                }
                else
                {
                    OnNextLayout(() =>
                    {
                        OnValidateHandler.CallForTargets(UnityObjects);

                        if (OnValueChanged != null)
                        {
                            OnValueChanged(this, Target);
                        }

                        if (parent != null)
                        {
                            parent.OnMemberValueChanged(Array.IndexOf(parent.Members, this), Target, null);
                        }
                    });
                }

                //if using built in enabled flag
                //don't consume click event so that it will cause
                //the enabled state of the component to change
                return;
            }

            base.OnMouseUpAfterDownOverControl(inputEvent, isClick);
        }
Пример #3
0
        /// <summary>
        /// Invokes the Method, returns method return value and outputs possible error descriptions encountered.
        /// </summary>
        /// <param name="index"> Index of target on which to invoke method. </param>
        /// <param name="error"> [out] True if should display message to user about invoking or possible exceptions. </param>
        protected object GetValue(int index, [NotNull] out string error)
        {
            // generics and parameter info is needed from members
            // so build them if they have not yet been built
            // (i.e. if MethodDrawer has yet to be unfolded)
            if (memberBuildState == MemberBuildState.BuildListGenerated)
            {
                BuildMembers();
            }

            bool runAsCoroutine;

            MethodInfo methodInfo;

            if (isGeneric)
            {
                runAsCoroutine = false;

                try
                {
                    var genericTypes = GenericsDrawer.Value;

                                        #if DEV_MODE && DEBUG_INVOKE
                    Debug.Log("Making generic method of " + MethodInfo.Name + " from " + genericTypes.Length + " generic types: " + StringUtils.ToString(genericTypes));
                                        #endif

                    //needed?
                    if (genericTypes.Length == 1)
                    {
                        methodInfo = MethodInfo.MakeGenericMethod(genericTypes[0]);
                    }
                    //needed?
                    else if (genericTypes.Length == 2)
                    {
                        methodInfo = MethodInfo.MakeGenericMethod(genericTypes[0], genericTypes[1]);
                    }
                    else
                    {
                        methodInfo = MethodInfo.MakeGenericMethod(genericTypes);
                    }
                }
                catch (Exception e)
                {
                    if (ExitGUIUtility.ShouldRethrowException(e))
                    {
                        throw;
                    }
                    error = e.ToString();
                    return(DefaultValue());
                }
            }
            else
            {
                try
                {
                    methodInfo = MethodInfo;
                }
                catch (Exception e)
                {
                    error = e.ToString();
                    return(DefaultValue());
                }

                if (isCoroutine)
                {
                    if (!Inspector.Preferences.askAboutStartingCoroutines)
                    {
                        runAsCoroutine = true;
                    }
                    else
                    {
                        switch (DrawGUI.Active.DisplayDialog("Invoke as coroutine?", "The method return type is IEnumerable. Would you like to start it as a coroutine?", "Start As Coroutine", "Invoke As Normal Method", "Cancel"))
                        {
                        case 0:
                            runAsCoroutine = true;
                            break;

                        case 1:
                            runAsCoroutine = false;
                            break;

                        case 2:
                            ExitGUIUtility.ExitGUI();
                            error = "";
                            return(result);

                        default:
                                                                #if DEV_MODE
                            throw new IndexOutOfRangeException();
                                                                #else
                            runAsCoroutine = false;
                            break;
                                                                #endif
                        }
                    }
                }
                else
                {
                    runAsCoroutine = false;
                }
            }

            object returnValue;

            var parameters = hasParameters ? ParameterDrawer.Value : null;

                        #if DEV_MODE && PI_ASSERTATIONS
            if (hasParameters && (parameters == null || parameters.Length == 0))
            {
                Debug.LogError("hasParameters was " + StringUtils.True + " but params was " + StringUtils.ToString(parameters));
            }
                        #endif

            try
            {
                                #if DEV_MODE && DEBUG_INVOKE
                Debug.Log("Invoking method " + methodInfo.Name + " with " + (parameters == null ? "" : parameters.Length + " ") + "params=" + StringUtils.ToString(parameters) + ", hasParameters=" + StringUtils.ToColorizedString(hasParameters) + ", runAsCoroutine=" + runAsCoroutine);
                                #endif

                // this can be null for static methods
                var fieldOwner = memberInfo.GetFieldOwner(index);

                //get return value by invoking method with current parameter values
                returnValue = methodInfo.Invoke(fieldOwner, parameters);

                if (runAsCoroutine)
                {
                                        #if UNITY_EDITOR
                    if (!Application.isPlaying)
                    {
                        StaticCoroutine.StartCoroutineInEditMode((IEnumerator)returnValue);
                    }
                    else if (monoBehaviour != null)
                                        #else
                    if (monoBehaviour != null)
                                        #endif
                    {
                        monoBehaviour.StartCoroutine((IEnumerator)returnValue);
                    }
                    else
                    {
                        StaticCoroutine.StartCoroutine((IEnumerator)returnValue);
                    }
                }

                if (hasParameters)
                {
                    //update parameter Drawer with values of parameters so that changes made to parameters
                    //(e.g. via ref and out) get shown in the ParameterDrawer
                    var paramMembers      = ParameterDrawer.Members;
                    int paramMembersCount = paramMembers.Length;
                    for (int n = ParameterDrawer.parameterInfos.Length - 1; n >= 0; n--)
                    {
                        var paramInfo = ParameterDrawer.parameterInfos[n];
                        if (paramInfo.ParameterType.IsByRef && paramMembersCount > n)
                        {
                            var memb = ParameterDrawer.Members[n];
                            if (memb.Type == paramInfo.ParameterType.GetElementType())
                            {
                                                                #if DEV_MODE && DEBUG_INVOKE
                                Debug.Log("param #" + n + " \"" + memb.Name + "\" value: " + StringUtils.ToString(parameters[n]));
                                                                #endif
                                memb.SetValue(parameters[n]);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Inspector.Preferences.messageDisplayMethod == MessageDisplayMethod.None)
                {
                    Debug.LogError(e);
                }
                else
                {
                    InspectorUtility.ActiveInspector.Message(e.ToString(), null, MessageType.Error);
                }
                returnValue = DefaultValue();
            }

                        #if CALL_ON_VALIDATE
            if (!methodInfo.IsStatic && methodInfo.GetCustomAttributes(typeof(PureAttribute), false).Length == 0)
            {
                OnValidateHandler.CallForTargets(UnityObjects);
            }
                        #endif

            error = "";
            return(returnValue);
        }