/// <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;
            }
        }
    }
Beispiel #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 {}
         }
     }
 }
Beispiel #3
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();
             }
         }
     }
 }
 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();
             }
         }
     }
 }
/// <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();
                }
            }
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag.Equals(Tags.ENEMY))
        {
            mAudioSource.Stop();
            mAudioSource.Play();
            isStunned = true;
            StartCoroutine(resetStun());
            return;
        }

        ICollectable collectable = other.GetComponent <ICollectable>();

        // we only care if we collid with an collectable
        if (collectable != null)
        {
            CollectableType type = collectable.Collect();
            if (type == CollectableType.NONE)
            {
                return;
            }

            if (type == CollectableType.HP_BOBBLE)
            {
                mHealthManager.GainHealth(HP_GAIN_VALUE);
                HighscoreManager.Instance.AddToScore(HighscoreManager.GET_HEALTH);
                return;
            }

            mInventory.AddInventoryItem(type);
            HighscoreManager.Instance.AddToScore(HighscoreManager.FIND_CORE);
        }
    }
    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();
                }
            }
        }
    }
    protected override void Update()
    {
        base.Update();

        if (Input.GetButtonDown("Collect"))
        {
            if (FPSCharacterController.Instance.lookingAtObject == null)
            {
                return;
            }

            ICollectable obj = FPSCharacterController.Instance.lookingAtObject.GetComponent(typeof(ICollectable)) as ICollectable;

            if (obj == null)
            {
                return;
            }

            obj.Collect();              //TODO the limitation, if collect method needs parameter, I don't know how to pass them properly

            if (pickEvent != null)
            {
                pickEvent();
            }
        }
    }
Beispiel #9
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();
             }
         }
     }
 }
Beispiel #10
0
    private void OnTriggerEnter(Collider other)
    {
        ICollectable collectable = other.transform.GetComponent <ICollectable>();

        if (collectable != null && !other.transform.CompareTag("striker"))
        {
            collectable.Collect(type);
        }
    }
Beispiel #11
0
    void OnTriggerEnter(Collider other)
    {
        ICollectable obj = other.GetComponent <ICollectable>();

        if (obj != null)
        {
            obj.Collect();
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        ICollectable collectable = other.GetComponent <ICollectable>();

        if (collectable != null)
        {
            collectable.Collect();
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        ICollectable collectable = other.GetComponent <ICollectable>();

        if (collectable == null)
        {
            return;
        }
        collectable.Collect();
        other.gameObject.SetActive(false);
    }
Beispiel #14
0
    private void OnTriggerStay(Collider other)
    {
        ICollectable collectable = other.transform.GetComponent <ICollectable>();

        if (collectable != null && !other.transform.CompareTag("striker"))
        {
            ZoneType collectableType = collectable.GetCollectableType();
            collectable.Collect(type);
            OnZoneHit(collectableType);
        }
    }
    public void CollectItem()
    {
        if (spawnedItem == null)
        {
            return;
        }

        spawnedItem.Collect();
        spawnedItem = null;
        StartCoroutine("Counter");
    }
Beispiel #16
0
        private void CollisionCheck()
        {
            int count = Physics.OverlapSphereNonAlloc(GetBallCenterPosition(), BallRadius, m_Colliders);

            for (int i = 0; i < count; i++)
            {
                if (m_Colliders[i].CompareTag(Entity.Tag))
                {
                    ICollectable collectable = m_Colliders[i].GetComponent <ICollectable>();

                    if (collectable != null)
                    {
                        collectable.Collect();
                    }
                }
            }
        }
    /// <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;
        }
    }
