Exemple #1
0
    public NoiseSplat(IPolluter setProvider, float death_time = 0f)
    {
        deathTime = death_time;
        provider  = setProvider;
        provider.Clear();
        position = provider.GetPosition();
        dB       = provider.GetNoise();
        int cell = Grid.PosToCell(position);

        if (!NoisePolluter.IsNoiseableCell(cell))
        {
            dB = 0;
        }
        if (dB != 0)
        {
            radius = provider.GetRadius();
            if (radius != 0)
            {
                int x = 0;
                int y = 0;
                Grid.CellToXY(cell, out x, out y);
                Vector2I vector2I = new Vector2I(x - radius, y - radius);
                Vector2I v        = vector2I + new Vector2I(radius * 2, radius * 2);
                vector2I      = Vector2I.Max(vector2I, Vector2I.zero);
                v             = Vector2I.Min(v, new Vector2I(Grid.WidthInCells - 1, Grid.HeightInCells - 1));
                effectExtents = new Extents(vector2I.x, vector2I.y, v.x - vector2I.x, v.y - vector2I.y);
                baseExtents   = new Extents(x, y, 1, 1);
                AddNoise();
            }
        }
    }
Exemple #2
0
    public NoiseSplat(NoisePolluter setProvider, float death_time = 0f)
    {
        deathTime = death_time;
        dB        = 0;
        radius    = 5;
        if (setProvider.dB != null)
        {
            dB = (int)setProvider.dB.GetTotalValue();
        }
        int cell = Grid.PosToCell(setProvider.gameObject);

        if (!NoisePolluter.IsNoiseableCell(cell))
        {
            dB = 0;
        }
        if (dB != 0)
        {
            setProvider.Clear();
            OccupyArea occupyArea = setProvider.occupyArea;
            baseExtents = occupyArea.GetExtents();
            provider    = setProvider;
            position    = setProvider.transform.GetPosition();
            if (setProvider.dBRadius != null)
            {
                radius = (int)setProvider.dBRadius.GetTotalValue();
            }
            if (radius != 0)
            {
                int x = 0;
                int y = 0;
                Grid.CellToXY(cell, out x, out y);
                int      widthInCells  = occupyArea.GetWidthInCells();
                int      heightInCells = occupyArea.GetHeightInCells();
                Vector2I vector2I      = new Vector2I(x - radius, y - radius);
                Vector2I v             = vector2I + new Vector2I(radius * 2 + widthInCells, radius * 2 + heightInCells);
                vector2I                     = Vector2I.Max(vector2I, Vector2I.zero);
                v                            = Vector2I.Min(v, new Vector2I(Grid.WidthInCells - 1, Grid.HeightInCells - 1));
                effectExtents                = new Extents(vector2I.x, vector2I.y, v.x - vector2I.x, v.y - vector2I.y);
                partitionerEntry             = GameScenePartitioner.Instance.Add("NoiseSplat.SplatCollectNoisePolluters", setProvider.gameObject, effectExtents, GameScenePartitioner.Instance.noisePolluterLayer, setProvider.onCollectNoisePollutersCallback);
                solidChangedPartitionerEntry = GameScenePartitioner.Instance.Add("NoiseSplat.SplatSolidCheck", setProvider.gameObject, effectExtents, GameScenePartitioner.Instance.solidChangedLayer, setProvider.refreshPartionerCallback);
            }
        }
    }