コード例 #1
0
        public void Remove(Vector3 pos, float radius)
        {
            List <UGrassGroup> toRemove = new List <UGrassGroup>();

            for (int i = 0, max = m_Groups.Count; i < max; i++)
            {
                UGrassGroup g = m_Groups[i];
                if (Vector3.Distance(pos, g.center + m_Terrain.transform.position) - radius > m_MaxRadius)
                {
                    continue;
                }
                g.Remove(pos, radius);
                if (g.length == 0)
                {
                    toRemove.Add(g);
                    m_ApplyGroup.Remove(i);
                }
                else
                {
                    if (!m_ApplyGroup.Contains(i))
                    {
                        m_ApplyGroup.Add(i);
                    }
                }
            }
            toRemove.ForEach(g => {
                m_Groups.Remove(g);
                g.Dispose();
            });
        }
コード例 #2
0
        public void Add(UGrassInstance instance)
        {
            UGrassGroup group = null;

            for (int i = 0; i < m_Groups.Count; i++)
            {
                UGrassGroup 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 UGrassGroup(m_GameObject.transform, m_Terrain, material, instance));
            }
            else
            {
                group.Add(instance);
            }
        }
コード例 #3
0
 bool CheckGrassDistance(UGrassGroup group, Vector3 position, float density)
 {
     foreach (UGrassInstance ins in group.instances)
     {
         if ((ins.position - position).magnitude < density)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #4
0
        public void AddArea(UGrassInstance instance, float density)
        {
            int         groupIndex = GetGroupIndex(instance);
            UGrassGroup group      = m_Groups[groupIndex];

            if (CheckGrassDistance(group, instance.position, density))
            {
                group.Add(instance);
                if (!m_ApplyGroup.Contains(groupIndex))
                {
                    m_ApplyGroup.Add(groupIndex);
                }
            }
        }
コード例 #5
0
        int GetGroupIndex(UGrassInstance instance)
        {
            int index = -1;

            for (int i = 0; i < m_Groups.Count; i++)
            {
                UGrassGroup 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 UGrassGroup(m_GameObject.transform, m_Terrain, material, instance));
                index = m_Groups.Count - 1;
                if (!m_ApplyGroup.Contains(index))
                {
                    m_ApplyGroup.Add(index);
                }
            }
            return(index);
        }