void Awake() { GlobalPheromoneConfiguration globalPheromoneConfiguration = FindObjectOfType(typeof(GlobalPheromoneConfiguration)) as GlobalPheromoneConfiguration; _pheromoneConfiguration = globalPheromoneConfiguration.configs [_pheromoneType]; _statisticsManager = (StatisticsManager)Object.FindObjectOfType(typeof(StatisticsManager)); }
void Awake() { _image = GetComponent <Image> (); _iconImage = transform.Find("IconImage").GetComponent <Image> (); GlobalPheromoneConfiguration globalPheromoneConfiguration = FindObjectOfType(typeof(GlobalPheromoneConfiguration)) as GlobalPheromoneConfiguration; _pheromoneConfiguration = globalPheromoneConfiguration.configs [_pheromoneType]; }
/** * Place a pheromone of given type at given position. * * If necessary, merge it with existing pheromones. A merge is triggered if more than * 4 pheromones are located at the same position, i.e. their centers lie within a circle of 0.5 units. */ public void PlacePheromone(Vector3 position, EPheromoneTypes type) { position.y = 0; PheromoneConfiguration pheromoneConfiguration = _pheromoneConfiguration.configs [type]; // Get current parameters from configuration. float initialIntensity = pheromoneConfiguration.initialIntensity; float initialScale = pheromoneConfiguration.initialRadius; float diffusionRate = pheromoneConfiguration.diffusionRate; float minimumConcentration = pheromoneConfiguration.minimumConcentration; Color color = pheromoneConfiguration.color; // If there are enough pheromones nearby, merge them into one Collider[] nearbyPheromoneCenters = Physics.OverlapSphere(position, 0.5f, _pheromoneOriginLayerMask); List <GameObject> nearbyPheromones = new List <GameObject> (); // Filter nearby pheromones by type. foreach (Collider pheromoneCenter in nearbyPheromoneCenters) { GameObject pheromone = pheromoneCenter.transform.parent.gameObject; if (pheromone.GetComponent <Pheromone> ().type == type) { nearbyPheromones.Add(pheromone); } } // Merge if enough pheromones of the same type are located on position. if (nearbyPheromones.Count > 4) { foreach (GameObject pheromone in nearbyPheromones) { initialIntensity += pheromone.GetComponent <Pheromone>().startIntensity; initialScale = Mathf.Max(initialScale, pheromone.transform.Find("DiffusionSphere").transform.localScale.x); //startScale += pheromone.transform.Find ("DiffusionSphere").transform.localScale.x; position += pheromone.transform.position; Destroy(pheromone); } // Make start scale the average of all scales //startScale = startScale / (nearbyPheromoneCenters.GetLength(0) + 1); position = position / (nearbyPheromones.Count + 1); } // Create and initialize new pheromone GameObject newPheromone = Instantiate(_pheromonePrefab, position, new Quaternion()) as GameObject; newPheromone.GetComponent <Pheromone>().Initialize(type, initialIntensity, initialScale, diffusionRate, minimumConcentration, color); }
// call to place specific type of pheromone public void PlacePheromone(Vector3 position, PheromoneTypes type) { PheromoneConfiguration pheromoneConfiguration = _pheromoneConfiguration.configs[type]; float initialIntensity = pheromoneConfiguration.initialIntensity; float initialScale = pheromoneConfiguration.initialRadius; float diffusionRate = pheromoneConfiguration.diffusionRate; float minimumConcentration = pheromoneConfiguration.minimumConcentration; Color color = pheromoneConfiguration.color; // instantiates the pheromone prefab in position GameObject newPheromone = Instantiate(pheromonePrefab, position, new Quaternion()) as GameObject; // initialize and visualizes new pheromone gameobject through pheromone script newPheromone.GetComponent <Pheromone>().Initialize(type, initialIntensity, initialScale, diffusionRate, minimumConcentration, color); }