12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class ThreatManager
- {
- private Dictionary<int, Threat> threatDict;
- private List<Threat> threatList;
- public ThreatManager()
- {
- threatDict = new Dictionary<int, Threat>();
- threatList = new List<Threat>();
- }
- public void AddThreat(int id, float value)
- {
- if(!threatDict.ContainsKey(id))
- {
- Threat threat = new Threat(id, value);
- threatDict.Add(id, threat);
- threatList.Add(threat);
- }
- threatDict[id].SetValue(value);
- }
- public void RemoveThreat(int id)
- {
- if(threatDict.ContainsKey(id))
- {
- Threat threat = threatDict[id];
- threatDict.Remove(id);
- threatList.Remove(threat);
- }
- }
- public float GetThreat(int id)
- {
- if(threatDict.ContainsKey(id))
- {
- return threatDict[id].GetValue();
- }
- return 0;
- }
- public int GetMaxThreatId()
- {
- int id = -1;
- float maxThread = 0;
- for(int i=0; i<threatList.Count; i++)
- {
- Threat threat = threatList[i];
- float threatValue = threat.GetValue();
- if(threatValue > maxThread)
- {
- id = threat.id;
- maxThread = threatValue;
- }
- }
- return id;
- }
- }
|