public void PushObject(object obj, string keyName = null) { if (mIsTxtMode) { mContext = StringSerialize.Serialize(obj); } else { if (string.IsNullOrEmpty(keyName)) { keyName = obj.GetType().Name; } BytesPack pack = null; if (mIsBinary) { pack = BytesSerialize.Serialize(obj); } else { string temps = StringSerialize.Serialize(obj); pack = new BytesPack(); pack.CreateReadBytes(System.Text.Encoding.UTF8.GetBytes(temps)); } mDataPacks[keyName] = pack; } }
// 重写Inspector检视面板 public override void OnInspectorGUI() { np.StartInit = EditorGUILayout.Toggle("运行显示", np.StartInit); np.StartDataConfig = EditorGUILayout.Toggle("启用数据", np.StartDataConfig); if (!string.IsNullOrEmpty(np.mDataConfig)) { if (GUILayout.Button("删除数据文件")) { np.mDataConfig = null; } } //数据序列化 if (np.StartDataConfig) { if (!string.IsNullOrEmpty(np.mDataConfig)) { GUILayout.Label("---------------------------------------------------"); GUILayout.Label("数据解析:" + np.mDataConfig); GUILayout.Label("---------------------------------------------------"); } if (np.mUnitObject != null) { MyEdior.DrawConverter.DrawObject(np.mUnitObject, null); if (GUILayout.Button("保存数据")) { np.mDataConfig = StringSerialize.Serialize(np.mUnitObject); } } } string tempName = np.StartConfig ? "保存配置" : "Delete"; mSelectPrefab.InitGUI(); np.nTypeKey = mSelectPrefab.getSelectKey(); if (mCurSelectName != np.nTypeKey) { mCurSelectName = np.nTypeKey; } if (np.mUnitObject == null) { GUILayout.Space(10); if (GUILayout.Button("Create")) { np.SetActive(true); } } else { GUILayout.Space(10); if (GUILayout.Button(tempName)) { GameObject.DestroyImmediate(np.mUnitObject.gameObject); } } MyEdior.KeepScene(); }
/* * public static void NormalRectTransform(this RectTransform rt) * { * rt.offsetMin = Vector2.zero; * rt.offsetMax = Vector2.zero; * rt.localPosition = Vector3.zero; * rt.localScale = Vector3.one; * rt.localRotation = Quaternion.identity; * } */ public static T EncryptObject <T>(this string str, bool isArray = false) where T : new() { string realyValue = str; if (realyValue.Contains("|")) { realyValue = "{" + realyValue.Replace("|", "},{") + "}"; } return(StringSerialize.Deserialize <T>("{" + realyValue + "}")); }
public static void SentMsg(string key, FNetHead json) { #if UNITY_EDITOR if (FEngine.instance.UDPOPEN) { FoxUdp fu = new FoxUdp(); fu.key = key; fu.json = StringSerialize.Serialize(json); Send(fu); } #endif }
private object _GetObject(object obj, System.Type type, string keyName) { if (mIsTxtMode) { if (obj == null) { return(StringSerialize.Deserialize(mContext, type)); } else { StringSerialize.Deserialize(mContext, obj); } } else { if (string.IsNullOrEmpty(keyName)) { keyName = type.Name; } BytesPack pack = null; if (mDataPacks.TryGetValue(keyName, out pack)) { if (mIsBinary) { if (obj == null) { return(BytesSerialize.Deserialize(pack, type)); } else { BytesSerialize.Deserialize(pack, obj); } } else { string str = System.Text.Encoding.UTF8.GetString(pack.GetStream()); if (obj == null) { return(StringSerialize.Deserialize(str, type)); } else { StringSerialize.Deserialize(str, obj); } } } } return(null); }
public void SaveFile(string fileName, Type type) { //保存配置 FSaveHandle sd = FSaveHandle.Create(fileName, FFilePath.FP_Abs, FOpenType.OT_Write); SaveTreeFile stf = new SaveTreeFile(); stf.typeName = type.FullName; stf.headHodeName = mRootNode.mData.nodeName; stf.data = new SaveTreeFile.Data[mBuffNodes.Count]; IList paramList = Array.CreateInstance(type, mBuffNodes.Count); int index = 0; stf.param = StringSerialize.Serialize(paramList); sd.PushObject(stf); sd.Save(); }
protected override void Solve() { // Limit of 15 digits at max value. ulong inputLimit = 999999999999999; ulong input = Input.RequestULong(Prompt + " The limit is 15 digits.", inputLimit); int root = (int)Math.Sqrt(input); int[] primes = Primes.Generate(root); List <int> factors = new List <int>(); int high = 0; foreach (int i in primes) { if (input % (ulong)i == 0) { factors.Add(i); high = i; } } if (factors.Count > 1) { string str = StringSerialize.StringListFromInts(factors.ToArray()); Console.WriteLine("\n" + str + "\n"); Console.WriteLine($"There are {factors.Count} prime factors for the number {input}, listed above."); Console.WriteLine($"Therefore, the largest prime factor of {input} is {high}.\n"); } else if (factors.Count == 1) { Console.WriteLine($"\nThere is only one prime factor for the number {input}, it is {factors[0]}"); Console.WriteLine($"Therefore, the largest prime factor of {input} is {high}.\n"); } else { Console.WriteLine($"\nThe number {input} is prime itself!"); Console.WriteLine("Therefore, its highest prime factor is itself!\n"); } int x = Input.RequestInt(".."); int[] y = Primes.Generate(x); Console.WriteLine($"The largest index generated from {x} is {y.Length}."); }
public T GetValue <T>() where T : new () { return(StringSerialize.Deserialize <T>("{" + Value + "}")); }
// Start is called before the first frame update public static void MenuExportConfig() { List <string> paths = new List <string>(); List <AssetBundleBuild> build_list = new List <AssetBundleBuild>(); /// 获得所有配置文件 EditorSearchFile.SearchPath(CONFIG_PATH, paths, null); /// 生成配置文件文本 for (int index = paths.Count - 1; index >= 0; index--) { string path = paths[index].Replace("\\", "/").Replace("//", "/"); string path_assets = path.Replace("/../Config/", "/_TEMP_CONFIG/"); if (path_assets.LastIndexOf(".") == -1) { Debug.LogError(string.Format("Export Config Error > {0}", path)); continue; } if (path_assets.LastIndexOf("/.") != -1) { Debug.LogWarning(string.Format("Export Config Error > {0}", path)); continue; } /// 创建目录 if (!System.IO.Directory.Exists(EditorSearchFile.FilePath(path_assets))) { System.IO.Directory.CreateDirectory(EditorSearchFile.FilePath(path_assets)); } path_assets = path_assets.Substring(0, path_assets.LastIndexOf(".")); path_assets = path_assets.Substring(path_assets.LastIndexOf("/Assets/") + 1); path_assets += ".asset"; byte[] data = StringSerialize.ByteEncrypt(System.IO.File.ReadAllBytes(path)); /// 如果相同 /// 这个文件就不在导出处理 /// 这样可以节省下来一些时间 if (System.IO.File.Exists(Application.dataPath + "/../" + path_assets)) { try { if (EditorSearchFile.EqualsBytes(data, AssetDatabase.LoadAssetAtPath <StringSerialize>(path_assets).bytes)) { Debug.Log(string.Format("Export Config : {0} -> Continue", path)); continue; } } catch { Debug.LogWarning(string.Format("Export Config (隐藏目录): {0} -> Continue", path)); continue; } } /// 设置 assetsbundle 打包 AssetBundleBuild buildTemp = new AssetBundleBuild(); buildTemp.assetNames = new string[] { path_assets }; buildTemp.assetBundleVariant = "ab"; buildTemp.assetBundleName = path_assets.Replace("Assets/_TEMP_CONFIG/", "").ToLower().Replace(".asset", ""); build_list.Add(buildTemp); Debug.Log(string.Format("Export Config : {0} -> New", path)); /// 序列化文件 StringSerialize data_serialize = ScriptableObject.CreateInstance <StringSerialize>(); data_serialize.bytes = data; data_serialize.isEncrypt = true; AssetDatabase.CreateAsset(data_serialize, path_assets); AssetDatabase.ImportAsset(path_assets); AssetDatabase.AssetPathToGUID(path_assets); AssetDatabase.SaveAssets(); } /// 导出 Config 资源 if (build_list.Count > 0) { if (!System.IO.Directory.Exists(EXPORT_PATH)) { System.IO.Directory.CreateDirectory(EXPORT_PATH); } #if UNITY_ANDROID BuildPipeline.BuildAssetBundles("Export/assetsbundle/config", build_list.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android); #endif #if UNITY_IOS BuildPipeline.BuildAssetBundles("Export/assetsbundle/config", build_list.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.iOS); #endif AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
public void Deserialize() { if (mValue == null) { return; } if (mDatas.Count == 0) { _LoadExcel(); } int errorLine = 4; try { var ass = Assembly.Load("Assembly-CSharp"); object assetObject = mValue; //if (assetObject == null) //{ // assetObject = ScriptableObject.CreateInstance(ass.GetType(mPath.ClassName)); //} FieldInfo field = assetObject.GetType().GetField("ProList"); Type[] tempTypes = field.FieldType.GetGenericArguments(); var listType = typeof(List <>).MakeGenericType(tempTypes); IList list = (IList)Activator.CreateInstance(listType); var subType = ass.GetType(tempTypes[0].FullName); ////特殊需求 List <string> mArrayName = new List <string>(); FieldInfo[] subFields = subType.GetFields(); for (int i = 0; i < subFields.Length; i++) { var sf = subFields[i]; var f = sf.FieldType; Type t = null; if (f.IsGenericType && f.GetGenericTypeDefinition() == typeof(List <>)) { Type[] xxx = f.GetGenericArguments(); t = xxx[0]; } else if (f.IsArray) { t = f.GetElementType(); } if (t != null && !t.IsPrimitive && t != typeof(string)) { mArrayName.Add(sf.Name); } } StringBuilder StrBuf = new StringBuilder(); for (int i = 0; i < mDatas.Count; i++) { Dictionary <string, string> tempBuff = mDatas[i]; object subTobject = System.Activator.CreateInstance(subType); StrBuf.Length = 0; StrBuf.Append("{"); foreach (var k in tempBuff) { ////特殊需求 string realyValue = ComputerString(k.Value, false); if (!realyValue.Contains("|")) { if (mArrayName.Contains(k.Key)) { if (realyValue != "") { if (!realyValue.Contains("{")) { realyValue = "{" + realyValue + "}"; } } } } StrBuf.Append(k.Key + "=" + "{" + realyValue + "},"); } if (StrBuf.Length > 2) { //去掉逗号 StrBuf.Length--; } StrBuf.Append("}"); errorLine++; StringSerialize.Deserialize(StrBuf.ToString(), subTobject); list.Add(subTobject); } field.SetValue(assetObject, list); } catch (System.Exception e) { mError = (mPath.ClassName + "错误行数:[" + errorLine.ToString() + "]---其他:" + e.ToString()); } }
public void SaveFile(string fileName, Type type) { //保存配置 FArpgNode roots = GetRoots(); Dictionary <string, FArpgNode> nodes = roots.mMainBuffs; FSaveHandle sd = FSaveHandle.Create(fileName, FFilePath.FP_Abs, FOpenType.OT_Write); ArpgFileData arpgFileData = new ArpgFileData(); arpgFileData.typeName = type.FullName; arpgFileData.headHodeName = mStartNodeName; ArpgFileData.Data[] datas = new ArpgFileData.Data[nodes.Count]; arpgFileData.data = datas; IList paramList = Array.CreateInstance(type, nodes.Count); int index = 0; foreach (var k in nodes) { var afd = new ArpgFileData.Data(); datas[index] = afd; afd.rect = new Unit_Rect(); afd.rect.SetRect(k.Value.mRect); //条件判断事件 var conditions = k.Value.mFArgpBaseData.ConditionCallBack; if (conditions != null && conditions.Length != 0) { afd.conditionMothods = new string[conditions.Length]; for (int i = 0; i < conditions.Length; i++) { afd.conditionMothods[i] = conditions[i].Method.Name; } } //状态执行事件 var states = k.Value.mFArgpBaseData.PlayStateCallBacks; if (states != null && states.Length != 0) { afd.playMothods = new string[states.Length]; for (int i = 0; i < states.Length; i++) { afd.playMothods[i] = states[i].Method.Name; } } if (k.Value.mSkipNode != null) { afd.skipNode = k.Value.mSkipNode.mFArgpBaseData.nodeName; } afd.nextData = new string[k.Value.mNextData.Count]; for (int i = 0; i < k.Value.mNextData.Count; i++) { afd.nextData[i] = k.Value.mNextData[i].mFArgpBaseData.nodeName; } paramList[index++] = k.Value.mFArgpBaseData; } arpgFileData.param = StringSerialize.Serialize(paramList); sd.PushObject(arpgFileData); sd.Save(); }
public string LoadFile(string name, FFilePath pathType = FFilePath.FP_Relative) { string tempPath = "." + ResConfig.ARPGEX; if (!name.EndsWith(tempPath)) { name += tempPath; } NewRoot(); //加载配置 FSaveHandle sd = FSaveHandle.Create(name, pathType); ArpgFileData afd = new ArpgFileData(); sd.FromObject(afd); mStartNodeName = afd.headHodeName; IList baseData = (IList)StringSerialize.Deserialize(afd.param, typeof(List <>).MakeGenericType(Assembly.Load("Assembly-CSharp").GetType(afd.typeName))); if (afd != null) { FArpgNode roots = GetRoots(); for (int i = 0; i < afd.data.Length; i++) { var d = afd.data[i]; FArgpBaseData farpgData = (FArgpBaseData)baseData[i]; if (d.conditionMothods != null) { farpgData.ConditionCallBack = new Func <FArpgNode, FArpgNode, bool> [d.conditionMothods.Length]; for (int c = 0; c < d.conditionMothods.Length; c++) { farpgData.ConditionCallBack[c] = (System.Func <FArpgMachine.FArpgNode, FArpgMachine.FArpgNode, bool>)System.Delegate.CreateDelegate(typeof(System.Func <FArpgMachine.FArpgNode, FArpgMachine.FArpgNode, bool>), farpgData, d.conditionMothods[c]); } } if (d.playMothods != null) { farpgData.PlayStateCallBacks = new Action <FArpgNode, float, int> [d.playMothods.Length]; for (int c = 0; c < d.playMothods.Length; c++) { farpgData.PlayStateCallBacks[c] = (System.Action <FArpgNode, float, int>)System.Delegate.CreateDelegate(typeof(System.Action <FArpgNode, float, int>), farpgData, d.playMothods[c]); } } FArpgNode node = roots.Regs(farpgData, true, null); node.mRect = d.rect.GetRect(); } for (int i = 0; i < afd.data.Length; i++) { var d = afd.data[i]; FArgpBaseData farpgData = (FArgpBaseData)baseData[i]; FArpgNode node = roots.mMainBuffs[farpgData.nodeName]; if (d.skipNode != "") { node.mSkipNode = roots.mMainBuffs[d.skipNode]; } if (d.nextData != null) { for (int j = 0; j < d.nextData.Length; j++) { var nextNode = roots.mMainBuffs[d.nextData[j]]; node.Regs(nextNode); } } } } SetStartNode(mStartNodeName); return(afd.typeName); }