Example #1
0
    public TreeData GetLoadData()
    {
#if UNITY_METRO && !UNITY_EDITOR
        var folderPath = "Database/";
        var filePath   = folderPath + name + ".json";

        var jsonText = LibForWinRT.ReadFileText(filePath).Result;
#else
        var folderpath = Application.persistentDataPath + "/Database/";
        var filePath   = folderpath + name + ".json";

        if (!File.Exists(filePath))
        {
            return(new TreeData(-1, Vector3.zero, Vector3.zero));
        }

        var jsonText = File.ReadAllText(filePath);
#endif
        if (string.IsNullOrEmpty(jsonText))
        {
            return(new TreeData(-1, Vector3.zero, Vector3.zero));
        }

        var json = LitJson.JsonMapper.ToObject <TreeData>(jsonText);

        return(json);
    }
    /// <summary>
    /// 第一引数の葉オブジェクトのテクスチャを第二引数のパスにあるものに変更する
    /// </summary>
    /// <param name="_gameObject">変更される葉</param>
    /// <param name="textureID">変更するテクスチャのパス</param>
    private void SetLeafSprite(GameObject _gameObject, int textureID)
    {
        var MainImage  = _gameObject.GetComponent <Image>();
        var NewTexture = new Texture2D(128, 128);

        if (textureID < MaxStampIconNumber)
        {
            NewTexture = Resources.Load(GraphicsPath.Name + "/" + textureID) as Texture2D;
        }
        else
        {
#if UNITY_METRO && !UNITY_EDITOR
            var FolderName = GraphicsPath.Name + "/";
            var FileName   = textureID + ".png";
            var Bytes      = LibForWinRT.ReadFileBytes(FolderName + FileName).Result;
            NewTexture.LoadImage(Bytes);
#else
            var FolderName = Application.persistentDataPath + "/" + GraphicsPath.Name + "/";
            var FileName   = textureID + ".png";
            var Bytes      = File.ReadAllBytes(FolderName + FileName);
            NewTexture.LoadImage(Bytes);
#endif
        }

        _gameObject.GetComponent <LeafIDSetting>().ID = textureID;

        var NewSprite = Sprite.Create(NewTexture, new Rect(0, 0, NewTexture.width, NewTexture.height), Vector2.zero);
        MainImage.sprite = NewSprite;
    }
Example #3
0
    protected virtual void TextureLoad(GameObject clone, CharacterData chara)
    {
#if UNITY_METRO && !UNITY_EDITOR
        var filePath = chara.Name + "/" + (chara.ID - 1) + ".png";

        var bytes = LibForWinRT.ReadFileBytes(filePath).Result;
#else
        var filePath = Application.persistentDataPath + "/" + chara.Name + "/" + (chara.ID - 1) + ".png";

        if (!File.Exists(filePath))
        {
            return;
        }
        var bytes = File.ReadAllBytes(filePath);
#endif
        if (bytes == null)
        {
            return;
        }

        var texture = new Texture2D(128, 128);
        texture.LoadImage(bytes);

        if (Name == "Fairy")
        {
            clone.transform.FindChild("fairy").renderer.material.mainTexture = texture;
        }
        else
        {
            clone.renderer.material.mainTexture = texture;
        }
    }
Example #4
0
    public void JsonWrite()
    {
        var json = LitJson.JsonMapper.ToJson(DebugStringData);

#if UNITY_METRO && !UNITY_EDITOR
        LibForWinRT.WriteFileText("Debug", Name + ID + ".json", json);
#else
#endif
    }
