public override void OnInspectorGUI() { base.OnInspectorGUI(); m_UI_Unit = (target as UI_Unit); selected = (Unit)EditorGUILayout.ObjectField(selected, typeof(Unit), true); if (selected != null && GUILayout.Button("Set Unit")) { m_UI_Unit.SetUnitInfo(selected); } }
public void SetUnit(Unit unit, UI_Unit unitUI) { m_UnitUI = unitUI; m_Unit = unit; m_EffectManager = m_Unit.GetComponent <Unit_EffectManager>(); m_EffectManager.OnEffectTick += SpawnEffectTickNotification; m_EffectManager.OnEffectAdded += SpawnEffectAppliedNotification; m_EffectManager.OnEffectRemoved += SpawnEffectExpiredNotification; UnitInventory inventory = unit.GetComponent <UnitInventory>(); inventory.OnInventoryUpdated += SpawnInventoryNotification; PlayerInventory.Instance.OnInventoryUpdated += SpawnInventoryNotification; Unit.OnTurnStart += ShowActiveEffects; Unit.OnUnitKilled += u => { if (u == unit) { RemoveListeners(); } ; }; Unit.OnEvacuated += u => { if (u == unit) { RemoveListeners(); } ; }; }
/// <summary> /// Returns the instance of a unit /// </summary> /// <param name="data">Unit Config to determine unit type, stats, actions</param> /// <returns></returns> public static Unit CreateUnit(ScriptableUnitConfig data, int group, M_Math.R_Range initiative_range, bool hide_player) { if (data == null) { Debug.LogWarning("cant create unit, data == null"); return(null); } MDebug.Log("^unitCreating Unit " + data.ID); GameObject base_unit = Instantiate(Resources.Load("base_unit")) as GameObject; SpawnLootOnDeath loot = base_unit.AddComponent <SpawnLootOnDeath>(); Unit_EffectManager effect_manager = base_unit.AddComponent <Unit_EffectManager>(); UnitStats stats = MakeStats(base_unit, data, effect_manager, initiative_range); UnitInventory inventory = MakeInventory(data, base_unit, stats); ActionManager actions = MakeActions(data, base_unit); UnitAdrenalineRushParticleManager adr_particles = base_unit.GetComponent <UnitAdrenalineRushParticleManager>(); Unit m_unit = base_unit.AddComponent <Unit>(); GameObject mesh = MakeMesh(data, m_unit); Unit_UnitDeath unit_death = base_unit.AddComponent <Unit_UnitDeath>(); Unit_UnitEvacuation unit_evac = base_unit.AddComponent <Unit_UnitEvacuation>(); UnitAnimationController animations = mesh.AddComponent <UnitAnimationController>(); Unit_SoundController sound = base_unit.AddComponent <Unit_SoundController>(); UnitRotationController rotator = base_unit.AddComponent <UnitRotationController>(); SpeechManager_Unit speech_mananger = base_unit.AddComponent <SpeechManager_Unit>(); m_unit.OwnerID = data.Owner; m_unit.Config = data; UI_Unit.CreateUnitUI(m_unit); sound.Init(m_unit); unit_evac.Init(m_unit); adr_particles.Init(stats); AddActiveTurnIndicator(m_unit, data.Owner == 0); GetName(data, base_unit); GiveWeapon(data, mesh, inventory); loot.Init(m_unit, data.LootCategory); effect_manager.SetUnit(m_unit); animations.Init(m_unit, mesh); speech_mananger.Init(data.SpeechConfig, m_unit); if (data.Owner == 1) { UnitAI ai = MakeAI(data, group, base_unit, m_unit); rotator.Init(m_unit.GetComponent <WaypointMover>(), ai.GetLookRotation); ai.OnPreferredTargetChange += unit => new TurnEventQueue.AIAggroEvent(ai, unit); } else { rotator.Init(m_unit.GetComponent <WaypointMover>(), delegate { return(m_unit.transform.position + m_unit.transform.forward); }); } //set mesh inactive mesh.gameObject.GetComponentsInChildren <Renderer>().ToList().ForEach(rend => rend.enabled = false); //and then identify InitIdentified(data, m_unit, hide_player); return(m_unit); }