protected override void OnSPInspectorGUI() { this.serializedObject.Update(); this.DrawPropertyField(EditorHelper.PROP_SCRIPT); var assetIdProp = this.serializedObject.FindProperty(PROP_ASSETID); var go = GameObjectUtil.GetGameObjectFromSource(this.serializedObject.targetObject); if (go != null) { switch (PrefabUtility.GetPrefabType(go)) { case PrefabType.None: SPEditorGUILayout.PropertyField(assetIdProp); break; case PrefabType.Prefab: { if (string.IsNullOrEmpty(assetIdProp.stringValue)) { var path = AssetHelper.GetRelativeResourcePath(AssetDatabase.GetAssetPath(go)); assetIdProp.stringValue = (string.IsNullOrEmpty(path)) ? go.name : path; } SPEditorGUILayout.PropertyField(assetIdProp); break; } case PrefabType.PrefabInstance: { if (string.IsNullOrEmpty(assetIdProp.stringValue)) { go = PrefabUtility.GetPrefabParent(go) as GameObject; if (go != null) { var path = AssetHelper.GetRelativeResourcePath(AssetDatabase.GetAssetPath(go)); assetIdProp.stringValue = (string.IsNullOrEmpty(path)) ? go.name : path; } } SPEditorGUILayout.PropertyField(assetIdProp); break; } default: //do nothing break; } } this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_ASSETID); this.serializedObject.ApplyModifiedProperties(); }
protected void DrawSyncButton() { if (this.serializedObject.isEditingMultipleObjects) { return; } var r = EditorGUILayout.GetControlRect(); var w = r.width * 0.9f; r = new Rect(r.xMin + (r.width - w) / 2f, r.yMin, w, r.height); if (GUI.Button(r, "Sync Resource Paths")) { var spath = AssetDatabase.GetAssetPath(this.serializedObject.targetObject); var dir = System.IO.Path.GetDirectoryName(spath); var relPathProp = this.serializedObject.FindProperty(PROP_RELATIVEPATH); var pathsProp = this.serializedObject.FindProperty(PROP_PATHS); if (!dir.Contains("Resources")) { relPathProp.stringValue = string.Empty; pathsProp.arraySize = 0; } else { var relDir = AssetHelper.GetRelativeResourcePath(dir); relPathProp.stringValue = relDir; var paths = (from p in AssetDatabase.GetAllAssetPaths() where p.StartsWith(dir) && p != spath && Path.HasExtension(p) let p2 = AssetHelper.GetRelativeResourcePath(p) orderby p2 select p2).ToArray(); pathsProp.arraySize = paths.Length; for (int i = 0; i < paths.Length; i++) { var elProp = pathsProp.GetArrayElementAtIndex(i); elProp.stringValue = paths[i]; } } this.serializedObject.FindProperty(PROP_PATHS).isExpanded = true; this.serializedObject.ApplyModifiedProperties(); } }