{"id":5665,"date":"2020-04-10T18:30:11","date_gmt":"2020-04-10T09:30:11","guid":{"rendered":"https:\/\/virtualcast.jp\/blog\/?p=5665"},"modified":"2020-04-10T18:13:47","modified_gmt":"2020-04-10T09:13:47","slug":"introduce_zenject_editor_window","status":"publish","type":"post","link":"https:\/\/blog.virtualcast.jp\/blog\/2020\/04\/introduce_zenject_editor_window\/","title":{"rendered":"ZenjectEditorWindow\u306e\u7d39\u4ecb"},"content":{"rendered":"<h3>\u5c0e\u5165<\/h3>\n<p>\u3053\u3093\u306b\u3061\u306f\uff01\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u306eNatsuki\u3067\u3059\u3002<\/p>\n<p>\u307f\u306a\u3055\u3093\u3001Unity\u306e\u958b\u767a\u3067<a href=\"https:\/\/github.com\/modesttree\/Zenject\" title=\"Zenject\">Zenject<\/a>(Extenject\u542b\u3080)\u306f\u4f7f\u3063\u3066\u307e\u3059\u304b\uff1f<br \/>\n\u672c\u65e5\u306fZenjectEditorWindow\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5bfe\u8c61\u8aad\u8005\u306fZenject\u521d\u7d1a\u8005\uff5e\u4e2d\u7d1a\u8005\u3042\u305f\u308a\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\nZenject\u81ea\u4f53\u306e\u8aac\u660e\u306f\u3057\u307e\u305b\u3093\u306e\u3067\u3054\u4e86\u627f\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u7d39\u4ecb<\/h3>\n<p>\u3055\u3066\u7a81\u7136\u3067\u3059\u304c\u3001Zenject\u306b\u306fContext\u3068\u3044\u3046\u6982\u5ff5\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\nZenject\u3067\u306f\u3001Context\u306b\u5c5e\u3059\u308bContainer\u3092\u4f7f\u3063\u3066\u4f9d\u5b58\u95a2\u4fc2\u3092\u89e3\u6c7a\u3057\u307e\u3059\u3002<\/p>\n<p>Context\u306b\u306f\u7a2e\u985e\u304c\u3042\u308a\u3001\u305d\u308c\u305e\u308c\u4f55\u3089\u304b\u306e\u5bff\u547d\u306b\u7d10\u3065\u3044\u3066\u3044\u307e\u3059\u3002<br \/>\nContext\u306e\u7a2e\u985e\u3092\u3056\u3063\u3068\u6319\u3052\u308b\u3068\u3001ProjectContext, SceneContext, GameObjectContext\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>ProjectContext\u306f\u30a2\u30d7\u30ea\u306e\u5bff\u547d(\u8d77\u52d5\/\u7d42\u4e86)\u306b\u7d10\u3065\u304fContext\u3001<br \/>\nSceneContext\u306f\u30b7\u30fc\u30f3\u306e\u5bff\u547d(Load\/Unload)\u306b\u7d10\u3065\u304fContext\u3001<br \/>\nGameObjectContext\u306fGameObject\u306e\u5bff\u547d(Instantiate\/Destroy)\u306b\u7d10\u3065\u304fContext\u3067\u3059\u3002<\/p>\n<p>Runtime\u3084Play\u30e2\u30fc\u30c9\u3067\u306f\u4e0a\u8a18\u306eContext\u3067\u554f\u984c\u306a\u3055\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n<p>\u3068\u3053\u308d\u3067\u3001\u300cEditor\u4e0a\u3067Zenject\u304c\u4f7f\u3044\u305f\u3044\u300d\u3068\u3044\u3046\u5834\u5408\u306f\u3069\u3046\u3059\u308b\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<br \/>\nContext\u3092\u7d10\u3065\u3051\u308b\u305f\u3081\u306e\u3001\u4f55\u3089\u304b\u5bff\u547d\u304c\u3042\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u5b58\u5728\u3059\u308b\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u5bff\u547d\u304c\u3042\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u5b58\u5728\u3057\u307e\u3059\u3002<br \/>\n\u305d\u308c\u306f\u30a6\u30a3\u30f3\u30c9\u30a6\u3067\u3059\uff01(\u30d6\u30ed\u30b0\u306e\u30bf\u30a4\u30c8\u30eb\u3067\u30cd\u30bf\u30d0\u30ec\u3057\u3066\u307e\u3059\u304c)<\/p>\n<p>\u78ba\u304b\u306b\u3001\u30a6\u30a3\u30f3\u30c9\u30a6\u306f\u958b\u3044\u305f\u77ac\u9593\u306b\u751f\u6210\u3055\u308c\u307e\u3059\u3057\u3001\u9589\u3058\u305f\u3089\u7834\u68c4\u3055\u308c\u307e\u3059\u3082\u3093\u306d\u3002<br \/>\n\u305d\u308c\u3092\u305d\u306e\u307e\u307eContext\u306b\u3057\u3066\u3057\u307e\u304a\u3046\u3001\u3068\u3044\u3046\u306e\u304cZenjectEditorWindow\u3067\u3059\u3002<br \/>\n(\u521d\u3081\u3066ZenjectEditorWindow\u3092\u77e5\u3063\u305f\u3068\u304d\u3001\u9762\u767d\u3044\u30a2\u30a4\u30c7\u30a2\u3060\u306a\uff5e\u3088\u304f\u601d\u3044\u3064\u3044\u305f\u306a\uff5e\u3068\u601d\u3044\u307e\u3057\u305f(\u5c0f\u4e26\u611f))<\/p>\n<p>\u3055\u3066\u3001\u7d39\u4ecb\u3059\u308b\u3060\u3051\u306a\u306e\u3082\u30a2\u30ec\u306a\u306e\u3067\u3001\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3092\u4ea4\u3048\u3066\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u305f\u3060\u3001\u30df\u30cb\u30de\u30e0\u306a\u72b6\u614b\u3067\u8aac\u660e\u3057\u305f\u3044\u306e\u3067\u3001\u30b3\u30fc\u30c9\u3067\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u81ea\u4f53\u306b\u7279\u306b\u610f\u5473\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3054\u4e86\u627f\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u5b9f\u8df5<\/h3>\n<p>Zenject\u3092Import\u3057\u305f\u72b6\u614b\u3067\u3001\u4ee5\u4e0b\u306e3\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>FilePathProvider: \u66f8\u304d\u8fbc\u3080\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u6240\u3092\u63d0\u4f9b\u3059\u308b\u30af\u30e9\u30b9<\/li>\n<li>TheEditorWindowInstaller: ZenjectEditorWindow\u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9<\/li>\n<li>TheEditorWindowCore: \u30a6\u30a3\u30f3\u30c9\u30a6\u306e\u5b9f\u884c\u90e8\u5206<\/li>\n<\/ul>\n<pre><code class=\"language-csharp\">namespace Scripts\n{\n    public class FilePathProvider\n    {\n        public readonly string TestText = &quot;test.txt&quot;;\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-csharp\">using UnityEditor;\nusing UnityEngine;\nusing Zenject;\n\nnamespace Scripts.Editor\n{\n    public class TheEditorWindowInstaller : ZenjectEditorWindow\n    {\n        [MenuItem(&quot;Window\/TheEditorWindow&quot;)]\n        public static TheEditorWindowInstaller GetOrCreateWindow()\n        {\n            var window = GetWindow&lt;TheEditorWindowInstaller&gt;();\n            window.titleContent = new GUIContent(&quot;TheEditorWindow&quot;);\n            return window;\n        }\n\n        public override void InstallBindings()\n        {\n            \/\/ IGuiRenderable\u3084IDisposable\u3092\u5b9f\u88c5\u3057\u3066\u3044\u308b\u30af\u30e9\u30b9\u306b\u5bfe\u3057\u3066BindInterfacesAndSelfTo\u3059\u308b\u3068\n            \/\/ Zenject\u304cGuiRender()\u3084Dispose()\u3092\u5b9f\u884c\u3057\u3066\u304f\u308c\u308b\n            Container.BindInterfacesAndSelfTo&lt;TheEditorWindowCore&gt;().AsSingle();\n            Container.Bind&lt;FilePathProvider&gt;().AsSingle();\n        }\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-csharp\">using System;\nusing System.IO;\nusing UnityEngine;\nusing Zenject;\n\nnamespace Scripts.Editor\n{\n    public class TheEditorWindowCore : IGuiRenderable, IDisposable\n    {\n        private readonly StreamWriter _streamWriter;\n\n        public TheEditorWindowCore(FilePathProvider filePathProvider)\n        {\n            _streamWriter = new StreamWriter(filePathProvider.TestText);\n            Debug.Log(&quot;\u751f\u6210\uff01&quot;);\n        }\n\n        public void GuiRender()\n        {\n            if (GUILayout.Button(&quot;Hello World!&quot;))\n            {\n                _streamWriter.WriteLine(&quot;Hello World!&quot;);\n                Debug.Log(&quot;\u66f8\u3044\u305f\uff01&quot;);\n            }\n        }\n\n        public void Dispose()\n        {\n            _streamWriter.Dispose();\n            Debug.Log(&quot;\u7834\u68c4\uff01&quot;);\n        }\n    }\n}<\/code><\/pre>\n<p>\u3053\u306e\u72b6\u614b\u3067Unity\u3092\u8d77\u52d5\u3059\u308b\u3068\u3001Window\u30e1\u30cb\u30e5\u30fc\u306bTheEditorWindow\u30e1\u30cb\u30e5\u30fc\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u306f\u305a\u3067\u3059\u3002<br \/>\nTheEditorWindow\u3092\u958b\u304f\u3068\u300c\u751f\u6210\uff01\u300d\u3001\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u300c\u66f8\u3044\u305f\uff01\u300d\u3001\u9589\u3058\u308b\u3068\u300c\u7834\u68c4\uff01\u300d\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30d5\u30a9\u30eb\u30c0\u3092\u898b\u308b\u3068\u300cHello World!\u300d\u3068\u3044\u3046\u4e2d\u8eab\u3067test.txt\u304c\u4f5c\u3089\u308c\u3066\u3044\u308b\u306f\u305a\u3067\u3059\u3002<br \/>\n<a href=\"https:\/\/virtualcast.jp\/blog\/wp-content\/uploads\/2020\/04\/ZenjectEditorWindowDemo.gif\"><img src=\"https:\/\/virtualcast.jp\/blog\/wp-content\/uploads\/2020\/04\/ZenjectEditorWindowDemo.gif\" alt=\"\" \/><\/a><\/p>\n<p>\u4ee5\u4e0a\u304b\u3089\u5206\u304b\u308b\u901a\u308a\u3001\u30a6\u30a3\u30f3\u30c9\u30a6\u3092Context\u3068\u3057\u3066\u6271\u3044\u3001Editor\u4e0a\u3067Zenject\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067\u306f\u7279\u306b\u30e1\u30ea\u30c3\u30c8\u304c\u611f\u3058\u3089\u308c\u306a\u304b\u3063\u305f\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001Editor\u4e0a\u3067Zenject\u304c\u4f7f\u3048\u308b\u306e\u306f\u975e\u5e38\u306b\u5f37\u529b\u3067\u3059\u3002<br \/>\n\u5148\u307b\u3069\u306e\u4f8b\u306e\u3088\u3046\u306b\u3001Context\u304c\u30a6\u30a3\u30f3\u30c9\u30a6\u306b\u7d10\u3065\u304f\u306e\u3067\u3001<\/p>\n<ul>\n<li>\u30a6\u30a3\u30f3\u30c9\u30a6\u3067\u306e\u307f\u4f7f\u3046\u30ea\u30bd\u30fc\u30b9\u306e\u6ce8\u5165\/\u89e3\u653e\u7b49\u3092Zenject\u306b\u4efb\u305b\u308b\u3053\u3068<\/li>\n<\/ul>\n<p>\u304c\u3067\u304d\u307e\u3059\u3002\u66f4\u306b\u306f<\/p>\n<ul>\n<li><strong>\u666e\u6bb5Zenject\u3067\u7ba1\u7406\u3057\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u30b7\u30fc\u30f3\u306b\u51fa\u3059<\/strong><\/li>\n<\/ul>\n<p>\u7b49\u3082\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059(\uff01)\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001ZenjectEditorWindow\u306e\u7d39\u4ecb\u3067\u3057\u305f\u3002<br \/>\n\u65e5\u672c\u8a9e\u3067\u306f\u3042\u307e\u308a\u53d6\u308a\u4e0a\u3052\u3089\u308c\u3066\u306a\u3044\u304b\u306a\u3068\u601d\u3063\u3066\u53d6\u308a\u4e0a\u3052\u3066\u307f\u307e\u3057\u305f\u2606<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0e\u5165 \u3053\u3093\u306b\u3061\u306f\uff01\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u306eNatsuki\u3067\u3059\u3002 \u307f\u306a\u3055\u3093\u3001Unity\u306e\u958b\u767a\u3067Zenject(Extenject\u542b\u3080)\u306f\u4f7f\u3063\u3066\u307e\u3059\u304b\uff1f \u672c\u65e5\u306fZenjectEditorWindow\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":3,"featured_media":5676,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[106,26],"tags":[23],"_links":{"self":[{"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/posts\/5665"}],"collection":[{"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/comments?post=5665"}],"version-history":[{"count":13,"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/posts\/5665\/revisions"}],"predecessor-version":[{"id":5700,"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/posts\/5665\/revisions\/5700"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/media\/5676"}],"wp:attachment":[{"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/media?parent=5665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/categories?post=5665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.virtualcast.jp\/blog\/wp-json\/wp\/v2\/tags?post=5665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}