コード例 #1
0
    public GameObject SpawnStation(long id, StationType type, Player player, Vector3 position, Quaternion rotation, float constructionProgress, bool setActive)
    {
        if (!PlayerDatabase.Instance.IsValidPlayer(player))
        {
            throw new System.Exception("Not a valid player");
        }

        GameObject prefab = trueStationDictionary[type];

        if (prefab == null)
        {
            throw new System.Exception("Station type not supported");
        }
        else
        {
            GameObject newStation = Instantiate(prefab, position, rotation);
            PlayerDatabase.Instance.AddObjectToPlayer(newStation, player);
            newStation.GetComponent <StationController>().Station              = StationFactory.getInstance().CreateStation(type);
            newStation.GetComponent <StationController>().Constructed          = constructionProgress >= 100;
            newStation.GetComponent <StationController>().constructionProgress = constructionProgress;
            newStation.SetActive(setActive);
            newStation.name += " " + player;

            newStation.GetComponent <MapObject>().id = id;

            return(newStation);
        }
    }
コード例 #2
0
    private void Start()
    {
        if (Station == null)
        {
            Station = StationFactory.getInstance().CreateStation(stationType);
        }

        shieldRegenerator      = GetComponent <ShieldRegenerator>();
        turretManager          = GetComponent <TurretManager>();
        Station.combatStats.HP = (int)(Station.combatStats.MaxHP * constructionProgress) / 100;

        if (constructionProgress >= 100)
        {
            Constructed = true;
            EnableShieldRegeneration(true);
        }
        else
        {
            Constructed = false;
            Station.combatStats.Shields = 0;
        }
    }
コード例 #3
0
    private void OnSelectionChange(List <GameObject> selectedGOs)
    {
        foreach (Transform child in constructionSection.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        if (selectedGOs.Count == 1)
        {
            ShipConstructor constructor = selectedGOs[0].GetComponent <ShipConstructor>();

            if (constructor != null)
            {
                List <ShipConstruction> shipConstructions = constructor.ShipConstructions;
                int size = shipConstructions.Count;

                for (int i = 0; i < size; i++)
                {
                    Ship  ship            = ShipFactory.getInstance().CreateShip(shipConstructions[i].shipType);
                    float buttonPositionX = (constructionButtonPrefabOriginalPosX - 10) + (constructionButtonPrefabWidth * i) + 10; //10 It's the offset between buttons

                    GameObject button = Instantiate(constructionButtonPrefab, constructionSection.transform);

                    RectTransform rectTransform = button.GetComponent <RectTransform>();

                    rectTransform.anchoredPosition3D = new Vector3(buttonPositionX, rectTransform.localPosition.y, rectTransform.localPosition.z);

                    //Debug.Log("( " + constructionButtonPrefabOriginalPosX + "- 10 )" + " + " + "( " + constructionButtonPrefabWidth + " * " + i + ") + 10 = " + buttonPositionX);

                    button.GetComponentInChildren <RawImage>().texture = ship.shipIcon;
                    button.SetActive(true);

                    SetShipConstructionButtonClickCallback(constructor, button, shipConstructions[i]);
                }
            }
            else
            {
                StationConstructor stationConstructor = selectedGOs[0].GetComponent <StationConstructor>();
                if (stationConstructor != null)
                {
                    List <StationConstruction> stationConstructions = stationConstructor.stationConstructions;
                    int size = stationConstructions.Count;
                    for (int i = 0; i < size; i++)
                    {
                        Station station         = StationFactory.getInstance().CreateStation(stationConstructions[i].stationType);
                        float   buttonPositionX = (constructionButtonPrefabOriginalPosX - 10) + (constructionButtonPrefabWidth * i) + 10; //10 It's the offset between buttons

                        GameObject button = Instantiate(constructionButtonPrefab, constructionSection.transform);

                        RectTransform rectTransform = button.GetComponent <RectTransform>();

                        rectTransform.anchoredPosition3D = new Vector3(buttonPositionX, rectTransform.localPosition.y, rectTransform.localPosition.z);

                        //Debug.Log("( " + constructionButtonPrefabOriginalPosX + "- 10 )" + " + " + "( " + constructionButtonPrefabWidth + " * " + i + ") + 10 = " + buttonPositionX);

                        button.GetComponentInChildren <RawImage>().texture = station.stationIcon;
                        button.SetActive(true);

                        //SetShipConstructionButtonClickCallback(constructor, button, stationConstructions[i]);
                        SetStationConstructionButtonClickCallback(stationConstructor, button, stationConstructions[i]);
                    }
                }
            }

            ResearchController researchController = selectedGOs[0].GetComponent <ResearchController>();

            if (researchController != null)
            {
                List <ResearchTree> researchTrees = researchController.researchTrees;
                for (int i = 0, j = 0; i < researchTrees.Count; i++)
                {
                    if (researchTrees[i].NextNode != null)
                    {
                        float buttonPositionX = (constructionButtonPrefabOriginalPosX - 10) + (constructionButtonPrefabWidth * j) + 10; //10 It's the offset between buttons

                        GameObject button = Instantiate(constructionButtonPrefab, constructionSection.transform);

                        RectTransform rectTransform = button.GetComponent <RectTransform>();

                        float yPosition = rectTransform.position.y - 550;
                        rectTransform.anchoredPosition3D = new Vector3(buttonPositionX, yPosition, rectTransform.localPosition.z);

                        //Debug.Log("( " + constructionButtonPrefabOriginalPosX + "- 10 )" + " + " + "( " + constructionButtonPrefabWidth + " * " + i + ") + 10 = " + buttonPositionX);

                        button.GetComponentInChildren <RawImage>().texture = researchTrees[i].NextNode.research.texture;
                        button.SetActive(true);

                        //SetShipConstructionButtonClickCallback(constructor, button, stationConstructions[i]);
                        SetResearchButtonCallback(researchController, researchTrees[i], button);
                        j++;
                    }
                }
            }
        }
    }