{"id":28408975,"url":"https://github.com/zeroultra/unityscriptableobjectsingleton","last_synced_at":"2025-06-24T22:31:09.146Z","repository":{"id":272242884,"uuid":"915943053","full_name":"ZeroUltra/UnityScriptableObjectSingleton","owner":"ZeroUltra","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-13T06:49:17.000Z","size":1227,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T13:12:08.178Z","etag":null,"topics":["plugins","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZeroUltra.png","metadata":{"files":{"readme":".github/README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-01-13T06:36:56.000Z","updated_at":"2025-01-14T03:18:17.000Z","dependencies_parsed_at":"2025-01-13T07:31:51.991Z","dependency_job_id":"b3f267fc-adea-44b1-b81a-d24f00aba9c2","html_url":"https://github.com/ZeroUltra/UnityScriptableObjectSingleton","commit_stats":null,"previous_names":["zeroultra/unityscriptableobjectsingleton"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ZeroUltra/UnityScriptableObjectSingleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FUnityScriptableObjectSingleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FUnityScriptableObjectSingleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FUnityScriptableObjectSingleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FUnityScriptableObjectSingleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZeroUltra","download_url":"https://codeload.github.com/ZeroUltra/UnityScriptableObjectSingleton/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FUnityScriptableObjectSingleton/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261766568,"owners_count":23206648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["plugins","unity"],"created_at":"2025-06-02T04:38:21.086Z","updated_at":"2025-06-24T22:31:09.135Z","avatar_url":"https://github.com/ZeroUltra.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity ScriptableObjectSingleton\n![](img/i.gif)\n\n## 说明\n\n### unity中的ScriptableSingleton\n\nunity中存在一个[ScriptableSingleton\u003cT0\u003e](https://docs.unity3d.com/2020.1/Documentation/ScriptReference/ScriptableSingleton_1.html)\n\n但是他有点难用\n\n* hideflag 为 dontsave\n* 并不会监听创建时是否已存在\n* ....\n\n### 如何使用\n\n* 如果是Editor的`ScriptableObject`可直接继承`ScriptableObjectSingletonEditor`使用,(也可以不继承,但是`必须要实现ISingletion接口`)\n* 如果是Runtime的`ScriptableObject`需要实现`ISingletion`接口\n\n示例:\n\n```c#\nusing System.Collections;\nusing UnityEngine;\nusing UnityScriptableObjectSingleton.Editor;\nusing UnityScriptableObjectSingleton.Runtime;\n/// \u003csummary\u003e\n/// ____DESC:      \n/// \u003c/summary\u003e\n[CreateAssetMenu(fileName = \"TestScriptableObjectSingleton\", menuName = \"Test/TestScriptableObjectSingleton\", order = 0)]\npublic class TestScriptableObjectSingleton : ScriptableObject, ISingletion\n{\n    //手动实现Instance\n    private static TestScriptableObjectSingleton _instance;\n    public static TestScriptableObjectSingleton Instance\n    {\n        get\n        {\n            if (_instance == null)\n            {\n                _instance = Resources.Load\u003cTestScriptableObjectSingleton\u003e(\"TestScriptableObjectSingleton\");\n                if (_instance == null)\n                {\n                    Debug.LogError(\"Can't find the instance of TestScriptableObjectSingleton\");\n                }\n            }\n            return _instance;\n        }\n    }\n    public int value;\n}\n```\n\n```c#\nusing System.Collections;\nusing UnityEngine;\nusing UnityScriptableObjectSingleton.Editor;\n/// \u003csummary\u003e\n/// ____DESC:      \n/// \u003c/summary\u003e\n[CreateAssetMenu(fileName = \"TestEditorScriptableObjectSingleton\", menuName = \"Test/TestEditorScriptableObjectSingleton\", order = 0)]\n\npublic class TestEditorScriptableObjectSingleton : ScriptableObjectSingletonEditor\u003cTestEditorScriptableObjectSingleton\u003e\n{\n    public int value;\n}\n```\n\n具体可查看`Samples`里面的示例\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroultra%2Funityscriptableobjectsingleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeroultra%2Funityscriptableobjectsingleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroultra%2Funityscriptableobjectsingleton/lists"}