コード例 #1
0
 //This method will run when subsequent node check is successful
 //This will first remove the ownerships information on all tiles  for current object
 //Then the next method will apply the ownership for the new placed tiles
 public void ClearOtherTilesOwnershipWhenSuccess()
 {
     //Loop through all tiles and clear my name
     for (int m = 0; m < mGridManager.transform.childCount; m++)
     {
         IndividualTile currentTileChecking = mGridManager.transform.GetChild(m).gameObject.GetComponent <IndividualTile>();
         if (currentTileChecking.objectThatOccupiedMySpace == gameObject)
         {
             currentTileChecking.objectThatOccupiedMySpace = null;
         }
     }
 }
コード例 #2
0
 //Update all tile's ownership on current tile and subsequent tiles that occupy by bodyparts
 //This will be ran when the placement is successful
 public void UpdateTileOwnership(Vector2Int droppedTile)
 {
     for (int m = 0; m < mGridManager.transform.childCount; m++)
     {
         for (int l = 0; l < myNodesDisplacements.Length; l++)
         {
             Vector2Int     tempDisplacedNodePosition = droppedTile + myNodesDisplacements[l];
             IndividualTile currentTileChecking       = mGridManager.transform.GetChild(m).gameObject.GetComponent <IndividualTile>();
             if (currentTileChecking.myTile == tempDisplacedNodePosition)
             {
                 currentTileChecking.objectThatOccupiedMySpace = gameObject;
             }
         }
     }
 }
コード例 #3
0
    //This method will be run when placement of item fails
    //Case 1: When an item is occupying one slot
    //Case 2: When you release the item in a non tile place
    //This functions resets all occupied node information on both tiles and item itself
    public void ZeroAllTileDataForThisItem()
    {
        // :( Foreach didn't work, so have to be ugly
        //Reset all item tile index to -1
        SingleGridOccupied = new Vector2Int(-5, -5);
        for (int k = 0; k < allMyPoints.Length; k++)
        {
            allMyPoints[k] = new Vector2Int(-5, -5);
        }

        GetComponent <ItemScript>().SetItemPosition(new Vector2Int(-5, -5));        //reset the itemscript vects as well
        //Loop through all tiles and clear my name
        //You guys are adopted and I'm not your dad //meat source
        for (int m = 0; m < mGridManager.transform.childCount; m++)
        {
            IndividualTile currentTileChecking = mGridManager.transform.GetChild(m).gameObject.GetComponent <IndividualTile>();
            if (currentTileChecking.objectThatOccupiedMySpace == gameObject)
            {
                currentTileChecking.objectThatOccupiedMySpace = null;
            }
        }
    }
コード例 #4
0
    //Checkng if your placement will be successful
    //Given your currently focused node, check all other nodes from your body parts
    public void CheckSubsequentPoints(Vector2Int droppedTile)
    {
        //If there is no starting position for furniture, check is not needed
        //print(droppedTile);
        if (droppedTile == new Vector2Int(-5, -5))
        {
            //Debug.Log("Skipping Check: " + gameObject.name);
            return;
        }
        //Added Ndoe Checked count to make sure all nodes are checked
        //If not all nodes are checked, fail
        //This prevents number of tiles limiting range of checking
        int nodesChecked = 0;

        for (int m = 0; m < mGridManager.transform.childCount; m++)
        {
            //Loop through all my displacements
            for (int l = 0; l < myNodesDisplacements.Length; l++)
            {
                //Getting the set of index that matters
                Vector2Int     tempDisplacedNodePosition = droppedTile + myNodesDisplacements[l];
                IndividualTile currentTileChecking       = mGridManager.transform.GetChild(m).gameObject.GetComponent <IndividualTile>();
                //Check if
                //1. the tile we are checking is the tile we are trying to occupy
                //2. If there is something already occupying  it
                //3, and the owner who is occupying it is not me
                if (currentTileChecking.myTile == tempDisplacedNodePosition &&
                    currentTileChecking.objectThatOccupiedMySpace != null &&
                    currentTileChecking.objectThatOccupiedMySpace != gameObject)
                {
                    //Report the placement failure
                    Debug.Log("Something in the node");
                    Debug.Log("CurrentTile: " + currentTileChecking.myTile.ToString());
                    Debug.Log("Node Owner: " + currentTileChecking.objectThatOccupiedMySpace.ToString());

                    //Reverse bool to stop the placement from continuing on top
                    detectSuccess = false;
                    return;
                }
                if (currentTileChecking.myTile == tempDisplacedNodePosition)
                {
                    nodesChecked += 1;
                    // Debug.Log("Checking Tile: " + currentTileChecking.myTile + " GridSize: " + mGridManager.GetComponent<GridManager>().GetGridSize());
                    //Check all tiles, see if they are out of bound
                    if (currentTileChecking.myTile.x > mGridManager.GetComponent <GridManager>().GetGridSize().x - 1 ||
                        currentTileChecking.myTile.x < 0 ||
                        currentTileChecking.myTile.y > mGridManager.GetComponent <GridManager>().GetGridSize().y - 1 ||
                        currentTileChecking.myTile.y < 0)
                    {
                        //Report the placement failure
                        Debug.Log("Something in the node");
                        Debug.Log("CurrentTile: " + currentTileChecking.myTile.ToString());
                        Debug.Log("Node Owner: " + currentTileChecking.objectThatOccupiedMySpace.ToString());

                        //Reverse bool to stop the placement from continuing on top
                        detectSuccess = false;
                        return;
                    }
                }
            }
        }

        //If nodes are not fully checked, fail as well
        if (nodesChecked != myNodesDisplacements.Length)
        {
            //Reverse bool to stop the placement from continuing on top
            Debug.Log("Nodes Aren't Fully Checked");
            detectSuccess = false;
        }
    }
