{"id":2033,"date":"2019-05-30T14:39:20","date_gmt":"2019-05-30T06:39:20","guid":{"rendered":"https:\/\/www.clonefactor.com\/wordpress\/?p=2033"},"modified":"2019-05-30T14:39:54","modified_gmt":"2019-05-30T06:39:54","slug":"u3d-tools-search-and-replace-gameobjects","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/program\/unity3d\/2033\/","title":{"rendered":"U3D : Tools &#8211; search and replace gameObjects"},"content":{"rendered":"\n<p>\u4e00\u6bb5\u7c21\u55ae\u7684 script \u53ef\u4ee5\u9078\u53d6\u5728 sceneview \u4e2d\u7684\u7684 GameObject \u7136\u5f8c\u7528\u5176\u4ed6 GameObject \u53d6\u4ee3\u5b83\u5011\u539f\u6709\u7684\u4f4d\u7f6e,\u89d2\u5ea6,\u5927\u5c0f\u7b49\u7b49.<br>\u5728\u5834\u666f\u6709\u5927\u91cf\u76f8\u540c\u7684\u6771\u897f\u9700\u8981\u8f49\u63db\u6642\u7684\u5c0f\u5de5\u5177.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using UnityEngine;\nusing UnityEditor;\nusing System.Collections;\n\npublic class SearchAndReplace : ScriptableWizard\n{\n\tpublic GameObject prefab;\n\tpublic GameObject[] OldObjects;\n\n\t[Header(\"Options\")]\n\tpublic bool copyParentTransform = true;\n\tpublic bool copyPosition = true;\n\tpublic bool copyRotation = true;\n\tpublic bool copyScale = true;\n\n\t[MenuItem(\"Kit\/Replace GameObjects\")]\n\tstatic void CreateWizard()\n\t{\n\t\tScriptableWizard.DisplayWizard(\"Replace GameObjects\", typeof(SearchAndReplace), \"Replace\");\n\t}\n\n\tvoid OnWizardCreate()\n\t{\n\t\tint undoIdx = Undo.GetCurrentGroup();\n\t\tforeach (GameObject go in OldObjects)\n\t\t{\n\t\t\tGameObject newObject;\n\t\t\tif (prefab.transform.root == null)\n\t\t\t\tnewObject = (GameObject)PrefabUtility.InstantiatePrefab(prefab); \/\/ prefab\n\t\t\telse\n\t\t\t\tnewObject = Instantiate(prefab); \/\/ scene object\n\n\t\t\tUndo.RegisterCreatedObjectUndo(newObject, \"NewObject\");\n\t\t\tif (copyParentTransform) newObject.transform.SetParent(go.transform.parent);\n\t\t\tif (copyPosition) newObject.transform.position = go.transform.position;\n\t\t\tif (copyRotation) newObject.transform.rotation = go.transform.rotation;\n\t\t\tif (copyScale) newObject.transform.localScale = go.transform.localScale;\n\t\t\tUndo.RecordObject(newObject, \"NewObjectParams\");\n\t\t\tUndo.DestroyObjectImmediate(go);\n\t\t}\n\t\tUndo.CollapseUndoOperations(undoIdx);\n\t}\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u6bb5\u7c21\u55ae\u7684 script \u53ef\u4ee5\u9078\u53d6\u5728 sceneview \u4e2d\u7684\u7684 GameObject \u7136\u5f8c\u7528\u5176\u4ed6  &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[43],"class_list":["post-2033","post","type-post","status-publish","format-standard","hentry","category-unity3d","tag-unity3d-2"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2033"}],"version-history":[{"count":0,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2033\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}