public override string ToString()
    {
        // Prepare properties for serialization
        SerializedUserData serialized = new SerializedUserData(this);

        return(StringUtility.ToJson <SerializedUserData>(serialized));
    }
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        SerializedProperty userNameProperty            = SerializedUserData.FindProperty(GetMemberName(() => UserData.userName));
        SerializedProperty userIdProperty              = SerializedUserData.FindProperty(GetMemberName(() => UserData.userId));
        SerializedProperty purchasesKeysListProperty   = SerializedUserData.FindProperty(GetMemberName(() => UserData.purchasesKeysList));
        SerializedProperty purchasesValuesListProperty = SerializedUserData.FindProperty(GetMemberName(() => UserData.purchasesValuesList));

        EditorGUILayout.PropertyField(userNameProperty);
        EditorGUILayout.PropertyField(userIdProperty);

        GUIContent label = new GUIContent();

        label.text = "Purchases count";
        EditorGUILayout.PropertyField(purchasesKeysListProperty, label);
        string toRemove = null;

        if (purchasesKeysListProperty.isExpanded)
        {
            for (int i = 0; i < purchasesKeysListProperty.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("PackId", GUILayout.Width(50));
                GUILayout.FlexibleSpace();
                EditorGUILayout.PropertyField(purchasesKeysListProperty.GetArrayElementAtIndex(i), GUIContent.none, true, GUILayout.MinWidth(50));
                GUILayout.Label("Count", GUILayout.Width(50));
                GUILayout.FlexibleSpace();
                EditorGUILayout.PropertyField(purchasesValuesListProperty.GetArrayElementAtIndex(i), GUIContent.none, true, GUILayout.MinWidth(50));
                if (GUILayout.Button("-"))
                {
                    toRemove = purchasesKeysListProperty.GetArrayElementAtIndex(i).stringValue;
                }
                EditorGUILayout.EndHorizontal();
            }
            if (GUILayout.Button("+"))
            {
                AddPurchase();
            }
            if (toRemove != null)
            {
                RemovePurchase(toRemove);
            }
        }

        if (GUILayout.Button("Save", GUILayout.Width(100)))
        {
            AssetDatabase.SaveAssets();
        }

        if (EditorGUI.EndChangeCheck())
        {
            SerializedUserData.ApplyModifiedProperties();
        }
    }
    public SerializedUserData(string json)
    {
        SerializedUserData data = StringUtility.FromJson <SerializedUserData>(json);

        this.username    = data.username;
        this.playerLevel = data.playerLevel;
        this.experience  = data.experience;
        this.metaData    = data.metaData;
        this.cards       = data.cards;
        this.items       = data.items;
    }
Exemple #4
0
    // Attempt to load User Data
    private void AttemptLogin()
    {
        // Load local data
        SerializedUserData data     = Persistence.LoadUserData();
        UserData           userData = new UserData(data);

        this.userManager.SetUserData(userData);

        // After setting the user data for this session, begin Adventure
        this.StartAdventure();
    }
    public static SerializedUserData LoadUserData()
    {
        if (DoesFileExistAtPath(userDataPath))
        {
            string             serializedUserData = File.ReadAllText(userDataPath);
            SerializedUserData userData           = new SerializedUserData(serializedUserData);
            Debug.Log("Loaded user data");
            return(userData);
        }

        return(new SerializedUserData());
    }
    public UserData(SerializedUserData serializedUserData)
    {
        this.username    = serializedUserData.username;
        this.playerLevel = serializedUserData.playerLevel;
        this.experience  = serializedUserData.experience;

        List <SerializedMetaData> serializedMetas = Serializer.ListFromArray <SerializedMetaData>(serializedUserData.metaData);

        foreach (SerializedMetaData serializedMeta in serializedMetas)
        {
            MetaData meta = new MetaData(serializedMeta);
            this.metaData.Add(meta);
        }

        this.cards = Serializer.ListFromArray <Card>(serializedUserData.cards);
        this.items = Serializer.ListFromArray <ItemData>(serializedUserData.items);
    }