Beispiel #18
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();
         }
     }
 }
 public void Detect()
 {
     /*
      * Detectar objetos del mundo
      * Estos objetos tiene ICollectable
      * Puedo leer la informacion del objeto detectado
      * Se recoge los objetos con el boton E del teclado
      */
     if (Physics.Raycast(detectorOrigin.transform.position, detectorOrigin.transform.forward, out RaycastHit hit, distance))
     {
         ICollectable collectable = hit.transform.GetComponent <ICollectable>();
         if (collectable != null)
         {
             Item actualItem = collectable.GetItemInfo();
             if (Input.GetKeyDown(KeyCode.E))
             {
                 collectable.Collect(owner.inventoryManager);
             }
             //mostramos la interface de los objetos
             if (actualItem != null)
             {
                 panelItem.SetActive(true);
                 textName.text         = actualItem.name;
                 textDescription.text  = actualItem.description;
                 textNumberWeight.text = actualItem.weight.ToString();
                 textNumberCount.text  = actualItem.count.ToString();
             }
             else
             {
                 // si el contenido del objeto es null, porque ya lo hemos cogido antes
                 panelItem.SetActive(false);
             }
         }
         else
         {
             // si no se detectan objetos, ocultamos la interface
             panelItem.SetActive(false);
         }
     }
 }
    /// <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();
                }
            }
        }
    }
Beispiel #21
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "water")
        {
            Destroy(other.gameObject);
            ICollectable icollectable = other.GetComponent <ICollectable>();

            if (icollectable != null)
            {
                icollectable.Collect();
            }
        }
        else if (other.gameObject.tag == "fire")
        {
            live         -= 5;
            livetext.text = live.ToString();
            ShowFloattingFailText();
            if (live <= 0)
            {
                failPanel.SetActive(true);
                Time.timeScale = 0;
            }
        }
    }
        private void OnCollierEntered(Collider2D other)
        {
            ICollectable collectable = other.GetComponent <ICollectable>();

            collectable?.Collect();
        }
Beispiel #23
0
    // Update is called once per frame
    void Update()
    {
        Debug.DrawLine(_flashlight.transform.position, _flashlight.transform.position + _flashlight.transform.forward * 10.0f, Color.green);
        if (!controlsBlocked)
        {
            MoveCharacter();
            if (toCollect != null && (Input.GetButtonDown("Interact")))
            {
                toCollect.Collect(this);
            }
            else if (toInteract != null && (Input.GetButtonDown("Interact")))
            {
                toInteract.Interact(this);
            }

            if (Input.GetButtonDown("Lantern"))
            {
                choosenLight = choosenLight == 2 ? 0 : 2;
                ChooseLight();
            }
            if (Input.GetButtonDown("Flashlight"))
            {
                choosenLight = choosenLight == 1 ? 0 : 1;
                ChooseLight();
            }
        }
        if (toCollect != null)
        {
            Debug.Log("Press E To Collect");
        }
        if (toInteract != null)
        {
            Debug.Log("Press E To Interact");
        }

        if (hidingLantern)
        {
            SphereGrowTime += Time.deltaTime;
            if (SphereGrowTime >= ssControler.growTime)
            {
                armLantern.SetActive(false);
                armFlashlight.SetActive(shouldShowFlashlight);
                _flashlight.enabled = shouldShowFlashlight;
                SphereGrowTime      = 0.0f;
                hidingLantern       = false;
            }
        }

        //Health update
        healthRegenTimer += Time.deltaTime;
        if (healthRegenTimer >= healthRegenTime)
        {
            healthRegenTimer = 0.0f;
            currentHealth   += healthRegen;
            if (currentHealth > maxHealth)
            {
                currentHealth = maxHealth;
            }
        }

        //Enemy checks
        foreach (var enemy in enemies)
        {
            enemy.GetComponent <EnemyController>().SetLightFlashed(false);
            if (Vector3.Dot(_flashlight.transform.forward, enemy.GetComponent <EnemyController>().lightTarget.transform.forward) <= flashLightThreshold && choosenLight == 1)
            {
                enemy.GetComponent <EnemyController>().SetLightFlashed(true);
            }
        }
    }
Beispiel #24
0
 public Collector Include(ICollectable child)
 {
     collectables = collectables.Concat(child.Collect());
     return(this);
 }