Exemplo n.º 1
0
        public bool WaitLocation(Location location)
        {
            if (location == currentPlayer.currentLocation && currentTime < timelineMax)
            {
                Action actionWait = new ActionWait(currentTime, 1);
                AddAction(actionWait);

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public void UpdateCharacter(float time)
        {
            float trackStart = GetTrackStart(time);
            float trackEnd   = GetTrackEnd(0, 0f, 0, false, false);

//            if (currentParadoxes.Count > 0)
//            {
//                Paradox paradox = currentParadoxes[0];
//
//                //GameObject paradoxVisuals = paradox.visuals;
//                //if (paradoxVisuals)
//                //   SetVisuals(paradoxVisuals);
//                //return;
//
//                if (time >= paradox.time)
//                {
//                    return;
//                }
//            }

            //Current action
            Action action = null;

            for (int i = 0, count = history.Count; i < count; i++)
            {
                Action a = history[i];
                //TODO, used to foreshadow move direction, maybe handle paradox visualsation differently
                if (time > a.time || (time == a.time && currentParadoxes.Count < 1))
                {
                    action = a;
                }
            }

            //Interpolate state
            Vector3 pos           = currentLocation.transform.position;
            Vector3 lookDirection = Vector3.back;

            GameObject nextVisuals = visualsDefault;

            if (action != null)
            {
                float timeFraction = time - action.time;
                //TODO, mf probably needs more generalised solution here

                if (action is ActionEnter)
                {
                    ActionEnter actionEnter = action as ActionEnter;

                    Vector3 fromPos = actionEnter.fromLocation.transform.position;
                    Vector3 toPos   = actionEnter.toLocation.transform.position;

                    lookDirection = (toPos - fromPos).normalized;

                    pos = Vector3.Lerp(fromPos, toPos, timeFraction);
                }
                else if (action is ActionWait)
                {
                    ActionWait actionWait = action as ActionWait;

                    if (actionWait != null && inventory.Count < 1)
                    {
                        nextVisuals = visualsWait;
                    }
                }
            }

            if (time > trackEnd)
            {
                nextVisuals   = visualsWait; //visualsWarning
                lookDirection = Vector3.back;
            }

            transform.position = pos;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(lookDirection), 15f * Time.deltaTime);

            Vector3 carryPos = pickupPivot.position;

            for (int i = 0, count = inventory.Count; i < count; i++)
            {
                Item item = inventory[i];
                item.transform.position = carryPos;
                carryPos += Vector3.up * item.height;
            }

            if (action != null)
            {
                float timeFraction = time - action.time;

                if (action is ActionPickup)
                {
                    if (timeFraction > 0f)
                    {
                        ActionPickup actionPickup = action as ActionPickup;
//					Vector3 itemTargetPos = carryPos - Vector3.up * actionPickup.item.height;
                        if (inventory.Count > 0)
                        {
                            Item itemPickup = inventory[inventory.Count - 1];
                            //Debug.Log(item == actionPickup.currentItem);

                            //if (actionPickup.currentItem)
                            //{
                            Vector3 towardsPos = pickupPivot.position + Vector3.up * actionPickup.pickupOffset;
//                        Debug.Log(inventory.Count);
//                        Item item = inventory[inventory.Count - 1];
//                        item.transform.position = Vector3.Lerp(actionPickup.fromPos, towardsPos, timeFraction);
                            itemPickup.transform.position = Vector3.Lerp(actionPickup.fromPos, towardsPos, timeFraction);
//                        }
//                        else
//                        {
//                            Debug.LogWarning("this should probably be prevented", gameObject);
//                        }
                        }
                    }
                }
                else if (action is ActionDrop)
                {
                    if (timeFraction > 0f)
                    {
                        ActionDrop actionDrop = action as ActionDrop;

                        if (actionDrop.currentItem)
                        {
                            Vector3 fromPos = pickupPivot.transform.position + Vector3.up * actionDrop.pickupOffset;
                            actionDrop.currentItem.transform.position = Vector3.Lerp(fromPos, actionDrop.towardsPos, timeFraction);
                        }
                    }
                }
            }

            if (currentParadoxes.Count > 0)
            {
                GameObject paradoxVisuals = currentParadoxes[0].visuals;

                if (paradoxVisuals)
                {
                    nextVisuals = paradoxVisuals;
                }
            }

            //Time line
            Vector3 localScale = timeLine.bar.localScale;

            localScale.x            = trackEnd - trackStart;
            timeLine.bar.localScale = localScale;

            Vector3 localPos = timeLine.bar.localPosition;

            localPos.x = trackStart;
            timeLine.bar.localPosition = localPos;

            SetVisuals(nextVisuals);
        }