Ejemplo n.º 1
0
    static bool GetStackFramListFromUnity(ref List <LogStackFrame> stackFrameList, out LogStackFrame orginStackFrame)
    {
        stackFrameList.Clear();
        orginStackFrame = null;
        StackTrace stackTrace = new StackTrace(true);

        StackFrame[] stackFrames            = stackTrace.GetFrames();
        bool         MeetFirstIgnoredMethod = false;

        for (int i = stackFrames.Length - 1; i > 0; i--)
        {
            StackFrame tempStackFrame = stackFrames[i];
            var        method         = tempStackFrame.GetMethod();
            if (method.IsDefined(typeof(OnlyUnityLog), true))
            {
                return(true);
            }
            if (!method.IsDefined(typeof(ExcludeStackTrace), true))
            {
                UnityMethod.MethodMode mode = UnityMethod.GetMehodMode(method);
                bool isShowed;
                if (mode == UnityMethod.MethodMode.Show)
                {
                    isShowed = true;
                }
                else
                {
                    isShowed = false;
                }
                if (mode == UnityMethod.MethodMode.ShowFirst)
                {
                    if (!MeetFirstIgnoredMethod)
                    {
                        MeetFirstIgnoredMethod = true;
                        mode = UnityMethod.MethodMode.Show;
                    }
                    else
                    {
                        mode = UnityMethod.MethodMode.Hide;
                    }
                }
                if (mode == UnityMethod.MethodMode.Show)
                {
                    LogStackFrame logStackFrame = new LogStackFrame(tempStackFrame);
                    stackFrameList.Add(logStackFrame);
                    if (isShowed)
                    {
                        orginStackFrame = logStackFrame;
                    }
                }
            }
        }
        return(false);
    }
        /// <inheritdoc />
        protected override void RenderMemberControl(Rect position)
        {
            // Other Targets
            // Some Unity Objects, like Assets, are not supported by the drawer.
            // Just display an error message to let the user change their target.

            if (targetType == UnityObjectType.Other)
            {
                EditorGUI.HelpBox(position, "Unsupported Unity Object type.", MessageType.None);
                return;
            }

            // Display a list of all available reflected members in a popup.

            var options = new List <PopupOption <TMember> >();

            TMember value = GetValue();

            PopupOption <TMember> selectedOption = null;
            PopupOption <TMember> noneOption     = new PopupOption <TMember>(null, string.Format("No {0}", memberLabel));

            if (targetType == UnityObjectType.GameObject)
            {
                // Check if all targets have a GameObject (none are empty).
                // If they do, display all members of the GameObject type.

                if (HasSharedGameObject())
                {
                    var gameObjectOptions = GetMemberOptions(typeof(GameObject));

                    foreach (var gameObjectOption in gameObjectOptions)
                    {
                        // Prefix label by GameObject for popup clarity.

                        gameObjectOption.label = string.Format("GameObject/{0}", gameObjectOption.label);

                        options.Add(gameObjectOption);
                    }
                }

                // Find all shared component types across targets.
                // Display all members of each one found.

                foreach (Type componentType in GetSharedComponentTypes())
                {
                    var componentOptions = GetMemberOptions(componentType, componentType.Name);

                    foreach (var componentOption in componentOptions)
                    {
                        // Prefix label and option by component type for clear distinction.

                        componentOption.label = string.Format("{0}/{1}", componentType.Name, componentOption.label);

                        options.Add(componentOption);
                    }
                }

                // Determine which option is currently selected.

                if (value != null)
                {
                    string label;

                    if (value.component == null)
                    {
                        label = string.Format("GameObject.{0}", value.name);
                    }
                    else
                    {
                        label = string.Format("{0}.{1}", value.component, value.name);
                    }

                    UnityMethod method = value as UnityMethod;

                    if (method != null)
                    {
                        string parameterString = string.Join(", ", method.parameterTypes.Select(t => t.PrettyName()).ToArray());

                        label += string.Format(" ({0})", parameterString);
                    }

                    TMember valueInOptions = options.Select(option => option.value).FirstOrDefault(member => member.Corresponds(value));

                    if (valueInOptions != null)
                    {
                        selectedOption = new PopupOption <TMember>(valueInOptions, label);
                    }
                    else
                    {
                        selectedOption = new PopupOption <TMember>(value, label);
                    }
                }
            }
            else if (targetType == UnityObjectType.ScriptableObject)
            {
                // ScriptableObject Target
                // Make sure all targets share the same ScriptableObject Type.
                // If they do, display all members of that type.

                Type scriptableObjectType = GetSharedScriptableObjectType();

                if (scriptableObjectType != null)
                {
                    options.AddRange(GetMemberOptions(scriptableObjectType));

                    // Determine which option is currently selected.

                    if (value != null)
                    {
                        selectedOption = options.Find(o => o.value.Corresponds(value));

                        if (selectedOption == null)
                        {
                            selectedOption = new PopupOption <TMember>(value, value.name);
                        }
                    }
                }
            }

            // Make sure the callback uses the property of this drawer, not at its later value.
            var propertyNow = property;

            bool enabled = targetType != UnityObjectType.None;

            if (!enabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            PopupGUI <TMember> .Render
            (
                position,
                newValue =>
            {
                Update(propertyNow);
                SetValue(newValue);
                propertyNow.serializedObject.ApplyModifiedProperties();
            },
                options,
                selectedOption,
                noneOption,
                hasMultipleDifferentValues
            );

            if (!enabled)
            {
                EditorGUI.EndDisabledGroup();
            }
        }