//==================================== // Prefaber //==================================== public void DrawPrefaber() { GUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField("Prefab", GUILayout.Width(60)); if (GUILayout.Button("Revert", GUILayout.Width(100))) { ProxyEditor.RegisterSceneUndo(this, "Revert Selected Prefabs"); foreach (GameObject current in Selection.gameObjects) { ProxyEditor.ReconnectToLastPrefab(current); } } if (GUILayout.Button("Apply", GUILayout.Width(100))) { ProxyEditor.RegisterSceneUndo(this, "Apply Selected Prefabs"); foreach (GameObject current in Selection.gameObjects) { GameObject root = ProxyEditor.GetPrefabRoot(current); ProxyEditor.ApplyPrefab(root, ProxyEditor.GetPrefab(root)); } } if (GUILayout.Button("Detach", GUILayout.Width(100))) { ProxyEditor.RegisterSceneUndo(this, "Apply Selected Prefabs"); foreach (GameObject current in Selection.gameObjects) { ProxyEditor.DisconnectPrefabInstance(current); } } GUILayout.EndHorizontal(); }
//==================================== // Material Replacer //==================================== public void DrawMaterialReplacer() { GUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField("Replace Material", GUILayout.Width(105)); this.materialRenameFrom = EditorGUILayout.TextField(this.materialRenameFrom, GUILayout.Width(100)); EditorGUILayout.LabelField("To", GUILayout.Width(25)); this.materialRenameTo = EditorGUILayout.TextField(this.materialRenameTo, GUILayout.Width(100)); if (GUILayout.Button("Apply", GUILayout.Width(100))) { ProxyEditor.RegisterSceneUndo(this, "Revert Material Replace"); GameObject[] selection = Selection.gameObjects; bool global = this.materialRenameFrom == "*"; string search = this.materialRenameFrom.Replace("*", ""); foreach (GameObject current in selection) { Renderer[] renderers = current.GetComponentsInChildren <Renderer>(this.materialIncludeInactive); foreach (Renderer renderer in renderers) { List <Material> replacedMaterials = new List <Material>(); foreach (Material material in renderer.sharedMaterials) { string name = material.name; Material currentMaterial = material; if (name.Contains(search)) { string replace = name.Replace(search, this.materialRenameTo); if (global) { replace = this.materialRenameTo; } Material swapMaterial = File.GetAsset <Material>(replace + ".mat", false); if (swapMaterial != null) { currentMaterial = swapMaterial; } } replacedMaterials.Add(currentMaterial); } renderer.sharedMaterials = replacedMaterials.ToArray(); } } } GUILayout.EndHorizontal(); this.materialIncludeInactive = EditorGUILayout.ToggleLeft("Include Inactive", this.materialIncludeInactive); }
//==================================== // Replace //==================================== public void PerformReplace() { if (this.optionA.type == ReplaceOption.Prefab) { ProxyEditor.RegisterSceneUndo(this, "Replace Operation"); Object prefab = ProxyEditor.CreateEmptyPrefab(null, this.optionA.targetPath); ProxyEditor.ApplyPrefab(this.optionB.found.First(), prefab); } if (this.optionA.type == ReplaceOption.GameObject) { foreach (GameObject current in new List <GameObject>(this.optionA.found)) { GameObject newObject = (GameObject)ProxyEditor.InstantiatePrefab(this.optionB.found.First()); newObject.transform.parent = current.transform.parent; newObject.transform.position = current.transform.position; newObject.transform.rotation = current.transform.rotation; if (this.preserveScale) { newObject.transform.localScale = current.transform.localScale; } DestroyImmediate(current); } } }