Ejemplo n.º 1
0
 bool CheckGrassDistance(UTreeGroup group, Vector3 position, float density)
 {
     foreach (UTreeInstance ins in group.instances)
     {
         if ((ins.position - position).magnitude < density)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        void DrawTrees(UTreeGroup group, Camera camera)
        {
            float   start  = m_Terrain.data.treeBillBoardStart;
            Vector3 pos    = camera.transform.position - group.transform.position;
            Vector3 center = group.center;
            Vector3 proPos = new Vector3(pos.x, center.y, pos.z);

            if (Vector3.Distance(center, proPos) - m_MaxRadius < start)
            {
                group.instances.ToList().ForEach(ins => {
                    ins.active = Vector3.Distance(ins.position, pos) < start;
                });
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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);
        }