コード例 #1
0
ファイル: Character.cs プロジェクト: mfasterholdt/JustInTime
        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);
        }
コード例 #2
0
        bool Interactions()
        {
            Item     item     = MouseDown <Item>();
            Location location = MouseDown <Location>();

            //----// Items //----//
            if (item && location == currentPlayer.currentLocation)
            {
                if (item.isMovable)
                {
                    //Item
                    if (item.itemAround)
                    {
                        float        pickupOffset = currentPlayer.GetPickupOffset();
                        Item         itemFound    = item.itemAround.itemsInside[item.itemAround.itemsInside.Count - 1];
                        ActionPickup actionPickup = new ActionPickup(currentTime, 1, itemFound, item.itemAround, location, pickupOffset);
                        AddAction(actionPickup);
                        return(true);
                    }
                    else if (item.characterCarrying)
                    {
//						Item foundContainer = currentPlayer.currentLocation.GetContainer();
//
//						if (foundContainer)
//						{
//							Item itemFound = currentPlayer.inventory[currentPlayer.inventory.Count - 1];
//
//							ActionDrop actionDrop = new ActionDrop(currentTime, 1, itemFound, foundContainer);
//							AddAction(actionDrop);
//							return true;
//						}
                    }
                }
                else if (item.isContainer)
                {
                    //Item Container
//					if (item.itemsInside.Count > 0)
//					{
//						ActionPickup actionPickup = new ActionPickup(currentTime, 1, item.itemsInside[0], item);
//						AddAction(actionPickup);
//						return true;
//					}
//					else
//					{
                    if (currentPlayer.inventory.Count > 0)
                    {
                        Item itemFound = currentPlayer.inventory[currentPlayer.inventory.Count - 1];

                        ActionDrop actionDrop = new ActionDrop(currentTime, 1, itemFound, item);
                        AddAction(actionDrop);
                        return(true);
                    }
//					}
                }
            }
            else
            {
                //----// Location //----//

                if (location)
                {
                    if (EnterLocation(location))
                    {
                        return(true);
                    }

                    if (WaitLocation(location))
                    {
                        return(true);
                    }
                }
            }

            if (Input.GetKey(KeyCode.Space))
            {
                if (WaitLocation(currentPlayer.currentLocation))
                {
                    return(true);
                }
            }

            return(false);
        }