Exemplo n.º 1
0
    private void Pickup(CarryEnabler carriable)
    {
        carriable.transform.parent           = holdSpot;
        carriable.transform.localEulerAngles = Vector3.zero;
        carriable.transform.localPosition    = Vector3.up * holdOffset;

        carriable.isCarried = true;

        heldObject = carriable;
    }
Exemplo n.º 2
0
    private bool TryPutDown()
    {
        List <PlacementPad> possiblePlacements = new List <PlacementPad>();

        bool foundPlacement = false;

        foreach (Collider2D hit in GetCollidersFacing())
        {
            PlacementPad placeable = hit.GetComponent <PlacementPad>();
            if (placeable != null)
            {
                foundPlacement = true;
                if (placeable.CanPlace(heldObject))
                {
                    possiblePlacements.Add(placeable);
                }
            }
        }

        if (possiblePlacements.Count > 0)
        {
            PlacementPad closest         = null;
            float        closestDistance = Mathf.Infinity;
            foreach (PlacementPad pad in possiblePlacements)
            {
                float distance = Vector3.Distance(pad.transform.position, holdSpot.transform.position);
                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    closest         = pad;
                }
            }

            closest.Place(heldObject);
            OnSetDown.Invoke();
            heldObject.isCarried = false;
            heldObject           = null;
        }
        else
        {
            if (!foundPlacement)
            {
                return(true);

                heldObject.Throw(transform.up);
                heldObject.isCarried = false;
                heldObject           = null;
            }
        }

        return(true);
    }
Exemplo n.º 3
0
    public bool IsEmpty(CarryEnabler o)
    {
        ContactFilter2D filter = new ContactFilter2D();

        filter.NoFilter();

        List <Collider2D> hits = new List <Collider2D>();

        placementCollider.OverlapCollider(filter, hits);

        foreach (Collider2D hit in hits)
        {
            CarryEnabler carriable = hit.GetComponent <CarryEnabler>();
            if (carriable != null && carriable != o)
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 4
0
    public IEnumerator DoSpawn()
    {
        spawning = true;
        yield return(new WaitForSeconds(delayUntilSpawn));

        CarryEnabler newObject = Instantiate(carryPrefab.gameObject, transform).GetComponent <CarryEnabler>();

        newObject.transform.localEulerAngles = Vector3.zero;
        newObject.transform.localPosition    = Vector3.zero;
        newObject.canPickUp = false;
        newObject.isCarried = false;
        while (!Mathf.Approximately(Vector3.Distance(newObject.transform.position, pad.transform.position), 0.0f))
        {
            newObject.transform.position = Vector3.MoveTowards(newObject.transform.position, pad.transform.position, spawnSpeed * Time.deltaTime);
            yield return(null);
        }
        newObject.transform.parent = null;
        newObject.canPickUp        = true;
        spawning = false;
    }
Exemplo n.º 5
0
    private void TryPickup()
    {
        ContactFilter2D filter = new ContactFilter2D();

        filter.NoFilter();

        List <Collider2D> hits = new List <Collider2D>();

        pickupCollider.OverlapCollider(filter, hits);

        foreach (Collider2D hit in hits)
        {
            CarryEnabler carriable = hit.GetComponent <CarryEnabler>();
            if (carriable != null && carriable.canPickUp)
            {
                Pickup(carriable);
                OnPickup.Invoke();
                return;
            }
        }
    }
Exemplo n.º 6
0
    private bool TryCauldron()
    {
        if (heldObject.GetComponent <FlaskContents>().contents == null)
        {
            return(false);
        }

        foreach (Collider2D hit in GetCollidersFacing())
        {
            Cauldron cauldron = hit.GetComponent <Cauldron>();
            if (cauldron != null)
            {
                if (cauldron.acceptingContents)
                {
                    heldObject.isCarried = false;
                    StartCoroutine(FlaskToCauldron(cauldron, heldObject));
                    heldObject = null;
                    OnPour.Invoke();
                }
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 7
0
 private IEnumerator FlaskToCauldron(Cauldron cauldron, CarryEnabler c)
 {
     cauldron.TakePotion(c.GetComponent <FlaskContents>());
     Destroy(c.gameObject);
     yield break;
 }
Exemplo n.º 8
0
 public void Place(CarryEnabler o)
 {
     o.transform.parent           = transform;
     o.transform.localEulerAngles = Vector3.zero;
     o.transform.localPosition    = Vector3.zero;
 }
Exemplo n.º 9
0
 public bool CanPlace(CarryEnabler o)
 {
     return(IsEmpty(o) && canUse);
 }