コード例 #5
0
    //Handles all the actions when an item is dropped onto a tile
    public void DetectDroppedTiles()
    {
        //Boolean to keep track if the checking tiles is successful during the method
        detectSuccess = true;
        //Debug.Log(mGridManager.GetComponent<GridManager>().mTiles[0, 1]);
        //Loop through all tiles
        for (int i = 0; i < mGridManager.transform.childCount; i++)
        {
            //Getting reference on each individual tile
            IndividualTile eachIndividualTile = mGridManager.transform.GetChild(i).GetComponent <IndividualTile>();
            //If this tile is the one we are hovering on
            if (eachIndividualTile.currentlyHovered == true)
            {
                //We put this tile as our occupied tile, then updateAllMyNodes to get subsequent nodes' indexes
                SingleGridOccupied = eachIndividualTile.myTile;
                //My Method to update all the subsequent tiles' coordinate
                UpdateAllMyNodes();

                //Merging : Added This
                iScript.itemPos = eachIndividualTile.myTile;
                iScript.SetItemPosition(eachIndividualTile.myTile);

                //Under MultiNode mode
                if (tileMode == tileOccupationMode.MultipleTiles)
                {
                    //First Loop check if any of the points is occupied by another object
                    //If there is other objects currently taking the point, abort entire
                    CheckSubsequentPoints(eachIndividualTile.myTile);
                    //If went pass the check above, object can be placed

                    //Loop through all the nodes, telling each tiles that I am the object that's occupying you
                    //Only when CheckSubsequentPoints was successful, determined by detectSuccess bool
                    if (detectSuccess)
                    {
                        ClearOtherTilesOwnershipWhenSuccess();
                        UpdateTileOwnership(eachIndividualTile.myTile);
                    }
                    else
                    {
                        //Return and zeroes everything
                        ReturnToOriginalLocation();
                        ZeroAllTileDataForThisItem();
                    }
                }
                else    //if tileMode is single
                {
                    //Still check subsequent node even only taking 1 node
                    CheckSubsequentPoints(eachIndividualTile.myTile);
                    //Only have to tell 1 tile that i am your object
                    //Only when CheckSubsequentPoints was successful, determined by detectSuccess bool
                    if (detectSuccess)
                    {
                        ClearOtherTilesOwnershipWhenSuccess();
                        eachIndividualTile.objectThatOccupiedMySpace = gameObject;
                    }
                    else
                    {
                        //Return and zeroes everything
                        ReturnToOriginalLocation();
                        ZeroAllTileDataForThisItem();
                    }
                }
                //Update the location of all objects, also snaps them in place
                //no matter success or not
                mGridManager.GetComponent <GridManager>().UpdateObjectLocations();
                return; //Return so we don't run the next few line, where we zero and return location
            }
        }
        //This will run only if player released on a non-tile location
        ReturnToOriginalLocation();
        ZeroAllTileDataForThisItem();
    }