Example #1
0
    public void UpdateOverlayColours()
    {
        GridArea visibleArea = GridVisibleArea.GetVisibleArea();
        Diseases diseases    = Db.Get().Diseases;
        Color32  color       = new Color32(0, 0, 0, byte.MaxValue);

        for (int i = 0; i < headers.Count; i++)
        {
            DiseaseContainer       payload    = payloads[i];
            DiseaseHeader          header     = headers[i];
            KBatchedAnimController controller = payload.controller;
            if ((UnityEngine.Object)controller != (UnityEngine.Object)null)
            {
                Color32 c        = color;
                Vector3 position = controller.transform.GetPosition();
                if (visibleArea.Min <= (Vector2)position && (Vector2)position <= visibleArea.Max)
                {
                    int num           = 0;
                    int disease_idx   = 255;
                    int disease_count = 0;
                    GetVisualDiseaseIdxAndCount(header, ref payload, out disease_idx, out disease_count);
                    if (disease_idx != 255)
                    {
                        c   = diseases[disease_idx].overlayColour;
                        num = disease_count;
                    }
                    if (payload.isContainer)
                    {
                        Storage           component = header.primaryElement.GetComponent <Storage>();
                        List <GameObject> items     = component.items;
                        for (int j = 0; j < items.Count; j++)
                        {
                            GameObject gameObject = items[j];
                            if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
                            {
                                HandleVector <int> .Handle handle = GetHandle(gameObject);
                                if (handle.IsValid())
                                {
                                    DiseaseHeader header2 = GetHeader(handle);
                                    if (header2.diseaseCount > num && header2.diseaseIdx != 255)
                                    {
                                        num = header2.diseaseCount;
                                        c   = diseases[header2.diseaseIdx].overlayColour;
                                    }
                                }
                            }
                        }
                    }
                    c.a = SimUtil.DiseaseCountToAlpha254(num);
                    if (payload.conduitType != 0)
                    {
                        ConduitFlow flowManager = Conduit.GetFlowManager(payload.conduitType);
                        int         cell        = Grid.PosToCell(position);
                        ConduitFlow.ConduitContents contents = flowManager.GetContents(cell);
                        if (contents.diseaseIdx != 255 && contents.diseaseCount > num)
                        {
                            num = contents.diseaseCount;
                            c   = diseases[contents.diseaseIdx].overlayColour;
                            c.a = byte.MaxValue;
                        }
                    }
                }
                controller.OverlayColour = c;
            }
        }
    }