Exemplo n.º 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();
            }
        }
    }
    private void RemoveExpiredSplats()
    {
        if (removeTime.Count > 1)
        {
            removeTime.Sort((Pair <float, NoiseSplat> a, Pair <float, NoiseSplat> b) => a.first.CompareTo(b.first));
        }
        int num = -1;

        for (int i = 0; i < removeTime.Count; i++)
        {
            Pair <float, NoiseSplat> pair = removeTime[i];
            if (pair.first > Time.time)
            {
                break;
            }
            Pair <float, NoiseSplat> pair2 = removeTime[i];
            NoiseSplat second = pair2.second;
            if (second != null)
            {
                IPolluter provider = second.GetProvider();
                FreePolluter(provider as Polluter);
            }
            num = i;
        }
        for (int num2 = num; num2 >= 0; num2--)
        {
            removeTime.RemoveAt(num2);
        }
    }
Exemplo n.º 3
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);
            }
        }
    }