public PlantsSetting()
 {
     PlantingSettings = new OnePlantSetting[6];
     Plants           = new GameObject[6];
     for (int i = 0; i < PlantingSettings.Length; i++)
     {
         PlantingSettings[i] = new OnePlantSetting();
     }
 }
Exemple #2
0
    void UseEraser(OnePlantSetting plant, Vector3 pos, float density, float brushSize)
    {
        pos.y = 0;
        //---范围内的都消除
        if (plantsContainer.mSetting.isSingleEraser)
        {
            for (int i = allPlantsDictionary[plant.Plant].Count - 1; i >= 0; i--)
            {
                Vector3 savePos = allPlantsDictionary[plant.Plant][i].Pos;
                savePos.y = 0;
                if (Vector3.Distance(savePos, pos) < brushSize)
                {
                    allPlantsDictionary[plant.Plant].RemoveAt(i);
                }
            }
        }
        else
        {
            //记录需要删除的key
            List <GameObject> toBeRemoveGos = new List <GameObject>();
            //--删除所有植被
            foreach (var plantKey in allPlantsDictionary.Keys)
            {
                for (int i = allPlantsDictionary[plantKey].Count - 1; i >= 0; i--)
                {
                    Vector3 savePos = allPlantsDictionary[plantKey][i].Pos;
                    savePos.y = 0;
                    if (Vector3.Distance(savePos, pos) < brushSize)
                    {
                        allPlantsDictionary[plantKey].RemoveAt(i);
                    }
                }

                if (allPlantsDictionary[plantKey].Count == 0)
                {
                    toBeRemoveGos.Add(plantKey);
                }
            }

            for (int i = 0; i < toBeRemoveGos.Count; i++)
            {
                allPlantsDictionary.Remove(toBeRemoveGos[i]);
            }
        }
        SaveData();
    }
Exemple #3
0
    void Planting(OnePlantSetting plant, Vector3 pos, float density, float brushSize)
    {
        //--数据填充--圆形区域内随机分布
        float area = Mathf.PI * brushSize * brushSize;
        //---向上取整
        int count = Mathf.CeilToInt(area * density);

        count = count == 0 ? 1 : count;
        for (int i = 0; i < count; i++)
        {
            //float x= pos.x+ Random.Range(-brushSize, brushSize);
            //float z = pos.z+ Random.Range(-brushSize, brushSize);
            Vector2 randomPoint = Random.insideUnitCircle;
            float   x           = pos.x + randomPoint.x * brushSize;
            float   z           = pos.z + randomPoint.y * brushSize;
            //---//---检测是否可以种植,有没有接种的地方
            Vector3 tempPos = SetHeight(new Vector3(x, 0, z));

            if (tempPos.y >= 1999.9)
            {
                continue;
            }
            //--
            if (CheckCanPlant(plant.Plant, new Vector3(x, 0, z), plant.SameRadius))
            {
                //--可以种植了
                var tempPlant = new PlantsContainer.PlantInfo();
                tempPlant.Pos    = tempPos + plant.Offset;
                tempPlant.Rot    = Quaternion.Euler(0, 0, 0);
                tempPlant.Scal.x = plant.Scale.x * (1 + Random.Range(-plant.ScaleRandom.x, plant.ScaleRandom.x));
                tempPlant.Scal.y = plant.Scale.y * (1 + Random.Range(-plant.ScaleRandom.y, plant.ScaleRandom.y));
                tempPlant.Scal.z = plant.Scale.z * (1 + Random.Range(-plant.ScaleRandom.z, plant.ScaleRandom.z));
                allPlantsDictionary[plant.Plant].Add(tempPlant);
            }
        }

        SaveData();
    }