{"id":446,"date":"2019-10-19T20:11:34","date_gmt":"2019-10-19T12:11:34","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=446"},"modified":"2020-12-05T17:56:14","modified_gmt":"2020-12-05T09:56:14","slug":"unity%e6%89%b9%e9%87%8f%e7%bc%96%e8%be%91prefab","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=446","title":{"rendered":"[Unity]\u6279\u91cf\u7f16\u8f91Prefab"},"content":{"rendered":"\n<p>\u4f5c\u7528\uff1a\u6279\u91cf\u4fee\u6539Prefab\u4e2d\u7684\u5185\u5bb9\uff0c\u6bd4\u5982Prefab\u4e2d\u6dfb\u52a0\u4e86\u8bb8\u591aEditorOnly\u7684\u7269\u4ef6\uff0c\u73b0\u5728\u7528\u5de5\u5177\u6279\u91cf\u5220\u9664<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u65b9\u6cd5\u4e00\uff1a\u65ad\u5f00\u6240\u6709\u8fde\u63a5\uff0c\u91cd\u65b0\u7ec4\u88c5Prefab\uff0c\u4e0d\u63a8\u8350\nvar prefabObj = AssetDatabase.LoadAssetAtPath&lt;GameObject>(prefabFilename);\nvar newInstance = GameObject.Instantiate(prefabObj);\n    \/\/ Edit: UnityEngine.Object.DestroyImmediate();\n    \/\/ Edit: GameObject.DestroyImmediate(obj);\nPrefabUtility.SaveAsPrefabAssetAndConnect(newInstance, newPath, InteractionMode.AutomatedAction);\nGameObject.DestroyImmediate(newInstance);\n\n\u65b9\u6cd5\u4e8c\uff1a\u4fdd\u6301Prefab\u5185\u7684\u5d4c\u5957\nvar prefabObj = PrefabUtility.LoadPrefabContents(prefabFilename);\n    \/\/ Edit: UnityEngine.Object.DestroyImmediate();\n    \/\/ Edit: GameObject.DestroyImmediate(obj);\nPrefabUtility.SaveAsPrefabAsset(prefabObj, newPath);\nPrefabUtility.UnloadPrefabContents(prefabObj); \/\/ \u6ce8\u610f\u8c03\u7528\u6b64API\uff0c\u5426\u5219UnityCrash\uff01<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u7528\uff1a\u6279\u91cf\u4fee\u6539Prefab\u4e2d\u7684\u5185\u5bb9\uff0c\u6bd4\u5982Prefab\u4e2d\u6dfb\u52a0\u4e86\u8bb8\u591aEditorOnly\u7684\u7269\u4ef6\uff0c\u73b0\u5728\u7528\u5de5\u5177\u6279\u91cf\u5220\u9664<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[18],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/446"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=446"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/446\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/446\/revisions\/571"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}