Ejemplo n.º 1
0
        /// <summary>
        /// Render and show a preview of a building.
        /// </summary>
        /// <param name="building">The building to render</param>
        public void Show(BuildingData building)
        {
            // Update current selection to the new building.
            currentSelection = building;
            renderPrefab     = (currentSelection == null || currentSelection.name == null) ? null : (PrefabCollection <BuildingInfo> .FindLoaded(currentSelection.name));

            // Generate render if there's a selection with a mesh.
            if (renderPrefab != null && renderPrefab.m_mesh != null)
            {
                // Set default values.
                previewRender.CameraRotation = 210f;
                previewRender.Zoom           = 4f;

                // Set mesh and material for render.
                previewRender.SetTarget(renderPrefab);

                // Set background.
                previewSprite.texture     = previewRender.Texture;
                noPreviewSprite.isVisible = false;

                // Render at next update.
                RenderPreview();
            }
            else
            {
                // No valid current selection with a mesh; reset background.
                previewSprite.texture     = null;
                noPreviewSprite.isVisible = true;
            }

            // Hide any empty building names.
            if (building == null)
            {
                buildingName.isVisible  = false;
                buildingLevel.isVisible = false;
                buildingSize.isVisible  = false;
            }
            else
            {
                // Set and show building name.
                buildingName.isVisible = true;
                buildingName.text      = currentSelection.DisplayName;
                UIUtils.TruncateLabel(buildingName, width - 45);
                buildingName.autoHeight = true;

                // Set and show building level.
                buildingLevel.isVisible = true;
                buildingLevel.text      = Translations.Translate("PRR_LEVEL") + " " + Mathf.Min((int)currentSelection.prefab.GetClassLevel() + 1, Util.MaxLevelOf(currentSelection.prefab.GetSubService()));
                UIUtils.TruncateLabel(buildingLevel, width - 45);
                buildingLevel.autoHeight = true;

                // Set and show building size.
                buildingSize.isVisible = true;
                buildingSize.text      = currentSelection.prefab.GetWidth() + "x" + currentSelection.prefab.GetLength();
                UIUtils.TruncateLabel(buildingSize, width - 45);
                buildingSize.autoHeight = true;
            }
        }
Ejemplo n.º 2
0
        public void Show(BuildingData item)
        {
            if (m_item == item) return;

            m_item = item;
            m_renderPrefab = (m_item == null) ? null : (PrefabCollection<BuildingInfo>.FindLoaded(m_item.name));

            // Preview
            if (m_renderPrefab != null && m_renderPrefab.m_mesh != null)
            {
                m_previewRenderer.cameraRotation = 210f;
                m_previewRenderer.zoom = 4f;
                m_previewRenderer.mesh = m_renderPrefab.m_mesh;
                m_previewRenderer.material = m_renderPrefab.m_material;

                RenderPreview();

                m_preview.texture = m_previewRenderer.texture;

                m_noPreview.isVisible = false;
            }
            else
            {
                m_preview.texture = null;
                m_noPreview.isVisible = true;
            }

            m_buildingName.isVisible = false;
            m_categoryIcon.isVisible = false;
            m_level.isVisible = false;
            m_size.isVisible = false;

            if (item == null) return;

            // Name
            m_buildingName.isVisible = true;
            m_buildingName.text = m_item.displayName;
            UIUtils.TruncateLabel(m_buildingName, width - 45);
            m_buildingName.autoHeight = true;

  
        }