コード例 #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;
    }
コード例 #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);
    }
コード例 #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);
    }
コード例 #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;
    }
コード例 #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;
            }
        }
    }
コード例 #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);
    }
コード例 #7
0
 private IEnumerator FlaskToCauldron(Cauldron cauldron, CarryEnabler c)
 {
     cauldron.TakePotion(c.GetComponent <FlaskContents>());
     Destroy(c.gameObject);
     yield break;
 }
コード例 #8
0
 public void Place(CarryEnabler o)
 {
     o.transform.parent           = transform;
     o.transform.localEulerAngles = Vector3.zero;
     o.transform.localPosition    = Vector3.zero;
 }
コード例 #9
0
 public bool CanPlace(CarryEnabler o)
 {
     return(IsEmpty(o) && canUse);
 }