Hello,
So, when I first saw the delegate parameters I just had to update NGUI because I really needed those things.
I quickly made some changes and I noticed that in the arguments you can't pass as a parameter a specific component of a gameobject (prefab in my case).
I did some snooping around and managed to make it work but I'm not sure if it breaks anything else.
Here are the modifications:
NGUITools.cs
static public string GetFuncName (object obj, string method)
{
if (obj == null) return "<null>";
//if (string.IsNullOrEmpty(method)) return "<Choose>";
string type = obj.GetType().ToString();
int period = type.LastIndexOf('.');
if (period > 0) type = type.Substring(period + 1);
if (string.IsNullOrEmpty(method))
return type;
return type + "." + method;
}
and
PrepertyReferenceDrawer.cs
static public List<Entry> GetProperties (GameObject target, bool read, bool write)
{
Component[] comps = target.GetComponents<Component>();
List
<Entry
> list
= new List
<Entry
>();
for (int i = 0, imax = comps.Length; i < imax; ++i)
{
Component comp = comps[i];
if (comp == null) continue;
Type type = comp.GetType();
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public;
FieldInfo[] fields = type.GetFields(flags);
PropertyInfo[] props = type.GetProperties(flags);
{
ent.target = comp;
list.Add(ent);
}
for (int b = 0; b < fields.Length; ++b)
{
FieldInfo field = fields[b];
{
if (canConvert)
{
if (!PropertyReference.Convert(field.FieldType, filter)) continue;
}
else if (!filter.IsAssignableFrom(field.FieldType)) continue;
}
ent.target = comp;
ent.name = field.Name;
list.Add(ent);
}
for (int b = 0; b < props.Length; ++b)
{
PropertyInfo prop = props[b];
if (read && !prop.CanRead) continue;
if (write && !prop.CanWrite) continue;
{
if (canConvert)
{
if (!PropertyReference.Convert(prop.PropertyType, filter)) continue;
}
else if (!filter.IsAssignableFrom(prop.PropertyType)) continue;
}
ent.target = comp;
ent.name = prop.Name;
list.Add(ent);
}
}
return list;
}
It would be swell if this change would be added directly on NGUI.
It basically enables buttons to call functions like this
public void OnShopBuilding(Building prefab)
{
StartPlacingBuilding(prefab);
}
where Building is derived from MonoBehavior