Ejemplo n.º 1
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)
    {
        base.OnWheelSelect(buildingSlot);

        // Get reference to the newly cloned building
        if (_ClonedWorldObject != null)
        {
            // Reset building time
            if (SceneManager.GetSceneByName("TutorialScene") == SceneManager.GetActiveScene())
            {
                _CurrentBuildTime = BuildingTimeTutorial;
            }
            else
            {
                _CurrentBuildTime = BuildingTime;
            }

            // Update building slot team for the outline colouring
            Building building = _ClonedWorldObject.GetComponent <Building>();
            building.AttachedBuildingSlot      = buildingSlot;
            building.AttachedBuildingSlot.Team = _ClonedWorldObject.Team;

            // Update building slot ref with building
            buildingSlot.SetBuildingOnSlot(building);
            buildingSlot.SetIsSelected(false);
            buildingSlot.SetOutlineVisibility(false);

            Base     attachedBase     = buildingSlot.AttachedBase;
            Building attachedBuilding = buildingSlot.AttachedBuilding;

            // Add the building to the buildingslot's building's queue (i know, confusing right?)
            if (buildingSlot.ObjectsCreatedAreQueued)
            {
                // Add to attached base list (if valid)
                if (attachedBase != null)
                {
                    attachedBase.AddBuildingToList(building);
                    ///attachedBase.AddToQueue(building);

                    // Get rally point reference
                    if (attachedBase.GetRallyPoint() == null)
                    {
                        attachedBase.CreateRallyPoint();
                    }
                    building._Rallypoint = attachedBase.GetRallyPoint();

                    // Add to queue wrapper
                    if (building._BuildingQueueUI != null)
                    {
                        if (!UI_BuildingQueueWrapper.Instance.ContainsQueue(building._BuildingQueueUI))
                        {
                            UI_BuildingQueueWrapper.Instance.AddNewQueue(building._BuildingQueueUI);
                        }
                        building._BuildingQueueUI.transform.SetParent(UI_BuildingQueueWrapper.Instance.QueueListTransform);
                        building._BuildingQueueUI.gameObject.SetActive(true);
                    }
                    else
                    {
                        building.CreateQueueWidget();
                    }
                }

                // Add to attached building list (if valid)
                if (attachedBuilding != null && attachedBase == null)
                {
                    if (!attachedBuilding.RemoveFromQueue(building))
                    {
                        attachedBuilding.AddToQueue(building);
                    }

                    // Add to queue wrapper
                    if (building._BuildingQueueUI != null)
                    {
                        if (!UI_BuildingQueueWrapper.Instance.ContainsQueue(building._BuildingQueueUI))
                        {
                            UI_BuildingQueueWrapper.Instance.AddNewQueue(building._BuildingQueueUI);
                        }
                        building._BuildingQueueUI.transform.SetParent(UI_BuildingQueueWrapper.Instance.QueueListTransform);
                        building._BuildingQueueUI.gameObject.SetActive(true);
                    }
                    else
                    {
                        building.CreateQueueWidget();
                    }
                }

                // Send message to match feed
                MatchFeed.Instance.AddMessage(string.Concat(ObjectName, " added to queue."));
            }

            // Skip the queue process and start building the object immediately
            else   /// (!buildingSlot.ObjectsCreatedAreQueued)

            // Remove it from the base/building's queue (WorldObject class adds it at the start!)
            {
                if (attachedBase != null)
                {
                    attachedBase.RemoveFromQueue(building);
                }
                if (attachedBuilding != null)
                {
                    attachedBuilding.RemoveFromQueue(building);
                }

                // Start building the object
                building.StartBuildingObject();
            }

            // Set rally point
            if (buildingSlot.AttachedBase != null)
            {
                _Rallypoint = buildingSlot.AttachedBase.GetRallyPoint();
            }
        }

        // Play building started sound
        SoundManager.Instance.PlaySound("SFX/_SFX_Building", 1f, 1f);
    }