Ejemplo n.º 1
0
    //******************************************************************************************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************************************************************************************

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        // Update building reference
        _BuildingToRecycle = buildingSlot.GetBuildingOnSlot();

        // Valid building check
        if (_BuildingToRecycle != null)
        {
            // Show the confirm screen popup
            GameObject confirmScreen = GameManager.Instance.ConfirmRecycleScreen;
            if (confirmScreen != null)
            {
                UI_RecycleScreenConfirmation recycleScreen = confirmScreen.GetComponent <UI_RecycleScreenConfirmation>();
                if (recycleScreen != null)
                {
                    recycleScreen.SetBuildingSlotInFocus(buildingSlot);
                    recycleScreen.SetBuildingToRecycle(_BuildingToRecycle);
                    recycleScreen.SetRecycleClass(this);
                    recycleScreen.gameObject.SetActive(true);
                }
            }
        }
        else
        {
            Debug.Log("_BuildingToRecycle == null");
        }
    }
Ejemplo n.º 2
0
    public void BuildGroundBuildingSlots()
    {
        Debug.Log("Building building slots.");
        float stepAngle = 2 * Mathf.PI / nbStartBuildingSlots;
        float radius    = mainPlanet.transform.localScale.x / 2;

        //Debug.Log("StepAngle: " + stepAngle + " | Rayon: " + radius);

        for (int i = 0; i < nbStartBuildingSlots; i++)
        {
            float   angle = stepAngle * i;
            Vector3 pos   = new Vector3(Mathf.Cos(angle) * radius, Mathf.Sin(angle) * radius, mainPlanet.transform.position.z);

            GameObject instantiatedSlot = Instantiate(buildingSlotPrefab, pos, Quaternion.identity);
            instantiatedSlot.transform.SetParent(buildingSlotsParent.transform);

            groundBuildingSlots.Add(instantiatedSlot);
            allBuildingSlots.Add(instantiatedSlot);

            BuildingSlot bs = instantiatedSlot.GetComponent <BuildingSlot>();
            bs.id           = (100 + i);
            bs.locationType = BuildingManager.BuildingType.BuildingLocationType.Planet;
            bs.SetDefaultColor();
            bs.angleRad = stepAngle * i;
        }

        ResetAllBuildingSlotsColor();
    }
Ejemplo n.º 3
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    /// <param name="buildingSlot"></param>
    private void AddBaseToQueue(BuildingSlot buildingSlot)
    {
        // Create the base and initialize it
        base.OnWheelSelect(buildingSlot);
        _ClonedWorldObject.SetClonedObject(_ClonedWorldObject);
        _ClonedWorldObject.GetComponent <Base>()._PreviousBase = _PreviousBase;

        // Start building the base (if were meant to)
        Base attachedBase = buildingSlot.AttachedBase; /// previous base

        if (attachedBase != null)
        {
            // This base is at the front of the queue
            if (attachedBase.GetBuildingQueue()[0] == _ClonedWorldObject)
            {
                // Start building it
                StartBuildingObject(buildingSlot);
            }
        }

        // Set matching team for all the building slots
        for (int i = 0; i < DepotSlots.Count; i++)
        {
            DepotSlots[i].Team    = Team;
            DepotSlots[i]._Player = _Player;
        }
        for (int i = 0; i < TowerSlots.Count; i++)
        {
            TowerSlots[i].Team    = Team;
            TowerSlots[i]._Player = _Player;
        }
    }
Ejemplo n.º 4
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        // Gets reference to the original base (before the upgrade)
        if (buildingSlot != null)
        {
            if (buildingSlot.AttachedBase != null)
            {
                _PreviousBase = buildingSlot.AttachedBase;
            }
        }

        if (_PreviousBase != null)
        {
            // Cant stack base upgrades
            if (!_PreviousBase._UpgradingBase)
            {
                AddBaseToQueue(buildingSlot);
            }
            _PreviousBase._UpgradingBase = true;
        }
        else
        {
            AddBaseToQueue(buildingSlot);
        }
    }
