コード例 #1
0
    public void CreateTextureFromSaveFile(TileMapSaveData st, SaveUtility saveUtility, LevelTilemap target)
    {
        Texture2D tex   = new Texture2D(st.sizeX, st.sizeY);
        var       datas = target.GetTileLevelDataFromSaveFile(st);

        for (int x = 0; x < st.sizeX; x++)
        {
            for (int y = 0; y < st.sizeY; y++)
            {
                tex.SetPixel(x, y, datas[x + y * st.sizeX].editorColor);
            }
        }
        // Encode texture into PNG
        byte[] bytes = tex.EncodeToPNG();

        //UnityEditor.AssetDatabase.CreateAsset(tex, "Assets/"+saveUtility.fileName+".asset");

        Object.DestroyImmediate(tex);

        //var asset = UnityEditor.AssetDatabase.LoadAssetAtPath<Texture2D>(saveUtility.path + saveUtility.fileName + ".png");

        //asset.filterMode = FilterMode.Point;
        File.WriteAllBytes(saveUtility.GetPath("png"), bytes);
        UnityEditor.AssetDatabase.Refresh();
    }
コード例 #2
0
ファイル: LevelTilemap.cs プロジェクト: claudyy/TileMap
    public void CreateSaveFile(TileMapSaveData st, SaveUtility saveUtility)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(TileMapSaveData));
        FileStream    stream     = new FileStream(saveUtility.GetPath(), FileMode.Create);

        serializer.Serialize(stream, st);
        stream.Close();
# if UNITY_EDITOR
コード例 #3
0
ファイル: LevelTilemap.cs プロジェクト: claudyy/TileMap
    public void Load()
    {
        XmlSerializer serializer = new XmlSerializer(typeof(TileMapSaveData));

        if (Application.isEditor == false)
        {
            TextAsset   textAsset = (TextAsset)Resources.Load(saveUtility.fileName);
            XmlDocument xmldoc    = new XmlDocument();
            xmldoc.LoadXml(textAsset.text);
            XmlReader       reader = new XmlNodeReader(xmldoc);
            TileMapSaveData result = (TileMapSaveData)serializer.Deserialize(reader);

            Load(result);
            return;
        }
        FileStream stream = new FileStream(saveUtility.GetPath(), FileMode.Open);



        var st = serializer.Deserialize(stream) as TileMapSaveData;

        stream.Close();
        Load(st);
    }