Skip to content

Commit

Permalink
Merge pull request #20 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.17
  • Loading branch information
OpOpYaDev committed Jul 13, 2024
1 parent c139cc6 commit bfecfc8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Better.Commons.Runtime.Utility;
using UnityEngine;

namespace Better.Commons.Runtime.DataStructures.SerializedTypes
{
[Serializable]
public class SerializedSortedDictionary<TKey, TValue> : SortedDictionary<TKey, TValue>, ISerializationCallbackReceiver
{
// TODO: Add CustomDrawer for key-item table
[SerializeField] private TKey[] _keys;
[SerializeField] private TValue[] _values;

public SerializedSortedDictionary()
{
}

public SerializedSortedDictionary(IComparer<TKey> comparer) : base(comparer)
{
}

public SerializedSortedDictionary(IDictionary<TKey, TValue> dictionary) : base(dictionary)
{
}

public SerializedSortedDictionary(IDictionary<TKey, TValue> dictionary, IComparer<TKey> comparer) : base(dictionary, comparer)
{
}

void ISerializationCallbackReceiver.OnBeforeSerialize()
{
_keys = Keys.ToArray();
_values = Values.ToArray();
}

void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (_keys == null || _values == null || _keys.Length != _values.Length)
{
DebugUtility.LogException<SerializationException>();
return;
}

Clear();
for (var i = 0; i < _keys.Length; ++i)
{
Add(_keys[i], _values[i]);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.tdw.better.commons",
"displayName": "Better Commons",
"version": "0.0.16",
"version": "0.0.17",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit bfecfc8

Please sign in to comment.