Ejemplo n.º 5
0
    public void SelectBuildingLocation(BuildingSlot buildingSpot = null)
    {
        // Tutorial indicator //
        TutorialManager.instance.DisplayIndicator(TutorialManager.IndicatorID.select_building_spot, false);
        //TutorialManager.instance.DisplayIndicator(TutorialManager.IndicatorID.protect_people, false);
        //TutorialManager.instance.DisplayIndicator(TutorialManager.IndicatorID.protect_people, false);
        TutorialManager.instance.DisplayIndicatorIfNotDisplayedYet(TutorialManager.IndicatorID.select_building);
        // ------------------ //

        // Chose Building Spot
        //chosenBuildingSlot = SelectBuildingSpotFromTouch(); // OLD

        if (buildingSpot != null)
        {
            chosenBuildingSlot = buildingSpot.gameObject;
        }

        if (chosenBuildingSlot != null)
        {
            BuildingSlotManager.instance.ResetAllBuildingSlotsColor();
            SurroundingAreasManager.instance.ResetAllSatelliteBuildingSlotsColor();

            buildingSpot.SetSelectionColor();

            // Display Build button if we can pay for the building
            UpdateBuildingState(1);
        }
        else
        {
            Debug.Log("SelectBuildingLocation | chosenBuildingSlot null");
        }
    }
Ejemplo n.º 6
0
    private void BuildBuildingOption(BuildingSlot bs)
    {
        //Create the UI:
        GameObject panelBuildingDetails = (GameObject)Instantiate(panelBuildingDetailsPrefab);

        panelBuildingDetails.transform.SetParent(content.transform);
        BuildingOption buildingOption = panelBuildingDetails.GetComponent <BuildingOption>();

        //Get the BuildingOption script and set Gameplay values:
        buildingOption.buildingSlotInfos = bs;
        buildingOption.setBuildingName(bs.Name);
        buildingOption.setBuildingSprite(Resources.Load <Sprite>(bs.Image));


        int numberOfResourcesNeedeed = bs.Resources.Resource.Count;

        for (int i = 0; i < numberOfResourcesNeedeed; i++)
        {
            GameObject panelResourcesNeededGo = panelResourcesNeededGo = (GameObject)Instantiate(panelResourcesNeedeedPrefab);
            panelResourcesNeededGo.transform.SetParent(panelBuildingDetails.transform);
            panelResourcesNeededGo.transform.localPosition = new Vector2(200 + (i * 80), -20);
            buildingOption.addPanelResourcesNeeded(panelResourcesNeededGo.GetComponent <PanelResourceNeeded>());
            BuildingResource br = bs.Resources.Resource[i];
            buildingOption.addResource((UsableObject)Activator.CreateInstance(Type.GetType(br.Text), 4), Convert.ToInt32(br.Quantity));
        }

        //Populate the UI:
        buildingOption.populateUI();
    }
Ejemplo n.º 7
0
        public BuildingSlot GetClosestSlot(Vector3 position, BuildingSlotType slotType, bool forPlacement, out float closestDistance)
        {
            closestDistance = float.MaxValue;
            BuildingSlot closestSlot = null;

            foreach (var slot in _slots)
            {
                if (slot.type != slotType && slotType != BuildingSlotType.All)
                {
                    continue;
                }

                if (forPlacement && slot.ignoreForPlacement)
                {
                    continue;
                }

                var dist = (slot.transform.position - position).sqrMagnitude;
                if (dist < closestDistance)
                {
                    closestDistance = dist;
                    closestSlot     = slot;
                }
            }
            return(closestSlot);
        }
Ejemplo n.º 8
0
    public void Build(BuildingSlot buildingSlotInfos)
    {
        GameObject bulidingToBuild = null;

        if (buildingSlotInfos.Prefab != null)
        {
            bulidingToBuild = Resources.Load <GameObject>("BuildingPrefabs/" + buildingSlotInfos.Prefab);
        }

        if (bulidingToBuild != null)
        {
            GameObject building = GameObject.Instantiate(bulidingToBuild);

            Vector3 buildingModificators = building.transform.position;
            building.transform.position = this.lastSelectedBuilding.transform.position + buildingModificators;

            Vector3 lastSelectedBuildingRotation = this.lastSelectedBuilding.transform.eulerAngles;
            building.transform.Rotate(lastSelectedBuildingRotation);

            GameObject.Destroy(this.lastSelectedBuilding.gameObject);
            OptionalBuilding ob = building.GetComponent <OptionalBuilding>();
            ob.InitBuilding(EntitiesController.INSTANCE.getPlayer());
        }
        else
        {
            Debug.LogWarning("Prefab not found for " + buildingSlotInfos.Name);
        }
    }
