Example #1
0
        /// <summary>
        /// 以客户端安装包默认的资源版本配置为基准创建一个新的本地缓存
        /// </summary>
        /// <param name="remoteVersions"></param>
        public void CreateVersionsCached(ref ResDataVersion remoteVersions)
        {
            string path = AppPaths.PersistentResDataRoot.Append(ResDataVersion.FILE_RES_DATA_VERSIONS_NAME);
            string data = FileOperater.ReadUTF8Text(path);

            ResDataVersion temp = JsonUtility.FromJson <ResDataVersion>(data);

            if (temp == default || temp.IsVersionsEmpty())
            {
#if LOG_CLIENT_VERSIONING
                "log".Log("Verision data is empty, will create new one.");
#endif
                temp = new ResDataVersion
                {
                    res_gateway = remoteVersions.res_gateway,
                    app_version = remoteVersions.app_version,
                    res_version = remoteVersions.res_version
                };

                ResDataVersion client = Versions;
                temp.CloneVersionsFrom(ref client);
            }
            else
            {
            }

            CachedVersion = temp;
            CachedVersion.resVersionType = ResDataVersionType.Cached;
        }
        public static void DelStreamingResource()
        {
            if (EditorUtility.DisplayDialog("警告", string.Format("即将删除 {0} 目录下所有文件,操作不可逆,是否继续?", Application.streamingAssetsPath), "立刻、马上", "我再想想"))
            {
                Action <BuildTarget> method = (buildTarget) =>
                {
                    string resRoot      = AppPaths.StreamingResDataRoot;
                    string platformRoot = GetSuffix(buildTarget);
                    FileOperater.DeleteFileDirection(resRoot.Append(platformRoot));
                    FileOperater.DeleteFileDirection(resRoot.Append(platformRoot.Append(",meta")));
                };

                method.Invoke(BuildTarget.Android);
                method.Invoke(BuildTarget.iOS);
                method.Invoke(BuildTarget.StandaloneOSX);
                method.Invoke(BuildTarget.StandaloneWindows);
                method.Invoke(BuildTarget.StandaloneWindows64);

                FileOperater.DeleteFileDirection(AppPaths.StreamingResDataRoot);
                FileOperater.DeleteFileDirection(AppPaths.StreamingResDataRoot.Append(",meta"));

                AssetDatabase.Refresh();//刷新
            }
            else
            {
            }
        }
Example #3
0
    //获取存档信息
    public static GameData getData(string ID = "0")
    {
        //读取信息
        FileOperater fileOp   = new FileOperater();
        string       fileName = Application.persistentDataPath + "/GameData" + ID + ".sav";
        GameData     theData  = fileOp.loadBinary(fileName);

        return(theData);
    }
 public static void DelPersistentResource()
 {
     if (EditorUtility.DisplayDialog("警告", string.Format("即将删除 {0} 目录下的资源文件,操作不可逆,是否继续?", Application.persistentDataPath), "立刻、马上", "我再想想"))
     {
         FileOperater.DeleteFileDirection(AppPaths.PersistentResDataRoot);
         AssetDatabase.Refresh();//刷新
     }
     else
     {
     }
 }
Example #5
0
        /// <summary>
        /// 作为本地正式缓存写入本地文件
        /// </summary>
        public void WriteAsCached()
        {
            Refresh();
            SaveUpdatings();

            string versions = JsonUtility.ToJson(this);
            string path     = AppPaths.PersistentResDataRoot.Append(FILE_RES_DATA_VERSIONS_NAME);

#if !RELEASE
            FileOperater.WriteUTF8Text(versions, path.Append(".json~"));//写入一个用于查看的文件
#endif
            "todo".Log("资源版本写入设备时需要加密");
            FileOperater.WriteBytes(versions, path);
        }
        /// <summary>
        /// 创建资源版本
        /// </summary>
        /// <param name="remoteVers"></param>
        private void BuildVersionConfig(ref ResDataVersion remoteVers)
        {
            string         versions       = default;
            ResDataVersion resDataVersion = default;

            GetVersionDataFromRemote(ref remoteVers, ref versions, ref resDataVersion);

            string[] abNamesValue = ABNamesWillBuild != default ? ABNamesWillBuild.ToArray() : new string[0];
            resDataVersion.CreateNewResVersion(ref resRemoteGateWay, isUpdateVersion, isUpdateResVersion, isSyncAppVersion, ref remoteVers, ref abNamesValue);
            resDataVersion.Refresh();

            bool applyClientGateway = false;

            if (isSyncClientVersions)
            {
                List <ScriptableObject> list = default;
                ShipDockEditorUtils.FindAssetInEditorProject(ref list, "t:ScriptableObject", @"Assets\Prefabs");
                ClientResVersion clientRes = default;// = (ClientResVersion)list[0];
                foreach (ScriptableObject i in list)
                {
                    if (i.name == ClientVersionFileName)
                    {
                        clientRes = (ClientResVersion)i;
                        break;
                    }
                    else
                    {
                    }
                }

                applyClientGateway = clientRes.ApplyCurrentResGateway;
                if (applyClientGateway)
                {
                    resDataVersion.res_gateway = clientRes.ClientResVersionGateway();
                }

                clientRes.Versions.CloneVersionsFrom(ref resDataVersion);
                clientRes.SetChanges(resDataVersion.ResChanges);
                UnityEditor.EditorUtility.SetDirty(clientRes);
            }
            versions = JsonUtility.ToJson(resDataVersion);
            string stamp = "_".Append(System.DateTime.Now.ToShortDateString().Replace("/", "_"));

            FileOperater.WriteUTF8Text(versions, Application.dataPath.Append("/Prefabs/ClientResVersions_Previews/", ResDataVersion.FILE_RES_DATA_VERSIONS_NAME, stamp, ".json")); //仅用于查看
            FileOperater.WriteBytes(versions, AppPaths.ABBuildOutputRoot.Append(ResDataVersion.FILE_RES_DATA_VERSIONS_NAME));                                                      //位于资源主目录里的正式文件

            resDataVersion.Clean();
            remoteVers?.Clean();
        }
Example #7
0
    public static bool LoadInformation(string ID = "0")
    {
        //读取信息
        FileOperater fileOp   = new FileOperater();
        string       fileName = Application.persistentDataPath + "/GameData" + ID + ".sav";
        GameData     theData  = fileOp.loadBinary(fileName);

        //存档校验
        if (theData == null)
        {
            return(false);
        }

        SystemValues.theSaveData = theData;
        UIController.GetInstance().ShowUI <UILoading> (theData.SceneName);
        return(true);
    }
 private void GetVersionDataFromRemote(ref ResDataVersion remoteVers, ref string versions, ref ResDataVersion resDataVersion)
 {
     if (remoteVers == default)
     {
         versions       = FileOperater.ReadUTF8Text(AppPaths.ABBuildOutputRoot.Append(ResDataVersion.FILE_RES_DATA_VERSIONS_NAME));
         resDataVersion = JsonUtility.FromJson <ResDataVersion>(versions);
         if (resDataVersion == default)
         {
             resDataVersion = new ResDataVersion
             {
                 app_version = Application.version,
                 res_version = remoteVers != default ? remoteVers.res_version : 0,//根据是否存在线上版本同步资源号
             };
         }
     }
     else
     {
         resDataVersion = new ResDataVersion();
         resDataVersion.CloneVersionsFrom(ref remoteVers);
     }
 }
