示例#1
0
        public void Add(UTreeInstance instance)
        {
            UTreeGroup group = null;

            for (int i = 0; i < m_Groups.Count; i++)
            {
                UTreeGroup g = m_Groups[i];
                if (Vector3.Distance(instance.position, g.center) < m_MaxRadius && g.length < m_MaxVector)
                {
                    group = g;
                    if (!m_ApplyGroup.Contains(i))
                    {
                        m_ApplyGroup.Add(i);
                    }
                }
            }
            if (group == null)
            {
                if (!m_ApplyGroup.Contains(m_Groups.Count))
                {
                    m_ApplyGroup.Add(m_Groups.Count);
                }
                m_Groups.Add(new UTreeGroup(this, instance));
            }
            else
            {
                group.Add(instance);
            }
        }
示例#2
0
        public void AddArea(Vector3 pos, Vector3 scale, float density)
        {
            UTreeInstance instance   = new UTreeInstance(pos, scale, m_TreeMesh.bounds.size);
            int           groupIndex = GetGroupIndex(instance);
            UTreeGroup    group      = m_Groups[groupIndex];

            if (CheckGrassDistance(group, instance.position, density))
            {
                group.Add(instance);
                if (!m_ApplyGroup.Contains(groupIndex))
                {
                    m_ApplyGroup.Add(groupIndex);
                }
            }
        }
示例#3
0
        int GetGroupIndex(UTreeInstance instance)
        {
            int index = -1;

            for (int i = 0; i < m_Groups.Count; i++)
            {
                UTreeGroup g = m_Groups[i];
                if (Vector3.Distance(instance.position, g.center) < m_MaxRadius && g.length < m_MaxVector)
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                m_Groups.Add(new UTreeGroup(this, instance));
                index = m_Groups.Count - 1;
                if (!m_ApplyGroup.Contains(index))
                {
                    m_ApplyGroup.Add(index);
                }
            }
            return(index);
        }