Exemple #1
0
    void LoadMapInfo()
    {
        string dir  = Application.persistentDataPath + "/General/MapsInfo.json";
        string json = File.ReadAllText(dir);

        mapInfoJson = JsonUtility.FromJson <MapInfoJson>(json);
    }
Exemple #2
0
    void Start()
    {
        print("gamemanager start");
        //MyUtils.InitFileSystem();

        eventSystem      = GameObject.Find("EventSystem").GetComponent <EventSystem>();
        graphicRayCaster = GameObject.Find("Canvas").GetComponent <GraphicRaycaster>();
        _fieldMaxDic     = new Dictionary <string, int>()
        {
            { "Acceleration", 99 },
            { "Gravitation", 99 },
            { "Teleport", 99 },
            { "Electromagnetic", 99 }
        };
        fieldDic    = new Dictionary <string, List <GameObject> >();
        mapFieldDic = new Dictionary <string, List <GameObject> >();
        foreach (KeyValuePair <string, int> kv in fieldMaxDic)
        {
            fieldDic.Add(kv.Key, new List <GameObject>());
            mapFieldDic.Add(kv.Key, new List <GameObject>());
        }

        if (!File.Exists(Application.persistentDataPath + "/General/MapsInfo.json"))
        {
            File.Create(Application.persistentDataPath + "/General/MapsInfo.json").Close();
            mapInfoJson = MyUtils.SyncMapInfo();
        }
        else
        {
            string json = File.ReadAllText(Application.persistentDataPath + "/General/MapsInfo.json");
            mapInfoJson = JsonUtility.FromJson <MapInfoJson>(json);
        }

        if (!editMode)
        {
            currentMapInfo.author = PlayerPrefs.GetString("currentLevelAuthor");
            currentMapInfo.name   = PlayerPrefs.GetString("currentLevelName");
            isOfficial            = PlayerPrefs.GetInt("isOfficial") == 1 ? true : false;
            RestoreMapObjects(currentMapInfo.name, currentMapInfo.author);
        }
    }
    /// <summary>
    /// ファイル読み込みする
    /// </summary>
    /// <param name="filePath">ファイルのある場所</param>
    /// <returns></returns>
    public MapInfoJson LoadFromJson(string filePath)
    {
        if (!File.Exists(filePath))
        {                              //ファイルがない場合FALSE.
            Debug.Log("FileEmpty!");
            return(new MapInfoJson()); //ファイルが無いときは適当に処す.
        }

        using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        {
            using (StreamReader sr = new StreamReader(fs))
            {
                MapInfoJson sd = JsonUtility.FromJson <MapInfoJson>(sr.ReadToEnd());
                if (sd == null)
                {
                    return(new MapInfoJson());
                }
                return(sd);
            }
        }
    }
Exemple #4
0
    public static MapInfoJson SyncMapInfo()
    {
        string dir = Application.streamingAssetsPath + "/Levels";

        FileSystemInfo[] files       = GetFiles(dir);
        BinaryFormatter  bf          = new BinaryFormatter();
        MapInfoJson      mapInfoJson = new MapInfoJson();

        foreach (FileSystemInfo tmp in files)
        {
            if (tmp is DirectoryInfo)
            {
                FileStream file = File.Open(tmp.FullName + "/general", FileMode.Open);
                MapObjInfo info = (MapObjInfo)bf.Deserialize(file);
                MapInfo    map  = info.mapInfo;
                mapInfoJson.officialMaps.Add(map);
                file.Close();
            }
        }

        dir   = Application.persistentDataPath + "/Levels";
        files = GetFiles(dir);
        foreach (FileSystemInfo tmp in files)
        {
            if (tmp is DirectoryInfo)
            {
                FileStream file = File.Open(tmp.FullName + "/general", FileMode.Open);
                MapObjInfo info = (MapObjInfo)bf.Deserialize(file);
                MapInfo    map  = info.mapInfo;
                mapInfoJson.customMaps.Add(map);
                file.Close();
            }
        }

        string json = JsonUtility.ToJson(mapInfoJson, true);

        File.WriteAllText(Application.persistentDataPath + "/General/MapsInfo.json", json);
        return(mapInfoJson);
    }
Exemple #5
0
    public void AddBuildings(int x, int y)
    {
        string filePath;
        float  centerX = AreaSize * x;
        float  centerY = AreaSize * y;

        filePath = Application.dataPath + "/json/mapinfo_" + x.ToString() + "x" + y.ToString() + ".json";

        if (!File.Exists(filePath))
        {
            return;
        }

        JsonController mapinfoJson = GetComponent <JsonController>();

        mapinfo = mapinfoJson.LoadFromJson(filePath);

        for (int i = 0; i < mapinfo.Count(); i++)
        {
            GameObject buildObj = (GameObject)Instantiate(
                buildprefab,
                new Vector3(0, 0, 0),
                Quaternion.identity
                );
            GameObject emptyObject = new GameObject();
            emptyObject.transform.rotation   = transform.rotation;
            emptyObject.transform.parent     = transform;
            emptyObject.transform.localScale = new Vector3(0.001f, 10, 0.001f);
            buildObj.transform.parent        = emptyObject.transform;

            BuildInfo build = mapinfo.List[i];

            float minX = 10000, maxX = -10000;
            float minY = 10000, maxY = -10000;
            float minZ = 10000, maxZ = -10000;


            for (int j = 0; j < build.CountVertex3(); j++)
            {
                if (minX > build.getVertex3[j].x)
                {
                    minX = build.getVertex3[j].x;
                }
                if (maxX < build.getVertex3[j].x)
                {
                    maxX = build.getVertex3[j].x;
                }
                if (minY > build.getVertex3[j].y)
                {
                    minY = build.getVertex3[j].y;
                }
                if (maxY < build.getVertex3[j].y)
                {
                    maxY = build.getVertex3[j].y;
                }
                if (minZ > build.getVertex3[j].z)
                {
                    minZ = build.getVertex3[j].z;
                }
                if (maxZ < build.getVertex3[j].z)
                {
                    maxZ = build.getVertex3[j].z;
                }
            }

            float sizeX = maxX - minX;
            float sizeY = maxY - minY;
            float sizeZ = maxZ - minZ;
            buildObj.transform.localScale    = new Vector3(sizeX, sizeY, sizeZ);
            buildObj.transform.localPosition = new Vector3(minX - centerX + (sizeX / 2), (maxY + minY) / 2, minZ - centerY + (sizeZ / 2));

            var vertices  = new List <Vector3>();
            var triangles = new List <int>();

            for (int j = 0; j < build.CountVertex3(); j++)
            {
                vertices.Add(new Vector3(build.getVertex3[j].x, build.getVertex3[j].y, build.getVertex3[j].z));
            }

            for (int k = 0; k < build.CountPolygon3(); k++)
            {
                Polygon3 poly = build.getPolygon3[k];
                triangles.Add(poly.i1);
                triangles.Add(poly.i2);
                triangles.Add(poly.i3);
            }

            BuildScript bs = buildObj.GetComponent <BuildScript>();
            bs.SetPosition((int)AreaSize, new Vector3(minX - centerX + (sizeX / 2), maxY, minZ - centerY + (sizeZ / 2)), new Vector3(minX + (sizeX / 2), maxY, minZ + (sizeZ / 2)));
            bs.MakeObject(vertices, triangles);
        }

        transform.position = new Vector3(x * AreaSize, 0, y * AreaSize);
    }