Example #9
0
    public static bool SaveInformation(string ID = "0")
    {
        //存档校验
        if (!SystemValues.thePlayer)
        {
            return(false);
        }

        Player thePlayers = SystemValues.thePlayer.GetComponent <Player> ();

        if (!thePlayers)
        {
            return(false);
        }

        //构建存档信息
        GameData theData = new GameData();

        theData.playerLv        = thePlayers.lvNow;
        theData.playerDamge     = thePlayers.attackDamage;
        theData.playerHp        = thePlayers.hpNow;
        theData.playerHpMax     = thePlayers.hpMaxNow;
        theData.playerLearn     = thePlayers.learningValue;
        theData.playerLearnMax  = thePlayers.learningValueMax;
        theData.plotIDs         = SystemValues.plotIDNow;
        theData.SceneName       = Application.loadedLevelName;
        theData.playerPositionX = thePlayers.transform.position.x;
        theData.playerPositionY = thePlayers.transform.position.y;
        theData.playerPositionZ = thePlayers.transform.position.z;

        theData.missions = thePlayers.theMissionPackage.theMissions;

        //真实存档
        FileOperater fileOp   = new FileOperater();
        string       fileName = Application.persistentDataPath + "/GameData" + ID + ".sav";

        print(fileName);
        fileOp.SaveBinary(fileName, theData);
        return(true);
    }
        public IHttpActionResult Get(string id)
        {
            FileOperater operater = new FileOperater();
            string       fileName = operater.GetFilePath(id);

            if (fileName != null)
            {
                string path   = System.Web.Hosting.HostingEnvironment.MapPath($"~/Resources/{fileName}");
                Stream stream = File.Open(path, FileMode.Open);
                HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StreamContent(stream),
                };
                message.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(MimeMapping.GetMimeMapping(fileName));
                return(ResponseMessage(message));
            }
            else
            {
                HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(ResponseMessage(message));
            }
        }
