├── .gitignore ├── Images ├── step0.jpg ├── step1.jpg ├── step2.jpg └── step3.jpg ├── LICENSE ├── README.md └── RuntimePrefabEditor └── Scripts └── Editor ├── EditorUtils.cs ├── GameObjectDiff.cs ├── PrefabSearchDB.cs └── RuntimePrefabEditor.cs /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.pidb.meta 28 | 29 | # Unity3D Generated File On Crash Reports 30 | sysinfo.txt 31 | 32 | # Builds 33 | *.apk 34 | *.unitypackage 35 | -------------------------------------------------------------------------------- /Images/step0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/novoselov-ab/unity-prefab-editor/54def108f467e72b0f7ddd774ba69756a771aff0/Images/step0.jpg -------------------------------------------------------------------------------- /Images/step1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/novoselov-ab/unity-prefab-editor/54def108f467e72b0f7ddd774ba69756a771aff0/Images/step1.jpg -------------------------------------------------------------------------------- /Images/step2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/novoselov-ab/unity-prefab-editor/54def108f467e72b0f7ddd774ba69756a771aff0/Images/step2.jpg -------------------------------------------------------------------------------- /Images/step3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/novoselov-ab/unity-prefab-editor/54def108f467e72b0f7ddd774ba69756a771aff0/Images/step3.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Prefab Editor 2 | 3 | Prefab Editor - is Unity3d tool for editing prefabs in runtime(playmode). You can change anything in prefab instance (root object or any child) in runtime, then select changes you want to apply and press apply. It is just that simple. 4 | 5 | For example, it is very convenient while editing a UI. You tweak positions, colors, and other properties of your elements and than you have to memorize changes (or write them down), press stop, find prefab and apply them again. With Prefab Editor you can just apply selectively changes you need. 6 | 7 | Key Features 8 | - Automatically searches for prefab you selected. If more than one is found - you can select the one you need. 9 | - Supports adding new components, deleting existing compoents, and changing any component property. 10 | - Supports changing reference properties. 11 | - Optimized to work very fast even on huge projects. 12 | 13 | Also available on the Unity Store: https://assetstore.unity.com/packages/tools/utilities/prefab-editor-24895 14 | 15 | ## Usage 16 | 17 | * Copy the `RuntimePrefabEditor` folder somewhere under the `Assets` folder. 18 | * Open Unity3d. 19 | * Open `Window/Prefab Editor`. 20 | * Select a GameObject in your scene to edit. Prefab Editor will show the prefab associated with that GameObject, it could be that there are few. 21 | * Edit your GameObject. 22 | * Prefab Editor show changes, select changes you want to apply and press `Apply Changes To Prefab` button. 23 | 24 | ## Usage in pictures 25 | 26 | ![Alt text](/Images/step0.jpg?raw=true "Step 0") 27 | ![Alt text](/Images/step1.jpg?raw=true "Step 1") 28 | ![Alt text](/Images/step2.jpg?raw=true "Step 2") 29 | ![Alt text](/Images/step3.jpg?raw=true "Step 3") 30 | 31 | ## Misc 32 | 33 | It was written few years ago and no longer developed. Though it should work quite well still and I hope someone will find it as useful as I once did. -------------------------------------------------------------------------------- /RuntimePrefabEditor/Scripts/Editor/EditorUtils.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Linq; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | namespace RuntimePrefabEditor 9 | { 10 | public static class EditorUtils 11 | { 12 | public static bool IsAnimationCurvesEqual(AnimationCurve curve1, AnimationCurve curve2) 13 | { 14 | if(curve1.postWrapMode != curve2.postWrapMode) return false; 15 | if(curve1.preWrapMode != curve2.preWrapMode) return false; 16 | if(curve1.length != curve2.length) return false; 17 | return curve1.keys.SequenceEqual(curve2.keys); 18 | } 19 | 20 | public static string GetPathForObjectInHierarchy(GameObject childGO, GameObject baseGO) 21 | { 22 | bool found = false; 23 | string path = ""; 24 | Transform t = childGO != null ? childGO.transform : null; 25 | while(t != null) 26 | { 27 | if(t == baseGO.transform) 28 | { 29 | found = true; 30 | break; 31 | } 32 | if(string.IsNullOrEmpty(path)) 33 | path = t.name; 34 | else 35 | path = t.name + "/" + path; 36 | t = t.parent; 37 | } 38 | return found ? path : null; 39 | } 40 | 41 | public static GameObject GetChildByPath(this GameObject gameObject, string path) 42 | { 43 | if(path != null) 44 | { 45 | Transform t = path.Length > 0 ? gameObject.transform.Find(path) : gameObject.transform; 46 | if(t != null) 47 | { 48 | return t.gameObject; 49 | } 50 | } 51 | return null; 52 | } 53 | 54 | public static string GetParentPath(string path) 55 | { 56 | path = path.TrimEnd('/'); 57 | int i = path.LastIndexOf("/"); 58 | if(i > 0) 59 | { 60 | return path.Substring(0, i); 61 | } 62 | return ""; 63 | } 64 | 65 | public static GameObject GetParent (this GameObject obj) 66 | { 67 | Transform tr = obj.transform.parent; 68 | return tr? tr.gameObject: null; 69 | } 70 | 71 | public static bool TryRemovePostfix(ref string str, string postfix) 72 | { 73 | if(!str.EndsWith(postfix)) 74 | { 75 | return false; 76 | } 77 | else 78 | { 79 | str = str.Substring(0, str.Length - postfix.Length); 80 | return true; 81 | } 82 | } 83 | 84 | public static string WithoutClonePostfix(string name) 85 | { 86 | TryRemovePostfix(ref name, "(Clone)"); 87 | return name; 88 | } 89 | 90 | public static string ToString255(this Color c) 91 | { 92 | return string.Format("({0:0},{1:0},{2:0},{3:0})", c.r * 255, c.g * 255, c.b * 255, c.a * 255); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /RuntimePrefabEditor/Scripts/Editor/GameObjectDiff.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Linq; 5 | using System.IO; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | 9 | namespace RuntimePrefabEditor 10 | { 11 | /// 12 | /// Helper class to find diff between gameobject and it's prefab 13 | /// 14 | public static class GameObjectDiff 15 | { 16 | // class to keep resulting diff 17 | public class Diff 18 | { 19 | public enum Operation 20 | { 21 | Delete, 22 | Add, 23 | Property, 24 | New 25 | } 26 | 27 | public Diff(Operation operation, Component component, string propertyPath) 28 | { 29 | id.operation = operation; 30 | id.component = component; 31 | id.propertyPath = propertyPath; 32 | } 33 | 34 | public struct Id 35 | { 36 | public Operation operation; 37 | public Component component; 38 | public string propertyPath; 39 | } 40 | 41 | public Id id; 42 | public Action Apply; 43 | public Action OnGUI; 44 | } 45 | 46 | public static List GetDiffs(GameObject instance, GameObject instanceRoot, GameObject prefab, GameObject prefabRoot) 47 | { 48 | List diffs = new List(); 49 | 50 | if( prefab ) 51 | { 52 | // compare existing components 53 | var prefabComponents = prefab.GetComponents(); 54 | var deletedComponents = new List(); 55 | foreach( var prefabComponent in prefabComponents ) 56 | { 57 | var instanceComponentsOfType = instance.GetComponents( prefabComponent.GetType() ); 58 | Component instanceComponent = instanceComponentsOfType.Length > 0 ? instanceComponentsOfType[0] : null; 59 | 60 | // if we have more than one same component -> try to get the same by order of GetComponents() 61 | if(instanceComponentsOfType.Length > 1) 62 | { 63 | int indexInPrefab = Array.IndexOf(prefab.GetComponents(prefabComponent.GetType()), prefabComponent); 64 | instanceComponent = instanceComponentsOfType[indexInPrefab % instanceComponentsOfType.Length]; 65 | } 66 | 67 | if( instanceComponent ) 68 | { 69 | FillDiffsFromComponent(ref diffs, instanceComponent, prefabComponent, instanceRoot, prefabRoot ); 70 | } 71 | else 72 | { 73 | deletedComponents.Add(prefabComponent); 74 | } 75 | } 76 | 77 | // delete obsolete components 78 | foreach( var deletedComponent in deletedComponents ) 79 | { 80 | Component prefabDeletedComponent = deletedComponent; 81 | Diff deleteDiff = new Diff(Diff.Operation.Delete, prefabDeletedComponent, null); 82 | deleteDiff.Apply = () => { GameObject.DestroyImmediate( prefabDeletedComponent, true ); }; 83 | deleteDiff.OnGUI = () => 84 | { 85 | GUI.color = new Color(1, 0.7f, 0.7f); 86 | EditorGUILayout.LabelField("Deleted component:", prefabDeletedComponent.GetType().Name); 87 | GUI.color = Color.white; 88 | EditorGUILayout.ObjectField(prefabDeletedComponent, typeof(Component), false); 89 | }; 90 | diffs.Add(deleteDiff); 91 | } 92 | 93 | // add new components 94 | var instanceComponents = instance.GetComponents(); 95 | foreach( var instanceComponent in instanceComponents ) 96 | { 97 | if( !System.Array.Find( prefabComponents, (x) => { return x.GetType() == instanceComponent.GetType(); } ) ) 98 | { 99 | Component instanceNewComponent = instanceComponent; 100 | Diff addDiff = new Diff(Diff.Operation.Add, instanceNewComponent, null); 101 | addDiff.Apply = () => { 102 | var prefabComponent = prefab.AddComponent( instanceNewComponent.GetType() ); 103 | UnityEditor.EditorUtility.CopySerialized( instanceNewComponent, prefabComponent ); 104 | }; 105 | addDiff.OnGUI = () => 106 | { 107 | GUI.color = new Color(0.7f, 1, 0.7f); 108 | EditorGUILayout.LabelField("Added component:", instanceNewComponent.GetType().Name); 109 | GUI.color = Color.white; 110 | EditorGUILayout.ObjectField(instanceNewComponent, typeof(Component), false); 111 | }; 112 | diffs.Add(addDiff); 113 | } 114 | } 115 | } 116 | else 117 | { 118 | // probably new gameobject 119 | GameObjectDiff.Diff d = new GameObjectDiff.Diff(GameObjectDiff.Diff.Operation.New, null, instance.name); 120 | d.Apply = () => 121 | { 122 | GameObject prefabInstance = PrefabUtility.InstantiatePrefab(prefabRoot) as GameObject; 123 | GameObject instanceCopy = new GameObject(instance.name); 124 | string path = EditorUtils.GetPathForObjectInHierarchy(instance, instanceRoot); 125 | instanceCopy.transform.parent = prefabInstance.GetChildByPath(path).transform; 126 | foreach(Component c in instance.GetComponents()) 127 | { 128 | if(c is Transform) 129 | continue; 130 | EditorUtility.CopySerialized(c, instanceCopy.AddComponent(c.GetType())); 131 | } 132 | EditorUtility.CopySerialized(instance.transform, instanceCopy.transform); 133 | PrefabUtility.ReplacePrefab(prefabInstance, prefabRoot); 134 | GameObject.DestroyImmediate(prefabInstance); 135 | }; 136 | d.OnGUI = () => 137 | { 138 | GUI.color = new Color(0, 1f, 0); 139 | EditorGUILayout.LabelField("New GameObject:", instance.name); 140 | GUI.color = Color.white; 141 | }; 142 | diffs.Add(d); 143 | } 144 | 145 | return diffs; 146 | } 147 | 148 | private static void FillDiffsFromComponent(ref List diffs, Component instanceComponent, Component prefabComponent, GameObject instanceRoot, GameObject prefabRoot ) 149 | { 150 | SerializedObject serializedInstance = new SerializedObject(instanceComponent); 151 | SerializedObject serializedPrefab = new SerializedObject(prefabComponent); 152 | SerializedProperty instanceProp = serializedInstance.GetIterator(); 153 | bool enterChildren = true; 154 | do 155 | { 156 | // Finding same property 157 | SerializedProperty prefabProp = serializedPrefab.FindProperty(instanceProp.propertyPath); 158 | if(prefabProp == null) 159 | continue; 160 | 161 | // black list 162 | if(propertyBlacklist.Contains(instanceProp.propertyPath)) 163 | { 164 | enterChildren = false; 165 | continue; 166 | } 167 | 168 | // Compare 169 | Action apply = null; 170 | Action onGUI = null; 171 | if(!CompareSerializedProperty(instanceProp.Copy(), prefabProp, instanceRoot, prefabRoot, ref apply, ref onGUI)) 172 | { 173 | Diff propertyDiff = new Diff(Diff.Operation.Property, instanceComponent, instanceProp.propertyPath ); 174 | propertyDiff.OnGUI = () => 175 | { 176 | onGUI(); 177 | //EditorGUILayout.LabelField("Property changed:" + prop.propertyType.ToString() + prop.propertyPath); 178 | }; 179 | propertyDiff.Apply = () => 180 | { 181 | apply(); 182 | serializedPrefab.ApplyModifiedProperties(); 183 | }; 184 | diffs.Add(propertyDiff); 185 | } 186 | 187 | // look for childs in generic properties (like class, structs) 188 | enterChildren = (instanceProp.propertyType == SerializedPropertyType.Generic); 189 | 190 | } while(instanceProp.Next(enterChildren)); 191 | } 192 | 193 | // ignore list, internal unity properties 194 | static HashSet propertyBlacklist = new HashSet(new string[] 195 | { 196 | "m_ObjectHideFlags", "m_PrefabParentObject", "m_PrefabInternal", "m_GameObject", "m_EditorHideFlags", "m_FileID", "m_PathID", "m_Children" 197 | }); 198 | 199 | static bool CompareSerializedProperty(SerializedProperty p1, SerializedProperty p2, GameObject root1, GameObject root2, ref Action apply, ref Action onGUI) 200 | { 201 | if(p1.propertyType != p2.propertyType) 202 | Debug.LogError("SerializedPropertys have different types!"); 203 | 204 | string SIMPLE_FORMAT = string.Format("{0}.{1}: {2}", p1.serializedObject.targetObject.GetType().Name, p1.propertyPath, "{1} -> {0}"); 205 | 206 | switch (p1.propertyType) 207 | { 208 | ///////////////////////////////////////////////////////// 209 | case SerializedPropertyType.Integer: 210 | case SerializedPropertyType.LayerMask: 211 | case SerializedPropertyType.Character: 212 | case SerializedPropertyType.ArraySize: 213 | apply = () => 214 | { 215 | p2.intValue = p1.intValue; 216 | }; 217 | onGUI = () => 218 | { 219 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.intValue, p2.intValue)); 220 | }; 221 | return (p2.intValue == p1.intValue); 222 | ///////////////////////////////////////////////////////// 223 | case SerializedPropertyType.Boolean: 224 | apply = () => 225 | { 226 | p2.boolValue = p1.boolValue; 227 | }; 228 | onGUI = () => 229 | { 230 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.boolValue, p2.boolValue)); 231 | }; 232 | return (p2.boolValue == p1.boolValue); 233 | ///////////////////////////////////////////////////////// 234 | case SerializedPropertyType.Float: 235 | apply = () => 236 | { 237 | p2.floatValue = p1.floatValue; 238 | }; 239 | onGUI = () => 240 | { 241 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.floatValue, p2.floatValue)); 242 | }; 243 | return (p2.floatValue == p1.floatValue); 244 | ///////////////////////////////////////////////////////// 245 | case SerializedPropertyType.String: 246 | apply = () => 247 | { 248 | p2.stringValue = p1.stringValue; 249 | }; 250 | onGUI = () => 251 | { 252 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.stringValue, p2.stringValue)); 253 | }; 254 | return (p2.stringValue == p1.stringValue); 255 | ///////////////////////////////////////////////////////// 256 | case SerializedPropertyType.Color: 257 | apply = () => 258 | { 259 | p2.colorValue = p1.colorValue; 260 | }; 261 | onGUI = () => 262 | { 263 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.colorValue.ToString255(), p2.colorValue.ToString255())); 264 | EditorGUILayout.ColorField(p2.colorValue, GUILayout.Width(45)); 265 | EditorGUILayout.LabelField(" -> ", GUILayout.Width(35)); 266 | EditorGUILayout.ColorField(p1.colorValue, GUILayout.Width(45)); 267 | }; 268 | return (p2.colorValue == p1.colorValue); 269 | ///////////////////////////////////////////////////////// 270 | case SerializedPropertyType.Enum: 271 | apply = () => 272 | { 273 | p2.enumValueIndex = p1.enumValueIndex; 274 | }; 275 | onGUI = () => 276 | { 277 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.enumNames[p1.enumValueIndex], p2.enumNames[p2.enumValueIndex])); 278 | }; 279 | return (p2.enumValueIndex == p1.enumValueIndex); 280 | ///////////////////////////////////////////////////////// 281 | case SerializedPropertyType.Vector2: 282 | apply = () => 283 | { 284 | p2.vector2Value = p1.vector2Value; 285 | }; 286 | onGUI = () => 287 | { 288 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.vector2Value, p2.vector2Value)); 289 | }; 290 | return (p2.vector2Value == p1.vector2Value); 291 | ///////////////////////////////////////////////////////// 292 | case SerializedPropertyType.Vector3: 293 | apply = () => 294 | { 295 | p2.vector3Value = p1.vector3Value; 296 | }; 297 | onGUI = () => 298 | { 299 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.vector3Value, p2.vector3Value)); 300 | }; 301 | return (p2.vector3Value == p1.vector3Value); 302 | ///////////////////////////////////////////////////////// 303 | case SerializedPropertyType.Quaternion: 304 | apply = () => 305 | { 306 | p2.quaternionValue = p1.quaternionValue; 307 | }; 308 | onGUI = () => 309 | { 310 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.quaternionValue.eulerAngles, p2.quaternionValue.eulerAngles)); 311 | }; 312 | return (p2.quaternionValue == p1.quaternionValue); 313 | ///////////////////////////////////////////////////////// 314 | case SerializedPropertyType.Rect: 315 | apply = () => 316 | { 317 | p2.rectValue = p1.rectValue; 318 | }; 319 | onGUI = () => 320 | { 321 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.rectValue, p2.rectValue)); 322 | }; 323 | return (p2.rectValue == p1.rectValue); 324 | ///////////////////////////////////////////////////////// 325 | case SerializedPropertyType.AnimationCurve: 326 | 327 | apply = () => 328 | { 329 | p2.animationCurveValue = p1.animationCurveValue; 330 | }; 331 | onGUI = () => 332 | { 333 | EditorGUILayout.LabelField(p2.serializedObject.targetObject.GetType().Name + "." + p2.propertyPath + ": animation curve changed"); 334 | }; 335 | return EditorUtils.IsAnimationCurvesEqual(p2.animationCurveValue, p1.animationCurveValue); 336 | ///////////////////////////////////////////////////////// 337 | case SerializedPropertyType.Bounds: 338 | apply = () => 339 | { 340 | p2.boundsValue = p1.boundsValue; 341 | }; 342 | onGUI = () => 343 | { 344 | EditorGUILayout.LabelField(string.Format(SIMPLE_FORMAT, p1.boundsValue, p2.boundsValue)); 345 | }; 346 | return (p2.boundsValue == p1.boundsValue); 347 | ///////////////////////////////////////////////////////// 348 | case SerializedPropertyType.ObjectReference: 349 | return CompareSerializedPropertyObjectReference(p1, p2, root1, root2, ref apply, ref onGUI); 350 | ///////////////////////////////////////////////////////// 351 | case SerializedPropertyType.Generic: 352 | // not implemented 353 | return true; 354 | ///////////////////////////////////////////////////////// 355 | ///////////////////////////////////////////////////////// 356 | default: 357 | // not implemented 358 | //Debug.LogError("Implement: " + p1.propertyType + " " + p1.propertyPath); 359 | return true; 360 | } 361 | } 362 | 363 | static bool CompareSerializedPropertyObjectReference(SerializedProperty p1, SerializedProperty p2, GameObject root1, GameObject root2, ref Action apply, ref Action onGUI) 364 | { 365 | // If this is objectReference property, we want to try to find same object in our hierarchy and use it. Otherwise 366 | // property is just copied and links same object. 367 | 368 | onGUI = () => 369 | { 370 | EditorGUILayout.LabelField(p2.serializedObject.targetObject.GetType().Name + "." + p2.propertyPath + ": reference changed"); 371 | EditorGUILayout.ObjectField(p1.objectReferenceValue, typeof(UnityEngine.Object), false, GUILayout.Width(200)); 372 | }; 373 | 374 | if(p1.objectReferenceValue == null || EditorUtility.IsPersistent(p1.objectReferenceValue)) 375 | { 376 | apply = () => 377 | { 378 | p2.objectReferenceValue = p1.objectReferenceValue; 379 | }; 380 | return (p2.objectReferenceValue == p1.objectReferenceValue); 381 | } 382 | else 383 | { 384 | GameObject referencedGO = null; 385 | if(p1.objectReferenceValue is GameObject) 386 | { 387 | referencedGO = p1.objectReferenceValue as GameObject; 388 | } 389 | else if(p1.objectReferenceValue is Component) 390 | { 391 | referencedGO = (p1.objectReferenceValue as Component).gameObject; 392 | } 393 | else 394 | { 395 | Debug.LogWarning(string.Format("Unknown object reference type {0}", p1.objectReferenceValue.GetType()), p1.serializedObject.targetObject); 396 | return true; 397 | } 398 | 399 | if(referencedGO == null) 400 | { 401 | Debug.LogError(string.Format("Wrong object reference type {0}", p1.objectReferenceValue.GetType()), p1.serializedObject.targetObject); 402 | return true; 403 | } 404 | 405 | string path1 = EditorUtils.GetPathForObjectInHierarchy(referencedGO, root1); 406 | if(path1 == null) 407 | { 408 | // It means it references to some of other assets, leave link as it is. 409 | return true; 410 | } 411 | 412 | //Debug.LogWarning("Path: {0} for: {1}", path, fromProp.objectReferenceValue.name); 413 | 414 | GameObject newGO = root2.GetChildByPath(path1); 415 | if(newGO == null) 416 | { 417 | //Debug.LogWarning(string.Format("Can't find transform for path {0}", path1), p1.serializedObject.targetObject); 418 | return true; 419 | } 420 | 421 | if(p1.objectReferenceValue is GameObject) 422 | { 423 | apply = () => { p2.objectReferenceValue = newGO.gameObject; }; 424 | return path1 == EditorUtils.GetPathForObjectInHierarchy(p2.objectReferenceValue as GameObject, root2); 425 | } 426 | else if(p1.objectReferenceValue is Component) 427 | { 428 | Component myComp = newGO.gameObject.GetComponent(p1.objectReferenceValue.GetType()); 429 | if(myComp == null) 430 | { 431 | // Can't apply this change since we can't find needed component in hierarchy 432 | //Debug.LogError(string.Format("Can't find component on object {0}", path1), p1.serializedObject.targetObject); 433 | } 434 | 435 | apply = () => { p2.objectReferenceValue = myComp; }; 436 | 437 | var c2 = p2.objectReferenceValue as Component; 438 | if(c2 != null) 439 | return path1 == EditorUtils.GetPathForObjectInHierarchy(c2.gameObject, root2); 440 | else 441 | return false; 442 | } 443 | } 444 | 445 | return true; 446 | } 447 | 448 | 449 | } 450 | } 451 | -------------------------------------------------------------------------------- /RuntimePrefabEditor/Scripts/Editor/PrefabSearchDB.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Linq; 5 | using System.IO; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Runtime.Serialization; 9 | using System.Runtime.Serialization.Formatters.Binary; 10 | using System.Xml.Serialization; 11 | 12 | namespace RuntimePrefabEditor 13 | { 14 | public class PrefabSearchDB 15 | { 16 | public PrefabSearchDB() 17 | { 18 | RefreshIndex(); 19 | } 20 | 21 | public struct PrefabCandidate 22 | { 23 | public bool IsValid() { return prefabRoot != null; } 24 | public void Reset() { prefabRoot = null; } 25 | 26 | public GameObject instanceRoot; 27 | public GameObject prefabRoot; 28 | public GameObject prefab; 29 | public string prefabPath; 30 | } 31 | 32 | public List GetPrefabCandidatesForSceneObject(GameObject instance) 33 | { 34 | List candidates = new List(); 35 | 36 | RefreshIndex(); 37 | 38 | GameObject instanceRoot = instance; 39 | while(instanceRoot != null) 40 | { 41 | string candidateName = EditorUtils.WithoutClonePostfix(instanceRoot.name); 42 | 43 | List paths; 44 | if(_index.TryGetValue(candidateName, out paths)) 45 | { 46 | foreach(var path in paths) 47 | { 48 | GameObject prefabRoot = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; 49 | if(!prefabRoot) continue; 50 | 51 | var prefabPath = EditorUtils.GetPathForObjectInHierarchy(instance, instanceRoot); 52 | GameObject prefab = prefabRoot.GetChildByPath(prefabPath); 53 | 54 | if(prefab == null) 55 | { 56 | // ATTENTION: 57 | // new gameobjects unsupported yet, comment "continue" to enable 58 | continue; 59 | 60 | // try find prefab for parent 61 | prefabPath = EditorUtils.GetParentPath(prefabPath); 62 | GameObject prefabParent = prefabRoot.GetChildByPath(prefabPath); 63 | if(prefabParent == null) 64 | continue; 65 | } 66 | 67 | PrefabCandidate candidate; 68 | candidate.instanceRoot = instanceRoot; 69 | candidate.prefabRoot = prefabRoot; 70 | candidate.prefab = prefab; 71 | candidate.prefabPath = prefabPath; 72 | 73 | candidates.Add(candidate); 74 | } 75 | } 76 | 77 | instanceRoot = instanceRoot.GetParent(); 78 | } 79 | 80 | // longer path is preferable 81 | if(candidates.Count > 0) 82 | { 83 | candidates.Sort((c1, c2) => c2.prefabPath.Length.CompareTo(c1.prefabPath.Length)); 84 | } 85 | 86 | return candidates; 87 | } 88 | 89 | private void RefreshIndex() 90 | { 91 | string[] assetGUIDs = AssetDatabase.FindAssets("t:prefab"); 92 | if(_assetsProcessedCount != assetGUIDs.Length) 93 | { 94 | _index = new Dictionary>(); 95 | foreach(string guid in assetGUIDs) 96 | { 97 | string path = AssetDatabase.GUIDToAssetPath(guid); 98 | 99 | string filename = System.IO.Path.GetFileNameWithoutExtension(path); 100 | List paths = null; 101 | if(!_index.TryGetValue(filename, out paths)) 102 | { 103 | paths = new List(); 104 | _index[filename] = paths; 105 | } 106 | paths.Add(path); 107 | } 108 | _assetsProcessedCount = assetGUIDs.Length; 109 | } 110 | } 111 | 112 | private static GameObject FindRootObject(GameObject gameObject, GameObject prefab) 113 | { 114 | GameObject result = gameObject; 115 | while( result ) 116 | { 117 | if(EditorUtils.WithoutClonePostfix(result.name).ToLower() == EditorUtils.WithoutClonePostfix(prefab.name).ToLower()) break; 118 | result = result.GetParent(); 119 | } 120 | 121 | return result; 122 | } 123 | 124 | Dictionary> _index = new Dictionary>(); 125 | int _assetsProcessedCount = 0; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /RuntimePrefabEditor/Scripts/Editor/RuntimePrefabEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Linq; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | namespace RuntimePrefabEditor 9 | { 10 | public class RuntimePrefabEditor : EditorWindow 11 | { 12 | static int MinWidth = 455; 13 | 14 | bool _saveAssetsRecommended = false; 15 | 16 | Vector2 _scrollPos = new Vector2 (0, 0); 17 | 18 | PrefabSearchDB _searchDB = null; 19 | 20 | 21 | private PrefabSearchDB.PrefabCandidate _selectedPrefabCandidate; 22 | private HashSet _selectedDiffs = new HashSet(); 23 | private HashSet _deselectedDiffs = new HashSet(); 24 | 25 | [MenuItem ("Window/Prefab Editor")] 26 | static void Init () 27 | { 28 | RuntimePrefabEditor window = (RuntimePrefabEditor)EditorWindow.GetWindow (typeof(RuntimePrefabEditor)); 29 | window.minSize = new Vector2 (MinWidth, 300); 30 | } 31 | 32 | private void InitDB() 33 | { 34 | if(_searchDB == null) 35 | { 36 | _searchDB = new PrefabSearchDB(); 37 | } 38 | } 39 | 40 | private void OnSelectionChange() 41 | { 42 | Repaint(); 43 | } 44 | 45 | private void OnInspectorUpdate() 46 | { 47 | Repaint(); 48 | } 49 | 50 | void OnGUI () 51 | { 52 | InitDB(); 53 | 54 | bool needRepaint = false; 55 | 56 | // current selection 57 | GameObject instance = Selection.activeGameObject; 58 | if(instance != null && EditorUtility.IsPersistent(instance)) 59 | { 60 | instance = null; 61 | } 62 | 63 | EditorGUILayout.BeginVertical(); 64 | 65 | DrawSelectedObject(instance); 66 | 67 | DrawPrefabCandidatesSelection(instance); 68 | 69 | DrawDiffs(instance); 70 | 71 | DrawSettings(); 72 | 73 | EditorGUILayout.EndVertical(); 74 | 75 | if(needRepaint) 76 | { 77 | GUI.changed = true; 78 | } 79 | } 80 | 81 | private void DrawSelectedObject(GameObject instance) 82 | { 83 | EditorGUILayout.Space(); 84 | 85 | // selected 86 | if(instance != null) 87 | { 88 | EditorGUILayout.BeginHorizontal(); 89 | EditorGUILayout.LabelField("Selected object:", EditorStyles.boldLabel, GUILayout.Width(120f)); 90 | EditorGUILayout.ObjectField(instance, typeof(GameObject), false); 91 | EditorGUILayout.EndHorizontal(); 92 | 93 | DrawSeparator(); 94 | } 95 | else 96 | { 97 | EditorGUILayout.HelpBox("Select GameObject in scene", MessageType.Info, true); 98 | //EditorGUILayout.LabelField("Select GameObject in scene."); 99 | } 100 | } 101 | 102 | private void DrawPrefabCandidatesSelection(GameObject instance) 103 | { 104 | if(instance == null) 105 | { 106 | _selectedPrefabCandidate.Reset(); 107 | return; 108 | } 109 | 110 | // find candidates 111 | List prefabCandidates = _searchDB.GetPrefabCandidatesForSceneObject(instance); 112 | if(!_selectedPrefabCandidate.IsValid() || !prefabCandidates.Contains(_selectedPrefabCandidate)) 113 | { 114 | _selectedPrefabCandidate = FindBestCandidate(prefabCandidates); 115 | } 116 | 117 | EditorGUILayout.LabelField("Prefab to edit:", EditorStyles.boldLabel); 118 | 119 | // draw candidates 120 | if(prefabCandidates.Count == 0) 121 | { 122 | EditorGUILayout.HelpBox("Can't find prefab for selected object.", MessageType.Warning, true); 123 | } 124 | else if(prefabCandidates.Count == 1) 125 | { 126 | } 127 | else if(prefabCandidates.Count > 1) 128 | { 129 | EditorGUILayout.LabelField("Few prefabs candidates found (select one that you want to edit):"); 130 | } 131 | 132 | foreach(var candidate in prefabCandidates) 133 | { 134 | EditorGUILayout.BeginHorizontal(); 135 | bool selected = (_selectedPrefabCandidate.Equals(candidate)); 136 | if(prefabCandidates.Count > 1) 137 | { 138 | if(selected != EditorGUILayout.Toggle(selected, GUILayout.Width(50))) 139 | { 140 | _selectedPrefabCandidate = candidate; 141 | GUI.changed = true; 142 | } 143 | } 144 | EditorGUILayout.ObjectField(candidate.prefabRoot, typeof(GameObject), false, GUILayout.Width(200)); 145 | EditorGUILayout.LabelField(AssetDatabase.GetAssetPath(candidate.prefabRoot), GUILayout.ExpandWidth(true)); 146 | EditorGUILayout.EndHorizontal(); 147 | } 148 | 149 | if(prefabCandidates.Count == 0 || !prefabCandidates.Contains(_selectedPrefabCandidate)) 150 | { 151 | _selectedPrefabCandidate.Reset(); 152 | } 153 | 154 | if(_selectedPrefabCandidate.IsValid()) 155 | { 156 | EditorGUILayout.Space(); 157 | EditorGUILayout.LabelField("Path in prefab:", EditorStyles.boldLabel); 158 | string path = _selectedPrefabCandidate.prefabRoot.name + (_selectedPrefabCandidate.prefabPath.Length > 0 ? "/" + _selectedPrefabCandidate.prefabPath : " (root)"); 159 | EditorGUILayout.LabelField(path, GUILayout.ExpandWidth(true)); 160 | } 161 | 162 | DrawSeparator(); 163 | } 164 | 165 | private void DrawDiffs(GameObject instance) 166 | { 167 | EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(true)); 168 | 169 | // selected prefab diff 170 | if(_selectedPrefabCandidate.IsValid()) 171 | { 172 | List _diffs = GameObjectDiff.GetDiffs(instance, _selectedPrefabCandidate.instanceRoot, 173 | _selectedPrefabCandidate.prefab, _selectedPrefabCandidate.prefabRoot); 174 | 175 | EditorGUILayout.LabelField("Changes:", EditorStyles.boldLabel); 176 | 177 | if(_diffs.Count > 0) 178 | { 179 | _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, false, false); 180 | 181 | bool anyDiffSelected = false; 182 | foreach(var diff in _diffs) 183 | { 184 | EditorGUILayout.BeginHorizontal(); 185 | bool diffSelected = IsDiffSelected(diff); 186 | bool selected = EditorGUILayout.Toggle(diffSelected, GUILayout.Width(15)); 187 | if(diffSelected != selected) 188 | { 189 | SetDiffSelected(diff, selected); 190 | GUI.changed = true; 191 | } 192 | anyDiffSelected |= diffSelected; 193 | diff.OnGUI(); 194 | EditorGUILayout.EndHorizontal(); 195 | } 196 | 197 | EditorGUILayout.EndScrollView (); 198 | 199 | // apply ? 200 | GUI.enabled = anyDiffSelected; 201 | GUI.color = anyDiffSelected ? Color.green : Color.grey; 202 | if(GUILayout.Button("Apply Changes To Prefab", GUILayout.Height(25))) 203 | { 204 | Undo.RecordObject(_selectedPrefabCandidate.prefabRoot, "Apply Changes"); 205 | 206 | AssetDatabase.StartAssetEditing(); 207 | foreach(var diff in _diffs) 208 | { 209 | if(IsDiffSelected(diff)) 210 | { 211 | diff.Apply(); 212 | } 213 | } 214 | 215 | AssetDatabase.StopAssetEditing(); 216 | EditorUtility.SetDirty( _selectedPrefabCandidate.prefabRoot ); 217 | _saveAssetsRecommended = true; 218 | if(saveAssetsOnApply) 219 | { 220 | SaveAssets(); 221 | } 222 | _diffs = null; 223 | GUI.changed = true; 224 | } 225 | GUI.color = Color.white; 226 | GUI.enabled = true; 227 | } 228 | else 229 | { 230 | EditorGUILayout.HelpBox("No changes found.", MessageType.Info, true); 231 | } 232 | } 233 | 234 | EditorGUILayout.EndVertical(); 235 | 236 | // save assets recommendation 237 | if(_saveAssetsRecommended) 238 | { 239 | EditorGUILayout.Separator(); 240 | EditorGUILayout.BeginHorizontal(); 241 | GUI.color = new Color(1, 1, 0.3f); 242 | if(GUILayout.Button("Save Assets", GUILayout.Height(37))) 243 | { 244 | SaveAssets(); 245 | GUI.changed = true; 246 | } 247 | GUI.color = Color.white; 248 | EditorGUILayout.HelpBox("Assets have been changed, it is recommended to save assets.", MessageType.Info, true); 249 | EditorGUILayout.EndHorizontal(); 250 | } 251 | } 252 | 253 | private void DrawSettings() 254 | { 255 | DrawSeparator(); 256 | 257 | EditorGUILayout.LabelField("Preferences:", EditorStyles.boldLabel); 258 | selectAllByDefault = EditorGUILayout.Toggle("Select All by default:", selectAllByDefault, GUILayout.Width(200)); 259 | saveAssetsOnApply = EditorGUILayout.Toggle("Save on apply (slower):", saveAssetsOnApply, GUILayout.Width(200)); 260 | if (GUILayout.Button("Refresh DB", GUILayout.Height(25), GUILayout.Width(90))) 261 | { 262 | _searchDB = null; 263 | InitDB(); 264 | } 265 | } 266 | 267 | private bool IsDiffSelected(GameObjectDiff.Diff diff) 268 | { 269 | return selectAllByDefault ? !_deselectedDiffs.Contains(diff.id) : _selectedDiffs.Contains(diff.id); 270 | } 271 | 272 | private void SetDiffSelected(GameObjectDiff.Diff diff, bool selected) 273 | { 274 | if(selected) 275 | { 276 | _selectedDiffs.Add(diff.id); 277 | _deselectedDiffs.Remove(diff.id); 278 | } 279 | else 280 | { 281 | _selectedDiffs.Remove(diff.id); 282 | _deselectedDiffs.Add(diff.id); 283 | } 284 | } 285 | 286 | private PrefabSearchDB.PrefabCandidate FindBestCandidate(List candidates) 287 | { 288 | return candidates.FirstOrDefault(); 289 | } 290 | 291 | void DrawSeparator() 292 | { 293 | EditorGUILayout.Space(); 294 | if (Event.current.type == EventType.Repaint) 295 | { 296 | Texture2D tex = EditorGUIUtility.whiteTexture; 297 | Rect rect = GUILayoutUtility.GetLastRect(); 298 | GUI.color = new Color(0f, 0f, 0f, 0.25f); 299 | GUI.DrawTexture(new Rect(0f, rect.yMin + 6f, rect.width, 4f), tex); 300 | GUI.DrawTexture(new Rect(0f, rect.yMin + 6f, rect.width, 1f), tex); 301 | GUI.DrawTexture(new Rect(0f, rect.yMin + 9f, rect.width, 1f), tex); 302 | GUI.color = Color.white; 303 | } 304 | EditorGUILayout.Space(); 305 | } 306 | 307 | static bool DrawFoldout(bool foldout, string content, GUIStyle style) 308 | { 309 | Rect position = GUILayoutUtility.GetRect(40f, 40f, 16f, 16f, style); 310 | // EditorGUI.kNumberW == 40f but is internal 311 | return EditorGUI.Foldout(position, foldout, new GUIContent(content), true, style); 312 | } 313 | 314 | void SaveAssets() 315 | { 316 | AssetDatabase.SaveAssets(); 317 | AssetDatabase.SaveAssets(); 318 | AssetDatabase.Refresh(); 319 | _saveAssetsRecommended = false; 320 | } 321 | 322 | 323 | // settings: 324 | public bool selectAllByDefault 325 | { 326 | get { return EditorPrefs.GetBool("RPE/selectAllByDefault", true); } 327 | set { EditorPrefs.SetBool("RPE/selectAllByDefault", value); } 328 | } 329 | 330 | public bool saveAssetsOnApply 331 | { 332 | get { return EditorPrefs.GetBool("RPE/saveAssetsOnApply", false); } 333 | set { EditorPrefs.SetBool("RPE/saveAssetsOnApply", value); } 334 | } 335 | 336 | } 337 | } --------------------------------------------------------------------------------