public static Color GetCellColorJson(int cellIndex)
        {
            SimHashes material = MaterialHelper.GetMaterialFromCell(cellIndex);

            return(material.ToCellMaterialColor());
        }
예제 #2
0
        public static void UpdateBuildingColor(BuildingComplete building)
        {
            var buildingName = building.name.Replace("Complete", string.Empty);
            var material     = MaterialHelper.ExtractMaterial(building);

            Color32 color;

            if (State.ConfiguratorState.Enabled)
            {
                switch (State.ConfiguratorState.ColorMode)
                {
                case Common.Data.ColorMode.Json:
                    color = material.GetMaterialColorForType(buildingName);
                    break;

                case Common.Data.ColorMode.DebugColor:
                    color = material.ToDebugColor();
                    break;

                case Common.Data.ColorMode.None:
                default:
                    color = DefaultColor;
                    break;
                }
            }
            else
            {
                color = DefaultColor;
            }

            if (State.TileNames.Contains(buildingName))
            {
                try
                {
                    if (TileColors == null)
                    {
                        TileColors = new Color?[Grid.CellCount];
                    }

                    TileColors[Grid.PosToCell(building.gameObject)] = color;

                    return;
                }
                catch (Exception e)
                {
                    State.Logger.Log("Error while aquiring cell color");
                    State.Logger.Log(e);
                }
            }

            var dimmedColor = color.SetBrightness(color.GetBrightness() / 2);

            // storagelocker
            var storageLocker = building.GetComponent <StorageLocker>();

            if (storageLocker != null)
            {
                SetFilteredStorageColors(storageLocker.filteredStorage, color, dimmedColor);
            }
            else // ownable
            {
                var ownable = building.GetComponent <Ownable>();

                if (ownable != null)
                {
                    ownable.ownedTint   = color;
                    ownable.unownedTint = dimmedColor;
                    ownable.UpdateTint();
                }
                else // rationbox
                {
                    var rationBox = building.GetComponent <RationBox>();

                    if (rationBox != null)
                    {
                        SetFilteredStorageColors(rationBox.filteredStorage, color, dimmedColor);
                    }
                    else // refrigerator
                    {
                        var fridge = building.GetComponent <Refrigerator>();

                        if (fridge != null)
                        {
                            SetFilteredStorageColors(fridge.filteredStorage, color, dimmedColor);
                        }
                        else // anything else
                        {
                            var kAnimControllerBase = building.GetComponent <KAnimControllerBase>();

                            if (kAnimControllerBase != null)
                            {
                                kAnimControllerBase.TintColour = color;
                            }
                            else
                            {
                                Debug.LogError($"Can't find KAnimControllerBase component in <{buildingName}> and its not a registered tile.");
                            }
                        }
                    }
                }
            }
        }