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()); }
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); }