/// <summary> /// public get for the Table, if it cant find a correct type here, it will check its own parent /// </summary> /// <returns>If Null, then we have hit the top level object</returns> public Table Table(Type type) { if (containedTypes.Count < 1) { GetAllTypes(); } foreach (SerializableSystemType t in containedTypes) { //Debug.Log(t.Name + " is assignable from: " + type.Name+ "? "+ t.SystemType.IsAssignableFrom(type) ); //Debug.Log(type.Name + " is assignable from " + t.Name +"? "+ type.IsAssignableFrom(t.SystemType) ); if (type.IsAssignableFrom(t.SystemType)) { //Debug.Log(gameObject.name + " has the type: " + type.ToString(), gameObject); return(GetTableOfType(type)); } } if (!transform.parent) { return(null); } TableHolder parentTable = transform.parent.GetComponentInParent <TableHolder>(); if (!parentTable) { return(null); } return(parentTable.Table(type)); }
/// <summary> /// Finds & returns a table with entries of the given type in the nearest table holder in the ancestry of t. /// For interior objects, <see cref="FindTableForInterior{T}(Transform)"/> /// </summary> /// <typeparam name="T">Type of entry to search for in the tables</typeparam> /// <param name="t">The transform looking for a table.</param> public static Table FindTable <T> (Transform t) where T : Entry { if (t == null) { Debug.Log("Given transform is null"); return(null); } // Search up the hierarchy looking for an appropriate table. TableHolder holder = t.GetComponentInParent <TableHolder>(); if (holder == null) { //Debug.Log(t.name + " can't find a table holder in hierarchy!", t.gameObject); return(null); } return(holder.Table(typeof(T))); }