Example #1
0
    private void InitGameRoot()
    {
        //1. Init all services
        //a. Resource service
        resourceService = GetComponent <ResourceService>();
        resourceService.InitService();

        //b. Audio service
        audioService = GetComponent <AudioService>();
        audioService.InitService();

        //2. Init all systems
        //a. Menu System
        menuSystem = GetComponent <MenuSystem>();
        menuSystem.InitSystem();

        //b. Puzzle System
        puzzleSystem = GetComponent <PuzzleSystem>();
        puzzleSystem.InitSystem();

        //3.Enter Menu Scene
        if (SceneManager.GetActiveScene().name == Constants.gameRootSceneName)
        {
            menuSystem.EnterMenu();
        }
    }
Example #2
0
 // Start is called before the first frame update
 void Start()
 {
     if (!singleton)
     {
         singleton = this;
     }
     else
     {
         DestroyImmediate(gameObject);
     }
     ShowUI(false);
 }
Example #3
0
 public bool CheckSolved()
 {
     if (!solved)
     {
         solved = (accumulatedBoxes == quota);
         if (solved)
         {
             PuzzleSystem.Score(this);
         }
         return(solved);
     }
     return(false);
 }
Example #4
0
    public virtual void Start()
    {
        time   = 0;
        locked = true;

        m_Animator = gameObject.GetComponent <Animator>();


        if (tracker != null)
        {
            basecolor = (ColorTracker)tracker.GetComponent(typeof(ColorTracker));
            if (basecolor == null)
            {
                Debug.Log("not in color");
            }
        }

        if (master != null)
        {
            puzzleboss = (PuzzleSystem)master.GetComponent(typeof(PuzzleSystem));
            if (puzzleboss == null)
            {
                Debug.Log("why though");
            }
        }



        if (square1 != null)
        {
            script1 = (TerrainSystem)square1.GetComponent(typeof(TerrainSystem));
        }
        if (square2 != null)
        {
            script2 = (TerrainSystem)square2.GetComponent(typeof(TerrainSystem));
        }
        if (square3 != null)
        {
            script3 = (TerrainSystem)square3.GetComponent(typeof(TerrainSystem));
        }
        if (square4 != null)
        {
            script4 = (TerrainSystem)square4.GetComponent(typeof(TerrainSystem));
        }
        if (square5 != null)
        {
            script5 = (TerrainSystem)square5.GetComponent(typeof(TerrainSystem));
        }
        if (square6 != null)
        {
            script6 = (TerrainSystem)square6.GetComponent(typeof(TerrainSystem));
        }
        if (square7 != null)
        {
            script7 = (TerrainSystem)square7.GetComponent(typeof(TerrainSystem));
        }
        if (square8 != null)
        {
            script8 = (TerrainSystem)square8.GetComponent(typeof(TerrainSystem));
        }

        //Additional();
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        //Check for collision with liftable objects
        RaycastHit hitInfo     = new RaycastHit();
        Ray        ray         = new Ray(transform.position, transform.rotation * Vector3.forward);
        bool       objectFound = Physics.Raycast(ray, out hitInfo, distanceMax, layerMaskPickup);

        if (Input.GetButtonDown("Snap"))
        {
            snap          = !snap;
            snapText.text = "<b>[X]Snap: </b>" + ((snap) ? "ON" : "OFF");
        }
        if (Input.GetButtonDown("ShowPreview"))
        {
            showPreview      = !showPreview;
            previewText.text = "<b>[V]Preview: </b>" + ((showPreview) ? "ON" : "OFF");
        }

        if (carriedObjects.Count > 0 && currentPickupState != PickupState.interactObjectTargeted)
        {
            //Check distance mod
            float scrollDelta = Input.GetAxis("DistanceModification");
            if (scrollDelta != 0)
            {
                distance = Mathf.Clamp(distance + scrollDelta, distanceMin, distanceMax);
            }

            //Set initial drop location
            dropCoords      = new Vector3Int[] { Vector3Int.zero, Vector3Int.zero };
            dropLocations   = new Vector3[] { Vector3.zero, Vector3.zero };
            canDropAtCoords = new bool[] { true, true };
            showDrop        = new bool[] { true, true };


            if (objectFound && hitInfo.distance <= distance)
            {
                dropLocations[0] = hitInfo.point + (hitInfo.normal * 0.53f) - (snap ? Vector3.zero : carriedItem.centerLocalTransform);
                dropCoords[0]    = placementGrid.WorldToCell(dropLocations[0]);
                Box box = hitInfo.transform.gameObject.GetComponent <Box>();
                if (box != null)
                {
                    dropCoords[1]      = box.GetBoxOnTopOfMyStack().GetHighestCoordAlignedWithStack() + Vector3Int.up;
                    canDropAtCoords[1] = Vector3.Distance(transform.position, placementGrid.CellToWorld(dropCoords[1])) < distanceMax;
                }
                else
                {
                    placementPreviews[1].transform.position = placementPreviews[0].transform.position;
                    placementPreviews[1].transform.rotation = placementPreviews[0].transform.rotation;
                    canDropAtCoords[1] = false;
                    showDrop[1]        = false;
                }
            }
            else
            {
                dropLocations[0]   = transform.position + (transform.rotation * (Vector3.forward * distance) - carriedItem.centerLocalTransform);
                dropCoords[0]      = placementGrid.WorldToCell(dropLocations[0] + carriedItem.centerLocalTransform);
                canDropAtCoords[1] = false;
                showDrop[1]        = false;
            }
            //Set pickup preview materials
            if (!canDropAtCoords[1] || dropCoords[0] == dropCoords[1])
            {
                placementPreviews[0].SetPreview(carriedItem, PickupPreview.Prompt.r);
                showDrop[1] = false;
            }
            else
            {
                placementPreviews[0].SetPreview(carriedItem, PickupPreview.Prompt.r);
                placementPreviews[1].SetPreview(carriedItem, PickupPreview.Prompt.g);
            }

            //Convert back to world space
            for (int i = 0; i < dropCoords.Length; ++i)
            {
                if (i > 0 || snap)
                {
                    dropLocations[i] = placementGrid.CellToWorld(dropCoords[i]);
                }
                bool obstructionNotDetected = !Physics.CheckBox(dropLocations[i] + new Vector3(0.5f, 0.55f, 0.5f), new Vector3(0.51f, 0.475f, 0.51f), Quaternion.identity, layerMaskObstructed);
                bool clippingNotDetected    = !Physics.CheckBox(dropLocations[i] + new Vector3(0.5f, 0.55f, 0.5f), new Vector3(0.51f, 0.475f, 0.51f), Quaternion.identity, layerMaskHide);
                bool insideOfPuzzleBounds   = true;
                if (carriedItem.puzzle != null)
                {
                    insideOfPuzzleBounds = carriedItem.puzzle.IsInPuzzleBoundry(dropLocations[i]);
                }
                if (i == 0 && (!obstructionNotDetected || !clippingNotDetected))
                {
                    exception.FadeInText("NO SPACE");
                }
                if (i == 0 && !insideOfPuzzleBounds)
                {
                    exception.FadeInText("OUT OF BOUNDS");
                }
                canDropAtCoords[i] = canDropAtCoords[i] && obstructionNotDetected && clippingNotDetected && insideOfPuzzleBounds;
                MaterialPropertyBlock properties = new MaterialPropertyBlock();
                if (showDrop[i] && showPreview)
                {
                    placementPreviews[i].gameObject.SetActive(true);
                    prompt.FadeInText("<b>[R]</b>Place");
                    if (canDropAtCoords[i])
                    {
                        placementPreviews[i].SetValid(true);
                        //properties.SetColor("_Color", new Color(0.7f, 0.89f, 1f, 0.75f));
                    }
                    else
                    {
                        prompt.FadeOutText();
                        placementPreviews[i].SetValid(false);
                        //properties.SetColor("_Color", new Color(1f, 0.89f, 0.7f, 0.75f));
                    }
                    placementPreviews[i].gameObject.transform.position = Vector3.Lerp(placementPreviews[i].gameObject.transform.position, dropLocations[i], 0.25f);
                    placementPreviews[i].gameObject.transform.rotation = Quaternion.Lerp(placementPreviews[i].gameObject.transform.rotation, Quaternion.identity, 0.25f);
                    //Graphics.DrawMesh(carriedItemMesh, dropLocations[i], Quaternion.identity, carriedItemMaterial, 0, GetComponent<Camera>(), 0, properties, false);
                }
                else
                {
                    placementPreviews[i].gameObject.SetActive(false);
                }
            }
            if ((Input.GetButtonDown("Drop") || (Input.GetButtonDown("DropOnStack") && !canDropAtCoords[1])) && canDropAtCoords[0])
            {
                DropObject(dropLocations[0], Quaternion.identity);
            }
            if (Input.GetButtonDown("DropOnStack") && canDropAtCoords[1])
            {
                DropObject(dropLocations[1], Quaternion.identity);
            }
        }
        else
        {
            placementPreviews[0].gameObject.SetActive(false);
            placementPreviews[1].gameObject.SetActive(false);
            if (Input.GetButtonDown("Fire3"))
            {
                if (Player.singleton.myPickup.carriedObjects.Count > 0) //Don't reset anything if player is carrying boxes
                {
                    return;
                }
                Puzzle[] puzzles      = FindObjectsOfType <Puzzle>();
                Puzzle   activePuzzle = null;
                foreach (Puzzle puzzle in puzzles)
                {
                    if (puzzle.IsInPuzzleBoundry(Player.singleton.transform.position) == true)
                    {
                        activePuzzle = puzzle;
                        break;
                    }
                }
                if (activePuzzle)
                {
                    PuzzleSystem.ResetPuzzle(activePuzzle);
                }
            }
        }

        switch (currentPickupState)
        {
        case PickupState.noObjectTargeted:
            if (objectFound)
            {
                targetedObject = hitInfo.transform.gameObject;
                bool        busy      = true;
                PickupState nextState = PickupState.noObjectTargeted;
                switch (hitInfo.transform.tag)
                {
                case "Interactable":
                    nextState = PickupState.interactObjectTargeted;
                    targetedItemInteraction = targetedObject.GetComponent <Interaction>();
                    busy = targetedItemInteraction.IsBusy();

                    break;

                case "Liftable":
                    nextState       = PickupState.pickupObjectTargeted;
                    targetedItemBox = targetedObject.GetComponent <Box>();
                    //HighlightGroup();
                    busy = false;
                    break;

                default:
                    break;
                }
                //Check the availability of the targeted object
                if (busy == false)
                {
                    currentPickupState = nextState;
                    //Debug.Log("Target found.");
                    //Debug.Log("Targeted item: " + targetedObject.name);
                }
            }


            break;

        case PickupState.interactObjectTargeted:
            if (!targetedItemInteraction.IsBusy())
            {
                RefreshText();
            }
            if (InteractTargetLost(objectFound, hitInfo))
            {
                //Object not targeted anymore
                LoseTarget();
            }
            else
            {
                if (Input.GetButtonDown("Interact/Pickup"))
                {
                    //Interact with object
                    targetedItemInteraction.Interact(this);
                }
            }
            break;

        case PickupState.pickupObjectTargeted:
            if (PickupTargetLost(objectFound, hitInfo))
            {
                //UnHighlightGroup();
                LoseTarget();
            }
            else
            {
                prompt.FadeInText("<b>[E]</b>Lift");
                bool pickup = false;
                Box  box    = targetedItemBox;
                if (Input.GetButtonDown("Interact/Pickup"))
                {
                    //Pickup object
                    pickup = true;
                }
                if (Input.GetButtonDown("PickupOnStack"))
                {
                    //Pickup object on top of a stack
                    pickup = true;
                    box    = targetedItemBox.GetBoxOnTopOfMyStack();
                }
                if (carriedObjects.Count == 0)    //TODO Find way to show exceptions for picking up and placing seperately
                {
                    if (box.isTooHeavy)
                    {
                        exception.FadeInText("TOO HEAVY");
                    }
                    else if (carriedObjects.Count == carryObjectLimit)
                    {
                        exception.FadeInText("INVENTORY FULL");
                    }
                    else if (pickup)
                    {
                        PickupObject(box);
                    }
                }
            }
            //else if (box.GetBoxOnTopOfMe() != null)
            //{

            //    exception.FlashText("BOX BLOCKED", 2f);
            //}
            break;
        }



        //if Input.GetButtonDown("Pickup"){

        //}
    }