Beispiel #1
0
        private static List <string> GetEntityKeys(Type entityType, string entityId)
        {
            List <string> entityKeys = new List <string>();

            foreach (DataMemberInfo dataMemberInfo in PlayerPrefsCache.GetDataMemberInfoWithFieldAttribute(entityType))
            {
                entityKeys.Add(GetFieldKey(entityId, entityType, dataMemberInfo));
            }
            return(entityKeys);
        }
Beispiel #2
0
        public static void Save(object entity)
        {
            string entityId   = GetEntityId(entity);
            Type   entityType = entity.GetType();
            List <DataMemberInfo> dataMemberInfos = PlayerPrefsCache.GetDataMemberInfoWithFieldAttribute(entityType);

            foreach (DataMemberInfo dataMemberInfo in dataMemberInfos)
            {
                string fieldKey  = GetFieldKey(entityId, entityType, dataMemberInfo);
                Type   fieldType = dataMemberInfo.GetMemberInfoType();
                PlayerPrefsFieldHandler fieldHandler = PlayerPrefsFieldFactory.Get(fieldType);
                fieldHandler.SetValue(fieldKey, dataMemberInfo, entity);
            }
            PlayerPrefs.Save();
        }
Beispiel #3
0
        public static void Load(object entity, string entityId)
        {
            Type entityType = entity.GetType();
            List <DataMemberInfo> dataMemberInfos = PlayerPrefsCache.GetDataMemberInfoWithFieldAttribute(entityType);

            foreach (DataMemberInfo dataMemberInfo in dataMemberInfos)
            {
                string fieldKey  = GetFieldKey(entityId, entityType, dataMemberInfo);
                Type   fieldType = dataMemberInfo.GetMemberInfoType();
                if (PlayerPrefs.HasKey(fieldKey))
                {
                    PlayerPrefsFieldHandler fieldHandler = PlayerPrefsFieldFactory.Get(fieldType);
                    dataMemberInfo.SetValue(entity, fieldHandler.GetValue(fieldKey));
                }
            }
        }
Beispiel #4
0
        private static void SetEntityId(object entity, string entityId)
        {
            Type entityType = entity.GetType();
            List <DataMemberInfo> dataMemberInfos = PlayerPrefsCache.GetDataMemberInfoWithEntityIdAttribute(entityType);

            if (dataMemberInfos.Count == 0)
            {
                throw new Exception(string.Format("Entity {0} doesn't contain EntityId attribute.", entityType));
            }

            if (dataMemberInfos.Count > 1)
            {
                throw new Exception(string.Format("Entity {0} contains more than one EntityId attribute.", entityType));
            }

            dataMemberInfos[0].SetValue(entity, entityId);
        }
Beispiel #5
0
        private static string GetEntityId(object entity)
        {
            Type entityType = entity.GetType();
            List <DataMemberInfo> dataMemberInfos = PlayerPrefsCache.GetDataMemberInfoWithEntityIdAttribute(entityType);

            if (dataMemberInfos.Count == 0)
            {
                return(SingleEntityId);
            }

            if (dataMemberInfos.Count > 1)
            {
                throw new Exception(string.Format("Entity {0} contains more than one EntityId attribute.", entityType));
            }

            return(dataMemberInfos[0].GetValue <string>(entity));
        }
        private static string GetFieldKey(string entityId, Type entityType, string dataMemberName)
        {
            string entityName = PlayerPrefsCache.GetEntityName(entityType);

            return($"{EntityKeyPrefix}.{entityName}.{entityId}.{dataMemberName}");
        }