// Update is called once per frame
    void Update()
    {
        if (this.gameObject.GetComponent <Canvas>().enabled)
        {
            //print(self.GetComponent<SpriteRenderer>().name);
            planet_img.sprite = self.GetComponent <SpriteRenderer>().sprite;
            planet_name.text  = self.name;

            if (self.GetComponent <Mine_Class>() != null)
            {
                facil[0] = self.GetComponent <Mine_Class>();
            }
            if (self.GetComponent <Shipyard_Class>() != null)
            {
                shipyard = self.GetComponent <Shipyard_Class>();
                facil[1] = shipyard;
            }
            pc = GameObject.FindObjectOfType <GameManager>().currentPlayer;
            if (self.GetComponent <SDS_Class>() != null)
            {
                facil[2] = self.GetComponent <SDS_Class>();
            }
            if (self.GetComponent <Barracks_Class>() != null)
            {
                facil[3] = (Facilities_Class)self.GetComponent <Barracks_Class>();
            }
            if (self.GetComponent <TradeCenter_Class>() != null)
            {
                facil[4] = self.GetComponent <TradeCenter_Class>();
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //print("HEY");
        if (ships.Length == 0)                                                                      //Set array length, after ships are initialized in Start
        {
            //print("Hey " + GameObject.FindObjectsOfType<Ship_Class>().Length);
            ships = new Ship_Class[GameObject.FindObjectsOfType <Ship_Class>().Length];
        }

        if (true)                                                                                   //Find selected ships to populate ships[]
        {
            int          j     = 0;
            Ship_Class[] temp2 = GameObject.FindObjectsOfType <Ship_Class>();
            foreach (Ship_Class i in temp2)
            {
                if (i != null && i.selected == true)
                {
                    ships[j] = i;
                    j++;
                }
                else
                {
                    ships[j] = null;
                }
            }
        }
        //print(selector+" "+ships[selector]);
        if (ships[selector] != null)                                                                 //If button has ship associated with it, select it
        {
            selected_ship = ships[selector];
        }
        if (selected_ship != null)
        {
            //if(part2 != null)
            //print(part2.name + " " + (selected_ship.getShipType() + "(Clone)"));
            if (part2 == null || part2.name != (selected_ship.getShipType() + "(Clone)"))
            {
                part2 = Instantiate((GameObject)Resources.Load(selected_ship.getShipType()), this.transform);
                int h = 0;
                foreach (Button i in part2.GetComponentsInChildren <Button>())
                {
                    //print("Button " + i.name + " " + h);
                    i.onClick.AddListener(() => install(int.Parse(i.name)));
                    part_view[h] = i.GetComponent <Image>();
                    h++;
                }
            }

            int u = 0;
            //part_view = new Image[selected_ship.parts_list.Length];
            foreach (Component_Class i in selected_ship.parts_list)
            {
                if (i != null)
                {
                    part_view[u].sprite = i.getSprite();
                }
                u++;
            }
        }
        //print("What up?");
        if (Ship_list[0].GetComponentInParent <Canvas>().enabled == true)                            //If Canvas enabled, update UI
        {
            if (selected_ship != null)
            {
                Ship_list[0].text = selected_ship.name;
            }
            int k = 0;
            //print("YO " + ships[0]);
            foreach (Ship_Class i in ships)                                                         //Populate text for ships list
            {
                //print("YOU " + i.name);
                if (Ship_list[k + 1] != null)
                {
                    //print("In if "+ships[k].name);
                    if (ships[k] != null)
                    {
                        //print("Fill text box "+Ship_list[k+1].name+ " with "+i.name);
                        Ship_list[k + 1].text = i.name;
                        k++;
                    }
                    else
                    {
                        Ship_list[k + 1].text = "";
                    }
                }
            }

            //print(selected_ship);
            if (selected_ship != null)                                                             //If Canvas enabled and ship is selected,
            {                                                                                      //Find faction Shipyard and available components
                bool             temp3 = true;
                Shipyard_Class[] temp;
                temp = GameObject.FindObjectsOfType <Shipyard_Class>();
                foreach (Shipyard_Class i in temp)
                {
                    if (selected_ship.pos == i.GetComponent <Transform>().position&& i.faction == selected_ship.faction)
                    {
                        print("truw");
                        inRange = i.component_storage;
                        current = i;
                        temp3   = false;
                    }
                }
                if (temp3 == true)                                                                       //If no shipyard found, set to -1
                {
                    inRange = new int[] { -1, -1, -1, -1, -1, -1, -1, -1 };
                    current = null;
                }
            }
            int p = 0;
            foreach (int i in inRange)
            {
                parts_avail[p].text = "" + i;
                p++;
            }
        }
    }