예제 #1
0
    private async Task LoadeMap()
    {
        Timer timer = new Timer();

        //map = new Map();
        int[]    mapForme    = FIleSys.OpenFile <int[]>(Path + "/mapForme.bin");
        string[] parcelsJson = FIleSys.OpenFile <string[]>(Path + "/mapConstruction.bin");
        timer.DebugTime("Load File");
        map = new Map(new Vector2Int(20, 20));
        await Task.Delay(1);

        for (int i = 0; i < mapForme.Length; i += 4)
        {
            int x = (i / 4) % map.Size.x;
            int y = (i / 4 - x) / map.Size.x;
            map.parcels[x, y] = new Parcel(new Vector2Int(x, y));
            for (int j = 0; j < 4; j++)
            {
                map.parcels[x, y].corner[j] = mapForme[i + j];
            }
        }
        timer.DebugTime("Load Forme");
        await Task.Delay(1);

        for (int i = 0; i < parcelsJson.Length; i++)
        {
            Parcel curParcel = GetObject <Parcel>(parcelsJson[i]);
            map.parcels[curParcel.pos.x, curParcel.pos.y] = curParcel;
            map.importParcels.Add(curParcel);
        }
        timer.DebugTime("Load Construction");
    }
예제 #2
0
    private void LoadIndustrise()
    {
        MaterialData[] materialList   = FIleSys.GetAllInstances <MaterialData>();
        string[]       industriseJson = FIleSys.OpenFile <string[]>(Path + "/industrise.bin");
        for (int i = 0; i < industriseJson.Length; i++)
        {
            Dictionary <string, object> industriseValue = GetObject <Dictionary <string, object> >(industriseJson[i]);

            Industrise curIndustrise = new Industrise((Vector2Int)industriseValue["pos"], map, FIleSys.GetAllInstances <IndustriseData>()[(Int64)(industriseValue["industriseData"])]);
            curIndustrise.materialProductionRatio = (float)((double)industriseValue["materialPoduction"]);

            if (industriseValue.ContainsKey("inpute"))
            {
                foreach (KeyValuePair <int, int> curMaterial in (Dictionary <int, int>)industriseValue["inpute"])
                {
                    curIndustrise.materialsInpute[materialList[curMaterial.Key]] = curMaterial.Value;
                }
            }

            if (industriseValue.ContainsKey("outpute"))
            {
                foreach (KeyValuePair <int, int> curMaterial in (Dictionary <int, int>)industriseValue["outpute"])
                {
                    curIndustrise.materialsOutpute[materialList[curMaterial.Key]] = curMaterial.Value;
                }
            }

            map.industrises.Add(curIndustrise);
        }
    }
예제 #3
0
 private void SaveIndustrise()
 {
     string[] industriseJson = new string[map.industrises.Count];
     for (int i = 0; i < industriseJson.Length; i++)
     {
         Industrise curIndustrise = map.industrises[i];
         Dictionary <string, object> industriseDic = new Dictionary <string, object>();
         industriseDic.Add("pos", curIndustrise.MasterPos);
         industriseDic.Add("materialPoduction", curIndustrise.materialProductionRatio);
         industriseDic.Add("industriseData", Array.IndexOf(FIleSys.GetAllInstances <IndustriseData>(), curIndustrise.industriseData));
         for (int j = 0; j < 1; j++)
         {
             Dictionary <int, int>          material = new Dictionary <int, int>();
             Dictionary <MaterialData, int> source   = j == 0 ? curIndustrise.materialsInpute : curIndustrise.materialsOutpute;
             MaterialData[] materialList             = FIleSys.GetAllInstances <MaterialData>();
             foreach (KeyValuePair <MaterialData, int> curMaterial in source)
             {
                 material.Add(Array.IndexOf(materialList, curMaterial.Key), curMaterial.Value);
             }
             industriseDic.Add(j == 0 ? "inpute" : "outpute", material);
         }
         industriseJson[i] = GetJson(industriseDic);
     }
     FIleSys.SaveFile(Path + "/industrise.bin", industriseJson);
 }
예제 #4
0
    private void SaveStatistique()
    {
        Dictionary <string, object> statistiques = new Dictionary <string, object>();

        statistiques.Add("money", GameManager.Money);
        FIleSys.SaveFile(Path + "/statistique.bin", GetJson(statistiques));
    }
