Пример #1
0
    // returns true if there is still space on the platform for a collidable object to spawn
    private void SpawnCollidable(ObjectType objectType, Vector3 position, Vector3 direction, Direction locationDirection,
                                 PlatformObject platform, int platformLocalIndex, bool activateImmediately)
    {
        int collidablePositions = platform.numCollidables;

        // can't do anything if the platform doesn't accept any collidable object spawns
        if (collidablePositions == 0)
        {
            return;
        }

        Vector3 offset = platformSizes[platformLocalIndex] * 0.1f;
        float   zDelta = platformSizes[platformLocalIndex].z * .8f / (1 + collidablePositions);

        for (int i = 0; i < collidablePositions; ++i)
        {
            if (platform.CanSpawnCollidable(i))
            {
                spawnData.slotPositions = platform.GetSlotsAvailable();
                int localIndex = ObjectPool.instance.GetNextObjectIndex(objectType, spawnData);
                if (localIndex != -1)
                {
                    CollidableObject collidable   = ObjectPool.instance.GetObjectFromPool(localIndex, objectType) as CollidableObject;
                    Quaternion       lookRotation = Quaternion.LookRotation(direction);
                    Vector3          spawnSlot    = collidable.GetSpawnSlot(platform.GetTransform().right *slotDistance, spawnData.slotPositions);
                    collidable.Orient(platform, position + (offset.z + ((i + 1) * zDelta)) * direction + spawnSlot, lookRotation);
                    if (activateImmediately)
                    {
                        collidable.Activate();
                    }

                    int objectIndex = ObjectPool.instance.GetObjectIndexFromLocalIndex(localIndex, objectType);
                    ObjectHistory.instance.ObjectSpawned(objectIndex, (offset.z + ((i + 1) * zDelta)), locationDirection,
                                                         lookRotation.eulerAngles.y, objectType);
                    platform.SpawnCollidable(i);

                    // don't allow any more of the same collidable type if we are forcing a different collidable
                    if (platform.hasDifferentCollidables)
                    {
                        break;
                    }
                }
            }
        }
        spawnData.slotPositions = 0;
    }