{"id":18498858,"url":"https://github.com/instance-id/usefulsnippets","last_synced_at":"2026-01-24T12:07:33.461Z","repository":{"id":98392554,"uuid":"297184177","full_name":"instance-id/UsefulSnippets","owner":"instance-id","description":"A collection of Unity / Unity3d code snippets that I found useful. Perhaps others will as well.","archived":false,"fork":false,"pushed_at":"2020-09-22T16:44:25.000Z","size":13,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-15T11:14:57.812Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/instance-id.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-20T23:47:38.000Z","updated_at":"2022-11-23T18:44:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"b9d7fdb5-62f9-4f9c-a3b5-5a8f909950f0","html_url":"https://github.com/instance-id/UsefulSnippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/instance-id/UsefulSnippets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instance-id%2FUsefulSnippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instance-id%2FUsefulSnippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instance-id%2FUsefulSnippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instance-id%2FUsefulSnippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/instance-id","download_url":"https://codeload.github.com/instance-id/UsefulSnippets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instance-id%2FUsefulSnippets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28727384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T10:24:43.181Z","status":"ssl_error","status_checked_at":"2026-01-24T10:24:36.112Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T13:42:52.216Z","updated_at":"2026-01-24T12:07:33.441Z","avatar_url":"https://github.com/instance-id.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# UsefulSnippets\nA collection of Unity / Unity3d code snippets that I found useful. Perhaps others will as well.\n\n## Color\n \n#### GetColor() Extension\n\nUsage: \n```cs \n// -- Standard Color\nColor color = \"#555555\".GetColor()\n\n// -- StyleColor\nStyleColor styleColor = new StyleColor(\"#555555\".GetColor());\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eColor Extension Code\u003c/summary\u003e\n \n```cs\nusing UnityEngine;\n\nnamespace instance.id.ColorExtensions\n{\n    public static class ColorExtensions\n    {\n        public static Color GetColor(this string color)\n        {\n            ColorUtility.TryParseHtmlString(color, out var outColor);\n            return outColor;\n        }\n    }\n\n```\n\u003c/details\u003e\n\n\n\n## UIElements\n \n#### UIElements - Draw IMGUI Reorderable Lists (2020.2)\n\n| ![](https://i.imgur.com/4IbSmKv.png) |  \n| --- |  \n\n\u003cdetails\u003e\n\u003csummary\u003eSerializedProperty Extension to determine if property is a List/Array\u003c/summary\u003e\n \n```cs\npublic static class PropertyExtensions\n{\n    public static bool IsReallyArray(this SerializedProperty property)\n    {\n        return property.isArray \u0026\u0026 property.propertyType != SerializedPropertyType.String;\n    }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eDraw IMGUI Reorderable Lists Code\u003c/summary\u003e\n  \n```cs\n[CustomEditor(typeof(Object), true, isFallback = true)]\n[CanEditMultipleObjects]\npublic class DefaultEditorDrawer : Editor\n{\n    public bool showScript;\n    public List\u003cstring\u003e excludedFields = new List\u003cstring\u003e();\n    string m_IMGUIPropNeedsRelayout;\n    ScrollView m_ScrollView;\n\n    public override VisualElement CreateInspectorGUI()\n    {\n        var root = new VisualElement();\n        var property = serializedObject.GetIterator();\n        m_ScrollView = new ScrollView();\n        root.Add(m_ScrollView);\n        if (property.NextVisible(true)) // Expand first child.\n        {\n            do\n            {\n                var field = new PropertyField(property) {name = \"PropertyField:\" + property.propertyPath};\n                if (property.propertyPath == \"m_Script\" \u0026\u0026 serializedObject.targetObject != null)\n                {\n                    if (showScript) field.SetEnabled(false);\n                    else continue;\n                }\n\n                if (property.IsReallyArray() \u0026\u0026 serializedObject.targetObject != null)\n                {\n                    var copiedProperty = property.Copy();\n                    var imDefaultProperty = new IMGUIContainer(() =\u003e\n                    {\n                        DoDrawDefaultIMGUIProperty(serializedObject, copiedProperty);\n                    }) {name = property.propertyPath};\n                    \n                    m_ScrollView.Add(imDefaultProperty);\n                    continue;\n                }\n\n                if (excludedFields.Contains(property.propertyPath) \u0026\u0026 serializedObject.targetObject != null) { continue; }\n\n                root.Add(field);\n            } while (property.NextVisible(false));\n        }\n\n        foreach (var foldout in m_ScrollView.Query\u003cFoldout\u003e().ToList())\n        {\n            foldout.RegisterValueChangedCallback(e =\u003e\n            {\n                var fd = e.target as Foldout;\n                if (fd == null) return;\n                var path = fd.bindingPath;\n                var container = m_ScrollView.Q\u003cIMGUIContainer\u003e(name: path);\n                RecomputeSize(container);\n            });\n        }\n\n        return root;\n    }\n\n    public void RecomputeSize(IMGUIContainer container)\n    {\n        if (container == null) return;\n        var parent = container.parent;\n        container.RemoveFromHierarchy();\n        parent.Add(container);\n    }\n\n    public void DoDrawDefaultIMGUIProperty(SerializedObject serializedObject, SerializedProperty property)\n    {\n        EditorGUI.BeginChangeCheck();\n        serializedObject.Update();\n        bool wasExpanded = property.isExpanded;\n        EditorGUILayout.PropertyField(property, true);\n        if (property.isExpanded != wasExpanded) m_IMGUIPropNeedsRelayout = property.propertyPath;\n        serializedObject.ApplyModifiedProperties();\n        EditorGUI.EndChangeCheck();\n    }\n}\n\n```\n\u003c/details\u003e\n\n---\n![alt text](https://i.imgur.com/cg5ow2M.png \"instance.id\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstance-id%2Fusefulsnippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finstance-id%2Fusefulsnippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstance-id%2Fusefulsnippets/lists"}