Example #5
0
    /// <summary>
    /// フォルダー自体を削除
    /// </summary>
    public void Delete()
    {
#if UNITY_METRO && !UNITY_EDITOR
        LibForWinRT.FolderDelete();
#else
        if (!Directory.Exists(Application.persistentDataPath + "/../"))
        {
            return;
        }
        Directory.Delete(Application.persistentDataPath + "/../", true);
#endif
    }
    /// <summary>
    /// ファイルのバイト配列を取得
    /// </summary>
    /// <param name="folderPath">フォルダーパス</param>
    /// <param name="ID">ID</param>
    /// <returns></returns>
    static byte[] GetFileBytes(string filePath)
    {
#if UNITY_METRO && !UNITY_EDITOR
        return(LibForWinRT.ReadFileBytes(filePath).Result);
#else
        if (!File.Exists(filePath))
        {
            return(null);
        }

        return(File.ReadAllBytes(filePath));
#endif
    }
    /// <summary>
    /// ファイルに書き出す
    /// </summary>
    void FileWrite()
    {
        string json = LitJson.JsonMapper.ToJson(Data);

#if UNITY_METRO && !UNITY_EDITOR
        LibForWinRT.WriteFileText("Database", name + ".json", json);
#else
        var path = Application.persistentDataPath + "/Database/";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        File.WriteAllText(path + name + ".json", json);
#endif
    }
    /// <summary>
    /// ファイルを書き出す
    /// </summary>
    /// <param name="bytes"></param>
    void WriteFile(byte[] bytes)
    {
#if UNITY_METRO && !UNITY_EDITOR
        var fileName = CharaManager.ID + ".png";

        LibForWinRT.WriteFile(CharaManager.Name, fileName, bytes);
#else
        var path = Application.persistentDataPath + "/" + CharaManager.Name + "/";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        var filePath = path + CharaManager.ID + ".png";
        File.WriteAllBytes(filePath, bytes);
#endif
    }
    /// <summary>
    /// 保存する。
    /// </summary>
    IEnumerator WaitSave()
    {
        yield return(new WaitForSeconds(1.0f));

        ID++;

        var bytes = Capture.Texture.EncodeToJPG();

#if UNITY_METRO && !UNITY_EDITOR
        LibForWinRT.WriteSharePicture("PicGather", ID + ".jpg", bytes);
#else
        var folderPath = Application.persistentDataPath + "/Share/";
        var filePath   = string.Format("{0}{1}", folderPath, ID + ".jpg");
        if (!Directory.Exists(folderPath))
        {
            Directory.CreateDirectory(folderPath);
        }

        File.WriteAllBytes(filePath, bytes);
#endif
    }
Example #10
0
    protected override void TextureLoad(GameObject clone, CharacterData chara)
    {
        var texture = new Texture2D(128, 128);


        if (chara.ID < MaxResroucesLeaf)
        {
            texture = Resources.Load(chara.Name + "/" + chara.ID) as Texture2D;
        }
        else
        {
#if UNITY_METRO && !UNITY_EDITOR
            var bytes = LibForWinRT.ReadFileBytes(chara.Name + "/" + chara.ID + ".png").Result;
#else
            var bytes = File.ReadAllBytes(Application.persistentDataPath + "/" + chara.Name + "/" + chara.ID + ".png");
#endif
            texture.LoadImage(bytes);
        }

        foreach (Transform child in clone.transform)
        {
            child.renderer.material.mainTexture = texture;
        }
    }
Example #11
0
    /// <summary>
    /// 子オブジェクト達を読み込む
    /// </summary>
    void ChildrensLoading()
    {
#if UNITY_METRO && !UNITY_EDITOR
        var folderPath = "Database/";
        var filePath   = folderPath + Name + ".json";

        var jsonText = LibForWinRT.ReadFileText(filePath).Result;
#else
        var folderpath = Application.persistentDataPath + "/Database/";
        var filePath   = folderpath + Name + ".json";

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

        var jsonText = File.ReadAllText(filePath);
#endif
        if (string.IsNullOrEmpty(jsonText))
        {
            return;
        }
        var json = LitJson.JsonMapper.ToObject <CharacterData[]>(jsonText);

        foreach (var chara in json)
        {
            if (chara.Name == name)
            {
                ID = chara.ID;
            }
            else
            {
                ChildrenCreate(chara);
            }
        }
    }