Exemplo n.º 1
0
        private NodeItem GetItem(CanvasData.Node node)
        {
            NodeItem value;

            if (nodeDictionary.TryGetValue(node, out value))
            {
                return(value);
            }

            return(null);
        }
Exemplo n.º 2
0
        private NodeItem AddItem(CanvasData.Node node)
        {
            // create view
            var view = viewPool.GetViewObject(node.prefab);

            // set as child
            var rt = view.GetComponent <RectTransform>();

            rt.SetParent(contentRT, false);

            // set pos and size
            rt.anchoredPosition = node.anchoredPosition;
            rt.sizeDelta        = node.sizeDelta;
            rt.rotation         = Quaternion.Euler(0f, 0f, node.rotation);

            // active view if not
            if (!view.activeSelf)
            {
                view.SetActive(true);
            }

            if (!string.IsNullOrEmpty(node.metadata))
            {
                var serializableCanvasNode = view.GetComponent <ISerializableCanvasNode>();
                Assert.IsNotNull(serializableCanvasNode);

                // deserialize metadata
                serializableCanvasNode.Deserialize(node.metadata);
            }

            // create item
            var item = nodeItemPool.GetObject();

            item.node      = node;
            item.transform = rt;

            // add it
            nodeDictionary.Add(node, item);
            nodeItemList.Add(item);

            if (NodeItemAdded != null)
            {
                // raise event
                NodeItemAdded.Invoke(item);
            }

            return(item);
        }
Exemplo n.º 3
0
        private void RemoveItem(CanvasData.Node node)
        {
            var item = nodeDictionary[node];

            // get view
            var view = item.transform.gameObject;

            // release view
            viewPool.ReleaseViewObject(view);

            // remove it
            nodeDictionary.Remove(node);
            nodeItemList.Remove(item);

            if (NodeItemRemoved != null)
            {
                // raise event
                NodeItemRemoved.Invoke(item);
            }

            // release item
            nodeItemPool.PutObject(item);
        }
Exemplo n.º 4
0
 public void Reset()
 {
     node            = null;
     transform       = null;
     referencedCount = 0;
 }