コード例 #1
0
 private static ContextGraph GetCurrentGraph()
 {
     if (!_cachedCurrent)
     {
         int guid = EditorPrefs.GetInt(_prefsKey, -1);
         if (guid > 0)
         {
             var ob = EditorUtility.InstanceIDToObject(guid);
             // BUG workaround: Should be looked at in the future to prevent data loss
             // Causes in some instances, Unity to retrieve the asset as a monoscript instance
             // rather than an actual instance of the asset's class type
             // For now, if this happens, the cached GUID reference to the asset is detached
             // to prevent casting errors
             if (!ob || ob.GetType() != typeof(ContextGraph))
             {
                 Debug.Log("<color=red>Context Grapher: Failed retrieving cached menu. Configuration needs to be reapplied.</color>");
                 EditorPrefs.SetInt(_prefsKey, -1);
             }
             else
             {
                 _cachedCurrent = ob != null ? (ContextGraph)ob : null;
             }
         }
     }
     return(_cachedCurrent);
 }
コード例 #2
0
        public static RecursiveNode GetRecursive(this ContextGraph graph)
        {
            if (graph.RootNode == null)
            {
                return(null);
            }
            Dictionary <string, RecursiveNode> nodes = new Dictionary <string, RecursiveNode>();

            foreach (var n in graph.Nodes)
            {
                var rn = new RecursiveNode
                {
                    id      = n.id,
                    label   = n.label,
                    command = n.command,
                    type    = n.Type,
                    yPos    = n.position.y
                };
                nodes.Add(rn.id, rn);
            }

            // check if there's a root node set
            RecursiveNode rootNode;

            if (!nodes.TryGetValue(graph.RootNode, out rootNode))
            {
                return(null);
            }



            foreach (var e in graph.Edges)
            {
                RecursiveNode from, to;
                if (!nodes.TryGetValue(e.from, out from))
                {
                    continue;
                }
                if (!nodes.TryGetValue(e.to, out to))
                {
                    continue;
                }
                from.children.Add(to);
            }
            SortChildren(rootNode);

            return(rootNode);
        }
コード例 #3
0
 public static void UseGraph(ContextGraph g)
 {
     EditorPrefs.SetInt(_prefsKey, g ? g.GetInstanceID() : -1);
     _cachedCurrent = g;
 }