//a method that assings a new faction for the unit public void AssignFaction(FactionManager factionMgr) { FactionMgr = factionMgr; //set the new faction FactionID = FactionMgr.FactionID; //set the new faction ID free = false; //if this was a free unit then not anymore Creator = gameMgr.GetFaction(FactionID).GetCapitalBuilding(); //make the unit's producer, the capital of the new faction UpdateFactionColors(gameMgr.GetFaction(FactionID).GetColor()); //set the new faction colors selection.UpdateMinimapIconColor(); //assign the new faction color for the unit in the minimap icon if (TaskLauncherComp != null) //if the unit has a task launcher { TaskLauncherComp.Init(gameMgr, this); //update the task launcher info } }
public override void Init(GameManager gameMgr, int fID, bool free) { base.Init(gameMgr, fID, free); //get the unit's components HealthComp = GetComponent <UnitHealth>(); ConverterComp = GetComponent <Converter>(); MovementComp = GetComponent <UnitMovement>(); WanderComp = GetComponent <Wander>(); EscapeComp = GetComponent <EscapeOnAttack>(); BuilderComp = GetComponent <Builder>(); CollectorComp = GetComponent <ResourceCollector>(); HealerComp = GetComponent <Healer>(); AllAttackComp = GetComponents <UnitAttack>(); //initialize them: if (ConverterComp) { ConverterComp.Init(gameMgr, this); } if (MovementComp) { MovementComp.Init(gameMgr, this); } if (WanderComp) { WanderComp.Init(gameMgr, this); } if (EscapeComp) { EscapeComp.Init(gameMgr, this); } if (BuilderComp) { BuilderComp.Init(gameMgr, this); } if (CollectorComp) { CollectorComp.Init(gameMgr, this); } if (HealerComp) { HealerComp.Init(gameMgr, this); } foreach (UnitAttack comp in AllAttackComp) //init all attached attack components { if (AttackComp == null) { AttackComp = comp; } comp.Init(gameMgr, this, MultipleAttackMgr); } if (MultipleAttackMgr) { MultipleAttackMgr.Init(this); } if (TaskLauncherComp) //if the entity has a task launcher component { TaskLauncherComp.Init(gameMgr, this); //initialize it } if (animator == null) //no animator component? { Debug.LogError("[Unit] The " + GetName() + "'s Animator hasn't been assigned to the 'animator' field"); } if (animator != null) //as long as there's an animator component { if (animatorOverrideController == null) //if there's no animator override controller assigned.. { animatorOverrideController = gameMgr.UnitMgr.GetDefaultAnimController(); } ResetAnimatorOverrideController(); //set the default override controller //Set the initial animator state to idle SetAnimState(UnitAnimState.idle); } Rigidbody rigidbody = GetComponent <Rigidbody>(); if (rigidbody == null) //no rigidbody component? { Debug.LogError("[Unit] The " + GetName() + "'s main object is missing a rigidbody component"); } //rigidbody settings: rigidbody.isKinematic = true; rigidbody.useGravity = false; //set the radius value: radius = MovementComp.GetAgentRadius(); //if this is a free unit if (this.free) { UpdateFactionColors(gameMgr.UnitMgr.GetFreeUnitColor()); //set the free unit color } gameMgr.MinimapIconMgr?.Assign(selection); //ask the minimap icon manager to create the a minimap icon for this unit CustomEvents.OnUnitCreated(this); //trigger custom event }