public IItem AddItem(IsoRect bounds, T content) { if (bounds.x.size > 0.0f && bounds.y.size > 0.0f) { if (_rootNode == null) { var initial_side = IsoUtils.Vec2From( IsoUtils.Vec2MaxF(bounds.size)); var initial_bounds = new IsoRect( bounds.center - initial_side * 2.0f, bounds.center + initial_side * 2.0f); _rootNode = _nodePool.Take().Init(null, initial_bounds); } Item item; while (!_rootNode.AddItem(bounds, content, out item, _nodePool, _itemPool)) { GrowUp( bounds.center.x < _rootNode.SelfBounds.center.x, bounds.center.y < _rootNode.SelfBounds.center.y); } return(item); } else { return(_itemPool.Take().Init(null, bounds, content)); } }
public bool AddItem( IsoRect bounds, T content, out Item item, IsoIPool <Node> node_pool, IsoIPool <Item> item_pool) { if (!SelfBounds.Contains(bounds)) { item = null; return(false); } for (int i = 0, e = Nodes.Length; i < e; ++i) { var node = Nodes[i]; if (node != null) { if (node.AddItem(bounds, content, out item, node_pool, item_pool)) { return(true); } } else if (Items.Count >= MinChildCountPerNode && NodeBounds[i].Contains(bounds)) { Nodes[i] = node = node_pool.Take().Init(this, NodeBounds[i]); if (node.AddItem(bounds, content, out item, node_pool, item_pool)) { return(true); } } } item = item_pool.Take().Init(this, bounds, content); Items.Add(item); return(true); }
// --------------------------------------------------------------------- // // Parents // // --------------------------------------------------------------------- void RegisterIsoObjectParent(IsoObject iso_object) { var parent = iso_object ? iso_object.transform.parent : null; if (parent) { ParentInfo parent_info; if (_parentToParentInfo.TryGetValue(parent, out parent_info)) { parent_info.IsoObjects.Add(iso_object); } else { parent_info = _parentInfoPool.Take().Init(parent); parent_info.IsoObjects.Add(iso_object); _parentToParentInfo.Add(parent, parent_info); _parentInfoList.Add(parent_info); } _isoObjectToParent.Add(iso_object, parent); } }