public void CreateScript(string newScriptName) { bool create = true; var fileFullPath = Path.Combine(Path.Combine(Application.dataPath, "Resources/AutoTest/"), newScriptName + ".json"); if (File.Exists(fileFullPath)) { if (!EditorUtility.DisplayDialog("⚠️ 警告!", string.Format("已存在名为{0}的脚本, 是否覆盖?", newScriptName), "确认", "取消")) { create = false; } } if (create) { var parentFolder = Path.GetDirectoryName(fileFullPath); if (!Directory.Exists(parentFolder)) { Directory.CreateDirectory(parentFolder); } File.Create(fileFullPath).Close(); AssetDatabase.Refresh(); m_CurrentAction = null; GetFileList(); SaveScript(); } }
//右侧Containner bool DrawContainer(float startX, AutoActionContainer container) { #region head EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("保存脚本", GUILayout.Width(ButtonWidth))) { SaveScript(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("删除脚本", GUILayout.Width(ButtonWidth))) { if (EditorUtility.DisplayDialog("⚠️ 提示!", string.Format("确定要删除名为{0}的脚本?", m_FileList[m_SelectScriptIndex].Name), "确认", "取消")) { File.Delete(m_FileList[m_SelectScriptIndex].FullName); AssetDatabase.Refresh(); m_CurrentAction = null; GetFileList(); } return(true); } EditorGUILayout.EndHorizontal(); #endregion EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("--Container--"); EditorGUILayout.EndHorizontal(); return(false); }
public static AutoAction Parse(JsonData content) { AutoActionContainer container = new AutoActionContainer(); ParseDataToContainer(container, content); return(container); }
public static void SaveAutoActions(AutoActionContainer actionContainer) { ValidateDirExists(); File.WriteAllText( AUTO_ACTIONS_CONFIG_PATH, JsonConvert.SerializeObject(actionContainer, Formatting.Indented) ); }
private static void AddMissingAutoActions(AutoActionContainer actionContainer) { var existingHotkeyTypes = actionContainer.autoActions.Select(hotkey => hotkey.GetType()).ToList(); var missingAutoActions = AbstractAutoAction.AutoActionTypes .Except(existingHotkeyTypes) .Select(type => (AbstractAutoAction)Activator.CreateInstance(type)); actionContainer.autoActions.AddRange(missingAutoActions); }
// 准备当前脚本信息 void PrepareCurrentScript() { if (m_FileList.Count > 0) { string json = File.ReadAllText(m_FileList[m_SelectScriptIndex].FullName); JsonData data = JsonMapper.ToObject(json); m_CurrentAction = AutoActionJsonParser.Parse(data) as AutoActionContainer; } }
private void LoadConfig() { Keybinds = Config.LoadKeybinds(); Hotkeys = Config.LoadHotkeyContainer(); Hotkeys.InitializeIKeyEventsAndSort(Hud.Input); AutoActions = Config.LoadAutoActions(); SnoToDefinitionGroups = Config.LoadDefinitions(); SnoToDefinitionGroups.ForEach(def => skillsWithDefinitionGroupsDisplayValues.Add(Hud.Sno.GetSnoPower(def.Key))); }
private void LoadConfig() { Keybinds = ConfigPersistence.LoadKeybinds(); Hotkeys = ConfigPersistence.LoadHotkeyContainer(); Hotkeys.InitializeIKeyEventsAndSort(Hud.Input); AutoActions = ConfigPersistence.LoadAutoActions(); profileToSkillDefinitionGroups = ConfigPersistence.LoadMasterProfiles(); SnoToDefinitionGroups = profileToSkillDefinitionGroups.FirstOrDefault().Value; SnoToDefinitionGroups.ForEach(def => skillsWithDefinitionGroupsDisplayValues.Add(Hud.Sno.GetSnoPower(def.Key))); }
private static void ParseDataToContainer(AutoActionContainer container, JsonData content) { for (int i = 0; i < content.Count; i++) { string key = content[i].TryGetString("name"); JsonData data = content[i]["data"]; AutoAction action = null; switch (key) { case "Container": action = Parse(data); break; case "WaitScene": string waitSceneName = data.TryGetString("scene_name"); action = new AutoWaitScene(waitSceneName); break; case "WaitObjectAppear": string objectAppear = data.TryGetString("object_name"); action = new AutoWaitObjectAppear(objectAppear); break; case "WaitObjectDisappear": string objectDisappear = data.TryGetString("object_name"); action = new AutoWaitObjectAppear(objectDisappear); break; case "WaitComponentAppear": string componentAppear = data.TryGetString("component_name"); action = new AutoWaitComponentAppear(Type.GetType(componentAppear)); break; case "WaitComponentDisappear": string componentDisappear = data.TryGetString("component_name"); action = new AutoWaitComponentDisappear(Type.GetType(componentDisappear)); break; case "LabelTextAppear": string labelObjectName = data.TryGetString("object_name"); string textContent = data.TryGetString("content"); action = new AutoLabelTextAppear(labelObjectName, textContent); break; case "Timer": string time = data.TryGetString("time_length"); action = new AutoTimer(float.Parse(time)); break; case "WaitButtonAccessible": string buttonName = data.TryGetString("button_name"); action = new AutoWaitButtonAccessiable(buttonName); break; case "Click": float x = float.Parse(data.TryGetString("pos_x")); float y = float.Parse(data.TryGetString("pos_y")); float z = float.Parse(data.TryGetString("pos_z")); action = new AutoClick(new UnityEngine.Vector3(x, y, z)); break; case "PressUI": string uiName = data.TryGetString("ui_name"); action = new AutoPressUI(uiName); break; case "LoadScene": string loadSceneName = data.TryGetString("scene_name"); action = new AutoLoadScene(loadSceneName); break; } if (action != null) { container.AddAction(action); } } }
public static string Write(AutoActionContainer container) { if (container.ActionList.Count == 0) { return(""); } StringBuilder sb = new StringBuilder(); sb.Append("["); for (int i = 0; i < container.ActionList.Count; i++) { AutoAction action = container.ActionList[i]; JsonData data = new JsonData(); switch (action.GetType().Name) { case "AutoActionContainer": data["name"] = "Container"; data["data"] = JsonMapper.ToObject(Write((AutoActionContainer)action)); break; case "AutoTimer": data["name"] = "Timer"; JsonData timerData = new JsonData(); timerData["time_length"] = (action as AutoTimer).Length.ToString(); data["data"] = timerData; break; case "AutoClick": data["name"] = "Click"; JsonData clickData = new JsonData(); clickData["pos_x"] = (action as AutoClick).Position.x.ToString(); clickData["pos_y"] = (action as AutoClick).Position.y.ToString(); clickData["pos_z"] = (action as AutoClick).Position.z.ToString(); data["data"] = clickData; break; case "AutoPressUI": data["name"] = "PressUI"; JsonData pressUIData = new JsonData(); pressUIData["ui_name"] = (action as AutoPressUI).UIName; data["data"] = pressUIData; break; case "AutoLoadScene": data["name"] = "LoadScene"; JsonData loadSceneData = new JsonData(); loadSceneData["scene_name"] = (action as AutoLoadScene).SceneName; data["data"] = loadSceneData; break; case "AutoWaitButtonAccessiable": data["name"] = "WaitButtonAccessible"; JsonData buttonAccessibleData = new JsonData(); buttonAccessibleData["button_name"] = (action as AutoWaitButtonAccessiable).ButtonName; data["data"] = buttonAccessibleData; break; case "AutoLabelTextAppear": data["name"] = "LabelTextAppear"; JsonData labelTextData = new JsonData(); labelTextData["object_name"] = (action as AutoLabelTextAppear).LabelName; labelTextData["content"] = (action as AutoLabelTextAppear).LableContent; data["data"] = labelTextData; break; case "AutoWaitComponentDisappear": data["name"] = "WaitComponentDisappear"; JsonData componentDisappearData = new JsonData(); componentDisappearData["component_name"] = (action as AutoWaitComponentDisappear).Type; data["data"] = componentDisappearData; break; case "AutoWaitComponentAppear": data["name"] = "WaitComponentAppear"; JsonData componentAppearData = new JsonData(); componentAppearData["component_name"] = (action as AutoWaitComponentAppear).Type; data["data"] = componentAppearData; break; case "AutoWaitObjectAppear": data["name"] = "WaitObjectAppear"; JsonData objectAppearData = new JsonData(); objectAppearData["object_name"] = (action as AutoWaitObjectAppear).ObjName; data["data"] = objectAppearData; break; case "AutoWaitObjectDisappear": data["name"] = "WaitObjectDisappear"; JsonData objectDisappearData = new JsonData(); objectDisappearData["object_name"] = (action as AutoWaitObjectDisappear).ObjName; data["data"] = objectDisappearData; break; case "AutoWaitScene": data["name"] = "WaitScene"; JsonData waitSceneLoad = new JsonData(); waitSceneLoad["scene_name"] = (action as AutoWaitScene).SceneName; data["data"] = waitSceneLoad; break; } sb.Append(data.ToJson()); if (i < container.ActionList.Count - 1) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); }
private void OnGUI() { if (GUI.Button(new Rect(50, 50, 50, 50), "test")) { AutoActionContainer container = new AutoActionContainer(); AutoLoadScene loadScene = new AutoLoadScene("test"); AutoClick click = new AutoClick(new Vector3(10, 20, 30)); AutoTimer timer = new AutoTimer(5); AutoPressUI pressUI = new AutoPressUI("bg"); container.AddAction(loadScene); container.AddAction(click); container.AddAction(timer); container.AddAction(pressUI); AutoActionContainer container2 = new AutoActionContainer(); AutoWaitObjectAppear objectAppear = new AutoWaitObjectAppear("page"); AutoWaitObjectAppear objectDisappear = new AutoWaitObjectAppear("pageDis"); AutoWaitComponentAppear componentAppear = new AutoWaitComponentAppear(typeof(Image)); AutoWaitComponentDisappear componentDisappear = new AutoWaitComponentDisappear(typeof(Button)); AutoLabelTextAppear labelText = new AutoLabelTextAppear("label", "hello world"); container2.AddAction(container); container2.AddAction(objectAppear); container2.AddAction(labelText); container2.AddAction(objectDisappear); container2.AddAction(componentAppear); container2.AddAction(componentDisappear); string json = AutoActionJsonWriter.Write(container2); Debug.Log("json is:" + json); JsonData data = JsonMapper.ToObject(json); AutoActionContainer newContainer = AutoActionJsonParser.Parse(data) as AutoActionContainer; foreach (AutoAction action in newContainer.ActionList) { Debug.Log(action.GetType().Name); if (action.GetType().Name == "AutoActionContainer") { foreach (AutoAction childAction in (action as AutoActionContainer).ActionList) { Debug.Log(childAction.GetType().Name); } } } } }