コード例 #1
0
        public void SaveState(bool saveFile = false)
        {
            if (!allowSaving)
            {
                return;
            }

            var fields = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(field => field.IsDefined(typeof(SaveStateAttribute), true));

            foreach (FieldInfo field in fields)
            {
                if (field.FieldType.IsEnum)
                {
                    PersistentEngine.SetState(GetObjectIdentifier(sceneName) + field.Name, (int)field.GetValue(this), saveFile);
                }
                else
                if (PersistentEngine.IsNumericType(field))
                {
                    PersistentEngine.SetState(GetObjectIdentifier(sceneName) + field.Name, (int)field.GetValue(this), saveFile);
                }
                else
                if (PersistentEngine.IsBooleanType(field))
                {
                    var val = (bool)field.GetValue(this) == true ? 1 : 0;
                    GetObjectIdentifier(sceneName);
                    PersistentEngine.SetState(GetObjectIdentifier(sceneName) + field.Name, val, saveFile);
                }
                else if (PersistentEngine.IsStringType(field))
                {
                    var val = field.GetValue(this);
                    GetObjectIdentifier(sceneName);
                    try
                    {
                        PersistentEngine.SetStateStr(GetObjectIdentifier(sceneName) + field.Name, (string)val, saveFile);
                    }
                    catch
                    {
                        PersistentEngine.SetState(GetObjectIdentifier(sceneName) + field.Name, null, saveFile);
                    }
                }
            }
        }