예제 #1
0
파일: Unit.cs 프로젝트: FarmLifeTeam/XDemo
 //See if the unit is in idle state or not:
 public bool IsIdle()
 {
     return(!(MovementComp.IsMoving() ||
              (BuilderComp && BuilderComp.IsActive()) ||
              (CollectorComp && CollectorComp.IsActive()) ||
              (AttackComp && AttackComp.IsActive() && AttackComp.Target != null) ||
              (HealerComp && HealerComp.IsActive()) ||
              (ConverterComp && ConverterComp.IsActive())));
 }
예제 #2
0
파일: Unit.cs 프로젝트: FarmLifeTeam/XDemo
 public void CancelJob(jobType job)
 {
     if (AttackComp && (job == jobType.all || job == jobType.attack))
     {
         AttackComp.Stop();
     }
     if (BuilderComp && (job == jobType.all || job == jobType.building))
     {
         BuilderComp.Stop();
     }
     if (CollectorComp && (job == jobType.all || job == jobType.collecting))
     {
         CollectorComp.CancelDropOff();
         CollectorComp.Stop();
     }
     if (HealerComp && (job == jobType.all || job == jobType.healing))
     {
         HealerComp.Stop();
     }
     if (ConverterComp && (job == jobType.all || job == jobType.converting))
     {
         ConverterComp.Stop();
     }
 }
예제 #3
0
파일: Unit.cs 프로젝트: FarmLifeTeam/XDemo
        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
        }