void PropertyDropDown(BindingBase.BindingInfo info) { var type = Target.Context.DataType; var members = new MemberInfo[0]; // filter switch (info.Filters) { case BindingBase.BindingFilter.Commands: members = EditorMembersHelper.GetMethods(type); break; case BindingBase.BindingFilter.Properties: members = EditorMembersHelper.GetProperties(type); break; } //filter if (info.FilterTypes != null) { members = members.Where(o => info.FilterTypes.Any(t => ValidType(t, o.GetParamaterType()))).ToArray(); } if (members.Length == 0) { EditorGUILayout.LabelField(string.Format("{0}->{1} has no valid members.", info.BindingName, type.Name)); return; } var labels = members.Select(o => string.Format("{0} : {1}", o.Name, o.GetParamaterType())).ToList(); var names = members.Select(o => o.Name).ToList(); labels.Insert(0, "Null"); names.Insert(0, ""); var index = Array.IndexOf(names.ToArray(), info.MemberName); var i = EditorGUILayout.Popup(info.BindingName, index, labels.ToArray()); if (i != index) { info.MemberName = names[i]; EditorUtility.SetDirty(target); } }
private void PropertyDropDown(BindingBase.BindingInfo info) { var type = Target.Context.DataType; var labels = new System.Collections.Generic.List <string>(); var names = new System.Collections.Generic.List <string>(); if (!Target.Context.DataType.IsAssignableFrom(typeof(GameSystem.LuaObservableBehaviour))) { var members = new MemberInfo[0]; // filter switch (info.Filters) { case BindingBase.BindingFilter.Commands: members = EditorMembersHelper.GetMethods(type); break; case BindingBase.BindingFilter.Properties: members = EditorMembersHelper.GetProperties(type); break; } // filter if (info.FilterTypes != null) { members = members.Where(o => info.FilterTypes.Any(t => ValidType(t, o.GetParamaterType()))).ToArray(); } labels = members.Select(o => string.Format("{0} : {1}", o.Name, o.GetParamaterType())).ToList(); names = members.Select(o => o.Name).ToList(); } else { var luaObervableBehaviour = Target.Context.DataInstance as GameSystem.LuaObservableBehaviour; string luaScript = luaObervableBehaviour.GetLuaScript(); if (!string.IsNullOrEmpty(luaScript)) { luaEnv.DoString(luaScript, GetType().Name, luaTable); var keys = luaTable.GetKeys <string>().OrderBy(c => c); foreach (var k in keys) { if (k == "set" || k == "get") { continue; } object value; if (info.FilterTypes != null) { foreach (var t in info.FilterTypes) { if (luaTable.TryGet(k, t, out value)) { labels.Add(string.Format("{0} : {1}", k, value.GetType())); names.Add(k); } } } else { if (luaTable.TryGet(k, out value)) { Type t = value.GetType(); if (info.Filters == BindingBase.BindingFilter.Commands && t == typeof(LuaFunction) || info.Filters == BindingBase.BindingFilter.Properties && t != typeof(LuaFunction)) { labels.Add(string.Format("{0} : {1}", k, value.GetType())); names.Add(k); } } } } luaEnv.Tick(); } } if (labels.Count == 0) { EditorGUILayout.LabelField(string.Format("{0}->{1} has no valid members.", info.BindingName, type.Name)); return; } labels.Insert(0, "Null"); names.Insert(0, ""); var index = names.FindIndex(c => c == info.MemberName); var i = EditorGUILayout.Popup(info.BindingName, index, labels.ToArray()); if (i < 0) { return; } if (i != index || info.MemberName != names[i]) { info.MemberName = names[i]; EditorUtility.SetDirty(target); } }