How to serialize Dictionary and DateTime in Unity without external libraries

  Рет қаралды 1,310

blazeDev

blazeDev

Күн бұрын

Пікірлер: 7
@clouleal
@clouleal 9 ай бұрын
Hi, I tried to code the SerializableDictionary with the SerializableDictionaryElement, however in the inspector I am only able to add one element. The plus sign did nothing neather If I set the elements number manually . You have any idea of why it is happening ?
@vamidicreations
@vamidicreations 9 ай бұрын
Same issue
@SantaGrapa
@SantaGrapa 7 ай бұрын
That's because when you click the plus sign, a new element is added that share the same key as the previous one, and dictionaries can't have duplicate keys, so it deletes itself. A way to solve it its to make a custom propertyDrawer (of an inherited class defining the generics, cause generics cant be serialized) and then you do this: if (GUI.Button(addButtonRect, "Add New Entry")) { SerializedProperty keyValuePairs = property.FindPropertyRelative("kvps"); //however you named the list keyValuePairs.InsertArrayElementAtIndex(keyValuePairs.arraySize); SerializedProperty newKeyValuePair = keyValuePairs.GetArrayElementAtIndex(keyValuePairs.arraySize - 1); SerializedProperty newKey = newKeyValuePair.FindPropertyRelative("key"); newKey.stringValue = "Key_" + keyValuePairs.arraySize; // Provide a default key value } Either way that just make it so you can change it from editor directly, but if you plan on making an editorWindow or you want to modify it anywhere else, values wont get propertly saved because of how ISerializationCallbackReceiver works.
@DigitomProductions
@DigitomProductions Жыл бұрын
Beauty thank you sir.
@dasmartkz
@dasmartkz Жыл бұрын
Why you created SerializedDataObject and didn't show how to get json from it?
@dasmartkz
@dasmartkz Жыл бұрын
var serializedData = JsonUtility.FromJson(json); Debug.Log(serializedData.customFields["Email"]); wiil be error
@blazeDev_vlog
@blazeDev_vlog Жыл бұрын
@@dasmartkz Hey, unfortunately I removed this project few weeks ago so I cannot check what error will be thrown. Let me know what you get, maybe I will be able to help. However SerializedDataObject was created to show serialization inside editor but still it should be possible to serialize this component also, because I just show how to serialize specific types, wrapper class should not impact this.
Implement cloud save in Unity using Firebase Firestore
12:52
blazeDev
Рет қаралды 2,8 М.
Which dictionary to choose in C# and which one is dangerous
11:12
Nick Chapsas
Рет қаралды 102 М.
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Serialize Reference, Serialize Field, Serializable and Scene Serialization in Unity | Unity Tutorial
10:40
4 Tips for Refactoring Your Code for Readability
14:58
Infallible Code
Рет қаралды 31 М.
Double the Performance of your Dictionary in C#
15:12
Nick Chapsas
Рет қаралды 70 М.
Using Attributes to Manage Data in Unity
9:14
Game Dev Guide
Рет қаралды 47 М.
How to Implement Blackboard Architecture in Unity C#
28:57
git-amend
Рет қаралды 16 М.
How to Program in Unity: State Machines Explained
18:56
iHeartGameDev
Рет қаралды 239 М.
How to Use Dictionaries in Unity and C# [BEGINNER FRIENDLY]
18:59
Wild Cockatiel Games
Рет қаралды 10 М.
Trump's Plan for Ukrainian Lands / U.S. President's Demand
11:59
NEXTA Live
Рет қаралды 634 М.
10 Signs Your Software Project Is Heading For FAILURE
17:59
Continuous Delivery
Рет қаралды 44 М.
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН