예제 #1
0
        private static UITextureAtlas LoadResources()
        {
            string[] spriteNames =
            {
                //"Anarchy",
                //"AnarchyDisabled",
                //"AnarchyFocused",
                //"AnarchyHovered",
                //"AnarchyPressed",
                "Add",
                "AddDisabled",
                "AddFocused",
                "AddHovered",
                "AddPressed",
                "Remove",
                "RemoveDisabled",
                "RemoveFocused",
                "RemoveHovered",
                "RemovePressed",
                //"Bending",
                //"BendingDisabled",
                //"BendingFocused",
                //"BendingHovered",
                //"BendingPressed",
                "Parallel",
                "ParallelDisabled",
                "ParallelFocused",
                "ParallelHovered",
                "ParallelPressed",
                "Reverse",
                "ReverseDisabled",
                "ReverseFocused",
                "ReverseHovered",
                "ReversePressed",
                "Tutorial"
            };

            var textureAtlas =
                ResourceLoader.CreateTextureAtlas("ParallelRoadTool", spriteNames, "ParallelRoadTool.Icons.");

            var defaultAtlas = ResourceLoader.GetAtlas("Ingame");

            Texture2D[] textures =
            {
                defaultAtlas["OptionBase"].texture,
                defaultAtlas["OptionBaseFocused"].texture,
                defaultAtlas["OptionBaseHovered"].texture,
                defaultAtlas["OptionBasePressed"].texture,
                defaultAtlas["OptionBaseDisabled"].texture,
                defaultAtlas["Snapping"].texture,
                defaultAtlas["SnappingFocused"].texture,
                defaultAtlas["SnappingHovered"].texture,
                defaultAtlas["SnappingPressed"].texture,
                defaultAtlas["SnappingDisabled"].texture
            };

            ResourceLoader.AddTexturesInAtlas(textureAtlas, textures);

            return(textureAtlas);
        }
예제 #2
0
        public static void AddThumbnailVariantsInAtlas(PrefabInfo prefab)
        {
            Texture2D texture = prefab.m_Atlas[prefab.m_Thumbnail].texture;

            prefab.m_Atlas = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + prefab.m_Thumbnail, new string[] { }, null);

            ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, GenerateMissingThumbnailVariants(texture));

            // Debugging.Message("Generated thumbnails variants for: " + prefab.name);
        }
예제 #3
0
        private void LoadResources()
        {
            Texture2D[] textures =
            {
                atlas["OptionBase"].texture,
                atlas["OptionBaseDisabled"].texture,
                atlas["OptionBaseHovered"].texture,
                atlas["OptionBasePressed"].texture
            };

            string[] spriteNames = new string[]
            {
                "ClapBoard"
            };

            atlas = ResourceLoader.CreateTextureAtlas("CinematicCameraExtended", spriteNames, "CinematicCameraExtended.Icons.");
            ResourceLoader.AddTexturesInAtlas(atlas, textures);
        }
예제 #4
0
        /// <summary>
        /// Generates  thumbnail images (normal, focused, hovered, and pressed) for the given prefab.
        /// </summary>
        /// <param name="name">FindIt asset name</param>
        /// <param name="prefab">The prefab to generate thumbnails for</param>
        /// <returns></returns>
        internal bool CreateThumbnail(string name, PrefabInfo prefab)
        {
            // Check for valid data.
            if (prefab == null || name.IsNullOrWhiteSpace())
            {
                return(false);
            }

            // Don't need to do anything if the name already matches.
            if (prefab.m_Thumbnail == name)
            {
                return(true);
            }

            // Reset zoom.
            renderer.Zoom = 4f;

            // Success flag.
            bool wasRendered = false;

            if (prefab is BuildingInfo building)
            {
                wasRendered = BuildingThumbnail(building);
            }
            else if (prefab is PropInfo prop)
            {
                // Different treatment for props with blend or solid shaders.
                if (prop.m_material.shader == Asset.shaderBlend || prop.m_material.shader == Asset.shaderSolid)
                {
                    Texture2D mainTexture = prop.m_material.GetTexture("_MainTex") as Texture2D;
                    Texture2D aci         = prop.m_material.GetTexture("_ACIMap") as Texture2D;

                    Texture2D texture = new Texture2D(mainTexture.width, mainTexture.height);
                    ResourceLoader.CopyTexture(mainTexture, texture);
                    Color32[] colors = texture.GetPixels32();

                    if (aci != null)
                    {
                        ResourceLoader.CopyTexture(aci, texture);
                        Color32[] aciColors = texture.GetPixels32();

                        for (int i = 0; i < colors.Length; i++)
                        {
                            colors[i].a -= aciColors[i].r;
                        }

                        texture.SetPixels32(0, 0, texture.width, texture.height, colors);
                        texture.Apply();
                    }

                    ImageUtils.ScaleTexture2(texture, 109 - 10, 100 - 10);
                    texture.name = name;

                    prefab.m_Thumbnail = name;
                    prefab.m_Atlas     = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);
                    ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, ImageUtils.GenerateMissingThumbnailVariants(texture));

                    // Debugging.Message("Generated thumbnails for: " + name);

                    return(true);
                }

                wasRendered = PropThumbnail(prop);
            }
            else if (prefab is TreeInfo tree)
            {
                wasRendered = TreeThumbnail(tree);
            }

            // See if we were succesful in rendering.
            if (wasRendered)
            {
                // Back up game's current active texture.
                Texture2D thumbnailTexture = ResourceLoader.ConvertRenderTexture(renderer.Texture);

                // Set names.
                thumbnailTexture.name = name;
                prefab.m_Thumbnail    = name;

                // Create new texture atlas and add thumbnail variants.
                prefab.m_Atlas = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);
                ResourceLoader.ResizeTexture(thumbnailTexture, 109, 100);
                ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, ImageUtils.GenerateMissingThumbnailVariants(thumbnailTexture));

                // Debugging.Message("Generated thumbnails for: " + name);
            }
            else
            {
                // Rendering didn't occur - apply default thumbnail sprite name.
                prefab.m_Thumbnail = "ThumbnailBuildingDefault";
            }

            return(wasRendered);
        }
예제 #5
0
        public static bool CreateThumbnailAtlas(string name, PrefabInfo prefab)
        {
            if (name.IsNullOrWhiteSpace() || prefab == null)
            {
                return(false);
            }
            if (prefab.m_Thumbnail == name)
            {
                return(true);
            }

            if (m_previewRenderer == null)
            {
                m_previewRenderer      = new GameObject("FindItPreviewRenderer").AddComponent <PreviewRenderer>();
                m_previewRenderer.size = new Vector2(109, 100) * 2f;
            }

            m_previewRenderer.cameraRotation = 210f;
            m_previewRenderer.zoom           = 4f;

            bool rendered = false;

            BuildingInfo buildingPrefab = prefab as BuildingInfo;

            if (buildingPrefab != null)
            {
                m_previewRenderer.mesh     = buildingPrefab.m_mesh;
                m_previewRenderer.material = buildingPrefab.m_material;

                if (m_previewRenderer.mesh != null)
                {
                    if (buildingPrefab.m_useColorVariations && m_previewRenderer.material != null)
                    {
                        Color materialColor = buildingPrefab.m_material.color;
                        buildingPrefab.m_material.color = buildingPrefab.m_color0;
                        m_previewRenderer.Render();
                        buildingPrefab.m_material.color = materialColor;
                    }
                    else
                    {
                        m_previewRenderer.Render();
                    }

                    rendered = true;
                }
            }

            PropInfo propPrefab = prefab as PropInfo;

            if (propPrefab != null)
            {
                if (propPrefab.m_material != null && (propPrefab.m_material.shader == Asset.shaderBlend || propPrefab.m_material.shader == Asset.shaderSolid))
                {
                    RenderTexture active = RenderTexture.active;

                    Texture2D mainTexture = propPrefab.m_material.GetTexture("_MainTex") as Texture2D;
                    Texture2D aci         = propPrefab.m_material.GetTexture("_ACIMap") as Texture2D;

                    Texture2D texture = new Texture2D(mainTexture.width, mainTexture.height);
                    ResourceLoader.CopyTexture(mainTexture, texture);
                    Color32[] colors = texture.GetPixels32();

                    if (aci != null)
                    {
                        ResourceLoader.CopyTexture(aci, texture);
                        Color32[] aciColors = texture.GetPixels32();

                        for (int i = 0; i < colors.Length; i++)
                        {
                            colors[i].a -= aciColors[i].r;
                        }

                        texture.SetPixels32(0, 0, texture.width, texture.height, colors);
                        texture.Apply();
                    }

                    ScaleTexture2(texture, 109 - 10, 100 - 10);
                    texture.name = name;

                    prefab.m_Thumbnail = name;
                    prefab.m_Atlas     = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);
                    ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, GenerateMissingThumbnailVariants(texture));

                    DebugUtils.Log("Generated thumbnails for: " + name);

                    return(true);
                }
                else
                {
                    m_previewRenderer.mesh     = propPrefab.m_mesh;
                    m_previewRenderer.material = propPrefab.m_material;

                    if (m_previewRenderer.mesh != null)
                    {
                        if (propPrefab.m_useColorVariations && m_previewRenderer.material != null)
                        {
                            Color materialColor = propPrefab.m_material.color;
                            propPrefab.m_material.color = propPrefab.m_color0;
                            m_previewRenderer.Render();
                            propPrefab.m_material.color = materialColor;
                        }
                        else
                        {
                            m_previewRenderer.Render();
                        }

                        rendered = true;
                    }
                }
            }

            TreeInfo treePrefab = prefab as TreeInfo;

            if (treePrefab != null)
            {
                m_previewRenderer.mesh     = treePrefab.m_mesh;
                m_previewRenderer.material = treePrefab.m_material;

                if (m_previewRenderer.mesh != null)
                {
                    m_previewRenderer.Render();
                    rendered = true;
                }
            }

            if (rendered)
            {
                Texture2D texture = ResourceLoader.ConvertRenderTexture(m_previewRenderer.texture);
                texture.name = name;

                prefab.m_Thumbnail = name;
                prefab.m_Atlas     = ResourceLoader.CreateTextureAtlas("FindItThumbnails_" + name, new string[] { }, null);

                ResourceLoader.ResizeTexture(texture, 109, 100);
                ResourceLoader.AddTexturesInAtlas(prefab.m_Atlas, GenerateMissingThumbnailVariants(texture));

                DebugUtils.Log("Generated thumbnails for: " + name);
            }
            else
            {
                prefab.m_Thumbnail = "ThumbnailBuildingDefault";
            }

            return(rendered);
        }