Esempio n. 1
0
        public void LoadState()
        {
            if (!allowSaving)
            {
                return;
            }

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

            foreach (var field in fields)
            {
                if (field.FieldType.IsEnum)
                {
                    if (PersistentEngine.GetState(GetObjectIdentifier(sceneName) + field.Name) != null)
                    {
                        field.SetValue(this, PersistentEngine.GetState(GetObjectIdentifier(sceneName) + field.Name));
                    }
                }
                else
                if (PersistentEngine.IsNumericType(field))
                {
                    if (PersistentEngine.GetState(GetObjectIdentifier(sceneName) + field.Name) != null)
                    {
                        field.SetValue(this, PersistentEngine.GetState(GetObjectIdentifier(sceneName) + field.Name));
                    }
                }
                else
                if (PersistentEngine.IsBooleanType(field))
                {
                    if (PersistentEngine.GetState(GetObjectIdentifier(sceneName) + field.Name) != null)
                    {
                        var val = PersistentEngine.GetState(GetObjectIdentifier(sceneName) + field.Name);
                        GetObjectIdentifier(sceneName);
                        field.SetValue(this, val == 1 ? true : false);
                    }
                }
                else
                if (PersistentEngine.IsStringType(field))
                {
                    var val = PersistentEngine.GetStateStr(GetObjectIdentifier(sceneName) + field.Name);
                    GetObjectIdentifier(sceneName);
                    field.SetValue(this, val);
                }
            }
        }