Beispiel #1
0
    public void InteractableInitialize()
    {
        //In case I forget...
        gameObject.layer = LayerMask.NameToLayer("Interactable");

        if (GetComponent <PowerCube>() != null)
        {
            pc = GetComponent <PowerCube>();
            it = InteractableType.PowerCube;
        }
        else if (GetComponent <PowerStation>() != null)
        {
            ps = GetComponent <PowerStation>();
            it = InteractableType.PowerStation;
        }
        else if (GetComponent <DoorButton>() != null)
        {
            db = GetComponent <DoorButton>();
            it = InteractableType.DoorButton;
        }
        else if (GetComponent <TimedDoorButton>() != null)
        {
            timd = GetComponent <TimedDoorButton>();
            it   = InteractableType.TimedDoorButton;
        }
        else
        {
            it = InteractableType.None;
        }

        //If universal functionality is needed, that will go here
    }
Beispiel #2
0
    public void RefreshReferences()
    {
        door     = GetComponent <Door> ();
        spikes   = GetComponent <Spikes> ();
        ladder   = GetComponent <Ladder> ();
        pullPush = GetComponent <PullPush> ();

        if (door != null)
        {
            interactableType = InteractableType.Door;
        }
        else if (spikes != null)
        {
            interactableType = InteractableType.Spikes;
        }
        else if (ladder != null)
        {
            interactableType = InteractableType.Ladder;
        }
        else if (pullPush != null)
        {
            interactableType = InteractableType.PullPush;
        }
        else
        {
            Debug.LogError("Error: Interactable component with no compatible component included.");
            Debug.Break();
        }
    }
Beispiel #3
0
 public void SetInteractableType(InteractableType interactableType)
 {
     this.interactableType = interactableType;
     selectorIcon.sprite   = interactableType.SelectorSprite;
     selectorText.text     = interactableType.DisplayName;
     UpdateAvailability();
 }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        switch (collision.gameObject.tag)
        {
        case "TP":
            currentInteractableType = InteractableType.teleporter;
            goto case "GENERAL CASE";

        case "Lever":
            currentInteractableType = InteractableType.lever;
            goto case "GENERAL CASE";

        case "ElectricLever":
            currentInteractableType = InteractableType.electricLever;
            goto case "GENERAL CASE";

        case "Leak":
            currentInteractableType = InteractableType.leak;
            goto case "GENERAL CASE";

        case "InversionBlock":
            currentInteractableType = InteractableType.inversionBlockLever;
            goto case "GENERAL CASE";

        case "GENERAL CASE":
            canInteract        = true;
            interactableObject = collision.gameObject;
            break;
        }
    }
Beispiel #5
0
        private IInteractable PickInteractable(Collider[] overlapSphere)
        {
            float         closestDistance     = float.MaxValue;
            IInteractable currentInteractable = null;

            foreach (var hitCollider in overlapSphere)
            {
                IInteractable interactable = hitCollider.GetComponent <IInteractable>();

                if (interactable != null)
                {
                    float            distance         = Vector3.Distance(transform.position, interactable.GetPosition());
                    InteractableType interactableType = interactable.GetInteractableType();

                    if (interactableType == InteractableType.Home)
                    {
                        continue;
                    }

                    if (currentInteractable == null)
                    {
                        currentInteractable = interactable;
                        closestDistance     = distance;
                        continue;
                    }

                    if (currentInteractable.GetInteractableType() == InteractableType.Log)
                    {
                        if (interactableType == InteractableType.Log)
                        {
                            if (closestDistance > distance)
                            {
                                currentInteractable = interactable;
                                closestDistance     = distance;
                                continue;
                            }
                        }
                    }
                    else
                    {
                        if (interactableType == InteractableType.Log)
                        {
                            currentInteractable = interactable;
                            closestDistance     = distance;
                            continue;
                        }

                        if (closestDistance > distance)
                        {
                            currentInteractable = interactable;
                            closestDistance     = distance;
                            continue;
                        }
                    }
                }
            }

            return(currentInteractable);
        }
Beispiel #6
0
        public Context(Interactable selected, Interactable focused)
        {
            Selected = selected;
            Focused  = focused;

            SelectedType = selected.Type;
            FocusedType  = focused.Type;
        }
Beispiel #7
0
 void InitializeInteractables()
 {
     _interactables = new List <IInteractable> [InteractableType.GetValues(typeof(InteractableType)).Length];
     for (int i = 0; i < _interactables.Length; i++)
     {
         _interactables[i] = new List <IInteractable>();
     }
 }
Beispiel #8
0
 public Command(GestureType gesture, KeywordType keyword, InteractableType focused, InteractableType selected)
     : this(gesture,
            keyword,
            focused,
            selected,
            StaticItem.Invariant)
 {
 }
