├── Documentation~ ├── example.gif └── propertydrawerexample.PNG ├── License.md.meta ├── README.md.meta ├── package.json.meta ├── Editor.meta ├── Runtime.meta ├── Samples~ ├── Examples.meta └── Examples │ ├── ExampleScene.unity.meta │ ├── ScriptableObjectExample.asset.meta │ ├── ScriptableObjectExample.cs │ ├── MonoBehaviourExample.cs.meta │ ├── ScriptableObjectExample.cs.meta │ ├── ScriptableObjectExample.asset │ ├── MonoBehaviourExample.cs │ └── ExampleScene.unity ├── Runtime ├── com.upscalebaby.generic-serializable-dictionary.asmdef.meta ├── GenericDictionary.cs.meta ├── com.upscalebaby.generic-serializable-dictionary.asmdef └── GenericDictionary.cs ├── Editor ├── com.upscalebaby.generic-serializable-dictionary-editor.asmdef.meta ├── GenericDictionaryPropertyDrawer.cs.meta ├── com.upscalebaby.generic-serializable-dictionary-editor.asmdef └── GenericDictionaryPropertyDrawer.cs ├── package.json ├── License.md └── README.md /Documentation~/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/upscalebaby/generic-serializable-dictionary/HEAD/Documentation~/example.gif -------------------------------------------------------------------------------- /Documentation~/propertydrawerexample.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/upscalebaby/generic-serializable-dictionary/HEAD/Documentation~/propertydrawerexample.PNG -------------------------------------------------------------------------------- /License.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9c54f444ac963748b104177913cd18f 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 838a832a8e359644b9426ba0ae30a4ac 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3c25d9677ce9a7428b6fee3f98e1854 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62b6601350977a94395506a72c8d6c0c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d7c9b979a61994e4da6252203284af7e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Examples.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 56de25e3af5b71149942bf084b44465e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Examples/ExampleScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9fc0d4010bbf28b4594072e72b8655ab 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/com.upscalebaby.generic-serializable-dictionary.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2218e9acf4363e04493a4aa50e7d278e 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/com.upscalebaby.generic-serializable-dictionary-editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 923503f6099047445a9a57f601b8e09a 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~/Examples/ScriptableObjectExample.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 70574cad21d479941978cb607e5805e7 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/GenericDictionary.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71eae38d67c58424f9adcefcc0d7cf99 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Examples/ScriptableObjectExample.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | [CreateAssetMenu] 6 | public class ScriptableObjectExample : ScriptableObject 7 | { 8 | [SerializeField] 9 | private GenericDictionary dictionary; 10 | } 11 | -------------------------------------------------------------------------------- /Editor/GenericDictionaryPropertyDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 25cc573671a84504fa26febaec8a65d0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Examples/MonoBehaviourExample.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19735a77a1b7baa4ea5dd98bfd9cd7ff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Examples/ScriptableObjectExample.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b407a984792c1b04e91f641e6bc9d6ff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/com.upscalebaby.generic-serializable-dictionary.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.upscalebaby.generic-serializable-dictionary", 3 | "rootNamespace": "", 4 | "references": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": false, 8 | "overrideReferences": false, 9 | "precompiledReferences": [], 10 | "autoReferenced": true, 11 | "defineConstraints": [], 12 | "versionDefines": [], 13 | "noEngineReferences": false 14 | } -------------------------------------------------------------------------------- /Editor/com.upscalebaby.generic-serializable-dictionary-editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.upscalebaby.generic-serializable-dictionary-editor", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:2218e9acf4363e04493a4aa50e7d278e" 6 | ], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Samples~/Examples/ScriptableObjectExample.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: b407a984792c1b04e91f641e6bc9d6ff, type: 3} 13 | m_Name: ScriptableObjectExample 14 | m_EditorClassIdentifier: 15 | dictionary: 16 | list: 17 | - Key: Example_1 18 | Value: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0} 19 | - Key: Example_2 20 | Value: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0} 21 | keyCollision: 0 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.upscalebaby.generic-serializable-dictionary", 3 | "version": "1.0.2", 4 | "displayName": "Generic Serializable Dictionary", 5 | "description": "Lightweight and minimalist dictionary for Unity 2020.1.x with a native look and feel.", 6 | "unity": "2020.1", 7 | "keywords": [ 8 | "Dictionary", 9 | "Serializable", 10 | "Serialization" 11 | ], 12 | "license": "MIT", 13 | "licensesUrl": "https://github.com/upscalebaby/generic-serializable-dictionary?tab=MIT-1-ov-file", 14 | "changelogUrl": "https://github.com/upscalebaby/generic-serializable-dictionary/releases", 15 | "documentationUrl": "https://github.com/upscalebaby/generic-serializable-dictionary", 16 | "samples": [ 17 | { 18 | "displayName": "Examples", 19 | "description": "Usage examples", 20 | "path": "Samples~/Examples" 21 | } 22 | ], 23 | "author": { 24 | "name": "upscalebaby", 25 | "url": "https://github.com/upscalebaby" 26 | } 27 | } -------------------------------------------------------------------------------- /Samples~/Examples/MonoBehaviourExample.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | /// 5 | /// Example of using the generic dictionary with a MonoBehaviour. 6 | /// 7 | public class MonoBehaviourExample : MonoBehaviour 8 | { 9 | // Simply declare the key/value types, zero boilerplate. 10 | public GenericDictionary myGenericDict; 11 | 12 | void Start() 13 | { 14 | // Runtime test 15 | string keyToCheck = "abc"; 16 | bool contains = myGenericDict.ContainsKey(keyToCheck); 17 | Debug.LogFormat("myGenericDict contains '{0}': {1}", keyToCheck, contains); 18 | } 19 | 20 | void Update() 21 | { 22 | // Runtime test showing that the inspector reflects runtime additions. 23 | if (Input.GetKeyDown(KeyCode.Space)) 24 | { 25 | string newKey = "runtime example"; 26 | myGenericDict.Add(newKey, this.gameObject); 27 | Debug.LogFormat("Added '{0}' to myGenericDict.", newKey); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Erik Eriksson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Editor/GenericDictionaryPropertyDrawer.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | /// 5 | /// Draws the dictionary and a warning-box if there are duplicate keys. 6 | /// 7 | [CustomPropertyDrawer(typeof(GenericDictionary<,>))] 8 | public class GenericDictionaryPropertyDrawer : PropertyDrawer 9 | { 10 | private static float lineHeight = EditorGUIUtility.singleLineHeight; 11 | private static float vertSpace = EditorGUIUtility.standardVerticalSpacing; 12 | private const float warningBoxHeight = 1.5f; 13 | 14 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 15 | { 16 | // Draw list of key/value pairs. 17 | var list = property.FindPropertyRelative("list"); 18 | EditorGUI.PropertyField(position, list, label, true); 19 | 20 | // Draw key collision warning. 21 | var keyCollision = property.FindPropertyRelative("keyCollision").boolValue; 22 | if (keyCollision) 23 | { 24 | position.y += EditorGUI.GetPropertyHeight(list, true); 25 | if (!list.isExpanded) 26 | { 27 | position.y += vertSpace; 28 | } 29 | position.height = lineHeight * warningBoxHeight; 30 | position = EditorGUI.IndentedRect(position); 31 | EditorGUI.HelpBox(position, "Duplicate keys will not be serialized.", MessageType.Warning); 32 | } 33 | } 34 | 35 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) 36 | { 37 | // Height of KeyValue list. 38 | float height = 0f; 39 | var list = property.FindPropertyRelative("list"); 40 | height += EditorGUI.GetPropertyHeight(list, true); 41 | 42 | // Height of key collision warning. 43 | bool keyCollision = property.FindPropertyRelative("keyCollision").boolValue; 44 | if (keyCollision) 45 | { 46 | height += warningBoxHeight * lineHeight; 47 | if (!list.isExpanded) 48 | { 49 | height += vertSpace; 50 | } 51 | } 52 | return height; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Generic Serializable Dictionary 2 | Lightweight and minimalist dictionary for Unity 2020.1.x with a native look and feel. 3 | 4 | ## What 5 | * Uses plain System.Collections.Generic objects in combination with Unity's generic serializer. 6 | 7 | * Implements the IDictionary interface and can also be passed around as an ICollection. 8 | 9 | * Optional property drawer that displays the Dictionary near pixel perfectly as a List but with standard spacing between each KeyValue-pair (to make it easier on the eyes). 10 | 11 | ![](Documentation~/example.gif) 12 | 13 | * Zero boilerplate, declare your field and start using it! See Example.cs for specifics. 14 | 15 | ```csharp 16 | // Simply declare the key/value types, zero boilerplate. 17 | public GenericDictionary myGenericDict; 18 | 19 | void Start() 20 | { 21 | myGenericDict.Add("test", this.gameObject); 22 | } 23 | ``` 24 | 25 | ## Why 26 | 27 | As of 2020.1.0a Unity supports generic serialization and native support for displaying generic Lists in the inspector. But for a long time the community has wanted a generic Dictionary implementation that doesn't require you to add boilerplate for each concrete Dictionary type. 28 | 29 | Also, personally I'm not a fan of heavily decorated or bloated inspectors that deviate from Unity's standard inspector look and feel. This dictionary aims to look and work like the standard components you already know and use. 30 | 31 | ## How 32 | 33 | The GenericDictionary class contains all the interesting bits. It implements the IDictionary interface to behave as a standard generic dictionary. But it also implements ISerializationCallback to receive serialization callbacks - upon (de)serialization it syncs the backend Dictionary with the frontend List. If there are any key collisions the property drawer displays a standard helpbox to highlight this. 34 | 35 | No datastructures were harmed or modified when creating this: it's all just plain old System.Collections.Generic but used behind a IDictionary interface used together with Unitys generic serializer to display a native feeling Dictionary in the inspector. 36 | 37 | ## Features 38 | 39 | * Native look and feel, renders much like a List (with some enhancements to visability/useability). 40 | 41 | * Runtime additions to the Dictionary immediately show up in the inspector (see Example.cs). 42 | 43 | * Works regardless of context, use in MonoBehaviours and the runtime additions are cleared from the dictionary - or use in ScriptableObjects and the runtime additions remain serialized - just as expected. 44 | 45 | * The custom property drawer displays a standard warning box for key collisions - similar to the floating point precision warning in the Transform component. 46 | 47 | ![](Documentation~/propertydrawerexample.PNG) 48 | 49 | ## How to use 50 | 51 | This repo is a UPM package by itself, so you can use Unity Package Manager 52 | 53 | * Press the plus sign and choose `Add package from git URL...`. There, use `https://github.com/upscalebaby/generic-serializable-dictionary.git`, or, with version: `https://github.com/upscalebaby/generic-serializable-dictionary#1.0.2` 54 | * You can also clone this repository and then add it as a local package using `Add package from disk...` option. 55 | * Another option is to manually edit the manifest.json file in your Packages folder. Add `"com.upscalebaby.generic-serializable-dictionary" : "https://github.com/upscalebaby/generic-serializable-dictionary"`, or, with version: `"com.upscalebaby.generic-serializable-dictionary" : "https://github.com/upscalebaby/generic-serializable-dictionary#1.0.2"` 56 | * Alternatively, you can copy the GenericDictionary.cs into your Assets folder and the GenericDictionaryPropertyDrawer.cs into an Editor folder and you're good to go. 57 | 58 | Examples can be installed from the package via Unity Package Manager. 59 | 60 | ## Requirements 61 | 62 | A Unity version with support for generic serialization (currently 2020.1.x and above). 63 | 64 | ## License 65 | Licensed under MIT, see [license file](License.md). -------------------------------------------------------------------------------- /Runtime/GenericDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System; 5 | 6 | /// 7 | /// Generic Serializable Dictionary for Unity 2020.1 and above. 8 | /// Simply declare your key/value types and you're good to go - zero boilerplate. 9 | /// 10 | [Serializable] 11 | public class GenericDictionary : IDictionary, ISerializationCallbackReceiver 12 | { 13 | // Internal 14 | [SerializeField] 15 | private List list = new List(); 16 | [SerializeField, HideInInspector] 17 | private Dictionary indexByKey = new Dictionary(); 18 | [SerializeField, HideInInspector] 19 | private Dictionary dict = new Dictionary(); 20 | 21 | #pragma warning disable 0414 22 | [SerializeField, HideInInspector] 23 | private bool keyCollision; 24 | #pragma warning restore 0414 25 | 26 | [Serializable] 27 | private struct KeyValuePair 28 | { 29 | public TKey Key; 30 | public TValue Value; 31 | public KeyValuePair(TKey Key, TValue Value) 32 | { 33 | this.Key = Key; 34 | this.Value = Value; 35 | } 36 | } 37 | 38 | // Lists are serialized natively by Unity, no custom implementation needed. 39 | public void OnBeforeSerialize() { } 40 | 41 | // Populate dictionary with pairs from list and flag key-collisions. 42 | public void OnAfterDeserialize() 43 | { 44 | dict.Clear(); 45 | indexByKey.Clear(); 46 | keyCollision = false; 47 | for (int i = 0; i < list.Count; i++) 48 | { 49 | var key = list[i].Key; 50 | if (key != null && !ContainsKey(key)) 51 | { 52 | dict.Add(key, list[i].Value); 53 | indexByKey.Add(key, i); 54 | } 55 | else 56 | { 57 | keyCollision = true; 58 | } 59 | } 60 | } 61 | 62 | // IDictionary 63 | public TValue this[TKey key] 64 | { 65 | get => dict[key]; 66 | set 67 | { 68 | dict[key] = value; 69 | if (indexByKey.ContainsKey(key)) 70 | { 71 | var index = indexByKey[key]; 72 | list[index] = new KeyValuePair(key, value); 73 | } 74 | else 75 | { 76 | list.Add(new KeyValuePair(key, value)); 77 | indexByKey.Add(key, list.Count - 1); 78 | } 79 | } 80 | } 81 | 82 | public ICollection Keys => dict.Keys; 83 | public ICollection Values => dict.Values; 84 | 85 | public void Add(TKey key, TValue value) 86 | { 87 | dict.Add(key, value); 88 | list.Add(new KeyValuePair(key, value)); 89 | indexByKey.Add(key, list.Count - 1); 90 | } 91 | 92 | public bool ContainsKey(TKey key) => dict.ContainsKey(key); 93 | 94 | public bool Remove(TKey key) 95 | { 96 | if (dict.Remove(key)) 97 | { 98 | var index = indexByKey[key]; 99 | list.RemoveAt(index); 100 | UpdateIndexLookup(index); 101 | indexByKey.Remove(key); 102 | return true; 103 | } 104 | else 105 | { 106 | return false; 107 | } 108 | } 109 | 110 | private void UpdateIndexLookup(int removedIndex) { 111 | for (int i = removedIndex; i < list.Count; i++) { 112 | var key = list[i].Key; 113 | indexByKey[key]--; 114 | } 115 | } 116 | 117 | public bool TryGetValue(TKey key, out TValue value) => dict.TryGetValue(key, out value); 118 | 119 | // ICollection 120 | public int Count => dict.Count; 121 | public bool IsReadOnly { get; set; } 122 | 123 | public void Add(KeyValuePair pair) 124 | { 125 | Add(pair.Key, pair.Value); 126 | } 127 | 128 | public void Clear() 129 | { 130 | dict.Clear(); 131 | list.Clear(); 132 | indexByKey.Clear(); 133 | } 134 | 135 | public bool Contains(KeyValuePair pair) 136 | { 137 | TValue value; 138 | if (dict.TryGetValue(pair.Key, out value)) 139 | { 140 | return EqualityComparer.Default.Equals(value, pair.Value); 141 | } 142 | else 143 | { 144 | return false; 145 | } 146 | } 147 | 148 | public void CopyTo(KeyValuePair[] array, int arrayIndex) 149 | { 150 | if (array == null) 151 | throw new ArgumentException("The array cannot be null."); 152 | if (arrayIndex < 0) 153 | throw new ArgumentOutOfRangeException("The starting array index cannot be negative."); 154 | if (array.Length - arrayIndex < dict.Count) 155 | throw new ArgumentException("The destination array has fewer elements than the collection."); 156 | 157 | foreach (var pair in dict) 158 | { 159 | array[arrayIndex] = pair; 160 | arrayIndex++; 161 | } 162 | } 163 | 164 | public bool Remove(KeyValuePair pair) 165 | { 166 | TValue value; 167 | if (dict.TryGetValue(pair.Key, out value)) 168 | { 169 | bool valueMatch = EqualityComparer.Default.Equals(value, pair.Value); 170 | if (valueMatch) 171 | { 172 | return Remove(pair.Key); 173 | } 174 | } 175 | return false; 176 | } 177 | 178 | // IEnumerable 179 | public IEnumerator> GetEnumerator() => dict.GetEnumerator(); 180 | IEnumerator IEnumerable.GetEnumerator() => dict.GetEnumerator(); 181 | } 182 | -------------------------------------------------------------------------------- /Samples~/Examples/ExampleScene.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 12 47 | m_GIWorkflowMode: 0 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 500 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 500 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 2 83 | m_PVRDenoiserTypeDirect: 0 84 | m_PVRDenoiserTypeIndirect: 0 85 | m_PVRDenoiserTypeAO: 0 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 0 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_LightingSettings: {fileID: 0} 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | maxJobWorkers: 0 122 | preserveTilesOutsideBounds: 0 123 | debug: 124 | m_Flags: 0 125 | m_NavMeshData: {fileID: 0} 126 | --- !u!1 &1582050388 127 | GameObject: 128 | m_ObjectHideFlags: 0 129 | m_CorrespondingSourceObject: {fileID: 0} 130 | m_PrefabInstance: {fileID: 0} 131 | m_PrefabAsset: {fileID: 0} 132 | serializedVersion: 6 133 | m_Component: 134 | - component: {fileID: 1582050390} 135 | - component: {fileID: 1582050389} 136 | m_Layer: 0 137 | m_Name: Example 138 | m_TagString: Untagged 139 | m_Icon: {fileID: 0} 140 | m_NavMeshLayer: 0 141 | m_StaticEditorFlags: 0 142 | m_IsActive: 1 143 | --- !u!114 &1582050389 144 | MonoBehaviour: 145 | m_ObjectHideFlags: 0 146 | m_CorrespondingSourceObject: {fileID: 0} 147 | m_PrefabInstance: {fileID: 0} 148 | m_PrefabAsset: {fileID: 0} 149 | m_GameObject: {fileID: 1582050388} 150 | m_Enabled: 1 151 | m_EditorHideFlags: 0 152 | m_Script: {fileID: 11500000, guid: 19735a77a1b7baa4ea5dd98bfd9cd7ff, type: 3} 153 | m_Name: 154 | m_EditorClassIdentifier: 155 | myGenericDict: 156 | list: 157 | - Key: Example_1 158 | Value: {fileID: 1746994369} 159 | - Key: Example_2 160 | Value: {fileID: 1582050388} 161 | keyCollision: 0 162 | --- !u!4 &1582050390 163 | Transform: 164 | m_ObjectHideFlags: 0 165 | m_CorrespondingSourceObject: {fileID: 0} 166 | m_PrefabInstance: {fileID: 0} 167 | m_PrefabAsset: {fileID: 0} 168 | m_GameObject: {fileID: 1582050388} 169 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 170 | m_LocalPosition: {x: 0, y: 3, z: 0} 171 | m_LocalScale: {x: 1, y: 1, z: 1} 172 | m_Children: [] 173 | m_Father: {fileID: 0} 174 | m_RootOrder: 0 175 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 176 | --- !u!1 &1746994369 177 | GameObject: 178 | m_ObjectHideFlags: 0 179 | m_CorrespondingSourceObject: {fileID: 0} 180 | m_PrefabInstance: {fileID: 0} 181 | m_PrefabAsset: {fileID: 0} 182 | serializedVersion: 6 183 | m_Component: 184 | - component: {fileID: 1746994370} 185 | m_Layer: 0 186 | m_Name: GameObject 187 | m_TagString: Untagged 188 | m_Icon: {fileID: 0} 189 | m_NavMeshLayer: 0 190 | m_StaticEditorFlags: 0 191 | m_IsActive: 1 192 | --- !u!4 &1746994370 193 | Transform: 194 | m_ObjectHideFlags: 0 195 | m_CorrespondingSourceObject: {fileID: 0} 196 | m_PrefabInstance: {fileID: 0} 197 | m_PrefabAsset: {fileID: 0} 198 | m_GameObject: {fileID: 1746994369} 199 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 200 | m_LocalPosition: {x: 0, y: 0, z: 0} 201 | m_LocalScale: {x: 1, y: 1, z: 1} 202 | m_Children: [] 203 | m_Father: {fileID: 0} 204 | m_RootOrder: 1 205 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 206 | --------------------------------------------------------------------------------