예제 #5
0
 public void UpdateWindow()
 {
     foreach (Transform child in listContente)
     {
         if (child.gameObject.activeSelf)
         {
             Destroy(child.gameObject);
         }
     }
     if (onStore)
     {
         groupesDropdown.gameObject.SetActive(true);
         List <string> dropdownOption = new List <string>();
         foreach (Group curGroupe in Group.groups)
         {
             dropdownOption.Add(curGroupe.name);
         }
         dropdownOption.Add("None");
         groupesDropdown.ClearOptions();
         groupesDropdown.AddOptions(dropdownOption);
         groupesDropdown.value = Group.groups.Count;
         foreach (VehicleData curVehicle in FIleSys.GetAllInstances <VehicleData>())
         {
             Transform _go = Instantiate(templateStoreVehicle).transform;
             _go.SetParent(listContente);
             _go.Find("Name").GetComponent <Text>().text        = curVehicle.name;
             _go.Find("Description").GetComponent <Text>().text = curVehicle.description;
             _go.Find("Buy").GetComponent <Button>().onClick.AddListener(delegate
             {
                 VehicleContoler vehicle = depot.BuyVehicle(curVehicle);
                 if (groupesDropdown.value != Group.groups.Count)
                 {
                     vehicle.MyGroup = Group.groups[groupesDropdown.value];
                 }
             });
             _go.Find("Buy").GetComponent <ButtonInteractMoney>().condiction = delegate()
             {
                 return(GameManager.Money >= curVehicle.price);
             };
             _go.gameObject.SetActive(true);
         }
     }
     else
     {
         groupesDropdown.gameObject.SetActive(false);
         foreach (VehicleContoler curVehicle in VehicleManager.GetVehicleByPos(depot))
         {
             Transform _go = Instantiate(templateDepotVehicle).transform;
             _go.SetParent(listContente);
             _go.Find("Name").GetComponent <Text>().text   = curVehicle.vehicleData.name;
             _go.Find("Damage").GetComponent <Text>().text = string.Format("Damage: {0}%", Mathf.Floor(curVehicle.damage * 100));
             _go.Find("ID").GetComponent <Text>().text     = "ID: " + curVehicle.Id;
             _go.Find("Info").GetComponent <Button>().onClick.AddListener(delegate { WindowsOpener.OpenVehicleWindow(curVehicle.GetComponent <VehicleContoler>()); });
             _go.gameObject.SetActive(true);
         }
     }
     templateDepotVehicle.SetActive(false);
     templateStoreVehicle.SetActive(false);
 }
    public static void MakeAuto(Vector2Int origine)
    {
        //Vector2Int origine = new Vector2Int(200, 200);
        for (int i = -30; i <= 0; i++)
        {
            MapManager.map.AddConstruction(origine + new Vector2Int(i, 1), new Road());
        }
        for (int i = 0; i <= 30; i++)
        {
            MapManager.map.AddConstruction(origine + new Vector2Int(0, i), new Road());
        }
        for (int i = -15; i <= 15; i += 15)
        {
            Industrise indus = MapManager.map.CreatIndustrise(origine + new Vector2Int(-35, i));
            indus.industriseData          = FIleSys.GetAllInstances <IndustriseData>()[0];
            indus.materialProductionRatio = 200;
            indus.SetInputeOutpure();
        }
        for (int i = -15; i <= 15; i += 15)
        {
            Industrise indus = MapManager.map.CreatIndustrise(origine + new Vector2Int(i, 35));
            indus.industriseData          = FIleSys.GetAllInstances <IndustriseData>()[1];
            indus.materialProductionRatio = 200;
            indus.SetInputeOutpure();
        }

        MapManager.map.AddConstruction(origine + new Vector2Int(-31, 1), new LoadingBay());
        MapManager.map.AddConstruction(origine + new Vector2Int(0, 31), new LoadingBay());

        MapManager.map.AddConstruction(origine, new Depot());
        Depot depot = MapManager.map.GetParcel <Depot>(origine);

        Debug.Log(depot);
        Debug.Log(FIleSys.GetAllInstances <VehicleData>()[1]);
        Group group = new Group()
        {
            name = "Auto Generate Groupe"
        };
        List <VehicleContoler> vehicles = new List <VehicleContoler>();

        for (int i = 0; i < 3; i++)
        {
            vehicles.Add(depot.BuyVehicle(FIleSys.GetAllInstances <VehicleData>()[1]));
            vehicles[i].MyGroup = Group.groups[0];
        }
        group.forceRoute = true;
        group.route      = new Route()
        {
            points = new List <Vector2Int>()
            {
                origine + new Vector2Int(-31, 1),
                origine + new Vector2Int(0, 31),
                origine,
            }
        };
        Group.groups[0].StartEveryVehicle();
    }
예제 #7
0
 public Industrise(Vector2Int _pos, Map _mapData)
 {
     MasterPos = _pos;
     IndustriseData[] allIndustriseData = FIleSys.GetAllInstances <IndustriseData>();
     industriseData = allIndustriseData[Random.Range(0, allIndustriseData.Length)];
     MakeBuilding(_mapData);
     materialProductionRatio = Random.Range(0.8f, 3f);
     SetInputeOutpure();
 }
예제 #8
0
 public void SetVehiclePorpertise(VehicleContoler vehicle)
 {
     vehicle.vehicleData  = FIleSys.GetAllInstances <VehicleData>()[vehicleData];
     vehicle.damage       = damage;
     vehicle.MyRoute      = myRoute;
     vehicle.RoutePointGo = RoutePointGo;
     vehicle.VehiclePos   = pos;
     vehicle.MyGroup      = Group.groups[myGroup];
 }
