Example #1
0
    //Add~Updateは現在使用不可
    //public void AddDBD(string name)
    //{
    //    var dataList = _database.GetDataList();
    //    if (dataList.Where(x=>x._Data._serchId==name).FirstOrDefault()!=null)
    //    {
    //        DebugMessage_miss("Add : already contain this name:"+name);
    //        return;
    //    }
    //    //scriptableObjectの追加
    //    var scriptable = AbstractDBData.GetInstance<T>();
    //    AssetDatabase.CreateAsset(scriptable, DBIO.CreateSavePath_asset(_dirName,name));
    //    scriptable.InitData();
    //    dataList.Add(scriptable);
    //    //txtデータ書き込み
    //    DBIO.WriteText(_database.CreateDataTxt(), DBIO.CreateSavePath_txt(_dirName));
    //    AssetDatabase.Refresh();
    //    DebugMessage_success("Add");
    //}
    //public void RemoveDBD(string name)
    //{

    //    //scriptableObjeの削除
    //    var dataList = _database.GetDataList();
    //    if (dataList.Where(x => x._Data._serchId == name).FirstOrDefault() == null)
    //    {
    //        DebugMessage_miss("Remove : not contain this name:"+name);
    //        return;
    //    }
    //    var scrData = dataList.Where(x => x._Data._serchId == name).First();
    //    dataList.Remove(scrData);
    //    AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(scrData));
    //    //txtの更新
    //    DBIO.WriteText(_database.CreateDataTxt(), DBIO.CreateSavePath_txt(_dirName));
    //    AssetDatabase.Refresh();
    //    DebugMessage_success("Remove");
    //}
    //public DBData EditDBD(string name)
    //{
    //    var data= _database.GetDataList().Where(x => x._Data._serchId == name).ToList();
    //    if (data == null||data.Count==0)
    //    {
    //        DebugMessage_miss("Edit:not contain this name:"+name);
    //        return null;
    //    }
    //    else DebugMessage_success("Edit");
    //    return new DBData( data.First()._Data,name);
    //}
    //public void UpdateDBD(DBData data,string oldName)
    //{
    //    var targetData = _database.GetDataList().Where(x => x._Data._serchId == oldName).FirstOrDefault();
    //    if (targetData==null)
    //    {
    //        DebugMessage_miss("Update:not containt this name:"+oldName);
    //        return;
    //    }
    //    //scriptableObjectの更新
    //    AssetDatabase.RenameAsset(DBIO.CreateSavePath_asset(_dirName,oldName), data._serchId);
    //    targetData.UpdateData(data);
    //    EditorUtility.SetDirty(targetData);
    //    //txtの更新
    //    DBIO.WriteText(_database.CreateDataTxt(), DBIO.CreateSavePath_txt(_dirName));
    //    AssetDatabase.Refresh();
    //    DebugMessage_success("Update");
    //}
    public void SyncDataByTxt(TextAsset textAsset, string parentDir)
    {
        string path = $"{parentDir}/{textAsset.name}";

        if (!DBIO.CheckDir(DBIO.CreateAssetDirectoryPath(path)))
        {
            DBIO.CreateDir(DBIO.CreateAssetDirectoryPath(path));
        }


        var textDataList = DBListCreator.CreateDBListBytxt(DBIO.TrimType(textAsset.text).replaced);
        var assetDBList  = _database.GetDataList(this);

        //重複チェック
        var doublelist = DBIO.CheckIdIsUnique(textDataList.Select(x => x._serchId).ToList());

        if (doublelist != null)
        {
            AbstractDBData.ThrowErrorLog(null, textAsset.name, "重複したidがあります", string.Join(",", doublelist), "");
        }
        //txtに書いてないものを削除
        for (int i = assetDBList.Count - 1; i >= 0; i--)
        {
            if (textDataList.Where(x => x._serchId == assetDBList[i].name).FirstOrDefault() == null)
            {
                AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(assetDBList[i]));
                assetDBList.RemoveAt(i);
            }
        }
        //txtに書いてあるけどデータがないものを追加
        foreach (var data in textDataList)
        {
            var target = assetDBList.Where(x => x.name == data._serchId).FirstOrDefault();
            if (target == null)
            {
                target = AbstractDBData.GetInstance <T>();
                AssetDatabase.CreateAsset(target, DBIO.CreateSavePath_asset(path, data._serchId));
                assetDBList.Add(target);
            }
            target.UpdateMember(data, textAsset.name);
            EditorUtility.SetDirty(target);
        }
        _database.SetDataList(assetDBList, this);
        EditorUtility.SetDirty(_database);
        AssetDatabase.Refresh();
        DebugMessage_success("SyncText");
    }
