Ejemplo n.º 1
0
        void HighlightIfOverInteractiveItem()
        {
            if (true)
            {
                bool enable = false;

                Collider2D[] col = Physics2D.OverlapPointAll(transform.position);

                var hoveredItem = inventory.ItemHoveringOver();
                if (hoveredItem != null && hoveredItem != this)
                {
                    enable = true;
                    SetHighlight(enable);
                }

                if (col.Length > 0)
                {
                    foreach (Collider2D c in col)
                    {
                        if (c.gameObject.layer == 10)
                        {
                            if (c.gameObject.GetComponent <DoorBetweenLevels>() == null)
                            {
                                enable = true;
                            }
                            else
                            {
                                DoorBetweenLevels     door       = c.gameObject.GetComponent <DoorBetweenLevels>();
                                InteractiveItemSwitch switchItem = c.gameObject.GetComponent <InteractiveItemSwitch>();
                                if (switchItem != null)
                                {
                                    if (door.enableOnlyForSwitchState != InteractiveItemSwitch.State.ANY && door.enableOnlyForSwitchState != switchItem.state)
                                    {
                                        enable = true;
                                    }
                                }
                            }
                            if (c.gameObject.GetComponent <InventoryItem>() != null)
                            {
                                InteractiveItem intItem = c.gameObject.GetComponent <InteractiveItem>();
                                bool            doBreak = false;
                                foreach (InventoryItem invItem1 in intItem.CanBeCombinedWith)
                                {
                                    if (invItem1 == this)
                                    {
                                        enable  = true;
                                        doBreak = true;
                                        break;
                                    }
                                }
                                if (doBreak)
                                {
                                    break;
                                }
                            }
                        }
                        if (c.gameObject.layer == 11)
                        {  //added to disable highlightning over Inventory
                            enable = false;
                            break;
                        }
                    }
                }

                SetHighlight(enable);
            }
        }
Ejemplo n.º 2
0
        public IEnumerator EnterRoom(string levelIndex)
        {
            DoorBetweenLevels           door    = (DoorBetweenLevels)doors[levelIndex];
            InteractiveItemChangeCamera doorCam = null;

            if (door == null)
            {
                SetInCutScene(true, CutsceneTools.Type.ZoomIn, transform.position + Vector3.up * advCamera.yFollowOffset, false);

                if (!staticCharacter)
                {
                    ChangeStateToIdleBasedOnDirection();
                }

                if (!scene.stayInCutsceneAfterInitialState)
                {
                    SetInCutScene(false);
                }
            }
            else
            {
                autoPilotSpeed     = door.walkInOutSpeed;
                transform.position = door.gameObject.transform.position + door.outsideOffset;

                ProcessDirectionAndScale();
                doorCam = door.gameObject.GetComponent <InteractiveItemChangeCamera>();

                if (doorCam)
                {
                    StartCoroutine(doorCam.ProcessArrivedAt());
                }

                heldItem   = combiningItem = null;
                targetItem = null;

                Vector3 cameraPos = transform.position + Vector3.up * advCamera.yFollowOffset;

                cameraPos.z = -5;

                advCamera.Move(new Vector3(cameraPos.x, advCamera.transform.position.y, cameraPos.z), true);

                if (door.zoomoutCircleTransformPosition != null)
                {
                    SetInCutScene(true, CutsceneTools.Type.ZoomIn, door.zoomoutCircleTransformPosition.position, false, 0.01f, false);
                }
                else
                {
                    SetInCutScene(true, CutsceneTools.Type.ZoomIn, transform.position + Vector3.up * advCamera.yFollowOffset, false, 0.01f, false);
                }

                if (door.openCloseAnimator)
                {
                    transform.position = door.gameObject.transform.position + door.outsideOffset;
                    door.openCloseAnimator.SetBool("open", true);
                    ChangeStateToIdleBasedOnWalkAnimation(door.animationWalkIn);
                    yield return(new WaitForSeconds(0.7f));
                }

                if (!staticCharacter)
                {
                    ChangeState(door.animationWalkIn);   //mr 18.11.2014 to enable walk in front in
                }
                autoPilotTarget = door.insideOffset + door.gameObject.transform.position;

                autoPilotDelta = (door.insideOffset - door.outsideOffset);

                isInAutopilot = true;

                direction = transform.position.x < (autoPilotTarget.x) ? 1 : -1;

                ProcessDirectionAndScale(false);
                yield return(new WaitForSeconds(1 / autoPilotSpeed));

                isInAutopilot = false;
                if (!staticCharacter)
                {
                    ChangeStateToIdleBasedOnDirection();
                }

                InteractiveItem interactiveItemDoor = door.GetComponent <InteractiveItem>();
                if (interactiveItemDoor == null || interactiveItemDoor.realyStayInCutscene != true)
                {
                    SetInCutScene(false);
                }

                advCamera.CenterOnElroy();

                if (door.openCloseAnimator)
                {
                    door.openCloseAnimator.SetBool("open", false);
                }
            }
        }
