/// <summary> /// 获取一个新的 Action Res 数据 /// </summary> /// <param name="path"></param> /// <returns></returns> Table_Client_Action_Res GetNewActionRes(string path) { Table_Client_Action_Res ar = new Table_Client_Action_Res(); if (action_res_list == null) { action_res_list = new List <Table_Client_Action_Res>(); } int count = action_res_list.Count; if (count > 0) { ar.id = action_res_list[count - 1].id + 1; } else { ar.id = 1; } ar.path = path; ar.remark = ""; action_res_list.Add(ar); return(ar); }
/// <summary> /// 获取动作资源数据完成 /// </summary> /// <param name="www"></param> void UpdateActionResDone(WWW www) { if (www == null || string.IsNullOrEmpty(www.text)) { return; } if (action_res_list == null) { action_res_list = new List <Table_Client_Action_Res>(); } action_res_list.Clear(); if (action_res_dic == null) { action_res_dic = new Dictionary <string, Table_Client_Action_Res>(); } action_res_dic.Clear(); string[] arr = www.text.Split(new char[] { '\n' }); int count = arr.Length; for (int i = 0; i < count; i++) { if (string.IsNullOrEmpty(arr[i])) { continue; } object obj = JsonUtility.FromJson(arr[i], typeof(Table_Client_Action_Res)); if (obj == null) { Debug.LogError("Table_Client_Action_Res Create Failure~ "); continue; } Table_Client_Action_Res res = (Table_Client_Action_Res)obj; if (res != null) { action_res_list.Add(res); action_res_dic[res.path] = res; } } count = action_res_list.Count; action_res_arr = new string[count]; action_res_int_arr = new int[count]; for (int i = 0; i < count; i++) { action_res_arr[i] = string.Format("Id:{0} Paht:{1} Remark:{2}", action_res_list[i].id, action_res_list[i].path, action_res_list[i].remark); action_res_int_arr[i] = action_res_list[i].id; } //获取服务器数据完成 is_get_server_info = false; }
/// <summary> /// 插入数据 /// </summary> /// <param name="url"></param> /// <param name="sa"></param> WWWForm SendUpdateInfo(Table_Client_Action_Res sa) { WWWForm wf = new WWWForm(); wf.AddField("id", sa.id); wf.AddField("path", sa.path); wf.AddField("remark", sa.remark); return(wf); }
/// <summary> /// 删除数据 /// </summary> void Delete() { if (action_res_list != null && ar != null) { action_res_list.Remove(ar); action_res_dic.Remove(ar.path); SendServerInfo(ar, UpdateServerInfoEnum.DELETE); ar = null; } }
/// <summary> /// 新加数据 /// </summary> void Add() { UnityEngine.Object go = Selection.activeObject; if (go == select_res || go == null) { ar = GetNewActionRes(""); //添加消息数据 SendServerInfo(ar, UpdateServerInfoEnum.INSERT); } else { List <string> list = new List <string>(); UnityEngine.Object[] objs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets); int count = objs.Length; for (int i = 0; i < count; i++) { if (select_res == objs[i]) { continue; } string path = AssetDatabase.GetAssetPath(objs[i]); AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(path); if (clip != null) { path = path.Remove(0, ActionEventConfig.RES_START_PATH.Length); if (!IsAlreadyHaveRes(path)) { list.Add(path); } } } //批量创建数据 count = list.Count; for (int i = 0; i < count; i++) { Table_Client_Action_Res ar = GetNewActionRes(list[i]); //添加消息数据 SendServerInfo(ar, UpdateServerInfoEnum.INSERT); } } }
void SendServerInfo(Table_Client_Action_Res ar, UpdateServerInfoEnum type) { string t = GetServerInfoType(type); string url = string.Format("{0}{1}{2}", ActionEventConfig.SERVER_URL, ActionEventConfig.SERVER_RES_URL, t); switch (type) { case UpdateServerInfoEnum.INSERT: case UpdateServerInfoEnum.UPDATE: EditorCoroutineRunner.StartEditorCoroutine(SendInfo(url, SendUpdateInfo(ar))); break; case UpdateServerInfoEnum.DELETE: EditorCoroutineRunner.StartEditorCoroutine(SendInfo(url, SendDeleteInfo(ar.id))); break; } }
/// <summary> /// 当前选中的显示列表中条目数据改变 /// </summary> /// <param name="obj"></param> /// <param name="colId"></param> void OnSelectChange(object obj, int colId) { if (obj == null) { return; } ar = (Table_Client_Action_Res)obj; if (ar != null && !string.IsNullOrEmpty(ar.path)) { select_res = AssetDatabase.LoadAssetAtPath <GameObject>(string.Format("{0}{1}", ActionEventConfig.RES_START_PATH, ar.path)); //设置选中目标 if (select_res != null) { Selection.activeObject = select_res; } } }