Beispiel #9
0
    private void Interact(GameObject interactableObject)
    {
        IInteractable interactable = interactableObject.GetComponent <IInteractable>();

        interactable.Interact();
        InteractableType interactableType = interactable.GetInteractableType();

        Interact(interactableType, interactable);
    }
 public ObjectModifierScriptableObject Init(ObjectModifierScriptableObjectConfig config)
 {
     interactableType           = config.interactableType;
     interactableInfluence      = config.interactableInfluence;
     interactableObjectLocation = config.interactableObjectLocation;
     upgradeObjectType          = config.upgradeObjectType;
     upgradeModifier            = config.upgradeModifier;
     powerupAmount     = config.powerupAmount;
     powerupObjectType = config.powerupObjectType;
     return(this);
 }
Beispiel #11
0
    private void Interact(InteractableType interactableType, IInteractable interactable)
    {
        switch (interactableType)
        {
        case InteractableType.Chest:
            StartCoroutine(OpenChest(interactable));
            break;

        default:
            break;
        }
    }
Beispiel #12
0
 public Command(GestureType gesture,
                KeywordType keyword,
                InteractableType focused,
                InteractableType selected,
                StaticItem item)
 {
     Gesture  = gesture;
     Keyword  = keyword;
     Focused  = focused;
     Selected = selected;
     Item     = item;
 }
    public void SetPromptType(InteractableType type)
    {
        switch (type)
        {
        case InteractableType.PICKUP:
            SetPromptType(InteractionIconType.A);
            break;

        case InteractableType.REPAIR:
            SetPromptType(InteractionIconType.B);
            break;
        }
    }
    private void ChangeCrossHair(InteractableType type)
    {
        switch (type)
        {
        case InteractableType.PHYSICAL:
            crosshair.sprite = physicInteractCrosshair;
            break;

        default:
            crosshair.sprite = normalCrosshair;
            break;
        }
    }
Beispiel #15
0
        /// <summary>
        /// Find nearest Interactable Object like wells or trees.
        /// Searches in dynamically generated list of GameObjects from spawner.
        /// Checks InteractableType and distance to villager.
        /// </summary>
        /// <param name="interactableType">InteractableType to filter list of possible GameObjects</param>
        /// <returns>nearest interactable obeject of given type</returns>
        public Interactable FindNearestInteractableOfType(InteractableType interactableType)
        {
            List <GameObject> possibleTargets = new List <GameObject>();

            if (interactableType == InteractableType.TREE)
            {
                possibleTargets = FindObjectOfType <Spawner>()
                                  .GetEntitiesPosition()
                                  .Values
                                  .Where(e => e.GetComponent <WorldEntities.Tree>() != null && e.GetComponent <WorldEntities.Tree>().GetInteractableType() == InteractableType.TREE)
                                  .ToList();
            }

            else if (interactableType == InteractableType.SPROUT)
            {
                possibleTargets = FindObjectOfType <Spawner>()
                                  .GetEntitiesPosition()
                                  .Values
                                  .Where(e => e.GetComponent <WorldEntities.Tree>() != null && e.GetComponent <WorldEntities.Tree>().GetInteractableType() == InteractableType.SPROUT)
                                  .ToList();
            }

            else if (interactableType == InteractableType.WELL)
            {
                possibleTargets = FindObjectOfType <Spawner>()
                                  .GetEntitiesPosition()
                                  .Values
                                  .Where(e => e.GetComponent <Well>() != null)
                                  .ToList();
            }

            else
            {
                return(null);
            }

            if (possibleTargets.Count() == 0)
            {
                return(null);
            }

            // Find nearest object (https://forum.unity.com/threads/clean-est-way-to-find-nearest-object-of-many-c.44315/#post-3129260) as Interactable
            Interactable nearestInteractable = possibleTargets
                                               .OrderBy(t => (t.transform.position - this.transform.position).sqrMagnitude)
                                               .FirstOrDefault()
                                               .GetComponent <Interactable>();

            return(nearestInteractable);
        }
Beispiel #16
0
    public IInteractable GetNearestInteractableInRange(Transform t, InteractableType type, float range)
    {
        float         dist = float.MaxValue;
        IInteractable ret  = null;

        foreach (IInteractable i in Interactables[(int)type])
        {
            float checkDist = Vector3.Distance(t.position, i.gameObject.transform.position);
            if (checkDist < dist && checkDist < range && i.InteractState == InteractionState.Ready)
            {
                dist = checkDist;
                ret  = i;
            }
        }
        return(ret);
    }
Beispiel #17
0
    void OnEnable()
    {
        // Set sprites to use for interact icon based on current input device
        // Add listener to get device change events
        SetIconsForCurrentControlScheme(playerInput.currentControlScheme);
        InputUser.onChange += onInputDeviceChange;

        if (Dialogue != null)
        {
            Type = InteractableType.Dialogue;
        }
        else
        {
            Type = InteractableType.SceneChange;
        }
    }
