示例#1
0
        public override void Init(GameManager gameMgr, int fID, bool free)
        {
            base.Init(gameMgr, fID, free);

            //get the building-specifc components:
            PlacerComp       = GetComponent <BuildingPlacer>();
            HealthComp       = GetComponent <BuildingHealth>();
            NavObstacle      = GetComponent <NavMeshObstacle>();
            BoundaryCollider = GetComponent <Collider>();
            BorderComp       = GetComponent <Border>();
            DropOffComp      = GetComponent <BuildingDropOff>();
            WorkerMgr        = GetComponent <WorkerManager>();
            PortalComp       = GetComponent <Portal>();
            GeneratorComp    = GetComponent <ResourceGenerator>();
            AllAttackComp    = GetComponents <BuildingAttack>();

            //initialize them:
            PlacerComp.Init(gameMgr, this);
            foreach (BuildingAttack comp in AllAttackComp) //init all attached attack components
            {
                if (AttackComp == null)
                {
                    AttackComp = comp;
                }

                comp.Init(gameMgr, this, MultipleAttackMgr);
            }
            if (MultipleAttackMgr)
            {
                MultipleAttackMgr.Init(this);
            }
            WorkerMgr.Init();

            if (BoundaryCollider == null) //if the building collider is not set.
            {
                Debug.LogError("[Building]: The building parent object must have a collider to represent the building's boundaries.");
            }
            else
            {
                BoundaryCollider.isTrigger = true; //the building's main collider must always have "isTrigger" is true.
            }
            RallyPoint = gotoPosition;             //by default the rally point is set to the goto position
            if (gotoPosition != null)              //Hide the goto position
            {
                gotoPosition.gameObject.SetActive(false);
            }

            if (Placed == false) //Disable the player selection collider object if the building has not been placed yet.
            {
                selection.gameObject.SetActive(false);
            }

            if (placedByDefault == false)                   //if the building is not placed by default.
            {
                PlaneRenderer.material.color = Color.green; //start by setting the selection texture color to green which implies that it's allowed to place building at its position.
            }
            //if this is no plaement instance:
            if (!PlacementInstance)
            {
                PlacerComp.PlaceBuilding();                                      //place the building
                if (GodMode.Enabled && FactionID == GameManager.PlayerFactionID) //if god mode is enabled and this is the local player's building
                {
                    placedByDefault = true;
                }
            }

            if (placedByDefault) //if the building is supposed to be placed by default or we're in god mode and this is the player's building -> meaning that it is already in the scene
            {
                HealthComp.AddHealthLocal(HealthComp.MaxHealth, null);
            }
        }
示例#2
0
 private BuildingAttack[] AllAttackComp = new BuildingAttack[0]; //holds all of the attack components attached to this unit
 public override void UpdateAttackComp(AttackEntity attackEntity)
 {
     AttackComp = (BuildingAttack)attackEntity;
 }