コード例 #1
0
        private void AddSites(List <Bubbles.Node> nodes)         //jf
        {
            Vector2 p = new Vector2();

            for (int i = 0; i < nodes.Count; ++i)
            {
                Bubbles.Node node = nodes[i];
                p.x = node.x; p.y = node.y;
                //move toward zero, so stay within plotBounds. Guarantee unique position of all nodes
                while (_sitesIndexedByLocation.ContainsKey(p))
                {
                    p.x += (p.x < 0)? UnityEngine.Random.Range(0, 0.000001f): -UnityEngine.Random.Range(0, 0.000001f);
                }
                if (node.site == null)
                {
                    node.site = Site.Create(p, (uint)i, node);
                }
                else
                {
                    node.site.Init(p, (uint)i, node);                   // both node and site reference each other
                }
                if (i >= _sites.Count)
                {
                    _sites.Add(node.site);
                }
                else
                {
                    _sites.Plant(node.site, i);
                }
                _sitesIndexedByLocation [p] = node.site;
            }
        }