Inheritance: UnityEngine.ScriptableObject
Example #1
0
 public static FGTextBufferManager Instance()
 {
     if (_instance == null)
     {
         var allInstances = Resources.FindObjectsOfTypeAll(typeof(FGTextBufferManager)) as FGTextBufferManager[];
         if (allInstances.Length > 0)
         {
             _instance = allInstances[0];
             //Debug.LogWarning("Found existing instances - " + allInstances.Length);
         }
         else
         {
             _instance = ScriptableObject.CreateInstance <FGTextBufferManager>();
             //Debug.LogWarning("Created a new instance!");
         }
         _instance.hideFlags = HideFlags.HideAndDontSave;
     }
     return(_instance);
 }
        private void DrawEventListener(Rect rect, int index, bool isactive, bool isfocused)
        {
            var  element            = listenersArray.GetArrayElementAtIndex(index);
            var  propertyMethodName = element.FindPropertyRelative("m_MethodName");
            bool isDefined          = !string.IsNullOrEmpty(propertyMethodName.stringValue);

            MethodInfo method = null;

            if (isDefined && currentEvent != null)
            {
                try
                {
                    rebuildMethod.Invoke(currentEvent, null);
                } catch {}
                persistentCallGroup = persistentCallsField.GetValue(currentEvent);
                var persistentCall = getListenerMethod.Invoke(persistentCallGroup, new object[] { index });
                method = findMethodMethod.Invoke(currentEvent, new [] { persistentCall }) as MethodInfo;

                isDefined = false;
                if (method != null)
                {
                    var declaringType = method.DeclaringType;
                    if (declaringType != null)
                    {
                        var name = declaringType.Assembly.GetName().Name.ToLowerInvariant();
                        isDefined = name == "assembly-csharp" || name == "assembly-csharp-firstpass" ||
                                    name == "assembly-csharp-editor" || name == "assembly-csharp-editor-firstpass";
                    }
                }
            }

            bool isDoubleClick = Event.current.type == EventType.MouseDown &&
                                 Event.current.clickCount == 2 && rect.Contains(Event.current.mousePosition);

            Rect rc = rect;

            rc.y     += 3f;
            rc.height = 15f;
            rc.xMin   = rc.xMax - 21f;
            rc.width  = 21f;

            rect.width -= 20f;
            if (originalCallback != null)
            {
                originalCallback(rect, index, isactive, isfocused);
            }

            if (isactive && isfocused && Event.current.type == EventType.KeyDown && Event.current.character == '\n')
            {
                isDoubleClick = true;
            }

            bool wasEnabled = GUI.enabled;

            GUI.enabled = isDefined;
            bool isButtonClick = GUI.Button(rc, "...", EditorStyles.miniButtonRight);

            if (isDefined && (isButtonClick || isDoubleClick && Event.current.type != EventType.Used))
            {
                var declaringType = ReflectedTypeReference.ForType(method.DeclaringType).definition;
                if (declaringType != null)
                {
                    var member = declaringType.FindName(method.IsSpecialName ? method.Name.Substring("set_".Length) : method.Name, 0, false);
                    if (member != null)
                    {
                        List <SymbolDeclaration> declarations = null;

                        var methodGroup = member as MethodGroupDefinition;
                        if (member.kind == SymbolKind.MethodGroup && methodGroup != null)
                        {
                            var parameters = method.GetParameters();
                            foreach (var m in methodGroup.methods)
                            {
                                if (m.IsStatic)
                                {
                                    continue;
                                }

                                var p = m.GetParameters() ?? new List <ParameterDefinition>();
                                if (p.Count != parameters.Length)
                                {
                                    continue;
                                }

                                for (var i = p.Count; i-- > 0;)
                                {
                                    var pType = p[i].TypeOf();
                                    if (pType == null)
                                    {
                                        goto nextMethod;
                                    }

                                    var parameterType = ReflectedTypeReference.ForType(parameters[i].ParameterType).definition as TypeDefinitionBase;
                                    if (!pType.IsSameType(parameterType))
                                    {
                                        goto nextMethod;
                                    }
                                }

                                // Yay! We found it :)
                                declarations = m.declarations;
                                if (declarations == null || declarations.Count == 0)
                                {
                                    declarations = FGFindInFiles.FindDeclarations(m);
                                    if (declarations == null || declarations.Count == 0)
                                    {
                                        // Boo! Something went wrong.
                                        break;
                                    }
                                }

nextMethod:
                                continue;
                            }
                        }
                        else
                        {
                            // It's a property

                            declarations = member.declarations;
                            if (declarations == null || declarations.Count == 0)
                            {
                                declarations = FGFindInFiles.FindDeclarations(member);
                            }
                        }

                        if (declarations != null && declarations.Count > 0)
                        {
                            foreach (var decl in declarations)
                            {
                                var node = decl.NameNode();
                                if (node == null || !node.HasLeafs())
                                {
                                    continue;
                                }

                                string cuPath = null;
                                for (var scope = decl.scope; scope != null; scope = scope.parentScope)
                                {
                                    var cuScope = scope as CompilationUnitScope;
                                    if (cuScope != null)
                                    {
                                        cuPath = cuScope.path;
                                        break;
                                    }
                                }
                                if (cuPath == null)
                                {
                                    continue;
                                }

                                var cuObject = AssetDatabase.LoadAssetAtPath(cuPath, typeof(MonoScript));
                                if (cuObject == null)
                                {
                                    continue;
                                }

                                var buffer = FGTextBufferManager.GetBuffer(cuObject);
                                if (buffer == null)
                                {
                                    continue;
                                }

                                // Declaration is valid!

                                if (buffer.lines.Count == 0)
                                {
                                    buffer.LoadImmediately();
                                }
                                var span = buffer.GetParseTreeNodeSpan(node);
                                EditorApplication.delayCall += () =>
                                {
                                    FGCodeWindow.OpenAssetInTab(AssetDatabase.AssetPathToGUID(cuPath), span.line + 1);
                                };
                            }
                        }
                    }
                }
            }
            GUI.enabled = wasEnabled;
        }
 private void OnEnable()
 {
     hideFlags = HideFlags.HideAndDontSave;
     if (_instance == null)
         _instance = this;
     else if (_instance != this)
         Debug.LogError("Multiple Managers!!!");
 }