Beispiel #18
0
    public void ChooseAudio(InteractableType type)
    {
        switch (type)
        {
        case InteractableType.Dot:
            PlaySound(SoundType.Normal);
            break;

        case InteractableType.Triangle:
            PlaySound(SoundType.ChangeColor);
            break;

        case InteractableType.PowerUp:
            PlaySound(SoundType.PowerUp);
            break;
        }
    }
Beispiel #19
0
 void AddPrompt(IInteractable target, InteractableType type)
 {
     if (!prompts.ContainsKey(target))
     {
         // TODO: When art supports it, set the text on the prompt based on the type
         GameObject            prompt       = GameObject.Instantiate(interactionPrompt);
         InteractionPromptIcon promptScript = prompt.GetComponent <InteractionPromptIcon>();
         if (promptScript != null)
         {
             promptScript.SetPromptType(type);
         }
         prompt.SetActive(true);
         prompt.transform.position = target.gameObject.transform.position + new Vector3(0.0f, 0.2f, 0.0f);
         prompt.transform.parent   = target.gameObject.transform;
         prompts.Add(target, prompt);
     }
 }
Beispiel #20
0
 public void SetInteractableType(InteractableType interactableType)
 {
     indicatorIcon.sprite = interactableType.SelectorSprite;
     SetProgress(0);
 }
    private void OnTriggerExit2D(Collider2D collision)
    {
        switch (collision.gameObject.tag)
        {
        case "Lever":
            if (currentInteractableType == InteractableType.lever)
            {
                goto case "CLEAN CASE";
            }
            else
            {
                break;
            }

        case "ElectricLever":
            if (currentInteractableType == InteractableType.electricLever)
            {
                goto case "CLEAN CASE";
            }
            else
            {
                break;
            }

        case "Leak":
            if (currentInteractableType == InteractableType.leak)
            {
                if (UI_Manager.instance.UI_leakGaugeCanvas)
                {
                    UI_Manager.instance.UI_leakGaugeCanvas.enabled = false;
                }
                InteractionHoldCanceled();
                goto case "CLEAN CASE";
            }
            else
            {
                break;
            }

        case "TP":
            if (currentInteractableType == InteractableType.teleporter && !CharacterController2D.instance.animator.GetBool("Teleporting"))
            {
                goto case "CLEAN CASE";
            }
            else
            {
                break;
            }

        case "InversionBlock":
            if (currentInteractableType == InteractableType.inversionBlockLever)
            {
                goto case "CLEAN CASE";
            }
            else
            {
                break;
            }

        case "CLEAN CASE":
            canInteract             = false;
            interactableObject      = null;
            currentInteractableType = InteractableType.none;
            break;
        }
    }
Beispiel #22
0
        public override DelayedActionInstance InteractWith(Interactable interactable, Interaction interaction, bool doAction = true)
        {
            DelayedActionInstance delayedActionInstance = new DelayedActionInstance {
                Duration      = 0f,
                ActionMessage = interactable.ContextualName
            };
            InteractableType action = interactable.Action;

            if (interaction.SourceSlot.Occupant is Screwdriver)
            {
                if (action == InteractableType.Button1)
                {
                    SimpleFabricatorBase nextReadable = GetNextReadable(CurrentFabricator, base.InputNetwork1DevicesSorted, interaction.AltKey);
                    if (!nextReadable)
                    {
                        return(delayedActionInstance.Fail(InterfaceStrings.LogicNoReadableDevices));
                    }
                    delayedActionInstance.StateMessage = string.Format(InterfaceStrings.ChangeSettingTo, nextReadable.ToTooltip());
                    if (!KeyManager.GetButton(KeyMap.QuantityModifier))
                    {
                        delayedActionInstance.ExtendedMessage = InterfaceStrings.HoldForPreviousObject;
                    }
                    if (!doAction)
                    {
                        return(delayedActionInstance.Succeed());
                    }
                    if (GameManager.IsServer)
                    {
                        NetworkServer.SendByChannelToAll(1077, new SetHashGenMessage {
                            FabricatorId  = nextReadable.netId,
                            LogicReaderId = base.netId
                        }, 0);
                        CurrentFabricator = nextReadable;
                        Setting           = 0.0;
                    }
                    return(delayedActionInstance.Succeed());
                }
            }
            else
            {
                if (action == InteractableType.Button1)
                {
                    if (!doAction)
                    {
                        return(delayedActionInstance.Succeed());
                    }
                    foreach (int key in InputPrefabs.PrefabReferences.Keys)
                    {
                        InputPrefabs.PrefabReferences[key].SetVisible(false);
                    }
                    if (InventoryManager.ParentHuman.IsLocalPlayer)
                    {
                        if (CurrentFabricator != null && CurrentFabricator)
                        {
                            if (InputPrefabs.ShowInputPanel("Recipe Hash Selector", null, CurrentFabricator.DynamicThings, CurrentFabricator.CurrentBuildState.ManufactureDat.MachinesTier))
                            {
                                InputPrefabs.OnSubmit += InputFinished;
                                StartCoroutine(WaitForDropdown());
                            }
                        }
                        else
                        {
                            if (InputPrefabs.ShowInputPanel("Recipe Hash Selector", null, GetDynamicThings(), MachineTier.Max))
                            {
                                InputPrefabs.OnSubmit += InputFinished;
                                StartCoroutine(WaitForDropdown());
                            }
                        }
                    }
                    return(delayedActionInstance.Succeed());
                }
            }
            return(base.InteractWith(interactable, interaction, doAction));
        }
