Esempio n. 1
0
        public Tuple <int, SceneItemType> UpdateInteractTarget(GameObject player)
        {
            var component = player.transform.Find("InteractTrigger").GetComponent <CharacterTriggerInteract>();

            var item  = component.GetNearestItem(player)?.GetComponent <SceneItem>();
            var table = component.GetNearestTable(player)?.GetComponent <SceneItem>();

            SceneItem target = null;

            if (table != null && item != null)
            {
                int itemOnTable = BabySmileManager.GetTableItemID(table.id);
                target = itemOnTable == item.id ? item : table;
            }
            else if (table != null)
            {
                target = table;
            }
            else if (item != null)
            {
                target = item;
            }

            var character = player.GetComponent <CharacterControl>();
            int prevId    = character.InteractTarget;
            var prevType  = character.InteractType;
            var dict      = prevType == SceneItemType.Item ? InteractItems : InteractTables;
            var prevObj   = dict.ContainsKey(prevId) ? dict[prevId] : null;
            var prevItem  = prevObj != null?prevObj.GetComponent <SceneItem>() : null;

            if (target != prevItem)
            {
                if (target != null)
                {
                    target.SetInteract(true);
                }

                if (prevItem != null)
                {
                    prevItem.SetInteract(false);
                }

                return(target == null
                    ? new Tuple <int, SceneItemType>(0, SceneItemType.Item)
                    : new Tuple <int, SceneItemType>(target.id, target.type));
            }

            return(new Tuple <int, SceneItemType>(prevId, prevType));
        }