Ejemplo n.º 9
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    public void HideWidget()
    {
        _BuildingToRecycle    = null;
        _BuildingSlotInFocus  = null;
        _RecycleBuildingClass = null;
        gameObject.SetActive(false);
    }
Ejemplo n.º 10
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Starts the construction process of this abstraction.
    /// </summary>
    public virtual void StartBuildingObject(BuildingSlot buildingSlot = null)
    {
        _ObjectState = WorldObjectStates.Building;

        // Send message to match feed
        MatchFeed.Instance.AddMessage(string.Concat(ObjectName, " started construction."));
    }
Ejemplo n.º 11
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    ///
    /// </summary>
    /// <param name="selectable"></param>
    public void UpdateListWithBuildables(List <Abstraction> selectable, BuildingSlot buildingSlotInFocus)
    {
        _BuildingSlotInstigator = buildingSlotInFocus;

        // Reset button click events for all buttons
        foreach (var button in _WheelButtons)
        {
            // Icon button defaults
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => RefreshButtons(selectable));

            // Update slice button defaults
            Button slice = button.GetComponent <SelectionWheelUnitRef>().RadialSliceButton;
            slice.onClick.RemoveAllListeners();
            slice.onClick.AddListener(() => RefreshButtons(selectable));
        }

        // Clear list & update
        _BuildingList.Clear();
        int i = 0;

        foreach (var obj in selectable)
        {
            if (obj != null)
            {
                // If slot is an upgrade
                UpgradeTree upgrade = obj.GetComponent <UpgradeTree>();
                if (upgrade != null)
                {
                    // Dont update wheel with this button since its the upgrade is maxed out
                    if (upgrade.HasMaxUpgrade())
                    {
                        continue;
                    }
                }

                // Update list with new slots
                _BuildingList.Add(obj);

                // Update reference unit
                SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                unitRef.AbstractRef = obj.GetComponent <Abstraction>();

                // Update button click event
                _WheelButtons[i].onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
                unitRef.RadialSliceButton.onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
            }

            // No selectable reference for this button item so give it an empty slot description
            else
            {
                // Update reference unit
                SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                unitRef.AbstractRef = null;
            }
            ++i;
        }
        RefreshButtons(selectable);
    }
Ejemplo n.º 12
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Sets the position of the object based on what building slot has been passed through.
    /// </summary>
    /// <param name="buildingSlot"><
    //  The building slot that is being used as reference for positioning.
    /// /param>
    protected void SetBuildingPosition(BuildingSlot buildingSlot)
    {
        // Initial transform update
        transform.SetPositionAndRotation(buildingSlot.transform.position, buildingSlot.transform.rotation);

        // Add offset
        transform.position = new Vector3(transform.position.x, transform.position.y + _OffsetY, transform.position.z);
    }
Ejemplo n.º 13
0
 public static void RegisterBuildingSlot(BuildingSlot buildingSlot)
 {
     if (instance.buildingSlots == null)
     {
         instance.buildingSlots = new List <BuildingSlot>();
     }
     instance.buildingSlots.Add(buildingSlot);
 }
    private void Deselect()
    {
        _selectedBuildingSlot.Deselect();
        _gameSystem.UIController.HideBuildMenu();
        _gameSystem.UIController.HideUpgradeMenu();

        _isBuildingSlotSelected = false;
        _selectedBuildingSlot   = null;
    }
Ejemplo n.º 15
0
 public void ClearBuildingModules()
 {
     foreach (GameObject go in mSlots)
     {
         BuildingSlot slot = go.GetComponent <BuildingSlot>();
         slot.ClearSlot();
     }
     mEmptySlots = mBuildingWidth * mBuildingHeight; // reinit to empty
 }
