public static void IterateAction(List <Base> objects, Type interfaceType)
 {
     foreach (var obj in objects)
     {
         if (interfaceType == typeof(IInteractive))
         {
             IInteractive ghostObject = obj as IInteractive;
             if (ghostObject != null)
             {
                 ghostObject.Interact();
             }
         }
         else if (interfaceType == typeof(IBreakable))
         {
             IBreakable ghostObject = obj as IBreakable;
             if (ghostObject != null)
             {
                 ghostObject.Break();
             }
         }
         else if (interfaceType == typeof(ICollectable))
         {
             ICollectable ghostObject = obj as ICollectable;
             if (ghostObject != null)
             {
                 ghostObject.Collect();
             }
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Iterates through a list
 /// </summary>
 /// <param name="roomObjects"></param>
 /// <param name="type"></param>
 public static void IterateAction(List <Base> roomObjects, Type type)
 {
     //if (typeof(IInteractive).IsAssignableFrom(type))
     foreach (var item in roomObjects)
     {
         if (typeof(IInteractive).IsAssignableFrom(type))
         {
             //dynamic changedObj = Convert.ChangeType(item, type);
             try
             {
                 IInteractive changedObj = (IInteractive)item;
                 changedObj.Interact();
             }
             catch {}
         }
         if (typeof(IBreakable).IsAssignableFrom(type))
         {
             try
             {
                 IBreakable changedObj = (IBreakable)item;
                 changedObj.Break();
             }
             catch {}
         }
         if (typeof(ICollectable).IsAssignableFrom(type))
         {
             try
             {
                 ICollectable changedObj = (ICollectable)item;
                 changedObj.Collect();
             }
             catch {}
         }
     }
 }
/// <summary>
/// IterateAction
/// </summary>
/// <param name="roomObjects"></param>
/// <param name="type"></param>
    public static void IterateAction(List <Base> roomObjects, Type type)
    {
        foreach (var cls in roomObjects)
        {
            if (type == typeof(IInteractive))
            {
                if (cls is IInteractive)
                {
                    IInteractive classou = (IInteractive)cls;
                    classou.Interact();
                }
            }
            else if (type == typeof(IBreakable))
            {
                if (cls is IBreakable)
                {
                    IBreakable classou = (IBreakable)cls;
                    classou.Break();
                }
            }
            else if (type == typeof(ICollectable))
            {
                if (cls is ICollectable)
                {
                    ICollectable classou = (ICollectable)cls;
                    classou.Collect();
                }
            }
        }
    }
예제 #4
0
 ///<summary> method should take a list of all objects, </summary>
 public static void IterateAction(List <Base> roomObjects, Type type)
 {
     foreach (var item in roomObjects)
     {
         if (type.ToString() == "IInteractive")
         {
             if (item is IInteractive)
             {
                 IInteractive tmp = item as IInteractive;
                 tmp.Interact();
             }
         }
         if (type.ToString() == "IBreakable")
         {
             if (item is IBreakable)
             {
                 IBreakable temp = item as IBreakable;
                 temp.Break();
             }
         }
         if (type.ToString() == "ICollectable")
         {
             if (item is ICollectable)
             {
                 ICollectable temp = item as ICollectable;
                 temp.Collect();
             }
         }
     }
 }
    /// <summary>
    /// execute methods depending on what interface that item implements
    /// </summary>
    /// <param name="roomObjects">list of objects</param>
    /// <param name="type">types</param>
    public static void IterateAction(List <Base> roomObjects, Type type)
    {
        foreach (var obj in roomObjects)
        {
            switch (type.ToString())
            {
            case "IInteractive":
                if (obj is IInteractive)
                {
                    IInteractive instance = (IInteractive)obj;
                    instance.Interact();
                }
                break;

            case "IBreakable":
                if (obj is IBreakable)
                {
                    IBreakable instance = (IBreakable)obj;
                    instance.Break();
                }
                break;

            case "ICollectable":
                if (obj is ICollectable)
                {
                    ICollectable instance = (ICollectable)obj;
                    instance.Collect();
                }
                break;

            default:
                break;
            }
        }
    }
예제 #6
0
 private void Update()
 {
     _annotationLabel.text = "";
     if (_currentInteractive == null)
     {
         for (int i = 0; i < Physics.RaycastNonAlloc(_transform.position, _transform.forward, _raycastHits, 2); i++)
         {
             var interactive = _raycastHits[i].transform.GetComponent <IInteractive>();
             if (interactive != null && interactive.CanInteract)
             {
                 _annotationLabel.text = interactive.Annotation + " (E)";
                 if (Input.GetKeyDown(KeyCode.E))
                 {
                     _currentInteractive = interactive;
                     _currentInteractive.OnStopInteraction += StopInteraction;
                     _playerMover.enabled       = false;
                     _puzzleCameraMover.enabled = true;
                     _puzzleCameraMover.SetTarget(_currentInteractive.CameraPosition);
                     _currentInteractive.Interact();
                 }
             }
         }
     }
     else
     {
         if (Input.GetKeyDown(KeyCode.E))
         {
             _currentInteractive.StopInteraction();
         }
     }
 }
예제 #7
0
 public void HandleInteraction(InputAction.CallbackContext context)
 {
     if (context.performed)
     {
         closestInteractive.Interact();
     }
 }
    public static void IterateAction(List <Base> roomObjects, Type type)
    {
        foreach (var element in roomObjects)
        {
            if (type == typeof(IInteractive))
            {
                IInteractive inter = element as IInteractive;
                if (inter != null)
                {
                    inter.Interact();
                }
            }

            if (type == typeof(ICollectable))
            {
                ICollectable inter = element as ICollectable;
                if (inter != null)
                {
                    inter.Collect();
                }
            }

            if (type == typeof(IBreakable))
            {
                IBreakable inter = element as IBreakable;
                if (inter != null)
                {
                    inter.Break();
                }
            }
        }
    }
예제 #9
0
 ///<summary>This method allows iteraction with the methods within the objects.</summary>
 public static void IterateAction(List <Base> roomObjects, Type type)
 {
     foreach (var element in roomObjects)
     {
         if (type.ToString() == "IInteractive")
         {
             if (element is IInteractive)
             {
                 IInteractive tmp = element as IInteractive;
                 tmp.Interact();
             }
         }
         else if (type.ToString() == "IBreakable")
         {
             if (element is IBreakable)
             {
                 IBreakable tmp = element as IBreakable;
                 tmp.Break();
             }
         }
         else if (type.ToString() == "ICollectable")
         {
             if (element is ICollectable)
             {
                 ICollectable tmp = element as ICollectable;
                 tmp.Collect();
             }
         }
     }
 }
예제 #10
0
    private void OnTriggerEnter(Collider other)
    {
        IInteractive interactive = other.GetComponent <IInteractive>();

        if (interactive != null)
        {
            interactive.Interact(this.transform.root.gameObject);
        }
    }
예제 #11
0
    private void Update()
    {
        if (!_interact)
        {
            return;
        }

        _interact = false;
        _obj.Interact();
    }
예제 #12
0
 protected virtual void TargetReached()
 {
     Velocity = Vector3.zero;
     TransformCached.position = Destination;
     if (Target != null)
     {
         IInteractive oldTarget = Target;
         Target = null;
         oldTarget.Interact(this);
     }
 }
예제 #13
0
    public void Interact()
    {
        if (_interactingWith == _target)
        {
            return;
        }

        CancelInteract();

        _interactingWith = _target;
        _interactingWith.Interact();
    }
예제 #14
0
    public void Interact(InputAction.CallbackContext context)
    {
        if (!context.performed)
        {
            return;
        }

        if (target != null && !target.Equals(null)) // To make sure we have a target and it wasn't destroyed
        {
            target.Interact();
        }
    }
예제 #15
0
    private void OnAttack(InputAction.CallbackContext i_Ctx)
    {
        RaycastHit2D interactiveObjectHit = m_InteractiveObjectsManager.InteractiveObjectInRange;

        if (interactiveObjectHit)
        {
            IInteractive interactiveObject = interactiveObjectHit.collider.GetComponent <IInteractive>();
            interactiveObject.Interact();
        }
        else
        {
            m_State = PlayerState.Attacking;
        }
    }
예제 #16
0
 private void Raychecked(RaycastHit2D ray)
 {
     //Color color = Color.green;
     if (ray.collider != null)
     {
         //color = Color.red;
         //Debug.Log(ray.collider.name);
         IInteractive item = ray.collider.GetComponent <IInteractive>();
         if (item != null)
         {
             item.Interact(this.gameObject);
         }
     }
     //Debug.DrawRay(bC2d.bounds.center, -transform.up * (bC2d.bounds.extents.y + 0.02f), color);
 }
예제 #17
0
 async void IEndDragHandler.OnEndDrag(PointerEventData eventData)
 {
     canvasGroup.blocksRaycasts = true;
     if (active)
     {
         var raycast = new List <RaycastResult>();
         EventSystem.current.RaycastAll(eventData, raycast);
         var onDrop = raycast.Where(r => r.gameObject == zone.gameObject).Any();
         if (onDrop)
         {
             await interactive.Interact();
         }
     }
     PutBack(eventData);
     zone.StopDragging();
 }
예제 #18
0
    public bool CheckInteraction()
    {
        bool isInteract;

        Collider2D[] collidersHit = Physics2D.OverlapBoxAll(collider2D.bounds.center, collider2D.size, 0f, layerToCheck);

        isInteract = collidersHit != null;

        for (int i = 0; i < collidersHit.Length; i++)
        {
            IInteractive interactive = collidersHit[i].GetComponent <IInteractive>();

            if (collidersHit[i].CompareTag("Item"))
            {
                WorldItem item = collidersHit[i].GetComponent <WorldItem>();
                item.PickUp(ref inventory);
                break;
            }
            else if (interactive.ToMonoBehaviour() != null && interactive.CanInteract(null))
            {
                interactive.Interact(null);
                break;
            }
            else if (collidersHit[i].CompareTag("Merchant"))
            {
                MerchantWorld merchant = collidersHit[i].GetComponentInParent <MerchantWorld>();
                merchant.Interact();

                break;
            }
            else if (collidersHit[i].CompareTag("EndMapEvent"))
            {
                EventEndScene nextLevel = collidersHit[i].GetComponent <EventEndScene>();
                nextLevel.Activate();
                break;
            }
            else if (collidersHit[i].CompareTag("WhaleDialogue"))
            {
                dialogue dialogue = collidersHit[i].GetComponent <dialogue>();
                dialogue.InitDialog();
                break;
            }
        }

        return(isInteract);
    }
예제 #19
0
    private void InteractWith(IInteractive obj)
    {
        if (obj == null)
        {
            return;
        }

        GameObject go = obj.GetGameObject();

        if (this.characterMovementController.DistanceTo(go.transform.position) > 3.0f)
        {
            this.characterMovementController.WalkTo(go.transform.position);             // walk to that point
        }
        else
        {
            obj.Interact(this.gameObject);
        }
    }
예제 #20
0
 /// <summary>
 /// Функция взаимодействия
 /// </summary>
 public virtual void Interact()
 {
     if (interactions.Count > 0)
     {
         if (interactions[0] != null)
         {
             IInteractive interaction = interactions[0].GetComponent <IInteractive>();
             if (interaction != null)
             {
                 interaction.Interact();
                 StartCoroutine(InteractionProcess());
             }
         }
         if (interactions[0] == null ? true : (interactions[0].GetComponent <IInteractive>() == null ||
                                               interactions[0].GetComponent <Collider2D>() == null ? true: !interactions[0].GetComponent <Collider2D>().enabled))
         {
             interactions.RemoveAt(0);
         }
     }
 }
    /// <summary>
    ///  Method that will perform primary action on set of given object and
    /// type.
    /// </summary>
    /// <param name="roomObjects"> List of objects to perform actions on
    /// </param>
    /// <param name="type">Interface action to invoke</param>
    public static void IterateAction(List <Base> roomObjects, Type type)
    {
        switch (type.Name)
        {
        case "IInteractive":
            foreach (var i in roomObjects)
            {
                if (i is IInteractive)
                {
                    IInteractive item = i as IInteractive;
                    item.Interact();
                }
            }

            break;

        case "IBreakable":
            foreach (var i in roomObjects)
            {
                if (i is IBreakable)
                {
                    IBreakable item = i as IBreakable;
                    item.Break();
                }
            }

            break;

        case "ICollectable":
            foreach (var i in roomObjects)
            {
                if (i is ICollectable)
                {
                    ICollectable item = i as ICollectable;
                    item.Collect();
                }
            }

            break;
        }
    }
예제 #22
0
 public static void IterateAction(List <Base> roomObjects, Type type)
 {
     foreach (Base roomObject in roomObjects)
     {
         if (type == typeof(IInteractive) && roomObject is IInteractive)
         {
             IInteractive iObj = roomObject as IInteractive;
             iObj.Interact();
         }
         if (type == typeof(IBreakable) && roomObject is IBreakable)
         {
             IBreakable iObj = roomObject as IBreakable;
             iObj.Break();
         }
         if (type == typeof(ICollectable) && roomObject is ICollectable)
         {
             ICollectable iObj = roomObject as ICollectable;
             iObj.Collect();
         }
     }
 }
    /// <summary>This method takes a list of all objects, iterate through it, and execute methods</summary>
    public static void IterateAction(List <Base> roomObjects, Type type)
    {
        foreach (var item in roomObjects)
        {
            if (type.ToString() == "IInteractive" && item is IInteractive)
            {
                // Create a Object temporal to execute methods
                IInteractive obj = item as IInteractive;
                // check if the conversion is successful.
                if (obj != null)
                {
                    obj.Interact();
                }
            }

            if (type.ToString() == "IBreakable" && item is IBreakable)
            {
                // Create a Object temporal to execute methods
                IBreakable obj = item as IBreakable;
                // check if the conversion is successful.
                if (obj != null)
                {
                    obj.Break();
                }
            }

            if (type.ToString() == "ICollectable" && item is ICollectable)
            {
                // Create a Object temporal to execute methods
                ICollectable obj = item as ICollectable;
                // check if the conversion is successful
                if (obj != null)
                {
                    obj.Collect();
                }
            }
        }
    }
예제 #24
0
 // Use this methode to perform your task
 public override BehaviourTree.Status Update()
 {
     in_interactiveObject.Interact(this.agent.gameObject);
     return(BehaviourTree.Status.RUNNING);
 }
예제 #25
0
 public override void Interact(IInteractive with)
 {
     Debug.Assert(Intersects(with));
     if (!_rectangle.Intersects(with.BoundingShape)) return;
     List<PlaygroundBlock> blocks = BlocksIntersects(with);
     foreach (PlaygroundBlock playgroundBlock in blocks)
     {
         playgroundBlock.Interact(with);
         with.Interact(playgroundBlock);
     }
 }