示例#1
0
    void CheckSetItem(int myX, int myY, int i, bool isin)
    {
        TileBaseScript myTile = Grid.s.myTiles [myX, myY].GetComponent <TileBaseScript> ();

        if (myTile.areThereItem)
        {
            PlacedItemBaseScript myItem = myTile.myItem.GetComponent <PlacedItemBaseScript> ();
            BeltScript           myBelt = myTile.myItem.GetComponent <BeltScript> ();


            if (myItem != null)
            {
                if (isin)
                {
                    inputItems [i] = myItem;
                    myItem.outConveyors [myItem.n_out] = this;
                    myItem.n_out++;
                }
                else
                {
                    feedingItems [i] = myItem;
                    myItem.inConveyors [myItem.n_in] = this;
                    myItem.n_in++;
                }
            }
            else if (myBelt != null)
            {
                if (isin)
                {
                    inputBelts [i] = myBelt;
                    myBelt.feedingBelts [RevertLocation(i)] = this;
                }
                else
                {
                    feedingBelts [i] = myBelt;
                    myBelt.inputBelts [RevertLocation(i)] = this;
                }
            }
            else
            {
                Debug.LogError(myTile + " = " + myX + " - " + myY + "weird shit happened there");
            }
        }
    }
示例#2
0
    void _PlaceSelf()
    {
        //print ("Place self");

        GameObject           InstantiatedItem = (GameObject)Instantiate(myPlacedItem, transform.position, Quaternion.identity);
        PlacedItemBaseScript InstItemScript   = InstantiatedItem.GetComponent <PlacedItemBaseScript> ();

        foreach (GameObject thisSprite in mySprites)
        {
            ItemSprite mySprite = null;
            try{
                mySprite = thisSprite.GetComponentInChildren <ItemSprite> ();
            }catch {
            }
            if (mySprite != null)
            {
                int checkX = x - mySprite.x;
                int checkY = y - mySprite.y;

                try {
                    TileBaseScript myTile = Grid.s.myTiles [checkX, checkY].GetComponent <TileBaseScript> ();
                    //myTile.itemPlaceable = false;
                    myTile.areThereItem = true;
                    myTile.myItem       = InstantiatedItem;
                    InstItemScript.tilesCovered [InstItemScript.n_cover] = myTile;
                    InstItemScript.n_cover++;
                } catch {
                }
            }
        }

        InstItemScript.x = x;
        InstItemScript.y = y;
        //print ("destroy");
        Destroy(gameObject);
    }