예제 #9
0
 private void LoadGroups()
 {
     string[] groupsJson = FIleSys.OpenFile <string[]>(Path + "/groups.bin");
     Group.groups.Clear();
     foreach (string curGroupsJson in groupsJson)
     {
         Group.groups.Add(GetObject <Group>(curGroupsJson));
     }
 }
예제 #10
0
 private void LoadVehicles()
 {
     string[] vehiclesJson = FIleSys.OpenFile <string[]>(Path + "/vehicles.bin");
     foreach (string curVehicleJson in vehiclesJson)
     {
         GameObject _go = Object.Instantiate(Resources.Load("Vehicle") as GameObject);
         GetObject <VehicleDateStruct>(curVehicleJson).SetVehiclePorpertise(_go.GetComponent <VehicleContoler>());
     }
 }
예제 #11
0
 private void SaveGroups()
 {
     string[] groupsJson = new string[Group.groups.Count];
     for (int i = 0; i < groupsJson.Length; i++)
     {
         groupsJson[i] = GetJson(Group.groups[i]);
     }
     FIleSys.SaveFile(Path + "/groups.bin", groupsJson);
 }
예제 #12
0
    private async Task SaveVehicle()
    {
        string[] vehiclesJson = new string[vehicles.Count];
        for (int i = 0; i < vehicles.Count; i++)
        {
            vehiclesJson[i] = GetJson(VehicleDateStruct.GetStruct(vehicles[i]));
        }
        await Task.Delay(1);

        FIleSys.SaveFile(Path + "/vehicles.bin", vehiclesJson);
    }
예제 #13
0
 public static VehicleDateStruct GetStruct(VehicleContoler vehicle)
 {
     return(new VehicleDateStruct
     {
         vehicleData = Array.IndexOf(FIleSys.GetAllInstances <VehicleData>(), vehicle.vehicleData),
         damage = vehicle.damage,
         myRoute = vehicle.MyRoute,
         RoutePointGo = vehicle.RoutePointGo,
         pos = vehicle.VehiclePos,
         myGroup = vehicle.MyGroup != null?Group.groups.IndexOf(vehicle.MyGroup) : -1,
     });
 }
예제 #14
0
    private async Task SaveMap()
    {
        Timer         timer           = new Timer();
        List <string> parcelsJsonList = new List <string>();

        int[] mapForm = new int[map.Size.x * map.Size.y * 4];
        for (int y = 0; y < map.Size.y; y++)
        {
            for (int x = 0; x < map.Size.x; x++)
            {
                if (map.GetparcelType(new Vector2Int(x, y)) != typeof(Parcel))
                {
                    Parcel parcel = map.GetParcel(new Vector2Int(x, y));
                    try
                    {
                        parcelsJsonList.Add(GetJson(parcel));
                    }
                    catch
                    {
                        parcel.DebugParcel();
                    }
                }
                for (int i = 0; i < 4; i++)
                {
                    mapForm[(y * map.Size.x + x) * 4 + i] = map.GetParcel <Parcel>(new Vector2Int(x, y)).corner[i];
                }
            }
        }
        await Task.Delay(1);

        timer.DebugTime("Creat Forme and JSON");
        await Task.Delay(1);

        //Debug.LogError("Finish");
        //return;
        string[] parcelsJsonArray = new string[parcelsJsonList.Count];
        for (int i = 0; i < parcelsJsonList.Count; i++)
        {
            parcelsJsonArray[i] = parcelsJsonList[i];
            //await AsyncTask.DelayIf(i, 100, 1);
            //await AsyncTask.DelayIfNeed(1);
        }
        await Task.Delay(1);

        timer.DebugTime("List => Array ");
        FIleSys.SaveFile(Path + "/mapForme.bin", mapForm);
        FIleSys.SaveFile(Path + "/mapConstruction.bin", parcelsJsonArray);
    }
예제 #15
0
    public void OpenLoadGameMenu()
    {
        mainMenu.SetActive(false);
        loadGameMenu.SetActive(true);
        GameObject template = loadGameMenuContente.Find("Template").gameObject;

        foreach (Transform curChild in loadGameMenuContente)
        {
            if (curChild.gameObject.activeSelf == true)
            {
                Destroy(curChild.gameObject);
            }
        }
        foreach (string curSave in FIleSys.GetFolder("/Save"))
        {
            Transform curSaveObj = Instantiate(template).transform;
            curSaveObj.SetParent(template.transform.parent);
            curSaveObj.Find("SaveName").GetComponent <Text>().text = curSave;
            curSaveObj.Find("Load").GetComponent <Button>().onClick.AddListener(delegate { GameLoader.LoadSave(curSave); });
            curSaveObj.gameObject.SetActive(true);
        }
    }
예제 #16
0
    private void LoadStatistique()
    {
        Dictionary <string, object> statistiques = GetObject <Dictionary <string, object> >(FIleSys.OpenFile <string>(Path + "/statistique.bin"));

        GameManager.Money = (long)statistiques["money"];
    }