Ejemplo n.º 3
0
        IEnumerator ProcessInteraction()
        {
            // TODO: refactor and clean up this method. Bad variable names, too tightly coupled with AdvCamera and Inventory

            bool            justLooking     = false;
            bool            clicked1        = false;
            bool            isHolding1      = false;
            Vector3         holdPosition1   = Vector3.zero;
            Vector3         worldPosition1  = Vector3.zero;
            InventoryItem   item1           = null;
            bool            inventoryClick  = false;
            bool            clicked         = false;
            bool            isHolding       = false;
            Vector3         holdPosition    = Vector3.zero;
            Vector3         worldPosition   = Vector3.zero;
            InteractiveItem interactiveItem = null;
            bool            justTouched     = false;

            if (!isInUninterruptibleAction)
            {
                if (inventory.ProcessInput(ref clicked1, ref isHolding1, ref holdPosition1, ref worldPosition1, ref item1))
                {
                    procesingInventory = 1;
                    if (clicked1)
                    {
                        procesingInventory = 0;
                        inventoryClick     = true;
                    }
                    if (item1 != null || heldItem != null)
                    {
                        procesingInventory = 0;
                    }
                }
            }

            if (inventory.MouseOverInventory())
            {
                procesingInventory = 1;
            }

            if (!isInUninterruptibleAction)
            {
                ProcessInput(ref clicked, ref isHolding, ref holdPosition, ref worldPosition, ref interactiveItem, ref justTouched);
            }
            else
            {
                if (navmeshWalker.GetVelocity().sqrMagnitude == 0)
                {
                    isInUninterruptibleAction = false;
                }
            }

            bool callElroyMoved = false;

            if (!wasHolding && isHolding)
            {
                holdingSince = Time.realtimeSinceStartup;
            }

            wasHolding = isHolding;

            if (isHolding1)
            {
                inventory.inventoryItemPosition = worldPosition1;

                if (inventory.heldItem == null && !advCamera.IsPeekPanning())
                {
                    if (item1 != null)
                    {
                        inventory.HoldItem(item1);
                    }
                }

                if (item1 == null && heldItem == null)
                {
                    if (Time.realtimeSinceStartup - holdingSince > timeDelayBeforePanning)
                    {
                        if (!advCamera.IsPeekPanning() && procesingInventory <= 0)
                        {
                            startHoldPosition = holdPosition;
                            advCamera.SetPeekPanning(true);
                        }
                        else if (Input.touches.Length < 2)//added because of two finger jumping screen
                        {
                            Vector3 delta = PersistentEngine.activeCamera.ScreenToWorldPoint(holdPosition) - PersistentEngine.activeCamera.ScreenToWorldPoint(startHoldPosition);

                            advCamera.AdjustPeekPanning(-delta);
                        }
                    }
                }
            }
            else
            {
                ReturnItemToInventory();
            }

            if (clicked && !inCutScene && !PersistentEngine.inPause)
            {
                if (!advCamera.WasPeekingLongEnough())
                {
                    clickIndicator.transform.position = worldPosition;

                    if (interactiveItem != null)
                    {
                        justLooking = ProcessItemInteraction(justLooking, inventoryClick, holdPosition, interactiveItem);
                    }
                    else if (!inventoryClick)
                    {
                        clickIndicator.isFlipped = false;
                        clickIndicator.ChangeState(ClickIndicator.State.Walk);
                    }

                    if (!isHolding)
                    {
                        combiningItem = heldItem;
                        heldItem      = null;
                    }

                    if (IsTalking(state))
                    {
                        interruptingSentence = true;
                        StopTalking();
                        SwitchToIdle();
                    }

                    if (IsIdleOrWalking())
                    {
                        if (!justLooking)
                        {
                            targetItem = interactiveItem;
                        }

                        var iho = PersistentEngine.inventory.ItemHoveringOver();
                        if (iho != null /* TG && targetItem == null */)
                        {
                            targetItem = iho.GetComponent <InteractiveItem>();
                        }

                        if (targetItem != null && combiningItem != null && targetItem.IsInInventory() && targetItem != combiningItem)
                        {
                            // Already there

                            ArrivedAt(combiningItem);
                        }

                        if (targetItem != null && targetItem.IsInInventory())
                        {
                            navmeshWalker.Stop();
                        }
                        else if (!inventoryClick)
                        {
                            if (!justLooking && !staticCharacter && (procesingInventory <= 0))
                            {
                                worldPosition = SetDestination(worldPosition);
                            }

                            callElroyMoved = true;

                            bool x = CheckIfCombiningMatchingItems(targetItem, combiningItem);

                            if (x)
                            {
                                isInUninterruptibleAction = x;
                            }

                            if (targetItem != null && (navmeshWalker.HasArrived() || staticCharacter) /*0.06f*/)
                            {
                                advCamera.SetPeekPanning(false);
                                yield return(null);

                                navmeshWalker.Stop();

                                yield return(null);

                                ArrivedAt(combiningItem);
                            }
                        }
                    }
                }

                advCamera.SetPeekPanning(false);
            }
            else if (clicked)
            {
                procesingInventory--;
                advCamera.SetPeekPanning(false);
            }

            if (callElroyMoved && !justLooking)
            {
                advCamera.ElroyMoved();
            }

            if (!inventory.MouseOverInventory())
            {
                procesingInventory = 0;
            }

            yield return(null);
        }
