private void CaptureAndPrepareTexture(WebCamTexture camTexture, ref Texture2D tex)
 {
     Profiler.BeginSample("Texture processing");
     TextureCropTools.CropToSquare(camTexture, ref tex);
     textureScaler.Scale(tex);
     Profiler.EndSample();
 }
Exemple #2
0
        private IEnumerator LoadAvatar(string id, string avatarID)
        {
            UnityWebRequest avatarURL = UnityWebRequestTexture.GetTexture($"https://cdn.discordapp.com/avatars/{id}/{avatarID}.png");

            yield return(avatarURL.SendWebRequest());

            avatar = ((DownloadHandlerTexture)avatarURL.downloadHandler).texture;

            if (avatar == null || avatar.height < 128)
            {
                UnityWebRequest standardAvatarURL = UnityWebRequestTexture.GetTexture("https://discordapp.com/assets/6debd47ed13483642cf09e832ed0bc1b.png");
                yield return(standardAvatarURL.SendWebRequest());

                avatar = ((DownloadHandlerTexture)standardAvatarURL.downloadHandler).texture;
            }

            TextureScaler.Scale(avatar, 64, 64);

            yield return(null);
        }
        private IEnumerator LoadAvatar(string id, string avatar_id)
        {
            WWW avatarURL = new WWW("https://cdn.discordapp.com/avatars/" + id + "/" + avatar_id + ".png");

            yield return(avatarURL);

            if (avatarURL.texture != null && avatarURL.texture.height >= 128)
            {
                avatar = avatarURL.texture;
            }
            else
            {
                WWW standardAvatarURL = new WWW("https://discordapp.com/assets/6debd47ed13483642cf09e832ed0bc1b.png");
                yield return(standardAvatarURL);

                avatar = standardAvatarURL.texture;
            }
            TextureScaler.Scale(avatar, 64, 64);

            yield return(null);
        }
Exemple #4
0
        private IEnumerator LoadAvatar(string id, string avatar_id)
        {
            UnityWebRequest avatarURL = UnityWebRequestTexture.GetTexture("https://cdn.discordapp.com/avatars/" + id + "/" + avatar_id + ".png");

            yield return(avatarURL.SendWebRequest());

            Texture2D avatarTexture = ((DownloadHandlerTexture)avatarURL.downloadHandler).texture;

            if (avatarTexture != null && avatarTexture.height >= 128)
            {
                avatar = avatarTexture;
            }
            else
            {
                UnityWebRequest standardAvatarURL = UnityWebRequestTexture.GetTexture("https://discordapp.com/assets/6debd47ed13483642cf09e832ed0bc1b.png");
                yield return(standardAvatarURL.SendWebRequest());

                avatar = ((DownloadHandlerTexture)standardAvatarURL.downloadHandler).texture;
            }
            TextureScaler.Scale(avatar, 64, 64);

            yield return(null);
        }
Exemple #5
0
        private static void Circle(Texture2D texture, int x, int y, int radius, Color color, bool filled = false, int dashWidth = int.MaxValue, int gapWidth = 0, Texture2D tex = null)
        {
            int       cx          = radius;
            int       cy          = 0;
            int       radiusError = 1 - cx;
            int       dashCnt     = 0;
            Texture2D resizedTex  = null;

            if (tex != null)
            {
#if false
                resizedTex = TextureScaler.scaled(tex, radius * 2, radius * 2);
#endif
#if false
                resizedTex = new Texture2D(tex.width, tex.height);
                Graphics.CopyTexture(tex, resizedTex);
                TextureScaler.Bilinear(resizedTex, radius * 2, radius * 2);
#endif
#if true
                resizedTex = TextureScaler.Scale(tex, radius * 2, radius * 2);
#endif
            }
            while (cx >= cy)
            {
                if (dashCnt >= 0 && dashCnt < dashWidth)
                {
                    if (!filled)
                    {
                        PlotCircle(texture, cx, x, cy, y, color);
                    }
                    else
                    {
                        if (tex == null)
                        {
                            ScanLineCircle(texture, cx, x, cy, y, color);
                        }
                        else
                        {
                            FillLineCircle(texture, cx, x, cy, y, resizedTex);
                        }
                    }
                }
                dashCnt++;
                if (dashCnt == dashWidth)
                {
                    dashCnt = -1 * gapWidth;
                }

                cy++;

                if (radiusError < 0)
                {
                    radiusError += 2 * cy + 1;
                }
                else
                {
                    cx--;
                    radiusError += 2 * (cy - cx + 1);
                }
            }
            if (tex != null)
            {
                UnityEngine.Object.Destroy(resizedTex);
            }
        }
Exemple #6
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            byte[]    bytes         = File.ReadAllBytes(ctx.assetPath);
            Texture2D sourceTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);

            sourceTexture.LoadImage(bytes);

            originalWidth  = sourceTexture.width;
            originalHeight = sourceTexture.height;

            cols = sourceTexture.width / pageSize;
            if (cols == 0)
            {
                cols = 1;
            }

            rows = sourceTexture.height / pageSize;
            if (rows == 0)
            {
                rows = 1;
            }

            bool changedPageSize = false;

            while (cols * rows > 2048)
            {
                pageSize       *= 2;
                cols           /= 2;
                rows           /= 2;
                changedPageSize = true;
            }

            if (changedPageSize)
            {
                ctx.LogImportWarning("Texture Width * Texture Height * Page Size must be less or equal to 2048, so the Page Size is increased to " + pageSize);
            }

            int resizeX = sourceTexture.width;
            int resizeY = sourceTexture.height;

            if (sourceTexture.width % pageSize != 0)
            {
                resizeX = cols * pageSize;
            }
            if (sourceTexture.height % pageSize != 0)
            {
                resizeY = rows * pageSize;
            }

            if (resizeX != sourceTexture.width || resizeY != sourceTexture.height)
            {
                TextureScaler.Scale(sourceTexture, resizeX, resizeY);
                ctx.LogImportWarning("The width and height of the texture must be equal to Page Size * N, so the texture size is changed to " + resizeX + "x" + resizeY);
            }

            Texture2DArray array = InitTexture2DArray(sourceTexture, ctx);

            ctx.AddObjectToAsset("_MainTex", array);
            ctx.SetMainObject(array);

            DestroyImmediate(sourceTexture);
        }