public string GetVMPropertyRefCode(JObject jo) { StringBuilder sb = new StringBuilder(); string ws_name = jo ["Workspace"].Value <string> (); JArray ja_members = jo ["Member"] as JArray; for (int i = 0; i < ja_members.Count; i++) { JObject jo_member = ja_members [i] as JObject; RxType rt = (RxType)Enum.Parse(typeof(RxType), jo_member ["RxType"].Value <string> ()); if (rt == RxType.Property) { string member_name = jo_member ["Name"].Value <string> (); string member_type = jo_member ["Type"].Value <string> (); DocType?dt = PGFrameTools.GetDocTypeByWorkspaceAndType(ws_name, member_type); if (dt.HasValue && dt.Value == DocType.Element) { string element_name = member_type.ConvertToElementName(); sb.AppendFormat(@" if (_{0}View != null) {{ if (_{0}View.GetViewModel () == null) {{ _{0}View.CreateViewModel (); }} ViewModelBase _{0}ViewModel = _{0}View.GetViewModel (); if (_{0}ViewModel != null) {{ VM.{0} = _{0}View.GetViewModel () as {1}ViewModel; }} }}" , member_name, element_name); } } } return(sb.ToString()); }
public static string GenReactiveMemberProperty(this JObject jom, JObject jo) { string template = @" /* {DESC} */ public ReactiveProperty<{TYPE}> RP_{NAME}; {JSONPROPERTY}{JSONCONVERTER} public {TYPE} {NAME} { get { return RP_{NAME}.Value; } set { RP_{NAME}.Value = value; } }" ; DocType?dt = PGFrameTools.GetDocTypeByWorkspaceAndType(jo ["Workspace"].Value <string> (), jom ["Type"].Value <string> ()); if (dt.HasValue && dt.Value == DocType.Element) { template = template.Replace("{JSONPROPERTY}", string.Empty); } else { template = template.Replace("{JSONPROPERTY}", "[JsonProperty]"); } template = template.Replace("{NAME}", jom ["Name"].Value <string> ()); template = template.Replace("{TYPE}", jom ["Type"].Value <string> ()); template = template.Replace("{DESC}", jom ["Desc"].Value <string> ()); template = template.Replace("{JSONCONVERTER}", GetAttributeCode(jom ["Type"].Value <string> ())); return(template); }
public string GetVMPropertyViewCode(JObject jo) { StringBuilder sb = new StringBuilder(); string ws_name = jo ["Workspace"].Value <string> (); JArray ja_members = jo ["Member"] as JArray; for (int i = 0; i < ja_members.Count; i++) { JObject jo_member = ja_members [i] as JObject; RxType rt = (RxType)Enum.Parse(typeof(RxType), jo_member ["RxType"].Value <string> ()); if (rt == RxType.Property) { string member_name = jo_member ["Name"].Value <string> (); string member_type = jo_member ["Type"].Value <string> (); DocType?dt = PGFrameTools.GetDocTypeByWorkspaceAndType(ws_name, member_type); if (dt.HasValue && dt.Value == DocType.Element) { string[] element_splited_type = PGFrameTools.SplitWorkspaceAndTypeName(string.Empty, member_type); string element_ws = element_splited_type [0]; string element_type = element_splited_type [1]; string element_name = element_type.ConvertToElementName(); sb.AppendFormat(@" {2}I{1}View {0}View {{ get; set; }}" , member_name, element_name, string.IsNullOrEmpty(element_ws) ? "" : element_ws + "."); } } } return(sb.ToString()); }
void ResetElementMembersList() { ElementViewTools evtools = new ElementViewTools(SelectedJsonElement.jo); JArray ja_member = SelectedJsonElement.jo ["Member"] as JArray; ElementMembersList = new ReorderableList(ja_member, typeof(JToken)); ElementMembersList.drawHeaderCallback += (Rect rect) => { GUI.Label(rect, "Members in Element"); }; float[] split = new float[] { 0f, .2f, .6f, 1f, 1.2f }; float[] split_c = new float[] { 0f, .3f, .6f, .9f, .95f, 1f }; ElementMembersList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => { JObject jo_member = ja_member [index] as JObject; Rect r = new Rect(rect); r.y += 2; r.height -= 4; int split_idx = 0; r.x = (rect.width - 25f) * split [split_idx] + 25f; r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f; if (!ShowDesc && jo_member ["Desc"].Value <string> ().Contains("#")) { GUI.Label(r, jo_member ["Desc"].Value <string> ().Split(new char[] { '#' }) [0] + "(" + jo_member ["RxType"].Value <string> ().Substring(0, 3).ToUpper() + ")", GUIStyleTemplate.GreenDescStyle()); } else { GUI.Label(r, jo_member ["RxType"].Value <string> ()); } split_idx++; r.x = (rect.width - 25f) * split [split_idx] + 25f; r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f; string new_member_name = GUI.TextField(r, jo_member ["Name"].Value <string> ()); if (new_member_name != jo_member ["Name"].Value <string> ()) { evtools.ChangeName(jo_member ["Name"].Value <string> (), new_member_name); jo_member ["Name"] = new_member_name; } if (jo_member ["RxType"].Value <string> () != "Command") { split_idx++; r.x = (rect.width - 25f) * split [split_idx] + 25f; r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f; jo_member ["Type"] = GUI.TextField(r, jo_member ["Type"].Value <string> ()); string jo_member_type = jo_member ["Type"].Value <string> (); if (jo_member ["RxType"].Value <string> () == "Dictionary") { string[] dic_type_split = jo_member_type.Split(new char[] { ',' }); if (dic_type_split.Length == 2) { jo_member_type = dic_type_split [1]; } } TypeType?tt = PGFrameTools.GetTypeTypeByType(jo_member_type); if (tt.HasValue && pgf_typetype_short_icons != null && pgf_typetype_short_icons.ContainsKey(tt.Value)) { split_idx++; r.x = (rect.width - 25f) * split [split_idx] + 25f; r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f; GUI.Label(r, this.pgf_typetype_short_icons [tt.Value]); } else { string[] ts = jo_member ["Type"].Value <string> ().Split(new char[] { '.' }); string workspace = ""; string single_name = ""; if (ts.Length == 1) { workspace = PGFrameWindow.Current.SelectedWorkspace.Name; single_name = ts [0]; } else if (ts.Length == 2) { workspace = ts [0]; single_name = ts [1]; } DocType?dt = CommonManager.GetTheDocTypeByName(workspace, single_name); if (dt.HasValue && pgf_doctype_short_icons != null && pgf_doctype_short_icons.ContainsKey(dt.Value)) { split_idx++; r.x = (rect.width - 25f) * split [split_idx] + 25f; r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f; GUI.Label(r, this.pgf_doctype_short_icons [dt.Value]); } } if (ShowDesc) { r.y = rect.y + singleRowHeight - 6f; r.x = (rect.width - 25f) * split [1] + 25f; r.width = (rect.width - 25f) * (split [3] - split [1]) - 2f; jo_member ["Desc"] = GUI.TextField(r, jo_member ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle()); } } else { split_idx++; r.x = (rect.width - 25f) * split [split_idx] + 25f; r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f; JArray ja_command_params = jo_member ["Params"] as JArray; if (GUI.Button(r, "+", GUIStyleTemplate.BlackCommandLink())) { if (ja_command_params == null) { jo_member.Add("Params", new JArray()); ja_command_params = jo_member ["Params"] as JArray; } JObject jo_command_param = new JObject(); jo_command_param.Add("Name", string.Format("Param{0}", ja_command_params.Count)); jo_command_param.Add("Type", "object"); jo_command_param.Add("Desc", ""); ja_command_params.Add(jo_command_param); } if (ShowDesc) { r.y = rect.y + singleRowHeight - 6f; r.x = (rect.width - 25f) * split [1] + 25f; r.width = (rect.width - 25f) * (split [3] - split [1]) - 2f; jo_member ["Desc"] = GUI.TextField(r, jo_member ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle()); } float show_desc_height_amplify = 1f; if (ShowDesc) { show_desc_height_amplify = 2f; } if (ja_command_params != null) { for (int i = 0; i < ja_command_params.Count; i++) { int split_c_idx = 0; r.y = rect.y + (singleRowHeight_c * (float)(i + 1)) * show_desc_height_amplify; JObject jo_command_param = ja_command_params [i] as JObject; split_c_idx = 0; r.x = (rect.width - 25f) * split_c [split_c_idx] + 25f; r.width = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f; if (!ShowDesc && jo_command_param ["Desc"].Value <string> ().Contains("#")) { GUI.Label(r, " - " + jo_command_param ["Desc"].Value <string> ().Split(new char[] { '#' }) [0] + "(P" + i + ")", GUIStyleTemplate.GreenDescStyle()); } else { GUI.Label(r, " - Command Params"); } split_c_idx = 1; r.x = (rect.width - 25f) * split_c [split_c_idx] + 25f; r.width = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f; string new_name = GUI.TextField(r, jo_command_param ["Name"].Value <string> ()); if (new_name != jo_command_param ["Name"].Value <string> ()) { jo_command_param ["Name"] = new_name; } split_c_idx = 2; r.x = (rect.width - 25f) * split_c [split_c_idx] + 25f; r.width = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f; jo_command_param ["Type"] = GUI.TextField(r, jo_command_param ["Type"].Value <string> ()); split_c_idx = 3; r.x = (rect.width - 25f) * split_c [split_c_idx] + 25f; r.width = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f; if (GUI.Button(r, "-", GUIStyleTemplate.BlackCommandLink())) { ja_command_params.RemoveAt(i); return; } if (i != 0) { split_c_idx = 4; r.x = (rect.width - 25f) * split_c [split_c_idx] + 25f; r.width = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f; if (GUI.Button(r, "^", GUIStyleTemplate.BlackCommandLink())) { JObject jo0 = ja_command_params [i] as JObject; JObject jo1 = ja_command_params [i - 1] as JObject; ja_command_params [i] = jo1; ja_command_params [i - 1] = jo0; } } if (ShowDesc) { r.y = rect.y + (singleRowHeight_c * (float)(i + 1)) * show_desc_height_amplify + singleRowHeight_c - 2f; r.x = (rect.width - 25f) * split_c [1] + 25f; r.width = (rect.width - 25f) * (split_c [3] - split_c [1]) - 2f; jo_command_param ["Desc"] = GUI.TextField(r, jo_command_param ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle()); } } } } }; ElementMembersList.elementHeightCallback += (int index) => { return(CalcHeight(index)); }; ElementMembersList.showDefaultBackground = false; ElementMembersList.drawElementBackgroundCallback += (Rect rect, int index, bool isActive, bool isFocused) => { if (Event.current.type == EventType.Repaint) { Color color = GUI.backgroundColor; if (ShowDesc) { if (isActive) { GUI.backgroundColor = Color.yellow; } if (isFocused) { GUI.backgroundColor = Color.cyan; } GUI.skin.box.Draw(new Rect(rect.x + 2f, rect.y, rect.width - 4f, CalcHeight(index) - 4f), false, isActive, isFocused, false); GUI.backgroundColor = color; } else { if (isFocused) { GUI.backgroundColor = Color.cyan; GUI.skin.box.Draw(new Rect(rect.x + 2f, rect.y, rect.width - 4f, CalcHeight(index) - 4f), false, isActive, isFocused, false); GUI.backgroundColor = color; } } } }; ElementMembersList.onAddCallback += (ReorderableList list) => { GenericMenu menu = new GenericMenu(); foreach (RxType rt in Enum.GetValues(typeof(RxType))) { menu.AddItem(new GUIContent(rt.ToString()), false, GenericElementMenuOnAddCallback, rt); } menu.ShowAsContext(); }; ElementMembersList.onRemoveCallback += (ReorderableList list) => { JObject jo_member = ja_member [list.index] as JObject; // string element_rxtype = jo_member ["RxType"].Value<string> (); string element_name = jo_member ["Name"].Value <string> (); ja_member.RemoveAt(list.index); evtools.DeleteMember(element_name); }; }
public static string GenEditorGUIProperty(this JObject jom, JObject jo) { string element_name = jo ["Common"] ["Name"].Value <string> (); string name = jom ["Name"].Value <string> (); string type = jom ["Type"].Value <string> (); string result = ""; string[] ts = type.Split(new char[] { '.' }); string workspace = ""; string single_name = ""; if (ts.Length == 1) { workspace = PGFrameWindow.Current.SelectedWorkspace.Name; single_name = ts [0]; } else if (ts.Length == 2) { workspace = ts [0]; single_name = ts [1]; } bool is_ese = false; if (string.IsNullOrEmpty(workspace) == false && string.IsNullOrEmpty(single_name) == false) { if (PGFrameWindow.Current != null) { DocType?dt = PGFrameWindow.Current.CommonManager.GetTheDocTypeByName(workspace, single_name); if (dt != null) { switch (dt.Value) { case DocType.Element: string[] element_splited_type = PGFrameTools.SplitWorkspaceAndTypeName(workspace, type); string element_ws = element_splited_type [0]; string element_type = element_splited_type [1]; string member_element_name = element_type.ConvertToElementName(); result = string.Format(@" vmk = ""{0}""; ViewBase {0}View = (target as I{1}View).{0}View as ViewBase; if (EditorApplication.isPlaying && VM.{0} == null) {0}View = null; ViewBase temp{0}View = (ViewBase)EditorGUILayout.ObjectField (vmk, {0}View, typeof(ViewBase), true); if (temp{0}View == null) {{ (target as I{1}View).{0}View = null; VM.{0} = null; }} else if ({0}View != temp{0}View) {{ var view = temp{0}View as {3}I{2}View; if (view != null) {{ (target as I{1}View).{0}View = temp{0}View as {3}I{2}View; VM.{0} = ({3}{2}ViewModel)temp{0}View.GetViewModel (); }} else {{ Debug.Log (""类型不匹配, 需要一个: {2}""); }} }}" , name, element_name, member_element_name, string.IsNullOrEmpty(element_ws) ? "" : element_ws + "."); is_ese = true; break; case DocType.SimpleClass: result = string.Format(@" vmk = ""{0}""; EditorGUILayout.BeginHorizontal (); if (VM.{0} == null) {{ EditorGUILayout.PrefixLabel (vmk); if (GUILayout.Button (""Create"")) {{ VM.{0} = new {1} (); }} }} else {{ string {0} = JsonConvert.SerializeObject (VM.{0}); string temp{0} = EditorGUILayout.DelayedTextField (vmk, {0}); if (temp{0} != {0}) {{ if (string.IsNullOrEmpty (temp{0})) {{ VM.{0} = null; }} else {{ VM.{0} = JsonConvert.DeserializeObject<{1}> ({0}); }} }} if (GUILayout.Button (""..."", GUILayout.MaxWidth (20))) {{ PopupWindow.Show ( new Rect (Event.current.mousePosition.x, Event.current.mousePosition.y, 0f, 0f), new SimpleClassReactivePropertyEditorPopupWindow<{1}> (this, VM.RP_{0}) ); }} }} EditorGUILayout.EndHorizontal ();" , name, type); is_ese = true; break; case DocType.Enum: result = string.Format(@" vmk = ""{0}""; VM.{0} = ({1})EditorGUILayout.EnumPopup (vmk, VM.{0});" , name, type); is_ese = true; break; case DocType.FSM: is_ese = false; break; default: throw new System.ArgumentOutOfRangeException(); } } } } if (is_ese == false) { switch (type) { case "bool": case "Boolean": result = string.Format(@" vmk = ""{0}""; VM.{0} = EditorGUILayout.Toggle (vmk, VM.{0});" , name); break; case "int": result = string.Format(@" vmk = ""{0}""; int temp{0} = EditorGUILayout.DelayedIntField (vmk, VM.{0}); if (temp{0} != VM.{0}) {{ VM.{0} = temp{0}; }}" , name); break; case "long": result = string.Format(@" vmk = ""{0}""; int temp{0} = EditorGUILayout.DelayedIntField (vmk, (int)VM.{0}); if ((long)temp{0} != VM.{0}) {{ VM.{0} = (long)temp{0}; }}" , name); break; case "float": result = string.Format(@" vmk = ""{0}""; float temp{0} = EditorGUILayout.DelayedFloatField (vmk, VM.{0}); if (temp{0} != VM.{0}) {{ VM.{0} = temp{0}; }}" , name); break; case "double": result = string.Format(@" vmk = ""{0}""; double temp{0} = EditorGUILayout.DelayedDoubleField (vmk, VM.{0}); if (temp{0} != VM.{0}) {{ VM.{0} = temp{0}; }}" , name); break; case "string": result = string.Format(@" vmk = ""{0}""; string temp{0} = EditorGUILayout.DelayedTextField (vmk, VM.{0}); if (temp{0} != VM.{0}) {{ VM.{0} = temp{0}; }}" , name); break; case "UnityEngine.Vector2": result = string.Format(@" vmk = ""{0}""; VM.{0} = EditorGUILayout.Vector2Field (vmk, VM.{0});" , name); break; case "UnityEngine.Vector3": result = string.Format(@" vmk = ""{0}""; VM.{0} = EditorGUILayout.Vector3Field (vmk, VM.{0});" , name); break; case "UnityEngine.Vector4": result = string.Format(@" vmk = ""{0}""; VM.{0} = EditorGUILayout.Vector4Field (vmk, VM.{0});" , name); break; case "UnityEngine.Quaternion": result = string.Format(@" vmk = ""{0}""; Vector3 temp{0}Vector3 = VM.{0}.eulerAngles; temp{0}Vector3 = EditorGUILayout.Vector3Field (vmk, temp{0}Vector3); VM.{0} = Quaternion.Euler (temp{0}Vector3);" , name); break; case "UnityEngine.Rect": result = string.Format(@" vmk = ""{0}""; VM.{0} = EditorGUILayout.RectField (vmk, VM.{0});" , name); break; case "UnityEngine.Bounds": result = string.Format(@" vmk = ""{0}""; VM.{0} = EditorGUILayout.BoundsField (vmk, VM.{0});" , name); break; case "UnityEngine.Color": result = string.Format(@" vmk = ""{0}""; VM.{0} = EditorGUILayout.ColorField (vmk, VM.{0});" , name); break; case "UnityEngine.AnimationCurve": result = string.Format(@" vmk = ""{0}""; EditorGUILayout.BeginHorizontal (); if (VM.{0} == null) {{ EditorGUILayout.PrefixLabel (vmk); if (GUILayout.Button (""Create"")) {{ VM.{0} = AnimationCurve.Linear (0f, 0f, 1f, 1f); }} }} else {{ VM.{0} = EditorGUILayout.CurveField (vmk, VM.{0}); if (GUILayout.Button (""-"", GUILayout.MaxWidth (20f))) {{ VM.{0} = null; }} }} EditorGUILayout.EndHorizontal ();" , name); break; case "DateTime": result = string.Format(@" vmk = ""{0}""; DateTime temp{0}; if (DateTime.TryParse (EditorGUILayout.DelayedTextField (vmk, VM.{0}.ToString ()), out temp{0})) {{ if (VM.{0} != temp{0}) {{ VM.{0} = temp{0}; }} }}" , name); break; case "TimeSpan": result = string.Format(@" vmk = ""{0}""; TimeSpan temp{0}; if (TimeSpan.TryParse (EditorGUILayout.DelayedTextField (vmk, VM.{0}.ToString ()), out temp{0})) {{ if (VM.{0} != temp{0}) {{ VM.{0} = temp{0}; }} }}" , name); break; case "JObject": result = string.Format(@" vmk = ""{0}""; string temp{0}String = JsonConvert.SerializeObject (VM.{0}); string temp2{0}String = EditorGUILayout.DelayedTextField (vmk, temp{0}String); if (temp{0}String != temp2{0}String) {{ try {{ VM.{0} = JsonConvert.DeserializeObject<JObject> (temp2{0}String); }} catch {{ VM.{0} = JsonConvert.DeserializeObject<JObject> (temp{0}String); }} }}" , name); break; case "JArray": result = string.Format(@" vmk = ""{0}""; string temp{0}String = JsonConvert.SerializeObject (VM.{0}); string temp2{0}String = EditorGUILayout.DelayedTextField (vmk, temp{0}String); if (temp{0}String != temp2{0}String) {{ try {{ VM.{0} = JsonConvert.DeserializeObject<JArray> (temp2{0}String); }} catch {{ VM.{0} = JsonConvert.DeserializeObject<JArray> (temp{0}String); }} }}" , name); break; default: result = string.Format(@" vmk = ""{0}""; EditorGUILayout.DelayedTextField (vmk, VM.{0} != null ? VM.{0}.ToString () : ""null ({1})"");" , name, type); break; } } return(result); }