private static SetValue GetGobalSetValue <T1, T2>(GobalData gobalData) where T1 : ISave <T2> { string ISaveName = typeof(T1).Name; string componentName = typeof(T2).Name; if (null == gobalData) { Debug.LogError(string.Format("存档未找到{0}全局数据", componentName)); return(null); } if (false == gobalData.SetValues.ContainsKey(componentName)) { Debug.LogError(string.Format("存档未找到{0}对应的组件类型", componentName)); return(null); } Dictionary <string, SetValue> setValues = gobalData.SetValues[componentName]; if (false == setValues.ContainsKey(ISaveName)) { Debug.LogError(string.Format("存档未找到{0}对应的赋值操作类型", ISaveName)); return(null); } return(setValues[ISaveName]); }
public static GobalData AddGobalObjectData(string name) { if (gameSaveSystem.GameData.GobalDatas.ContainsKey(name)) { Debug.LogError(string.Format("存档已存在{0}对应的物体", name)); return(null); } else { GobalData gobalData = new GobalData(name); gameSaveSystem.GameData.GobalDatas.Add(name, gobalData); return(gobalData); } }
public void SaveGobal <T1, T2>(string componentName, string value) where T1 : ISave <T2> { if (string.IsNullOrEmpty(componentName)) { return; } string ISaveName = typeof(T1).Name; GobalData gobalData = GameSaveUtility.GetGobalObjectData(componentName); if (null == gobalData) { gobalData = GameSaveUtility.AddGobalObjectData(componentName); } if (gobalData.SetValues.CheckEmpty()) { gobalData.SetValues = new Dictionary <string, Dictionary <string, SetValue> >(); } Dictionary <string, SetValue> setValues; if (gobalData.SetValues.ContainsKey(componentName)) { setValues = gobalData.SetValues[componentName]; } else { setValues = new Dictionary <string, SetValue>(); gobalData.SetValues.Add(componentName, setValues); } SetValue setValue = new SetValue { FunOpera = ISaveName, Value = value }; if (setValues.ContainsKey(ISaveName)) { setValues[ISaveName] = setValue; } else { setValues.Add(ISaveName, setValue); } }
/// <summary> /// 读取内存中的全局数据 /// </summary> /// <typeparam name="T1">赋值操作对象类型。</typeparam> /// <typeparam name="T2">你希望保存组件对象类型 /// 请务必保证该类型中的泛型,是你希望保存组件对象类型</typeparam> /// <param name="component">全局对象</param> /// <returns></returns> public static bool LoadGobal <T1, T2>(this T2 component) where T1 : ISave <T2> { if (component.CheckEmpty()) { return(false); } string componentName = typeof(T2).Name; GobalData gobalData = GetGobalObjectData(componentName); SetValue setValue = GetGobalSetValue <T1, T2>(gobalData); if (null == setValue) { return(false); } bool result = GameSaveSystem.Load <T1, T2>(component, setValue); return(result); }