public void GenerateHandler(string scriptPath) { var handlerScriptPath = UIManCodeGenerator.GeneratPathWithSubfix(scriptPath, ".Handler.cs"); var config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(false); var handlerCode = UIManCodeGenerator.GenerateHandler(this.typeName, this.baseType, config, this.namespaceField.Text); UIManCodeGenerator.SaveScript(handlerScriptPath, handlerCode, false, this.typeName, this.baseType); }
private void Initialize() { if (!this.inited) { if (this.baseTypePopup == null) { var config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(); this.namespaceField = new TextFieldHelper(config.classNamespace); this.baseTypePopup = new EditablePopup(this.arrSupportType, config.name, null); } this.minSize = new Vector2(300, 160); this.maxSize = this.minSize; this.inited = true; } }
private static void GetConfig() { _config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(); }
public static Animator GenerateAnimator(GameObject target, params string[] clipsName) { var config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(false); Animator anim = target.GetComponent <Animator>(); if (anim == null) { anim = target.AddComponent <Animator>(); } // Create folder var assetPath = Application.dataPath.Substring(Application.dataPath.IndexOf("/Assets") + 1) + "/" + config.animRootFolder; var rootFolderPath = string.Format("{0}{1}", assetPath, target.name); EditorUtils.CreatePath(rootFolderPath); // Create controller var controllerFilePath = string.Format("{0}/{1}.controller", rootFolderPath, target.name); var controller = AnimatorController.CreateAnimatorControllerAtPath(controllerFilePath); // Change the name of the first layer. AnimatorControllerLayer[] layers = controller.layers; layers[0].name = "Base Layer"; controller.layers = layers; // Get the root state machine . AnimatorStateMachine rootStateMachine = controller.layers[0].stateMachine; // Set the default state. AnimatorState defaultState = rootStateMachine.AddState("Default"); defaultState.motion = null; rootStateMachine.defaultState = defaultState; // Add states and transitions for (var i = 0; i < clipsName.Length; i++) { // Create empty clip and add motion var clip = new AnimationClip(); var clipName = clipsName[i]; var clipPath = string.Format("{0}/{1}.anim", rootFolderPath, clipName); clip.name = clipName; AssetDatabase.CreateAsset(clip, clipPath); // Add motion to controller var motion = AssetDatabase.LoadAssetAtPath(clipPath, typeof(AnimationClip)) as Motion; AnimatorState newState = rootStateMachine.AddState(clipName); newState.motion = motion; var smb = (UIAnimationState)newState.AddStateMachineBehaviour(typeof(UIAnimationState)); if (clipName == UIManDefine.ANIM_SHOW) { smb.Init(UIAnimationType.Show, true, false); } else if (clipName == UIManDefine.ANIM_HIDE) { smb.Init(UIAnimationType.Hide, true, true); } else if (clipName == UIManDefine.ANIM_IDLE) { smb.Init(UIAnimationType.Idle, true, false); } } anim.runtimeAnimatorController = controller; return(anim); }
private void OnGUI() { Initialize(); GUILayout.Space(10); LabelHelper.HeaderLabel("Type"); LineHelper.Draw(Color.gray); this.baseTypePopup.Draw(); GUILayout.Space(10); LabelHelper.HeaderLabel("Namespace"); LineHelper.Draw(Color.gray); this.namespaceField.Draw(GUIContent.none, 0); GUILayout.Space(10); if (ColorButton.Draw("Create", CommonColor.LightGreen, GUILayout.Height(30))) { var lastPath = ""; var config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(false); if (config != null) { if (this.baseTypePopup.SelectedItem == this.arrSupportType[0]) { lastPath = config.modelScriptFolder; this.typeName = "NewViewModel"; } else if (this.baseTypePopup.SelectedItem == this.arrSupportType[1]) { lastPath = config.screenScriptFolder; this.typeName = "UINewScreen"; } else if (this.baseTypePopup.SelectedItem == this.arrSupportType[2]) { lastPath = config.dialogScriptFolder; this.typeName = "UINewDialog"; } } lastPath = EditorUtility.SaveFilePanel("Save script", Application.dataPath + lastPath, this.typeName, "cs"); if (!string.IsNullOrEmpty(lastPath)) { this.typeName = Path.GetFileNameWithoutExtension(lastPath); lastPath = Path.GetDirectoryName(lastPath).Replace("\\", "/").Replace(Application.dataPath, ""); if (this.baseTypePopup.SelectedItem == this.arrSupportType[0]) { config.modelScriptFolder = lastPath; config.generatingTypeIsDialog = false; } else if (this.baseTypePopup.SelectedItem == this.arrSupportType[1]) { config.screenScriptFolder = lastPath; config.generatingTypeIsDialog = false; } else if (this.baseTypePopup.SelectedItem == this.arrSupportType[2]) { config.dialogScriptFolder = lastPath; config.generatingTypeIsDialog = true; } EditorUtility.SetDirty(config); GenerateType(); } } }
public void GenerateType() { if (this.typeName.Contains(" ")) { EditorUtility.DisplayDialog("Error", "Class name cannot constain special characters", "OK"); return; } var warn = false; if (this.typeName.Length <= 1 || (!this.typeName.Substring(0, 2).Equals("UI") && !this.baseTypePopup.SelectedItem.Equals(UIGenerator.GetSupportTypeName(0)))) { this.typeName = "UI" + this.typeName; warn = true; } this.baseType = this.baseTypePopup.SelectedItem; var config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(false); var savePath = ""; if (this.baseType.Equals(UIGenerator.GetSupportTypeName(0))) { savePath = config.modelScriptFolder; config.generatingTypeIsDialog = false; } else if (this.baseType.Equals(UIGenerator.GetSupportTypeName(1))) { savePath = config.screenScriptFolder; config.generatingTypeIsDialog = false; } else if (this.baseType.Equals(UIGenerator.GetSupportTypeName(2))) { savePath = config.dialogScriptFolder; config.generatingTypeIsDialog = true; } savePath = Application.dataPath + "/" + savePath + "/" + this.typeName + ".cs"; if (File.Exists(savePath) || UIGenerator.IsViewModelExisted(this.typeName)) { EditorUtility.DisplayDialog("Error", "A class of the same name has already existed", "OK"); return; } var paths = Regex.Split(savePath, "/"); var inheritance = string.Empty; if (this.baseType != this.arrSupportType[0]) { config.generatingType = this.typeName; } else { inheritance = $" : {this.baseType}"; } var code = UIManCodeGenerator.GenerateType(this.typeName, inheritance, false, config, this.namespaceField.Text); UIManCodeGenerator.SaveScript(savePath, code, true); if (this.baseType != this.arrSupportType[0]) { GenerateHandler(savePath); } AssetDatabase.Refresh(ImportAssetOptions.Default); if (warn) { UnuLogger.LogWarning("Code generation warning: Class name is invalid. New name is generated."); } Close(); }