Example #1
0
    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     = GameSaveUtility.GetGobalObjectData(componentName);
        SetValue  setValue      = GameSaveUtility.GetGobalSetValue <T1, T2>(gobalData);

        if (null == setValue)
        {
            return(false);
        }
        bool result = gameSaveSystem.Load <T1, T2>(component, setValue);

        return(result);
    }