Ejemplo n.º 1
0
    public List <SavableRessource> ToSavableData()
    {
        List <SavableRessource> toSave = new List <SavableRessource> ();

        foreach (var item in listRessource)
        {
            SavableRessource toSaveRessource = new SavableRessource();
            toSaveRessource.pos  = item.pos;
            toSaveRessource.type = item.ressource.ressourceType.GetRessourceType;
            switch (toSaveRessource.type)
            {
            case RessourceData.RessourceType.PlantType:
                toSaveRessource.plantData = item.ressource.ToSavableData() as SavablePlant;
                break;

            default:
                break;
            }
            toSaveRessource.data = item.ressource.ToSavableData().data;
            toSave.Add(toSaveRessource);
        }
        foreach (var savedRessource in listSavedRessource)
        {
            if (!toSave.Exists(ressource => savedRessource.pos == ressource.pos))
            {
                toSave.Add(savedRessource);
            }
        }
        return(toSave);
    }
Ejemplo n.º 2
0
 public RessourceData MakeRessource(SavableRessource ressource)
 {
     foreach (var item in ressourceType.Find((_ressource) => _ressource.type == ressource.type).ModelList)
     {
         if (item.ressourceName == ressource.data.ressourceName)
         {
             return(item);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
    public IEnumerator onColliderRecivedCoroutine(InfiniteTerrain.TerrainChunk chunk)
    {
        while (savableRessourceOfChunk[chunk].Count > 0)
        {
            SavableRessource ressource = savableRessourceOfChunk[chunk].Dequeue();
            Ray          ray           = new Ray(new Vector3(ressource.pos.x, 100, ressource.pos.y), Vector3.down);
            RaycastHit[] hitList       = Physics.RaycastAll(ray, 100);
            Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue, 10);
            for (int i = 0; hitList.Length == 0 && i < 10; i++)
            {
                yield return(new WaitForSeconds(.1f));

                hitList = Physics.RaycastAll(ray, 100);
                Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue, 10);
            }
            foreach (var hit in hitList)
            {
                if (hit.collider.CompareTag("Chunk"))
                {
                    GameObject placed = placeRessource(hit.point, RessourceFactory.Instance.MakeRessource(ressource));
                    switch (ressource.type)
                    {
                    case RessourceData.RessourceType.PlantType:
                        if (placed != null)
                        {
                            placed.GetComponent <Plant> ().CurrentGrowth = ressource.plantData.currentGrowth;
                        }
                        break;

                    default:
                        break;
                    }
                    break;
                }
            }
        }
        savableRessourceOfChunk.Remove(chunk);
    }