private void loadData()
        {
            if (popDBFile.list.Count > 0)
            {
                foreach (ActorData ad in popDBFile.list)
                {
                    CitizenFactory.quantity_Production = ad.quantidade;
                    Debug.Log("LoadXML: quantity citizens " + ad.quantidade);
                    CitizenFactory.anchorRadius_Production = ad.anchorRadius;
                    Debug.Log("LoadXML: anchorRadius " + ad.anchorRadius);
                    CitizenFactory.anchors_Production = new List <GameObject>();
                    for (int i = 0; i < ad.anchors.Count; i++)
                    {
                        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                        go.name = "WalkerAnchor" + i;
                        go.transform.position = new Vector3(ad.anchors[i].x, ad.anchors[i].y, ad.anchors[i].z);
                        Renderer renderer = go.GetComponent <Renderer>();
                        renderer.enabled = false;
                        CitizenFactory.anchors_Production.Add(go);
                    }
                    Debug.Log("LoadXML:Carregou anchors " + CitizenFactory.anchors_Production.Count);

                    foreach (string adult in ad.adults)
                    {
                        GameObject template = (GameObject)Resources.Load(adult);
                        if (template != null)
                        {
                            CitizenFactory.listaTemplates_Adults_Production.Add(template);
                        }
                        else
                        {
                            Debug.Log("Nao consegui encontrar a resource (GameObject) espcificada:" + adult);
                        }
                    }
                    foreach (string child in ad.children)
                    {
                        GameObject template = (GameObject)Resources.Load(child);
                        if (template != null)
                        {
                            CitizenFactory.listaTemplates_Children_Production.Add(template);
                        }
                        else
                        {
                            Debug.Log("Nao consegui encontrar a resource (GameObject) espcificada:" + child);
                        }
                    }
                    Debug.Log("LoadXML:Carregou templates Adult Citizens " + CitizenFactory.listaTemplates_Adults_Production.Count);
                    Debug.Log("LoadXML:Carregou templates Children " + CitizenFactory.listaTemplates_Children_Production.Count);


                    for (int i = 0; i < ad.worker.Count; i++)
                    {
                        TrabalhadorData     worker = ad.worker[i];
                        ClassWorkerProducao family = new ClassWorkerProducao();
                        family.tipo   = (Profession.ProfessionType)worker.tipo;
                        family.count  = worker.count;
                        family.boneco = (GameObject)Resources.Load(worker.nome);

                        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                        go.name = "KeyAnchor" + i;
                        go.transform.position = new Vector3(worker.posicao.x, worker.posicao.y, worker.posicao.z);
                        Renderer renderer = go.GetComponent <Renderer>();
                        renderer.enabled = false;
                        CitizenFactory.keys_Production.Add(go);
                        family.posicaoInicial = go;


                        //  string dataPath = string.Empty;
                        //if (Application.platform == RuntimePlatform.IPhonePlayer)
                        //    dataPath = System.IO.Path.Combine(Application.persistentDataPath, "Resources/EasyPopulation" + worker.animacao);
                        //else
                        //    dataPath = System.IO.Path.Combine(Application.dataPath, "Resources/EasyPopulation" + worker.animacao);

                        AnimationClip[] anim = Resources.FindObjectsOfTypeAll <AnimationClip>();
                        foreach (AnimationClip ac in anim)
                        {
                            if (ac.name == worker.animacao)
                            {
                                family.animacaoInicial = ac;
                            }
                            else if (ac.name == worker.animacao2)
                            {
                                family.animacao2 = ac;
                            }
                        }

                        //AnimationClip aclip1 = Resources.Load(path, typeof(AnimationClip)) as AnimationClip;
                        //family.animacaoInicial = aclip1;
                        //if (!aclip1) Debug.LogError("XML Loader-1 Clip Production, failed to load " + path);

                        // AnimationClip aclip2 = Resources.Load(path, typeof(AnimationClip)) as AnimationClip;
                        //family.animacaoInicial = aclip2;
                        //if (!aclip2) Debug.LogError("XML Loader-1 Clip Production, failed to load " + path);
                        // family.animacao2 = aclip2;

                        GameObject goDelivery = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                        goDelivery.name = "KeyAnchor" + i;
                        goDelivery.transform.position = new Vector3(worker.delivery.x, worker.delivery.y, worker.delivery.z);
                        renderer         = goDelivery.GetComponent <Renderer>();
                        renderer.enabled = false;
                        CitizenFactory.keys_Production.Add(goDelivery);
                        family.posicaoDelivery = goDelivery;

                        family.raioAtracao = worker.raioAtracao;
                        family.freedom     = worker.freedom;
                        //--//

                        CitizenFactory.listaDefinicaoWorkers.Add(family);
                    }
                    Debug.Log("LoadXML:Carregou workers ");
                }
            }
        }
Ejemplo n.º 2
0
      private void loadDataFromCitizenFactoryData()
      {
          popDBFile = new populationDB();

          if (popDBFile != null)
          {
              popDBFile.list.Clear();
              ActorData ad = new ActorData();
              ad.quantidade = CitizenFactory.quantity_Production;
              foreach (GameObject adult in CitizenFactory.listaTemplates_Adults_Production)
              {
                  if (adult == null)
                  {
                      Debug.LogError("There is no associated 3d model (citizen)!");
                  }
                  else
                  {
                      ad.adults.Add(adult.name);
                  }
              }
              foreach (GameObject child in CitizenFactory.listaTemplates_Children_Production)
              {
                  if (child == null)
                  {
                      Debug.LogError("There is no associated 3d model (children)!");
                  }
                  else
                  {
                      ad.children.Add(child.name);
                  }
              }
              foreach (GameObject anchor in CitizenFactory.anchors_Production)
              {
                  if (anchor == null)
                  {
                      Debug.LogError("There is no anchors (anchor)!");
                  }
                  else
                  {
                      ad.anchors.Add(new Vector3(anchor.transform.position.x, anchor.transform.position.y, anchor.transform.position.z));
                  }
              }
              ad.anchorRadius = (int)CitizenFactory.anchorRadius_Production;
              ad.anchorHeight = (int)CitizenFactory.anchorHeight_Production;
              foreach (ClassWorkerProducao worker in CitizenFactory.listaDefinicaoWorkers)
              {
                  TrabalhadorData tr = new TrabalhadorData();
                  tr.tipo  = (int)worker.tipo;
                  tr.count = worker.count;
                  if (worker.boneco != null)
                  {
                      tr.nome = worker.boneco.name;
                  }
                  if (worker.posicaoInicial != null)
                  {
                      tr.posicao = worker.posicaoInicial.transform.position;
                  }
                  tr.raioAtracao = worker.raioAtracao;
                  if (worker.animacaoInicial != null)
                  {
                      tr.animacao = worker.animacaoInicial.name;
                  }
                  if (worker.posicaoDelivery != null)
                  {
                      tr.delivery = worker.posicaoDelivery.transform.position;
                  }
                  tr.freedom = worker.freedom;
                  if (worker.animacao2 != null)
                  {
                      tr.animacao2 = worker.animacao2.name;
                  }
                  ad.worker.Add(tr);
              }
              popDBFile.list.Add(ad);
          }
          else
          {
              Debug.LogError("XMLManager Before Serialize popPrep e null");
          }
      }