private static void CreateAssets() { if (!Directory.Exists(_scaffoldingConfig.FullViewPrefabPath())) { Directory.CreateDirectory(_scaffoldingConfig.FullViewPrefabPath()); } UnityEngine.Object obj = PrefabUtility.CreateEmptyPrefab(_scaffoldingConfig.FullViewPrefabPath() + _fileName + ".prefab"); GameObject go = new GameObject(); go.name = _fileName; _createdViewObject = PrefabUtility.ReplacePrefab(go, obj, ReplacePrefabOptions.ConnectToPrefab); DestroyImmediate(go); if (_createModel) { obj = PrefabUtility.CreateEmptyPrefab(_scaffoldingConfig.FullViewPrefabPath() + _modelFileName + ".prefab"); go = new GameObject(); go.name = _modelFileName; GameObject modelHolder = _scaffoldingConfig.DetermineParentModelGameObjectPath(); if (modelHolder == null) { modelHolder = new GameObject(); modelHolder.name = "Model"; } go.transform.parent = modelHolder.transform; _createdModelObject = PrefabUtility.ReplacePrefab(go, obj, ReplacePrefabOptions.ConnectToPrefab); } }
private void ClosedViewButtons(string viewName) { if (_renamingView != "" && _renamingView != viewName) { GUI.enabled = false; } else { GUI.enabled = true; } if (_renamingView == viewName) { _tempViewName = GUILayout.TextArea(_tempViewName); } else { GUILayout.Label(viewName, EditorStyles.boldLabel); } if (IsViewBeingEdited(viewName)) { GUI.enabled = false; } if (GUILayout.Button("Open", GUILayout.Width(100))) { GameObject obj = PrefabUtility.InstantiatePrefab(Resources.Load(_scaffoldingConfig.ViewPrefabPath() + viewName)) as GameObject; #if UNITY_4_6 obj.transform.SetParent(_scaffoldingConfig.DetermineParentGameObjectPath().transform); #else obj.transform.parent = _scaffoldingConfig.DetermineParentGameObjectPath().transform; #endif Selection.activeObject = obj; } GUI.enabled = true; if (IsViewBeingEdited(viewName)) { if (GUILayout.Button("Done", GUILayout.Width(60))) { _renamingView = ""; string oldNamePrefab = _scaffoldingConfig.FullViewPrefabPath() + viewName; string oldNameScript = _scaffoldingConfig.ScriptsPath() + viewName; string newNamePrefab = _scaffoldingConfig.FullViewPrefabPath() + _tempViewName; string newNameScript = _scaffoldingConfig.ScriptsPath() + _tempViewName; AssetDatabase.MoveAsset(oldNamePrefab + ".prefab", newNamePrefab + ".prefab"); RenameFile(oldNameScript + ".cs", viewName, _tempViewName); AssetDatabase.MoveAsset(oldNameScript + ".cs", newNameScript + ".cs"); AssetDatabase.MoveAsset(oldNamePrefab + "Model.prefab", newNamePrefab + "Model.prefab"); RenameFile(oldNameScript + "Model.cs", viewName, _tempViewName); AssetDatabase.MoveAsset(oldNameScript + "Model.cs", newNameScript + "Model.cs"); AssetDatabase.Refresh(); CreateAllViews(); } } else { if (_renamingView != "" && _renamingView != viewName) { GUI.enabled = false; } if (GUILayout.Button("Rename", GUILayout.Width(60))) { _renamingView = viewName; _tempViewName = viewName; } } if (_renamingView != "" && _renamingView != viewName || IsViewBeingEdited(viewName)) { GUI.enabled = false; } if (GUILayout.Button("Delete", GUILayout.Width(50))) { if (EditorUtility.DisplayDialog("Delete " + viewName + " from your project?", "Deleting this view will permenantly remove it from your project, are you sure?", "Yes", "No")) { string name = viewName + "Model"; GameObject go = GameObject.Find(name); DestroyImmediate(go); AssetDatabase.DeleteAsset(_scaffoldingConfig.FullViewPrefabPath() + viewName + ".prefab"); AssetDatabase.DeleteAsset(_scaffoldingConfig.ScriptsPath() + viewName + ".cs"); AssetDatabase.DeleteAsset(_scaffoldingConfig.FullViewPrefabPath() + viewName + "Model.prefab"); AssetDatabase.DeleteAsset(_scaffoldingConfig.ScriptsPath() + viewName + "Model.cs"); AssetDatabase.Refresh(); } } }