Ejemplo n.º 4
0
        private bool ProcessItemInteraction(bool justLooking, bool inventoryClick, Vector3 holdPosition, InteractiveItem interactiveItem)
        {
            if (interactiveItem.IsInInventory() == false && !inventoryClick)
            {
                if (interactiveItem.SupportsDoubleClick() && interactiveItem.DoubleClickTime() < 0.75f && !isInAutopilot && !inCutScene)
                {
                    interactiveItem.DoubleClick();
                }

                if (interactiveItem.isClickIndicatorFlipped)
                {
                    clickIndicator.isFlipped = true;
                }
                else
                {
                    clickIndicator.isFlipped = false;
                }

                if (interactiveItem.IsPerson() && heldItem == null)
                {
                    clickIndicator.ChangeState(ClickIndicator.State.Talk);
                }
                else
                if (interactiveItem.IsExit())
                {
                    clickIndicator.ChangeState(ClickIndicator.State.Exit);
                }
                else
                if (interactiveItem.CanBeUsed())
                {
                    clickIndicator.ChangeState(ClickIndicator.State.Use);
                }
                else
                if (interactiveItem.CanBeCombinedWith.Length > 0 && heldItem != null)
                {
                    clickIndicator.ChangeState(ClickIndicator.State.Use);
                }
                else
                if (heldItem != null)
                {
                    clickIndicator.ChangeState(ClickIndicator.State.Use);
                }
                else
                {
                    clickIndicator.ChangeState(ClickIndicator.State.Look);

                    if (!interactiveItem.needToWalkToItem && !isInAutopilot && !inCutScene)
                    {
                        targetItem = interactiveItem;
                        navmeshWalker.Stop();
                        talkDirection = TalkDirection.Front;

                        ProcessDirectionAndScale(false);

                        justLooking = true;

                        if (IsTalking(state))
                        {
                            talkDirection        = TalkDirection.Front;
                            interruptingSentence = true;
                            StopTalking();
                        }

                        talkDirection = TalkDirection.Front;
                        ArrivedAt(heldItem);

                        targetItem = null;
                    }
                }
            }

            interactiveItem.Selected();

            clickIndicator.transform.position = advCamera.GetComponent <Camera>().ScreenToWorldPoint(holdPosition);
            return(justLooking);
        }
Ejemplo n.º 5
0
        void ProcessInput(ref bool isHit, ref bool holding, ref Vector3 holdPosition, ref Vector3 worldPosition, ref InteractiveItem interactiveItem, ref bool justTouched)
        {
            justTouched = false;

            foreach (Touch touch in Input.touches)
            {
                holding = true;
                if (touch.phase == TouchPhase.Began)
                {
                    justTouched  = true;
                    holdPosition = touch.position;

                    startHoldPosition = holdPosition;
                }

                if (touch.phase == TouchPhase.Ended)
                {
                    holding      = false;
                    holdPosition = touch.position;
                    isHit        = true;
                }
            }

            if (Input.GetButtonUp("Fire1"))
            {
                holding      = false;
                holdPosition = Input.mousePosition;
                isHit        = true;
            }

            if (Input.GetButtonDown("Fire1"))
            {
                justTouched       = true;
                startHoldPosition = Input.mousePosition;
            }

            if (Input.GetButton("Fire1"))
            {
                holding      = true;
                holdPosition = Input.mousePosition;
            }

            worldPosition = PersistentEngine.activeCamera.ScreenToWorldPoint(holdPosition);

            if (isHit)
            {
                Vector2 v = PersistentEngine.activeCamera.ScreenToWorldPoint(holdPosition);

                Collider2D[] col = Physics2D.OverlapPointAll(v);

                interactiveItem = null;

                if (col.Length > 0)
                {
                    int lastLayer = int.MinValue;

                    foreach (Collider2D c in col)
                    {
                        if (c.gameObject.layer == 10)
                        {
                            var elroyItem1 = c.gameObject.GetComponent <InteractiveItem>();

                            if (elroyItem1 != null && elroyItem1.enabled && elroyItem1.itemLayer > lastLayer)
                            {
                                lastLayer = elroyItem1.itemLayer;

                                interactiveItem = elroyItem1;

                                Vector3 posx = interactiveItem.transform.position + interactiveItem.GetCenterOffset(heldItem);// interactiveItem.collider2D.bounds.center;// + interactiveItem.transform.position;

                                worldPosition = posx + interactiveItem.GetStoppingDistance(heldItem);
                            }
                        }
                    }
                }
            }
        }