示例#3
0
    void PlaceBeltsCheck()
    {
        if (Input.touchCount > 0)
        {
            Ray        myRay = mycam.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit hit   = new RaycastHit();
            if (Physics.Raycast(myRay, out hit))                                                                                        // cast the ray
            {
                TileBaseScript tileS;
                try {
                    tileS = hit.collider.gameObject.GetComponent <TileBaseScript> ();                           //hit something
                } catch {
                    return;
                }

                if (b_lastTile == tileS)                                                                                                                //is it still the same tile?
                //print ("do nothing");
                {
                    return;
                }
                if (b_lastTile != null)                                                                                                                 //how much did we moved - if too much do shit
                {
                    if (Mathf.Abs(b_lastTile.x - tileS.x) >= 2 || Mathf.Abs(b_lastTile.y - tileS.y) >= 2 || Mathf.Abs(b_lastTile.y - tileS.y) + Mathf.Abs(b_lastTile.x - tileS.x) >= 2)
                    {
                        print("we moved 2 blocks");

                        if (b_lastBelt != null)
                        {
                            b_lastBelt.UpdateGraphic();
                        }

                        b_lastBelt = null;
                        b_lastItem = null;
                        b_lastTile = null;
                    }
                }

                if (tileS.beltPlaceable)                                                        //can we place a belt here
                {
                    if (!tileS.areThereItem)                                                    //there are no items here so place a belt
                    {
                        BeltScript myBelt = ((GameObject)Instantiate(beltPrefab, tileS.transform.position, Quaternion.identity)).GetComponent <BeltScript> ();
                        myBelt.gameObject.name = myBelt.gameObject.name + " - " + n;
                        myBelt.x = tileS.x;
                        myBelt.y = tileS.y;
                        n++;
                        tileS.areThereItem = true;
                        tileS.myItem       = myBelt.gameObject;

                        if (b_lastTile != null)                                                                                                         //this is not the starting point - update in location
                        {
                            UpdateBeltInOut(b_lastTile, tileS, myBelt, true);
                        }

                        if (b_lastBelt != null)                                                                                                         //there was a belt before this one - update its out stuff
                        {
                            UpdateBeltInOut(b_lastTile, tileS, b_lastBelt, false);

                            b_lastBelt.feedingBelts [movementToArrayNum(b_lastTile, tileS)]           = myBelt;
                            myBelt.inputBelts [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastBelt;
                        }

                        if (b_lastItem != null)                                                                                                         //there was an item before us - update its out stuff
                        {
                            b_lastItem.outConveyors [b_lastItem.n_out] = myBelt;
                            b_lastItem.n_out++;
                            myBelt.inputItems [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastItem;
                        }

                        if (b_lastBelt != null)
                        {
                            b_lastBelt.UpdateGraphic();
                        }
                        if (myBelt != null)
                        {
                            myBelt.UpdateGraphic();
                        }

                        b_lastBelt = myBelt;
                        b_lastItem = null;
                        b_lastTile = tileS;
                    }
                    else                                                                                                                                                //there is an item below us
                    {
                        PlacedItemBaseScript myItem = null;
                        BeltScript           myBelt = null;
                        myItem = tileS.myItem.GetComponent <PlacedItemBaseScript> ();
                        myBelt = tileS.myItem.GetComponent <BeltScript> ();

                        if (b_lastBelt == null && b_lastItem == null)                                                                                   //nothing to something
                        //do nothing

                        {
                        }
                        else if (b_lastBelt == null && b_lastItem != null && myItem != null)                                    //item to item
                        //do nothing

                        {
                        }
                        else if (b_lastBelt == null && b_lastItem != null && myBelt != null)                                    //item to belt
                        {
                            b_lastItem.outConveyors [b_lastItem.n_out] = myBelt;
                            b_lastItem.n_out++;
                            b_lastBelt.inputItems [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastItem;
                            UpdateBeltInOut(b_lastTile, tileS, myBelt, true);
                        }
                        else if (b_lastBelt != null && b_lastItem == null && myBelt != null)                                    //belt to belt
                        {
                            UpdateBeltInOut(b_lastTile, tileS, b_lastBelt, false);
                            b_lastBelt.feedingBelts [movementToArrayNum(b_lastTile, tileS)]           = myBelt;
                            myBelt.inputBelts [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastBelt;

                            UpdateBeltInOut(b_lastTile, tileS, myBelt, true);
                        }
                        else if (b_lastBelt != null && b_lastItem == null && myItem != null)                                    //belt to item
                        {
                            UpdateBeltInOut(b_lastTile, tileS, b_lastBelt, false);
                            b_lastBelt.feedingItems [movementToArrayNum(b_lastTile, tileS)] = myItem;

                            myItem.inConveyors [myItem.n_in] = b_lastBelt;
                            myItem.n_in++;
                        }
                        else
                        {
                            Debug.LogError("weird shit happened: " + b_lastTile + " - " + tileS + " - " + b_lastBelt + " - " + b_lastItem + " - " + myBelt + " - " + myItem);
                        }

                        if (b_lastBelt != null)
                        {
                            b_lastBelt.UpdateGraphic();
                        }
                        if (myBelt != null)
                        {
                            myBelt.UpdateGraphic();
                        }

                        b_lastBelt = myBelt;
                        b_lastItem = myItem;
                        b_lastTile = tileS;
                    }
                }
            }
        }
        else
        {
            if (b_lastBelt != null)
            {
                b_lastBelt.UpdateGraphic();
            }

            b_lastBelt = null;
            b_lastItem = null;
            b_lastTile = null;
        }
    }