Example #11
0
        /// <summary>
        /// 读取表数据,生成对应的数组
        /// </summary>
        /// <param name="filePath">excel文件全路径</param>
        /// <returns>Item数组</returns>
        public static void CreateItemArrayWithExcel(string filePath, out string relativeName, ref string log)
        {
            InitExeclDefs();
            log += filePath + "开始解析... \r\n";

            DataRowCollection collect = ReadExcel(filePath, out int rowSize, out int colSize);//获得表数据
            ExeclDefination   defination = Setting.classDefine;
            int    col = defination.column, row = defination.row;
            string className = collect[row][col].ToString();//类名

            defination = Setting.generateFileName;
            col        = defination.column;
            row        = defination.row;
            string fileName = collect[row][col].ToString();//生成的配置文件名

            fileName = string.IsNullOrEmpty(fileName) ? className : fileName;

            defination = Setting.classType;
            col        = defination.column;
            row        = defination.row;
            string classType = collect[row][col].ToString();//类模板的类别

            defination = Setting.IDFieldName;
            col        = defination.column;
            row        = defination.row;
            string IDName = collect[row][col].ToString();//id字段的名称

            defination = Setting.dataStart;
            int dataStartRow = defination.row;
            int dataStartCol = defination.column;

            Debug.Log(rowSize);

            string cellData;

            for (int i = dataStartRow; i < rowSize; i++)
            {
                cellData = collect[i][dataStartCol].ToString();
                if (string.IsNullOrEmpty(cellData))
                {
                    rowSize = i;//找到数据起始列为空的一行,作为数据最终行
                    Debug.Log(rowSize);
                    break;
                }
                else
                {
                }
            }

            StringBuilder sb = new StringBuilder();

            int typeRow  = Setting.dataType.row;     //类型名所在行
            int keyRow   = Setting.keyFieldDef.row;  //字段名所在行
            int notesRow = Setting.noteFieldDef.row; //注释所在行

            DataRow rowData    = collect[typeRow];
            object  colData    = rowData[dataStartCol];
            object  IDTypeCell = collect[typeRow][dataStartCol];

            string            typeValue = GetCSharpForTypeValueCode(IDTypeCell.ToString());
            ClassTemplateInfo info      = new ClassTemplateInfo
            {
                sb           = sb,
                collect      = collect,
                className    = className,
                notesRow     = notesRow,
                dataStartCol = dataStartCol,
                typeValue    = typeValue,
                IDName       = IDName,
            };

            switch (classType)
            {
            case "mapper":
                TranslateConfigCSharpClassCode(info);
                break;

            case "const":    //常量类
                sb.Append("namespace StaticConfig");
                sb.Append("{");
                sb.Append("    public static class %cls%".Replace(info.rplClsName, className));
                sb.Append("    {");
                sb.Append("    }");
                sb.Append("}");
                break;
            }
            string field, notes, valueInitCode;
            string CSharpScript = sb.ToString();

            sb.Clear();

            object item;
            string parserCode = IDName.Append(GetCSharpForSetValueCode(IDTypeCell.ToString())); //获取到翻译后的 id 赋值语句

            for (int i = dataStartCol + 1; i < colSize; i++)                                    //从id列顺延下一个字段开始构建剩余的脚本
            {
                item      = collect[typeRow][i];                                                //类型
                typeValue = item.ToString();

                if (string.IsNullOrEmpty(typeValue))
                {
                    colSize = i;//读取到无效的表头,此前的所有字段为完整的类成员字段,并更新到列数
                    break;
                }
                else
                {
                }

                typeValue = GetCSharpForTypeValueCode(typeValue);

                item          = collect[keyRow][i];//字段名
                field         = item.ToString();
                notes         = collect[notesRow][i].ToString();
                valueInitCode = collect[typeRow][i].ToString();

                sb.Append("/// <summary>");
                sb.Append("\r\n        /// %notes%")
                .Replace(info.notes, notes);
                sb.Append("\r\n        /// <summary>\r\n        ");
                sb.Append("public %type% %fieldName%;\r\n")
                .Replace(info.typeName, typeValue)
                .Replace(info.fieldName, field);
                sb.Append("        ");

                parserCode = parserCode.Append(field, GetCSharpForSetValueCode(valueInitCode));//获取到翻译后的其他成员字段赋值语句
            }

            CSharpScript = CSharpScript.Replace(info.codes, sb.ToString());  //合成类成员字段的声明语句
            CSharpScript = CSharpScript.Replace(info.parseCode, parserCode); //合成类成员字段的初始化赋值语句
            sb.Clear();

            object     ID;
            string     IDValue;
            DataRow    itemRow;
            ByteBuffer byteBuffer   = ByteBuffer.Allocate(0);
            int        dataRealSize = rowSize - dataStartRow;

            byteBuffer.WriteInt(dataRealSize);
            for (int i = dataStartRow; i < rowSize; i++)
            {
                itemRow = collect[i];
                ID      = itemRow[dataStartCol];

                IDValue = ID.ToString();
                if (string.IsNullOrEmpty(IDValue))
                {
                    Debug.LogWarning("Config ID invalid in row " + i + ", it do not allow empty, config bytes parse will be break.");
                    break;
                }
                else
                {
                    Debug.Log("Writing in ID = " + IDValue.ToString());
                    for (int j = dataStartCol; j < colSize; j++)//从id列顺延下一个字段开始构建剩余的脚本
                    {
                        item = collect[typeRow][j];

                        typeValue = item.ToString();       //字段类型
                        field     = itemRow[j].ToString(); //字段数据

                        WriteField(ref byteBuffer, typeValue, field, collect[keyRow][j].ToString());
                    }
                }
            }
            Debug.Log("Write finished.. length = " + byteBuffer.GetCapacity());

            string path = GetCSharpCodeFilePath(className);

            FileOperater.WriteUTF8Text(CSharpScript, path);//生成代码

            path = GetConfigFilePath(fileName, out relativeName);
            FileOperater.WriteBytes(byteBuffer.ToArray(), path);//生成配置数据文件
        }