Пример #1
0
        //called to activate the border
        public void Init(GameManager gameMgr, Building building)
        {
            //if the border is already active
            if (IsActive == true)
            {
                return; //do not proceed
            }
            this.gameMgr  = gameMgr;
            this.building = building;            //get the building that is controlling this border component
            buildingsInRange.Add(this.building); //add source buildings to buildings in range list

            Order = gameMgr.BuildingMgr.LastBorderSortingOrder;

            if (spawnObj == true)                                                                                                                //if it's allowed to spawn the border object
            {
                obj = (GameObject)Instantiate(obj, new Vector3(transform.position.x, height, transform.position.z), Quaternion.identity);        //create the border obj
                obj.transform.localScale = new Vector3(Size * sizeMultiplier, obj.transform.localScale.y, Size * sizeMultiplier);                //set the correct size for the border obj
                obj.transform.SetParent(transform, true);                                                                                        //make sure it's a child object of the building main object

                Color FactionColor = gameMgr.GetFaction(this.building.FactionID).GetColor();                                                     //set its color to the faction that it belongs to
                obj.GetComponent <MeshRenderer>().material.color = new Color(FactionColor.r, FactionColor.g, FactionColor.b, colorTransparency); //set the color transparency

                obj.GetComponent <MeshRenderer>().sortingOrder = Order;                                                                          //set the border object's sorting order according to the previosuly placed borders
            }

            CheckAllResources();                  //check the resources around the border

            IsActive = true;                      //mark the border as active

            CustomEvents.OnBorderActivated(this); //trigger custom event
        }