示例#1
0
 //a method called to disable the faction entity related components
 public virtual void Disable(bool destroyed)
 {
     if (TaskLauncherComp != null)                    //if the unit has a task manager and there are pending tasks there
     {
         TaskLauncherComp.CancelAllInProgressTasks(); //cancel all the in progress tasks
     }
     if (APCComp != null)                             //if this unit has an APC component attached to it
     {
         APCComp.EjectAll(destroyed);                 //remove all the units stored in the APC
     }
 }
        /// <summary>
        /// Disables the FactionEntity instance to prepare for it to be destroyed, upgraded or converted.
        /// </summary>
        /// <param name="destroyed">True if the faction entity is being disabled because it's getting destroyed, otherwise false.</param>
        public virtual void Disable(bool destroyed)
        {
            TaskLauncherComp?.CancelAllInProgressTasks(); //cancel all the in progress tasks

            APCComp?.EjectAll(destroyed);                 //remove all the units stored in the APC

            if (!free)
            {
                gameMgr.ResourceMgr.UpdateResource(factionID, disableResources); //add the disable resources to the entity's faction.
            }
        }
示例#3
0
        //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
            }
        }
示例#4
0
        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
        }