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); } }
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); } } }
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); }