Improve BTC GetNamedObject
This commit is contained in:
parent
a48c4f42cb
commit
2f7f9b2bec
@ -61,23 +61,49 @@ public class BTC : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ComponentController> namedObjects = new List<ComponentController>();
|
public List<ComponentController> namedObjects = new List<ComponentController>();
|
||||||
|
private Dictionary<string, ComponentController> namedLookup = new();
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
BuildLookup();
|
||||||
|
}
|
||||||
|
|
||||||
#region update list of objects in rooms
|
#region update list of objects in rooms
|
||||||
public void ClearObjects() {
|
public void ClearObjects() {
|
||||||
namedObjects = new List<ComponentController>();
|
//namedObjects = new List<ComponentController>();
|
||||||
|
namedObjects.Clear();
|
||||||
|
namedLookup.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetNamedObject<T>(string objectName) where T : ComponentController {
|
/* public T GetNamedObject<T>(string objectName) where T : ComponentController {
|
||||||
for (int i = namedObjects.Count - 1; i >= 0; i--) {
|
for (int i = namedObjects.Count - 1; i >= 0; i--) {
|
||||||
T ngo = namedObjects[i] as T;
|
T ngo = namedObjects[i] as T;
|
||||||
if (ngo != null) {
|
if (ngo != null) {
|
||||||
// if name equals
|
// if name equals
|
||||||
if (ngo.objectName == objectName) {
|
if (ngo.objectName == objectName) {
|
||||||
|
Debug.Log("BTC returns namedObject");
|
||||||
return ngo;
|
return ngo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public void BuildLookup()
|
||||||
|
{
|
||||||
|
namedLookup.Clear();
|
||||||
|
foreach (var ctrl in namedObjects)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(ctrl.objectName))
|
||||||
|
namedLookup[ctrl.objectName] = ctrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetNamedObject<T>(string objectName) where T : ComponentController
|
||||||
|
{
|
||||||
|
if (namedLookup.TryGetValue(objectName, out var obj))
|
||||||
|
return obj as T;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ComponentHandler> GetHandlers (string objectName) {
|
public List<ComponentHandler> GetHandlers (string objectName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user