public object Load(INodeLoader loader, out int errors)
        {
            object instance = FindOrMakeInstance();

            errors = Load(loader, ref instance);
            return(instance);
        }
示例#2
0
        /// <summary>
        ///     Adds a node loader to this manager, for the given type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="nodeType"></param>
        /// <param name="loader"></param>
        internal void AddLoader <T>(Type nodeType, INodeLoader <T> loader) where T : NodeModel
        {
            if (!nodeType.IsSubclassOf(typeof(NodeModel)))
            {
                throw new ArgumentException(@"Given type is not a subclass of NodeModel.", "nodeType");
            }

            nodeLoaders[nodeType] = loader;
            alsoKnownAsMappings[nodeType.FullName] = nodeType;
        }
示例#3
0
        private bool GetNodeSourceFromType(Type type, out INodeLoader <NodeModel> data)
        {
            if (GetNodeSourceFromTypeHelper(type, out data))
            {
                return(true); // Found among built-in types, return it.
            }
            Log(string.Format("Could not load node of type: {0}", type.FullName));

            return(false);
        }
示例#4
0
        // TODO: Need furture clarification about the load process
        internal bool UpdateFromHierarchy(INodeLoader assembleController)
        {
            var needFresh = UpdateWindowList(assembleController);

            if (needFresh)
            {
                PrepareList(this.windowList);
                UpdateVisibility();
            }
            return(needFresh);
        }
        public int Load(INodeLoader loader, ref object instance)
        {
            var load = new NodeLoader {
                Loader = loader
            };
            var node = instance as IConfigNode;

            node?.BeforeLoaded();
            int count = Apply(ref instance, load);

            node?.AfterLoaded();
            return(count);
        }
示例#6
0
        private bool GetNodeSourceFromTypeHelper(Type type, out INodeLoader <NodeModel> data)
        {
            while (true)
            {
                if (type == null || type == typeof(NodeModel))
                {
                    data = null;
                    return(false);
                }

                if (nodeLoaders.TryGetValue(type, out data))
                {
                    return(true); // Found among built-in types, return it.
                }
                type = type.BaseType;
            }
        }
示例#7
0
        public void LoadWindows(INodeLoader assembleController, Action <Rect> layoutCallback)
        {
            if (assembleController == null)
            {
                // TODO: Clean the screen when assembleController is null
                layoutCallback(Rect.zero);
            }
            this.assembleController = assembleController;
            var needRefresh = UpdateFromHierarchy(assembleController);

            if (needRefresh)
            {
                ApplyAssembleFlow(this.windowList, assembleController);
                PrepareList(windowList);
                this.isDirty = false;
            }
            LayoutWindows(layoutCallback);
        }
示例#8
0
        private bool UpdateWindowList(INodeLoader assembleController)
        {
            bool needRefresh = false;
            // A bit hacky, but so far the best way to convert any type to T
            IEnumerable <T> nodeList           = assembleController.GetAllNodes <T>();
            var             nodeSetToBeDeleted = new HashSet <int>(windowList.Keys);

            foreach (var node in nodeList)
            {
                WindowItem <T> window;
                this.windowList.TryGetValue(node.GetID(), out window);
                if (window != null)
                {
                    // Exist item, just remove from node set and do nothing
                    nodeSetToBeDeleted.Remove(node.GetID());

                    if (window.IsDeleted())
                    {
                        window.MarkDeleted(false);
                    }
                    if (node.GetName() != window.GetNodeName())
                    {
                        window.UpdateNodeName(node.GetName());
                        needRefresh = true;
                    }
                }
                else
                {
                    // The key is new, add new item
                    var newWindow = new WindowItem <T>(node);
                    this.windowList.Add(newWindow.GetNodeId(), newWindow);
                    needRefresh = true;
                    //Debug.Log("Added item " + newWindow.GetNodeId());
                }
            }
            foreach (var item in nodeSetToBeDeleted)
            {
                this.windowList[item].MarkDeleted(true);
                needRefresh = true;
                Debug.Log("Item deleted " + item);
            }
            return(needRefresh);
        }
示例#9
0
 /// <summary>
 ///     Adds a node loader to this manager.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="loader"></param>
 internal void AddLoader <T>(INodeLoader <T> loader) where T : NodeModel
 {
     AddLoader(typeof(T), loader);
 }
示例#10
0
        private void ApplyAssembleFlow(IDictionary <int, WindowItem <T> > windowList, INodeLoader assembleController)
        {
            var flowString = assembleController.GetAssembleFlowAsset() == null ? "" : assembleController.GetAssembleFlowAsset().text;

            assembleController.ParseAssembleFlowFile(flowString, (int step0, int step1) =>
            {
                WindowItem <T> w0;
                WindowItem <T> w1;
                if (windowList.TryGetValue(step0, out w0) && windowList.TryGetValue(step1, out w1))
                {
                    w1.AddPreviousStep(w0);
                }
                else
                {
                    Debug.LogError("Failed to create flow nodes of " + step0 + "->" + step1);
                }
            });
        }
 public void LoadContent(INodeLoader myController)
 {
     this.target        = myController;
     this.windowManager = new WindowManager <T>();
     windowManager.LoadWindows(myController, (r) => this.panelSize = r.size);
 }
示例#12
0
 public LazyLoadedGraph(INodeLoader <TNode, TEdgeTag> nodeLoader)
 {
     _nodeLoader = nodeLoader;
 }