├── .gitattributes
├── .gitignore
├── CHANGELOG.md
├── CHANGELOG.md.meta
├── Editor.meta
├── Editor
├── SerializableGuidPropertyDrawer.cs
├── SerializableGuidPropertyDrawer.cs.meta
├── Unity.SerializableGuid.Editor.asmdef
└── Unity.SerializableGuid.Editor.asmdef.meta
├── LICENSE.md
├── LICENSE.md.meta
├── README.md
├── README.md.meta
├── Runtime.meta
├── Runtime
├── SerializableGuid.cs
├── SerializableGuid.cs.meta
├── Unity.SerializableGuid.asmdef
└── Unity.SerializableGuid.asmdef.meta
├── package.json
└── package.json.meta
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 | [Bb]uild/
5 | [Bb]uilds/
6 | Assets/AssetStoreTools*
7 |
8 | # Visual Studio cache directory
9 | .vs/
10 |
11 | # Autogenerated VS/MD/Consulo solution and project files
12 | ExportedObj/
13 | .consulo/
14 | *.csproj
15 | *.unityproj
16 | *.sln
17 | *.suo
18 | *.tmp
19 | *.user
20 | *.userprefs
21 | *.pidb
22 | *.booproj
23 | *.svd
24 | *.pdb
25 | *.opendb
26 | *.VC.db
27 |
28 | # Unity3D generated meta files
29 | *.pidb.meta
30 | *.pdb.meta
31 |
32 | # Unity3D Generated File On Crash Reports
33 | sysinfo.txt
34 |
35 | # Builds
36 | *.apk
37 | *.unitypackage
38 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 1.0.0
2 | + Release.
--------------------------------------------------------------------------------
/CHANGELOG.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8a4bc03c51aa5c84b9f0f1594b797c6a
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0aa5ff3481b575349b34474223b8d7d9
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/SerializableGuidPropertyDrawer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEditor;
3 | using UnityEngine;
4 |
5 | ///
6 | /// Property drawer for SerializableGuid
7 | ///
8 | /// Author: Searous
9 | ///
10 | [CustomPropertyDrawer(typeof(SerializableGuid))]
11 | public class SerializableGuidPropertyDrawer : PropertyDrawer {
12 |
13 | private float ySep = 20;
14 | private float buttonSize;
15 |
16 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
17 | // Start property draw
18 | EditorGUI.BeginProperty(position, label, property);
19 |
20 | // Get property
21 | SerializedProperty serializedGuid = property.FindPropertyRelative("serializedGuid");
22 |
23 | // Draw label
24 | position = EditorGUI.PrefixLabel(new Rect(position.x, position.y + ySep / 2, position.width, position.height), GUIUtility.GetControlID(FocusType.Passive), label);
25 | position.y -= ySep / 2; // Offsets position so we can draw the label for the field centered
26 |
27 | buttonSize = position.width / 3; // Update size of buttons to always fit perfeftly above the string representation field
28 |
29 | // Buttons
30 | if(GUI.Button(new Rect(position.xMin, position.yMin, buttonSize, ySep - 2), "New")) {
31 | serializedGuid.stringValue = Guid.NewGuid().ToString();
32 | }
33 | if(GUI.Button(new Rect(position.xMin + buttonSize, position.yMin, buttonSize, ySep - 2), "Copy")) {
34 | EditorGUIUtility.systemCopyBuffer = serializedGuid.stringValue;
35 | }
36 | if(GUI.Button(new Rect(position.xMin + buttonSize * 2, position.yMin, buttonSize, ySep - 2), "Empty")) {
37 | serializedGuid.stringValue = Guid.Empty.ToString();
38 | }
39 |
40 | // Draw fields - passs GUIContent.none to each so they are drawn without labels
41 | Rect pos = new Rect(position.xMin, position.yMin + ySep, position.width, ySep - 2);
42 | EditorGUI.PropertyField(pos, serializedGuid, GUIContent.none);
43 |
44 | // End property
45 | EditorGUI.EndProperty();
46 | }
47 |
48 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
49 | // Field height never changes, so ySep * 2 will always return the proper hight of the field
50 | return ySep * 2;
51 | }
52 | }
--------------------------------------------------------------------------------
/Editor/SerializableGuidPropertyDrawer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4e050073233a8624c8ce843312079f25
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Editor/Unity.SerializableGuid.Editor.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Unity.SerializableGuid.Editor",
3 | "references": [
4 | "GUID:c85f41d4379abdb4eafe8f0f3fe7380b"
5 | ],
6 | "includePlatforms": [
7 | "Editor"
8 | ],
9 | "excludePlatforms": [],
10 | "allowUnsafeCode": false,
11 | "overrideReferences": false,
12 | "precompiledReferences": [],
13 | "autoReferenced": true,
14 | "defineConstraints": [],
15 | "versionDefines": [],
16 | "noEngineReferences": false
17 | }
18 |
--------------------------------------------------------------------------------
/Editor/Unity.SerializableGuid.Editor.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2fc9a682160dd4548ab661ccb3edf7e9
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Katie Kennedy
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 |
--------------------------------------------------------------------------------
/LICENSE.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ab358ade24e499648b664512b7381245
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unity.SerializableGuid
2 | A simple wrapper for System.Guid
3 | # Preview
4 | 
--------------------------------------------------------------------------------
/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b4207f8a6b6358f46b033550bd9a36c8
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e8f05455a47f9e24b8fa3a8fe0cf431a
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Runtime/SerializableGuid.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | ///
5 | /// Serializable wrapper for System.Guid.
6 | /// Can be implicitly converted to/from System.Guid.
7 | ///
8 | /// Author: Katie Kennedy (Searous)
9 | ///
10 | [Serializable]
11 | public struct SerializableGuid : ISerializationCallbackReceiver {
12 | private Guid guid;
13 | [SerializeField] private string serializedGuid;
14 |
15 | public SerializableGuid(Guid guid) {
16 | this.guid = guid;
17 | serializedGuid = null;
18 | }
19 |
20 | public override bool Equals(object obj) {
21 | return obj is SerializableGuid guid &&
22 | this.guid.Equals(guid.guid);
23 | }
24 |
25 | public override int GetHashCode() {
26 | return -1324198676 + guid.GetHashCode();
27 | }
28 |
29 | public void OnAfterDeserialize() {
30 | try {
31 | guid = Guid.Parse(serializedGuid);
32 | } catch {
33 | guid = Guid.Empty;
34 | Debug.LogWarning($"Attempted to parse invalid GUID string '{serializedGuid}'. GUID will set to System.Guid.Empty");
35 | }
36 | }
37 |
38 | public void OnBeforeSerialize() {
39 | serializedGuid = guid.ToString();
40 | }
41 |
42 | public override string ToString() => guid.ToString();
43 |
44 | public static bool operator ==(SerializableGuid a, SerializableGuid b) => a.guid == b.guid;
45 | public static bool operator !=(SerializableGuid a, SerializableGuid b) => a.guid != b.guid;
46 | public static implicit operator SerializableGuid(Guid guid) => new SerializableGuid(guid);
47 | public static implicit operator Guid(SerializableGuid serializable) => serializable.guid;
48 | public static implicit operator SerializableGuid(string serializedGuid) => new SerializableGuid(Guid.Parse(serializedGuid));
49 | public static implicit operator string(SerializableGuid serializedGuid) => serializedGuid.ToString();
50 | }
--------------------------------------------------------------------------------
/Runtime/SerializableGuid.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b2658ef6b23fab94b98ce76444fac86f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Runtime/Unity.SerializableGuid.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Unity.SerializableGuid"
3 | }
--------------------------------------------------------------------------------
/Runtime/Unity.SerializableGuid.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c85f41d4379abdb4eafe8f0f3fe7380b
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "searous.serializableguid",
3 | "version": "1.0.0",
4 | "displayName": "Serializable GUID",
5 | "description": "A simple serializable wrapper for System.Guid.",
6 | "unity": "",
7 | "author": {
8 | "name": "Katie Kennedy (Searous)",
9 | "email": "searousx20@gmail.com"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 85984c84bde6e8f4c920e27d8c836534
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------