Example #2
0
    //Add~Updateは現在使用不可
    //public void AddDBD(string name)
    //{
    //    var dataList = _database.GetDataList();
    //    if (dataList.Where(x=>x._Data._serchId==name).FirstOrDefault()!=null)
    //    {
    //        DebugMessage_miss("Add : already contain this name:"+name);
    //        return;
    //    }
    //    //scriptableObjectの追加
    //    var scriptable = AbstractDBData.GetInstance<T>();
    //    AssetDatabase.CreateAsset(scriptable, DBIO.CreateSavePath_asset(_dirName,name));
    //    scriptable.InitData();
    //    dataList.Add(scriptable);
    //    //txtデータ書き込み
    //    DBIO.WriteText(_database.CreateDataTxt(), DBIO.CreateSavePath_txt(_dirName));
    //    AssetDatabase.Refresh();
    //    DebugMessage_success("Add");
    //}
    //public void RemoveDBD(string name)
    //{

    //    //scriptableObjeの削除
    //    var dataList = _database.GetDataList();
    //    if (dataList.Where(x => x._Data._serchId == name).FirstOrDefault() == null)
    //    {
    //        DebugMessage_miss("Remove : not contain this name:"+name);
    //        return;
    //    }
    //    var scrData = dataList.Where(x => x._Data._serchId == name).First();
    //    dataList.Remove(scrData);
    //    AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(scrData));
    //    //txtの更新
    //    DBIO.WriteText(_database.CreateDataTxt(), DBIO.CreateSavePath_txt(_dirName));
    //    AssetDatabase.Refresh();
    //    DebugMessage_success("Remove");
    //}
    //public DBData EditDBD(string name)
    //{
    //    var data= _database.GetDataList().Where(x => x._Data._serchId == name).ToList();
    //    if (data == null||data.Count==0)
    //    {
    //        DebugMessage_miss("Edit:not contain this name:"+name);
    //        return null;
    //    }
    //    else DebugMessage_success("Edit");
    //    return new DBData( data.First()._Data,name);
    //}
    //public void UpdateDBD(DBData data,string oldName)
    //{
    //    var targetData = _database.GetDataList().Where(x => x._Data._serchId == oldName).FirstOrDefault();
    //    if (targetData==null)
    //    {
    //        DebugMessage_miss("Update:not containt this name:"+oldName);
    //        return;
    //    }
    //    //scriptableObjectの更新
    //    AssetDatabase.RenameAsset(DBIO.CreateSavePath_asset(_dirName,oldName), data._serchId);
    //    targetData.UpdateData(data);
    //    EditorUtility.SetDirty(targetData);
    //    //txtの更新
    //    DBIO.WriteText(_database.CreateDataTxt(), DBIO.CreateSavePath_txt(_dirName));
    //    AssetDatabase.Refresh();
    //    DebugMessage_success("Update");
    //}
    public void SyncDataByTxt(TextAsset textAsset)
    {
        if (!DBIO.CheckDir(DBIO.CreateAssetDirectoryPath(textAsset.name)))
        {
            DBIO.CreateDir(DBIO.CreateAssetDirectoryPath(textAsset.name));
        }

        var textDataList = DBListCreator.CreateDBListBytxt(DBIO.TrimType(textAsset.text).replaced);
        var assetDBList  = _database.GetDataList();

        //txtに書いてないものを削除
        for (int i = assetDBList.Count - 1; i >= 0; i--)
        {
            if (textDataList.Where(x => x._serchId == assetDBList[i]._Data._serchId).FirstOrDefault() == null)
            {
                AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(assetDBList[i]));
                assetDBList.RemoveAt(i);
            }
        }
        //txtに書いてあるけどデータがないものを追加
        foreach (var data in textDataList)
        {
            var target = assetDBList.Where(x => x._Data._serchId == data._serchId).FirstOrDefault();
            if (target == null)
            {
                target = AbstractDBData.GetInstance <T>();
                AssetDatabase.CreateAsset(target, DBIO.CreateSavePath_asset(textAsset.name, data._serchId));
                _database.GetDataList().Add(target);
            }
            target.UpdateData(data);
            EditorUtility.SetDirty(target);
        }

        EditorUtility.SetDirty(_database);
        AssetDatabase.Refresh();
        DebugMessage_success("SyncText");
    }