Exemple #1
0
        /// <summary>
        /// Spawns a single loot object, without delay, and regardless of the defined quantities
        /// </summary>
        public virtual void SpawnOneLoot()
        {
            _objectToSpawn = GetObject();

            if (_objectToSpawn == null)
            {
                return;
            }

            if (RemainingQuantity <= 0)
            {
                return;
            }

            _spawnedObject = Instantiate(_objectToSpawn);

            if (AvoidObstacles)
            {
                bool placementOK      = false;
                int  amountOfAttempts = 0;
                while (!placementOK && (amountOfAttempts < MaxAvoidAttempts))
                {
                    MMSpawnAround.ApplySpawnAroundProperties(_spawnedObject, SpawnProperties, this.transform.position);

                    if (DimensionMode == DimensionModes.TwoD)
                    {
                        _raycastOrigin = _spawnedObject.transform.position;
                        _raycastHit2D  = Physics2D.BoxCast(_raycastOrigin + Vector3.right * AvoidRadius, AvoidRadius * Vector2.one, 0f, Vector2.left, AvoidRadius, AvoidObstaclesLayerMask);
                        if (_raycastHit2D.collider == null)
                        {
                            placementOK = true;
                        }
                        else
                        {
                            amountOfAttempts++;
                        }
                    }
                    else
                    {
                        _raycastOrigin = _spawnedObject.transform.position;
                        _overlapBox    = Physics.OverlapBox(_raycastOrigin, Vector3.one * AvoidRadius, Quaternion.identity, AvoidObstaclesLayerMask);

                        if (_overlapBox.Length == 0)
                        {
                            placementOK = true;
                        }
                        else
                        {
                            amountOfAttempts++;
                        }
                    }
                }
            }
            else
            {
                MMSpawnAround.ApplySpawnAroundProperties(_spawnedObject, SpawnProperties, this.transform.position);
            }
            _spawnedObject.SendMessage("OnInstantiate", SendMessageOptions.DontRequireReceiver);
            RemainingQuantity--;
        }
Exemple #2
0
 /// <summary>
 /// OnDrawGizmos, we display the shape at which objects will spawn when looted
 /// </summary>
 protected virtual void OnDrawGizmos()
 {
     if (DrawGizmos)
     {
         MMSpawnAround.DrawGizmos(SpawnProperties, this.transform.position, GizmosQuantity, GimosSize, GizmosColor);
     }
 }
Exemple #3
0
        /// <summary>
        /// Spawns the associated prefab
        /// </summary>
        public virtual void SpawnPrefab()
        {
            if (TargetInventory != null)
            {
                // if there's a prefab set for the item at this slot, we instantiate it at the specified offset
                if (Prefab != null && TargetInventory.TargetTransform != null)
                {
                    GameObject droppedObject = (GameObject)Instantiate(Prefab);
                    if (droppedObject.GetComponent <ItemPicker>() != null)
                    {
                        droppedObject.GetComponent <ItemPicker>().Quantity = Quantity;
                    }

                    MMSpawnAround.ApplySpawnAroundProperties(droppedObject, DropProperties,
                                                             TargetInventory.TargetTransform.position);
                }
            }
        }