Ejemplo n.º 16
0
 public SlotViewModel(Province province, Region region, BuildingSlot slot)
 {
     this.slot             = slot;
     this.region           = region;
     this.province         = province;
     this.Buildings        = new ObservableCollection <BuildingLevel>();
     this.selectedBuilding = slot.Building;
     this.seek             = false;
 }
Ejemplo n.º 17
0
    //******************************************************************************************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************************************************************************************

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        base.OnWheelSelect(buildingSlot);

        // Call the OnWheelSelect() function in the attached minefield wrapper
        if (_MineFieldAttached != null)
        {
            _MineFieldAttached.OnWheelSelect(buildingSlot);
        }
    }
Ejemplo n.º 18
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        // Gets reference to the original turret (before the upgrade)
        BaseTurret originalTurret = null;

        if (buildingSlot != null)
        {
            if (buildingSlot.GetBuildingOnSlot() != null)
            {
                originalTurret = buildingSlot.GetBuildingOnSlot().GetComponent <BaseTurret>();
            }
        }

        // Remove old healthbar (if valid)
        float hitpoints = MaxHitPoints;

        if (originalTurret != null)
        {
            hitpoints = originalTurret.GetHitPoints();
            if (originalTurret._HealthBar != null)
            {
                ObjectPooling.Despawn(originalTurret._HealthBar.gameObject);
            }
        }

        // Create weapon
        if (_TowerWeapon != null)
        {
            _TowerWeapon = ObjectPooling.Spawn(_TowerWeapon.gameObject).GetComponent <Weapon>();
        }

        // Start building process
        base.OnWheelSelect(buildingSlot);
        if (_ClonedWorldObject != null)
        {
            // Only proceed if there was a previous building & we're upgrading from that
            if (originalTurret != null)
            {
                // Update player ref
                _ClonedWorldObject.SetPlayer(originalTurret._Player);

                // Set the new base's building state object to be the currently active object
                _ClonedWorldObject.BuildingState = originalTurret.gameObject;
            }

            // Update attached building slot turret reference
            if (buildingSlot != null)
            {
                buildingSlot.SetBuildingOnSlot(_ClonedWorldObject.GetComponent <BaseTurret>());
            }

            // Reset turret's health
            _ClonedWorldObject.SetHitPoints(_ClonedWorldObject.MaxHitPoints);
        }
    }
Ejemplo n.º 19
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Starts the construction process of this building.
    /// </summary>
    /// <param name="buildingSlot"></param>
    public override void StartBuildingObject(BuildingSlot buildingSlot = null)
    {
        base.StartBuildingObject(buildingSlot);

        // Determine build time
        if (_Player != null)
        {
            UpgradeManager upgradeManager = _Player.GetUpgradeManager();
            BuildingTime *= (int)upgradeManager._BuildingSpeedMultiplier;
        }
    }
Ejemplo n.º 20
0
    private void SetPlaceability()
    {
        isPlaceable = false;
        Vector3    origin = new Vector3(transform.position.x, 100f, transform.position.z);
        RaycastHit hit;

        if (Physics.Raycast(origin, Vector3.down, out hit, 200f, LayerMask.GetMask(new string[] { "BuildingArea" })))
        {
            BuildingSlot bS = hit.collider.GetComponent <BuildingSlot> ();
            if (bS.species == player.species && !bS.isOccupied)
            {
                transform.position = bS.transform.position;
                currBuildingSlot   = bS;
                Collider[] colls = Physics.OverlapSphere(transform.position, buildingRadius, GameManager.woLayerMask);
                if (colls.Length == 0)
                {
                    isPlaceable = true;
                }
                else if (searchTimer > 1f)
                {
                    foreach (Collider coll in colls)
                    {
                        MobileWorldObject wO = coll.GetComponent <MobileWorldObject>();
                        if (wO && wO.GetSpecies() == player.species && !wO.isMoving && !wO.attacking)
                        {
                            Vector3 buildingPos = new Vector3(transform.position.x, 0f, transform.position.z);
                            Vector3 woPos       = new Vector3(wO.transform.position.x, 0f, wO.transform.position.z);
                            if (woPos == buildingPos)
                            {
                                woPos += new Vector3(Random.Range(-1f, 1f), 0f, Random.Range(-1f, 1f));
                            }
                            Vector3 moveVector  = woPos - buildingPos;
                            float   distance    = buildingRadius + (wO.mainCollider as SphereCollider).radius - moveVector.magnitude + 1f;
                            Vector3 destination = wO.transform.position + moveVector.normalized * distance;
                            wO.SetNavAgentDestination(destination, distance + moveVector.magnitude);
                        }
                    }
                    searchTimer = 0f;
                }
            }
        }
        else
        {
            currBuildingSlot = null;
        }
        if (isPlaceable)
        {
            thisRenderer.material.color = activeSpriteColor;
        }
        else
        {
            thisRenderer.material.color = inactiveSpriteColor;
        }
    }
    private void InitializeBuildingSlotes()
    {
        _buildingSlotsContainer = _gameSystem.MapController.CurrentLevel.BuildingSlots;
        foreach (Transform go in _buildingSlotsContainer)
        {
            BuildingSlot buildingSlot = go.GetComponent <BuildingSlot>();
            buildingSlot.Initialize(_gameSystem);

            _buildingSlots.Add(buildingSlot);
        }
    }