Beispiel #23
0
 public TargetingEventArgs(InteractableType type)
 {
     typeOfInteractable = type;
 }
        /// <summary>
        /// Create interactable object of the given type
        /// </summary>
        /// <param name="objType">Type</param>
        /// <param name="pos">Position</param>
        /// <returns>Item entity</returns>
        public static EntityID CreateInteractable(InteractableType objType, Vector2i pos)
        {
            EntityID obj = EntityID.empty;

            switch (objType)
            {
            case InteractableType.Stairs:
            {
                obj = EntityStore.CreateEntity();
                obj.e.Initialize(
                    pos,
                    S.STAIRS_DOWN,
                    Color.white,
                    C.FSTR.Set("Stairs down"),
                    RenderFunctions.RenderOrder.STAIRS);
            }

            break;

            case InteractableType.Portal:
            {
                obj = EntityStore.CreateEntity();
                obj.e.Initialize(
                    pos,
                    S.PORTAL,
                    new Color32(0x3c, 0xac, 0xd7, 255),
                    C.FSTR.Set("Escape Portal"),
                    RenderFunctions.RenderOrder.INTERACTABLE);
            }

            break;

            case InteractableType.Well:
            {
                obj = EntityStore.CreateEntity();
                obj.e.Initialize(
                    pos,
                    S.WELL,
                    new Color32(0xbb, 0xbb, 0xbb, 255),
                    C.FSTR.Set("Old Well"),
                    RenderFunctions.RenderOrder.INTERACTABLE);
            }

            break;

            case InteractableType.GameExit:
            {
                obj = EntityStore.CreateEntity();
                obj.e.Initialize(
                    pos,
                    PackedSpriteID.empty,
                    new Color32(0xbb, 0xbb, 0xbb, 255),
                    C.FSTR.Set("Old Well"),
                    RenderFunctions.RenderOrder.INTERACTABLE);

                obj.e.groundTrigger = new GroundTrigger(GroundTrigger.GroundTriggerType.GameWon);
            }

            break;

            case InteractableType.Web:
            {
                obj = EntityStore.CreateEntity();
                obj.e.Initialize(
                    pos,
                    S.WEB,
                    new Color32(0xff, 0xff, 0xee, 150),
                    C.FSTR.Set("Web"),
                    RenderFunctions.RenderOrder.INTERACTABLE);

                obj.e.groundTrigger = new GroundTrigger(GroundTrigger.GroundTriggerType.Web);
            }

            break;
            }

            return(obj);
        }
Beispiel #25
0
        public (GameObject provider, float[] properties) GetData(InteractableType type)
        {
            var interactableInfo = _interactableInfos.First(info => info.Type == type);

            return(interactableInfo.Provider, interactableInfo.Properties);
        }
 public bool CanInteract(InteractableType type)
 {
     return((_allowedInteractions & type) != InteractableType.NONE);
 }
Beispiel #27
0
 /// <summary>
 /// Set the type of the interactable object.
 /// </summary>
 /// <param name="interactableType">type of the interactable object</param>
 public void SetInteractableType(InteractableType interactableType)
 {
     this.interactableType = interactableType;
 }
 public void GeneratePowerupObject(ObjectModifierScriptableObject objectModifierScriptableObject, InteractableType interactableType)
 {
     SpawnObject();
     interactableController.powerupObjectType = powerupObjectType;
     interactableController.powerupAmount     = powerupAmount;
     interactableController.objectModifierScriptableObject = objectModifierScriptableObject;
     interactableController.InteractableType = interactableType;
 }
 public void GenerateUpgradeObject(ObjectModifierScriptableObject objectModifierScriptableObject, InteractableType interactableType)
 {
     SpawnObject();
     interactableController.upgradeObjectType = upgradeObjectType;
     interactableController.upgradeModifier   = upgradeModifier;
     interactableController.objectModifierScriptableObject = objectModifierScriptableObject;
     interactableController.InteractableType = interactableType;
 }