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 }
private UnitAttack[] AllAttackComp = new UnitAttack[0]; //holds all of the attack components attached to this unit public override void UpdateAttackComp(AttackEntity attackEntity) { AttackComp = (UnitAttack)attackEntity; }