internal void removeSensor(Brain brain, IMonoBehaviourSensor sensor) { lock (getLock(brain)) { instantiatedSensors[brain].Remove(sensor); } }
internal void addSensor(Brain brain, IMonoBehaviourSensor sensor) { lock (getLock(brain)) { if (!instantiatedSensors.ContainsKey(brain)) { instantiatedSensors.Add(brain, new List <IMonoBehaviourSensor>()); } instantiatedSensors[brain].Add(sensor); } }
private void enlargedList(string property, int newSize, Type propertyType, Type collectionElementType) { for (int i = sizeToTrack[property][0]; i < newSize; i++) { IMonoBehaviourSensor newSensor = addSensor(sensorNameForCollectionProperty[property], property, 0, propertyType); newSensor.indexes.Add(i); newSensor.collectionElementProperty = currentSubProperty; newSensor.collectionElementType = collectionElementType.Name; newSensor.done(); SensorsManager.GetInstance().addSensor(brain, newSensor); } }
private IMonoBehaviourSensor addSensor(string confName, string property, int currentOperationPerProperty, Type type) { MyDebugger.MyDebug("ACTUALLY ADDING COMPONENT TO " + gameObject.name); sensorsAdded++; MyDebugger.MyDebug("Added " + sensorsAdded + "sensors to " + gameObject.name); Component component = gameObject.AddComponent(SensorsUtility.actualMonoBehaviourSensor[type]); //MyDebugger.MyDebug("component " + component); component.hideFlags = HideFlags.HideInInspector; IMonoBehaviourSensor sensor = component as IMonoBehaviourSensor; if (!sensor.ready) { sensor.propertyType = currentPropertyType; sensor.path = property; sensor.sensorName = confName; sensor.operationType = currentOperationPerProperty; sensor.brain = brain; if (executeRepeteadly) { sensor.executeRepeteadly = executeRepeteadly; sensor.frequency = frequence; } else { sensor.triggerClass = triggerClass; sensor.updateMethod = updateMethod; } } /*MyDebugger.MyDebug("adding " + sensor.path); * if (sensor.indexes.Count > 0) * { * MyDebugger.MyDebug(" index " + sensor.indexes[0]); * } */ return(sensor); }
private void configureSensor(object[] result, Type type, SensorConfiguration conf, string property, int currentOperationPerProperty, List <IMonoBehaviourSensor> generatedSensors) { //MyDebugger.MyDebug("configuring sensors for " + property); if (result != null) { type = (Type)result[0]; } if (type != null && currentPropertyType.Equals("VALUE")) { IMonoBehaviourSensor sensor = addSensor(conf.name, property, currentOperationPerProperty, type); //MyDebugger.MyDebug("AND IT'S VALUE"); sensor.done(); generatedSensors.Add(sensor); } else if (type != null) { List <int> currentSize = new List <int>(); if (currentPropertyType.Equals("LIST")) { //MyDebugger.MyDebug("AND IT'S LIST"); currentSize.Add((int)result[1]); for (int i = 0; i < (int)result[1]; i++) { IMonoBehaviourSensor sensor = addSensor(conf.name, property, currentOperationPerProperty, type); sensor.indexes.Add(i); sensor.collectionElementProperty = currentSubProperty; sensor.collectionElementType = ((Type)result[2]).Name; sensor.done(); generatedSensors.Add(sensor); } } else if (currentPropertyType.Equals("ARRAY2")) { MyDebugger.MyDebug("AND IT'S ARRAY2"); currentSize.Add((int)result[1]); currentSize.Add((int)result[2]); for (int i = 0; i < (int)result[1]; i++) { for (int j = 0; j < (int)result[2]; j++) { IMonoBehaviourSensor sensor = addSensor(conf.name, property, currentOperationPerProperty, type); sensor.indexes.Add(i); sensor.indexes.Add(j); sensor.collectionElementProperty = currentSubProperty; sensor.collectionElementType = ((Type)result[3]).Name; sensor.done(); generatedSensors.Add(sensor); } } } if (!sizeToTrack.ContainsKey(property)) { //MyDebugger.MyDebug("property " + property); //MyDebugger.MyDebug("size " + currentSize.Count); sizeToTrack.Add(property, currentSize); typeForCollectionProperty.Add(property, currentPropertyType); elementForCollectionProperty.Add(property, new List <string>()); sensorNameForCollectionProperty.Add(property, conf.name); } elementForCollectionProperty[property].Add(currentSubProperty); } }