Ejemplo n.º 22
0
    public void EnableTempBuilding(string buildingname)
    {
        gameObject.SetActive(true);
        Building newBuilding = GameManager.GetGameObject(buildingname).GetComponent <Building>();

        spriteRenderer.sprite = GameManager.mainSpriteDick[newBuilding.name];
        buildingRadius        = newBuilding.GetComponent <SphereCollider> ().radius;
        transform.localScale  = newBuilding.GetComponentsInChildren <SpriteParent> (true) [0].transform.localScale;
        name             = buildingname;
        currBuildingSlot = null;
        GameManager.HumanPlayer.userInput.enabled = false;
    }
Ejemplo n.º 23
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    ///
    /// </summary>
    /// <param name="selectables"></param>
    public void UpdateListWithBuildings(List <Abstraction> selectables, BuildingSlot buildingSlotInFocus)
    {
        _BuildingSlotInstigator = buildingSlotInFocus;

        // Reset button click events for all buttons
        foreach (var button in _WheelButtons)
        {
            // Icon button defaults
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => HideSelectionWheel());

            // Update slice button defaults
            Button slice = button.GetComponent <SelectionWheelUnitRef>().RadialSliceButton;
            slice.onClick.RemoveAllListeners();
            slice.onClick.AddListener(() => HideSelectionWheel());
        }

        // Clear list & update
        _BuildingList.Clear();
        int i = 0;

        foreach (var obj in selectables)
        {
            if (obj != null)
            {
                // Update list with new slots
                Building building = obj.GetComponent <Building>();
                if (building != null)
                {
                    _BuildingList.Add(building);

                    // Update reference unit
                    SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                    unitRef.AbstractRef = building;

                    // Update button click event
                    _WheelButtons[i].onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
                    unitRef.RadialSliceButton.onClick.AddListener(delegate { unitRef.AbstractRef.OnWheelSelect(buildingSlotInFocus); });
                }
            }

            // No selectable reference for this button item so give it an empty slot description
            else
            {
                // Update reference unit
                SelectionWheelUnitRef unitRef = _WheelButtons[i].GetComponent <SelectionWheelUnitRef>();
                unitRef.AbstractRef = null;
            }
            ++i;
        }
        RefreshButtons(selectables);
    }
    public void DisplayBuilding(BuildingSlot buildingSlot)
    {
        this.currentSlot         = buildingSlot;
        BuildingName.text        = buildingSlot.Name;
        BuildingDesc.text        = buildingSlot.building.Description;
        buildButton.interactable = buildingSlot.IsAvailable;
        ClearResourceRows();

        foreach (Building.BuildingCost cost in currentSlot.building.buildingCosts)
        {
            CreateResourceRow(cost.resource, cost.amount);
        }
    }
