private void HandleTargetLost(object arg1, object arg2) { TargetSensor sender = (TargetSensor)arg1; Target target = (Target)arg2; Debug.Log(name + "'s " + sender.name + " Scanner has Lost Target " + target.gameObject.name); }
public void InitializeModules(AgentGenome genome, Agent agent) { atmosphereSensorList = new List <AtmosphereSensor>(); basicJointList = new List <BasicJoint>(); basicWheelList = new List <BasicWheel>(); contactSensorList = new List <ContactSensor>(); gravitySensorList = new List <GravitySensor>(); healthModuleList = new List <HealthModule>(); oscillatorList = new List <InputOscillator>(); raycastSensorList = new List <RaycastSensor>(); shieldList = new List <Shield>(); targetSensorList = new List <TargetSensor>(); thrusterEffectorList = new List <ThrusterEffector>(); torqueEffectorList = new List <TorqueEffector>(); trajectorySensorList = new List <TrajectorySensor>(); valueList = new List <InputValue>(); weaponProjectileList = new List <WeaponProjectile>(); weaponTazerList = new List <WeaponTazer>(); for (int i = 0; i < genome.bodyGenome.atmosphereSensorList.Count; i++) { AtmosphereSensor atmosphereSensor = new AtmosphereSensor(); atmosphereSensor.Initialize(genome.bodyGenome.atmosphereSensorList[i], agent); atmosphereSensorList.Add(atmosphereSensor); } for (int i = 0; i < genome.bodyGenome.basicJointList.Count; i++) { BasicJoint basicJoint = new BasicJoint(); basicJoint.Initialize(genome.bodyGenome.basicJointList[i], agent); basicJointList.Add(basicJoint); //basicJointList[i].Initialize(genome.basicJointList[i]); } for (int i = 0; i < genome.bodyGenome.basicWheelList.Count; i++) { BasicWheel basicWheel = new BasicWheel(); basicWheel.Initialize(genome.bodyGenome.basicWheelList[i], agent); basicWheelList.Add(basicWheel); //OLD: //basicWheelList[i].Initialize(genome.basicWheelList[i]); } for (int i = 0; i < genome.bodyGenome.contactSensorList.Count; i++) { ContactSensor contactSensor = new ContactSensor(); //agent.segmentList[genome.contactSensorList[i].parentID].AddComponent<ContactSensorComponent>(); contactSensor.Initialize(genome.bodyGenome.contactSensorList[i], agent); contactSensorList.Add(contactSensor); //contactSensorList[i].Initialize(genome.contactSensorList[i]); } for (int i = 0; i < genome.bodyGenome.gravitySensorList.Count; i++) { GravitySensor gravitySensor = new GravitySensor(); gravitySensor.Initialize(genome.bodyGenome.gravitySensorList[i], agent); gravitySensorList.Add(gravitySensor); } for (int i = 0; i < genome.bodyGenome.healthModuleList.Count; i++) { HealthModule healthModule = new HealthModule(); //agent.segmentList[genome.healthModuleList[i].parentID].AddComponent<HealthModuleComponent>(); healthModule.Initialize(genome.bodyGenome.healthModuleList[i], agent); healthModuleList.Add(healthModule); //healthModuleList[i].Initialize(genome.healthModuleList[i]); } for (int i = 0; i < genome.bodyGenome.oscillatorInputList.Count; i++) { InputOscillator inputOscillator = new InputOscillator(); inputOscillator.Initialize(genome.bodyGenome.oscillatorInputList[i], agent); oscillatorList.Add(inputOscillator); //oscillatorList[i].Initialize(genome.oscillatorInputList[i]); } for (int i = 0; i < genome.bodyGenome.raycastSensorList.Count; i++) { RaycastSensor raycastSensor = new RaycastSensor(); raycastSensor.Initialize(genome.bodyGenome.raycastSensorList[i], agent); raycastSensorList.Add(raycastSensor); //raycastSensorList[i].Initialize(genome.raycastSensorList[i]); } for (int i = 0; i < genome.bodyGenome.shieldList.Count; i++) { Shield shield = new Shield(); shield.Initialize(genome.bodyGenome.shieldList[i], agent); shieldList.Add(shield); } for (int i = 0; i < genome.bodyGenome.targetSensorList.Count; i++) { TargetSensor targetSensor = new TargetSensor(); targetSensor.Initialize(genome.bodyGenome.targetSensorList[i], agent); targetSensorList.Add(targetSensor); //targetSensorList[i].Initialize(genome.targetSensorList[i]); } for (int i = 0; i < genome.bodyGenome.thrusterList.Count; i++) { // Create Functional GameObjects & Components: // none in this case // Create Logic Module: ThrusterEffector thrusterEffector = new ThrusterEffector(); // Initialize and HookUp Logic Module: thrusterEffector.Initialize(genome.bodyGenome.thrusterList[i], agent); // If Visible, Create Renderable GameObjects & Components: if (isVisible) { // Find appropriate Prefab based on Agent & Module Genome: GameObject thrusterGO = Instantiate(Resources.Load("Prefabs/Modules/Thrusters/thrusterTest")) as GameObject; thrusterGO.transform.parent = agent.segmentList[genome.bodyGenome.thrusterList[i].parentID].transform; thrusterGO.transform.localPosition = genome.bodyGenome.thrusterList[i].forcePoint; thrusterGO.transform.localRotation = Quaternion.identity; // Hook into Logic Module thrusterEffector.thrusterComponent = thrusterGO.GetComponent <ThrusterComponent>(); } // Add Logic Module to Agent's Master List thrusterEffectorList.Add(thrusterEffector); } for (int i = 0; i < genome.bodyGenome.torqueList.Count; i++) { TorqueEffector torqueEffector = new TorqueEffector(); torqueEffector.Initialize(genome.bodyGenome.torqueList[i], agent); torqueEffectorList.Add(torqueEffector); //torqueEffectorList[i].Initialize(genome.torqueList[i]); } for (int i = 0; i < genome.bodyGenome.trajectorySensorList.Count; i++) { TrajectorySensor trajectorySensor = new TrajectorySensor(); trajectorySensor.Initialize(genome.bodyGenome.trajectorySensorList[i], agent); trajectorySensorList.Add(trajectorySensor); } for (int i = 0; i < genome.bodyGenome.valueInputList.Count; i++) { InputValue inputValue = new InputValue(); inputValue.Initialize(genome.bodyGenome.valueInputList[i], agent); valueList.Add(inputValue); //valueList[i].Initialize(genome.valueInputList[i]); } for (int i = 0; i < genome.bodyGenome.weaponProjectileList.Count; i++) { WeaponProjectile weaponProjectile = new WeaponProjectile(); weaponProjectile.Initialize(genome.bodyGenome.weaponProjectileList[i], agent); if (isVisible) { // Find appropriate Prefab based on Agent & Module Genome: GameObject weaponGO = Instantiate(Resources.Load("Prefabs/Modules/WeaponProjectiles/projectileTest")) as GameObject; weaponGO.transform.parent = agent.segmentList[genome.bodyGenome.weaponProjectileList[i].parentID].transform; weaponGO.transform.localPosition = genome.bodyGenome.weaponProjectileList[i].muzzleLocation; weaponGO.transform.localRotation = Quaternion.identity; // Hook into Logic Module weaponProjectile.weaponProjectileComponent = weaponGO.GetComponent <WeaponProjectileComponent>(); } weaponProjectileList.Add(weaponProjectile); /*weaponProjectileList[i].Initialize(genome.weaponProjectileList[i]); * * if (isVisible) { * GameObject particleGO = Instantiate(Resources.Load(weaponProjectileList[i].GetParticleSystemURL())) as GameObject; * ParticleSystem particle = particleGO.GetComponent<ParticleSystem>(); * ParticleSystem.EmissionModule emission = particle.emission; * emission.enabled = false; * particle.gameObject.transform.parent = rootObject.transform; * particle.gameObject.transform.localPosition = new Vector3(0f, 0.5f, 0f); * particle.gameObject.transform.localRotation = Quaternion.identity; * weaponProjectileList[i].particles = particle; // save reference * } */ } for (int i = 0; i < genome.bodyGenome.weaponTazerList.Count; i++) { WeaponTazer weaponTazer = new WeaponTazer(); weaponTazer.Initialize(genome.bodyGenome.weaponTazerList[i], agent); if (isVisible) { // Find appropriate Prefab based on Agent & Module Genome: GameObject weaponGO = Instantiate(Resources.Load("Prefabs/Modules/WeaponTazers/tazerTest")) as GameObject; weaponGO.transform.parent = agent.segmentList[genome.bodyGenome.weaponTazerList[i].parentID].transform; weaponGO.transform.localPosition = genome.bodyGenome.weaponTazerList[i].muzzleLocation; weaponGO.transform.localRotation = Quaternion.identity; // Hook into Logic Module weaponTazer.weaponTazerComponent = weaponGO.GetComponent <WeaponTazerComponent>(); } weaponTazerList.Add(weaponTazer); /*weaponTazerList[i].Initialize(genome.weaponTazerList[i]); * if (isVisible) { * GameObject particleGO = Instantiate(Resources.Load(weaponTazerList[i].GetParticleSystemURL())) as GameObject; * ParticleSystem particle = particleGO.GetComponent<ParticleSystem>(); * ParticleSystem.EmissionModule emission = particle.emission; * emission.enabled = false; * particle.gameObject.transform.parent = weaponTazerList[i].parentBody.transform; * particle.gameObject.transform.localPosition = weaponTazerList[i].muzzleLocation; * particle.gameObject.transform.localRotation = Quaternion.identity; * weaponTazerList[i].particles = particle; // save reference * } */ } }