Beispiel #1
0
    public bool PlaceObject(CircuitPiece grabbable, Vector3 position)
    {
        GameObject newParent = underlyingGrid.GetClosestGridLocatorObject(position);

        if (newParent == null)
        {
            return(false);
        }

        //Check that nothing's already here
        CircuitPiece[] grabbablesInGrid = newParent.GetComponentsInChildren <CircuitPiece>();

        foreach (CircuitPiece piece in grabbablesInGrid)
        {
            if (piece.type == GrabbableObjectType.Missing && (piece.partType == grabbable.partType || !onlyAllowMatchingPieces))
            {
                continue;
            }
            return(false);
        }

        grabbable.transform.parent        = newParent.transform;
        grabbable.transform.localPosition = Vector3.zero;
        return(true);
    }
Beispiel #2
0
    public void GrabObjectUnderMouse()
    {
        //Raycast under this shit
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit[] hits = Physics.RaycastAll(ray);
        for (int i = 0; i < hits.Length; ++i)
        {
            GameObject   objectUnderMouse = hits[i].collider.gameObject;
            CircuitPiece grabbable        = objectUnderMouse.GetComponent <CircuitPiece>();
            if (grabbable != null && !grabbable.disableGrabbing)
            {
                grabbedObject = grabbable;
                grabbedObject.transform.parent = transform;
                //grabbedObject.transform.position = new Vector3(grabbedObject.transform.position.x, grabbedObject.transform.position.y, this.transform.position.z + 0.1f);
                break;
            }
        }
    }
Beispiel #3
0
    public void DropObjectUnderMouse()
    {
        //Raycast under this shit
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit[] hits = Physics.RaycastAll(ray);
        for (int i = 0; i < hits.Length; ++i)
        {
            GameObject    objectUnderMouse = hits[i].collider.gameObject;
            PlaceableGrid placeableGrid    = objectUnderMouse.GetComponent <PlaceableGrid>();
            if (placeableGrid != null)
            {
                if (placeableGrid.PlaceObject(grabbedObject, grabbedObject.transform.position))
                {
                    grabbedObject = null;
                    break;
                }
                else
                {
                    Debug.Log("Placement failed");
                }
            }
        }
    }
    public void CreatePuzzle()
    {
        Shuffle(ref partsListS);
        int partListIndex = 0;

        Vector3 tempscaleholderbecausebullshit;

        Debug.Log("GetNumGridLocations: " + phone.underlyingGrid.GetNumGridLocations());

        for (int i = 0; i < phone.underlyingGrid.GetNumGridLocations(); ++i)
        {
            if (partListIndex >= partsListS.Count)
            {
                partListIndex = partListIndex % partsListS.Count;
            }

            while (locationInfo.Count > i && locationInfo[i].disallowedParts.Contains(partListIndex + 1))
            {
                partListIndex++;
                if (partListIndex >= partsListS.Count)
                {
                    partListIndex = partListIndex % partsListS.Count;
                }
            }

            //Spawn a correct part and a missing part at each location
            //GameObject part = Instantiate(partsList[partListIndex], Vector3.back * 0.4f, Quaternion.identity);
            Debug.Log(partsListS[partListIndex]);
            GameObject part = Instantiate(Resources.Load(partsListS[partListIndex]) as GameObject, Vector3.back * 0.4f, Quaternion.identity);
            if (part == null)
            {
                Debug.Log("Part " + partsList[partListIndex] + " failed to instantiate.");
            }
            //GameObject placement = Instantiate(partsList[partListIndex], Vector3.back * 0.3f, Quaternion.identity);
            GameObject placement = Instantiate(Resources.Load(partsListS[partListIndex]) as GameObject, Vector3.back * 0.3f, Quaternion.identity);

            CircuitPiece partPiece      = part.GetComponent <CircuitPiece>();
            CircuitPiece placementPiece = placement.GetComponent <CircuitPiece>();

            partPiece.type                 = GrabbableObjectType.Part;
            partPiece.disableGrabbing      = true;
            placementPiece.type            = GrabbableObjectType.Missing;
            placementPiece.disableGrabbing = true;

            //Place them both on the grid
            tempscaleholderbecausebullshit = partPiece.transform.localScale;
            phone.PlaceObjectAt <CircuitPiece>(partPiece, i);
            partPiece.transform.localPosition += Vector3.back * 0.4f;
            partPiece.transform.localScale     = tempscaleholderbecausebullshit;

            tempscaleholderbecausebullshit = placementPiece.transform.localScale;
            phone.PlaceObjectAt <CircuitPiece>(placementPiece, i);
            placementPiece.transform.localPosition += Vector3.back * 0.4f;
            placementPiece.transform.localScale     = tempscaleholderbecausebullshit;

            partPiece.SetGameObjectSprite();
            placementPiece.SetGameObjectSprite();

            circuitPieces.Add(partPiece);

            partListIndex++;
        }

        Shuffle(ref circuitPieces);
        int j = 0;

        for (; j < numBrokenParts; ++j)
        {
            if (j < circuitPieces.Count)
            {
                //Replace the part here with a broken one
                circuitPieces[j].type            = GrabbableObjectType.Broken;
                circuitPieces[j].disableGrabbing = false;
                circuitPieces[j].SetGameObjectSprite();

                //And spawn a correct one in the bag
                GameObject   correctPart = Instantiate(circuitPieces[j].gameObject, Vector3.zero, Quaternion.identity);
                CircuitPiece piece       = correctPart.GetComponent <CircuitPiece>();
                piece.type = GrabbableObjectType.Part;
                piece.SetGameObjectSprite();
                //TODO: Replace this with placing it on the table
                tempscaleholderbecausebullshit = piece.transform.localScale;
                bag.PlaceObjectAt <CircuitPiece>(piece, j);
                piece.transform.localPosition += Vector3.back * 0.4f;
                piece.transform.localScale     = tempscaleholderbecausebullshit;
            }
        }

        GameObject   bug                = Instantiate(bugToSpawn, Vector3.zero, Quaternion.identity);
        GameObject   bugHolder          = Instantiate(bugToSpawn, Vector3.zero, Quaternion.identity);
        CircuitPiece bugGrabbable       = bug.GetComponent <CircuitPiece>();
        CircuitPiece bugHolderGrabbable = bugHolder.GetComponent <CircuitPiece>();

        bugHolderGrabbable.disableGrabbing = true;
        bugHolderGrabbable.partType        = 0;
        bugHolderGrabbable.type            = GrabbableObjectType.Missing;
        bugHolderGrabbable.SetGameObjectSprite();

        bugGrabbable.disableGrabbing = false;
        bugGrabbable.partType        = 0;
        bugGrabbable.type            = GrabbableObjectType.Part;
        bugGrabbable.SetGameObjectSprite();

        tempscaleholderbecausebullshit = bugGrabbable.transform.localScale;
        bag.PlaceObjectAt <CircuitPiece>(bugGrabbable, j);
        bugGrabbable.transform.localPosition += Vector3.back * 0.4f;
        bugGrabbable.transform.localScale     = tempscaleholderbecausebullshit;

        tempscaleholderbecausebullshit = bugHolderGrabbable.transform.localScale;
        wiretapGrid.PlaceObjectAt <CircuitPiece>(bugHolderGrabbable, 0);
        bugHolderGrabbable.transform.localPosition += Vector3.back * 0.4f;
        bugHolderGrabbable.transform.localScale     = tempscaleholderbecausebullshit;
    }