Ejemplo n.º 25
0
    //******************************************************************************************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************************************************************************************

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        base.OnWheelSelect(buildingSlot);

        // Detonate all known mines on the attached minefield
        MineField mineField = buildingSlot.GetBuildingOnSlot() as MineField;

        for (int i = 0; i < mineField.GetUndetonatedMines().Count; i++)
        {
            Mine mine = mineField.GetUndetonatedMines()[i];
            mine.DetonateMine();
        }
    }
Ejemplo n.º 26
0
    public void Select(BuildingSlot buildingSlot)
    {
        touchMode            = TouchMode.BUILDING_SELECTED;
        selectedBuildingSlot = buildingSlot;
        foreach (BuildingSlot buildingSlotToHide in buildingSlots)
        {
            buildingSlotToHide.HideIndicator();
        }
        selectedBuildingSlot.ShowIndicator();

        UIController.SetUpgradeButton(selectedBuildingSlot.child);
        UIController.SetPanel(UIController.Panel.BUILDING_SELECTED);
    }
    private BuildMenuData GetMenuData(BuildingSlot slot)
    {
        BuildMenuData menuData = new BuildMenuData();

        menuData.position = Camera.main.WorldToScreenPoint(slot.transform.position);
        if (slot.Occupied)
        {
            menuData.BuildingData     = _buildingsData[slot.Building.Type];
            menuData.BuildingLevel    = slot.Building.Level;
            menuData.MaxBuildingLevel = _buildingsData[slot.Building.Type].MaxLevel;
        }

        return(menuData);
    }
Ejemplo n.º 28
0
    // Start is called before the first frame update
    void Start()
    {
        for (int i = contentList.transform.childCount - 1; i >= 0; i--)
        {
            Destroy(contentList.transform.GetChild(i).gameObject);
        }

        foreach (var building in buildings)
        {
            BuildingSlot slot = Instantiate(buildingSlotPrefab, contentList.transform);
            slot.SetBuilding(building);
            slot.Init();
        }
    }
Ejemplo n.º 29
0
 private void InitPlants()
 {
     PlantPanel = GameObject.Find("PlantPanel");
     plantSlots = new List <BuildingSlot>();
     for (int i = 0; i < GameManager.instance.GetPlantCount(); i++)
     {
         GameObject   slot       = Instantiate(prefabBuildingSlot, PlantPanel.transform);
         BuildingSlot plantSlot  = slot.GetComponent <BuildingSlot>();
         Button       slotButton = slot.GetComponent <Button>();
         slotButton.onClick.AddListener(delegate { CreatePlant(plantSlot.objectId); });
         plantSlot.InitPlant(GameManager.instance.Plants[i].GetComponent <AbstractPlant>().buildingData);
         plantSlots.Add(plantSlot);
     }
 }
Ejemplo n.º 30
0
    //******************************************************************************************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************************************************************************************

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        // Gets reference to the original generator (before the upgrade)
        Generator originalGenerator = null;

        if (buildingSlot != null)
        {
            if (buildingSlot.GetBuildingOnSlot() != null)
            {
                originalGenerator = buildingSlot.GetBuildingOnSlot().GetComponent <Generator>();
            }
        }

        // Remove old healthbar (if valid)
        float hitpoints = MaxHitPoints;

        if (originalGenerator != null)
        {
            hitpoints = originalGenerator.GetHitPoints();
            if (originalGenerator._HealthBar != null)
            {
                ObjectPooling.Despawn(originalGenerator._HealthBar.gameObject);
            }
        }

        // Start building process
        base.OnWheelSelect(buildingSlot);
        if (_ClonedWorldObject != null)
        {
            // Only proceed if there was a previous building and we are upgrading from that
            if (originalGenerator != null)
            {
                // Update player ref
                _ClonedWorldObject.SetPlayer(originalGenerator._Player);

                // Set the new bases building state object to be the currently active object
                _ClonedWorldObject.BuildingState = originalGenerator.gameObject;
            }

            // Update attached buildingSlot generator reference
            if (buildingSlot != null)
            {
                buildingSlot.SetBuildingOnSlot(_ClonedWorldObject.GetComponent <Generator>());
            }

            // Reset building's health
            _ClonedWorldObject.SetHitPoints(_ClonedWorldObject.MaxHitPoints);
        }
    }