예제 #1
0
 private SpritePackingMode GetPackingMode(string packingTag, SpriteMeshType meshType)
 {
     if ((meshType == SpriteMeshType.Tight) && (this.IsTagPrefixed(packingTag) == this.AllowTightWhenTagged))
     {
         return SpritePackingMode.Tight;
     }
     return SpritePackingMode.Rectangle;
 }
예제 #2
0
        public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot)
        {
            Vector4        border        = Vector4.zero;
            SpriteMeshType meshType      = SpriteMeshType.Tight;
            uint           extrude       = 0;
            float          pixelsPerUnit = 100.0f;

            return(INTERNAL_CALL_Create(texture, ref rect, ref pivot, pixelsPerUnit, extrude, meshType, ref border));
        }
예제 #3
0
    public Sprite LoadNewSprite(string FilePath, float PixelsPerUnit = 100.0f, SpriteMeshType spriteType = SpriteMeshType.Tight)
    {
        // Load a PNG or JPG image from disk to a Texture2D, assign this texture to a new sprite and return its reference
        //Sprite NewSprite = Resources.Load<Sprite>(FilePath);
        Texture2D SpriteTexture = LoadTexture(FilePath);
        Sprite    NewSprite     = Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0, 0), PixelsPerUnit, 0, spriteType);

        return(NewSprite);
    }
예제 #4
0
        public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit)
        {
            bool           generateFallbackPhysicsShape = false;
            Vector4        zero     = Vector4.zero;
            SpriteMeshType meshType = SpriteMeshType.Tight;
            uint           extrude  = 0u;

            return(Sprite.INTERNAL_CALL_Create(texture, ref rect, ref pivot, pixelsPerUnit, extrude, meshType, ref zero, generateFallbackPhysicsShape));
        }
예제 #5
0
 public TextureSpriteSettings(string packingTag, int pixelsPerUnit, SpriteMeshType meshType, uint extrudeEdges, bool qualifyForPacking, SpriteImportData[] spriteSheetData = null)
 {
     this.packingTag        = packingTag;
     this.pixelsPerUnit     = pixelsPerUnit;
     this.meshType          = meshType;
     this.extrudeEdges      = extrudeEdges;
     this.qualifyForPacking = qualifyForPacking;
     this.spriteSheetData   = spriteSheetData;
 }
예제 #6
0
    private Sprite LoadNewSprite(string FilePath, float PixelsPerUnit = 100.0f, SpriteMeshType spriteType = SpriteMeshType.Tight)
    {
        //https://forum.unity.com/threads/generating-sprites-dynamically-from-png-or-jpeg-files-in-c.343735/

        Texture2D texture   = LoadTexture(FilePath);
        Sprite    NewSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), PixelsPerUnit, 0, spriteType);

        return(NewSprite);
    }
예제 #7
0
    public static Sprite LoadSprite(string FilePath, float PixelsPerUnit = 100f, SpriteMeshType spriteType = SpriteMeshType.Tight)
    {
        Texture2D texture2D = ImageUtils.LoadTexture(FilePath, TextureFormat.DXT5);

        if (!texture2D)
        {
            return(null);
        }
        return(Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), new Vector2(0f, 0f), PixelsPerUnit, 0u, spriteType));
    }
예제 #8
0
        public static Sprite ConvertTextureToSprite(Texture2D texture, float PixelsPerUnit = 100.0f,
                                                    SpriteMeshType spriteType = SpriteMeshType.Tight)
        {
            // Converts a Texture2D to a sprite, assign this texture to a new sprite and return its reference

            Sprite NewSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0),
                                             PixelsPerUnit, 0, spriteType);

            return(NewSprite);
        }
예제 #9
0
        public SpriteSettings(BinaryReader reader)
        {
            settingsRaw = reader.ReadUInt32();

            packed          = settingsRaw & 1;                                   //1
            packingMode     = (SpritePackingMode)((settingsRaw >> 1) & 1);       //1
            packingRotation = (SpritePackingRotation)((settingsRaw >> 2) & 0xf); //4
            meshType        = (SpriteMeshType)((settingsRaw >> 6) & 1);          //1
            //reserved
        }
예제 #10
0
 private SpritePackingMode GetPackingMode(string packingTag, SpriteMeshType meshType)
 {
     if (meshType == SpriteMeshType.Tight)
     {
         if (IsTagPrefixed(packingTag) == AllowTightWhenTagged)
         {
             return(SpritePackingMode.Tight);
         }
     }
     return(SpritePackingMode.Rectangle);
 }
예제 #11
0
    public Sprite LoadNewSprite(int cardIndex, float PixelsPerUnit = 100.0f, SpriteMeshType spriteType = SpriteMeshType.Tight)
    {
        FileStream fs;

        string[] card;
        string   ImageFile;
        string   filePath;

        bool unlock = false;

        if (cardIndex != -1)
        {
            card      = CardBase.CardCollection[cardIndex];
            ImageFile = CardBase.FieldValue(card, Global.ImageHeader);
        }
        else
        {
            ImageFile = "cardback";
        }
        filePath = Global.ImageDir + @"\" + ImageFile + ".jpg";
        if (_fh.GetFileFromURL(cardIndex))
        {
            if (File.Exists(filePath))
            {
                while (!unlock)
                {
                    try
                    {
                        fs     = File.Open(filePath, FileMode.Open);
                        unlock = true;
                        fs.Close();
                    }
                    catch (IOException ex)
                    {
                        unlock = false;
                        Debug.Log(ex.Message);
                    }
                }
            }
            else
            {
                filePath = Global.ImageDir + @"\CardMissing.jpg";
            }
        }
        else
        {
            filePath = Global.ImageDir + @"\CardMissing.jpg";
        }
        Texture2D SpriteTexture = LoadTexture(filePath);
        Sprite    NewSprite     = Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0.5f, 0.5f), PixelsPerUnit, 0, spriteType);

        return(NewSprite);
    }
예제 #12
0
 /// <summary>
 /// 从StreamingAsset目录下加载Sprite (不会缓存图片,相同图片会重复加载)
 /// 如果要缓存加载图片或对下载数量进行限制,请使用LoadAsset 或 LoadGroup接口
 /// </summary>
 /// <param name="url">取StreamingAsset下的图片路径.</param>
 /// <param name="onLoaded">加载后的回调.</param>
 /// <param name="pivot">Sprite的原点.</param>
 /// <param name="isAsyncInIOS">IOS中读取图片是否为异步.</param>
 /// <param name="useSearchPath">是否使用预设的search path.</param>
 /// <param name="meshType">默认为FullRect.</param>
 public void LoadSpriteFromStreamingAsset(string url, Action <Sprite> onLoaded, Vector2 pivot,
                                          bool isAsyncInIOS       = true, Action <string> onLoadFailed = null, bool useSearchPath = true,
                                          SpriteMeshType meshType = SpriteMeshType.FullRect)
 {
     LoadTexture2DFromStreamingAsset(url, delegate(Texture2D t)
     {
         Sprite s = Sprite.Create(t, new Rect(0, 0, t.width, t.height), pivot, 100, 0, meshType);
         if (onLoaded != null)
         {
             onLoaded(s);
         }
     }, isAsyncInIOS, false, onLoadFailed, useSearchPath);
 }
예제 #13
0
        //Static class instead of _instance
        // Usage from any other script:
        // MySprite = IMG2Sprite.instance.LoadNewSprite(FilePath, [PixelsPerUnit (optional)])

        public static Sprite LoadNewSprite(string filePath, SpriteMeshType spriteType = SpriteMeshType.Tight)
        {
            // Load a PNG or JPG image from disk to a Texture2D, assign this texture to a new sprite and return its reference


            var   spriteTexture = LoadTexture(filePath);
            float max           = Mathf.Min(spriteTexture.width, spriteTexture.height);

            var newSprite =
                Sprite.Create(spriteTexture, new Rect(0, 0, spriteTexture.width, spriteTexture.height), new Vector2(spriteTexture.width / 2.0f / max, 0), max, 0, spriteType);

            return(newSprite);
        }
예제 #14
0
        public static IEnumerator LoadSprites()
        {
            var dbase     = GameDatabase.Instance;
            var node_list = dbase.GetConfigNodes("KodeUI_Sprite");

            for (int i = 0; i < node_list.Length; i++)
            {
                var    node = node_list[i];
                string name = node.GetValue("name");
                if (String.IsNullOrEmpty(name))
                {
                    Debug.Log("[KodeUI.SpriteLoader] skipping unnamed sprite");
                    continue;
                }

                string    textureUrl = node.GetValue("textureUrl");
                Texture2D tex        = dbase.GetTexture(textureUrl, false);
                if (tex == null)
                {
                    Debug.LogFormat("[KodeUI.SpriteLoader] error loading texture {0}", textureUrl);
                    continue;
                }

                Rect rect = new Rect(0, 0, tex.width, tex.height);
                node.TryGetValue("rect", ref rect);

                Vector2 pivot = new Vector2(0.5f, 0.5f);
                node.TryGetValue("pivot", ref pivot);

                float pixelsPerUnit = 100;
                node.TryGetValue("pixelsPerUnit", ref pixelsPerUnit);

                uint extrude = 0;
                node.TryGetValue("extrude", ref extrude);

                string         type_str = "";
                SpriteMeshType type     = SpriteMeshType.Tight;
                node.TryGetValue("type", ref type_str);
                type = KodeUI_Utils.ToEnum <SpriteMeshType> (type_str, type);

                Vector4 border = Vector4.zero;
                node.TryGetValue("border", ref border);

                Debug.LogFormat("[KodeUI.SpriteLoader] {0}: {1} {2} {3} {4} {5} {6} {7}",
                                name, textureUrl, rect, pivot, pixelsPerUnit,
                                extrude, type, border);
                sprites[name] = Sprite.Create(tex, rect, pivot, pixelsPerUnit,
                                              extrude, type, border);
                yield return(null);
            }
        }
예제 #15
0
 public SpriteLoader(IFileInfoResolver resolver,
                     Vector2 pivot,
                     Vector4 borders,
                     SpriteMeshType meshType = SpriteMeshType.FullRect,
                     uint extrude            = 0,
                     int pxPerUnit           = 100)
     : base(resolver)
 {
     DefaultMeshType      = meshType;
     DefaultBorders       = borders;
     DefaultExtrude       = extrude;
     DefaultPixelsPerUnit = pxPerUnit;
     DefaultPivot         = pivot;
 }
예제 #16
0
        private SpritePackingMode GetPackingMode(string packingTag, SpriteMeshType meshType)
        {
            SpritePackingMode result;

            if (meshType == SpriteMeshType.Tight && this.IsTagPrefixed(packingTag) == this.AllowTightWhenTagged)
            {
                result = SpritePackingMode.Tight;
            }
            else
            {
                result = SpritePackingMode.Rectangle;
            }
            return(result);
        }
예제 #17
0
    public static Sprite getSpriteFromWWW(string fullPath, bool packTight = false)
    {
        Texture2D tex = getTextureFromWWW(fullPath);

        Rect           rect     = new Rect(0, 0, tex.width, tex.height);
        SpriteMeshType meshType = SpriteMeshType.FullRect;

        if (packTight)
        {
            meshType = SpriteMeshType.Tight;
        }

        // use 100f to scale down
        Sprite spr = Sprite.Create(tex, rect, new Vector2(0.5f, 0.5f), 100f, 0, meshType);

        spr.name = fullPath.Substring(fullPath.LastIndexOf("/") + 1);
        return(spr);
    }
예제 #18
0
    private void Revert()
    {
        textureType         = TextureImporterType.Image;
        grayscaleToAlpha    = false;
        alphaIsTransparency = false;
        wrapMode            = TextureWrapMode.Repeat;
        filterMode          = FilterMode.Bilinear;
        anisoLevel          = 1;
        createFromGrayscale = true;
        bumpiness           = 0.25f;
        filtering           = 0;
        spriteMode          = SpriteImportMode.Single;
        packingTag          = "";
        pixelsToUnits       = 100;
        meshType            = SpriteMeshType.Tight;
        extrudeEdges        = 1;
        pivot              = 505;
        pivotX             = 0.5f;
        pivotY             = 0.5f;
        mapping            = 4;
        fixupEdgeSeams     = false;
        lightType          = LightType.Spot;
        nonPowerOf2        = TextureImporterNPOTScale.ToNearest;
        generateCubemap    = TextureImporterGenerateCubemap.None;
        readWriteEnabled   = false;
        importType         = 0;
        bypassSRGBSampling = false;
        generateMipMaps    = true;
        inLinearSpace      = false;
        borderMipMaps      = false;
        mipMapFiltering    = TextureImporterMipFilter.BoxFilter;
        fadeoutMipMaps     = false;
        fadeoutMin         = 1;
        fadeoutMax         = 3;

        for (int i = 0, length = textureFormats.Length; i < length; i++)
        {
            textureFormats[i] = TextureImporterFormat.AutomaticCompressed;
        }
        for (int i = 0, length = compressionQualitys.Length; i < length; i++)
        {
            compressionQualitys[i] = (int)TextureCompressionQuality.Normal;
        }
    }
 public void Apply(TextureImporterSettings settings)
 {
     this.seamlessCubemap                    = settings.seamlessCubemap;
     this.mipmapBias                         = settings.mipmapBias;
     this.wrapMode                           = settings.wrapMode;
     this.wrapModeU                          = settings.wrapModeU;
     this.wrapModeV                          = settings.wrapModeV;
     this.wrapModeW                          = settings.wrapModeW;
     this.alphaIsTransparency                = settings.alphaIsTransparency;
     this.spriteMode                         = settings.spriteMode;
     this.spritePixelsPerUnit                = settings.spritePixelsPerUnit;
     this.spriteTessellationDetail           = settings.spriteTessellationDetail;
     this.spriteExtrude                      = settings.spriteExtrude;
     this.spriteMeshType                     = settings.spriteMeshType;
     this.spriteAlignment                    = settings.spriteAlignment;
     this.spritePivot                        = settings.spritePivot;
     this.spriteBorder                       = settings.spriteBorder;
     this.spriteGenerateFallbackPhysicsShape = settings.spriteGenerateFallbackPhysicsShape;
     this.aniso                    = settings.aniso;
     this.filterMode               = settings.filterMode;
     this.cubemapConvolution       = settings.cubemapConvolution;
     this.textureType              = settings.textureType;
     this.textureShape             = settings.textureShape;
     this.mipmapFilter             = settings.mipmapFilter;
     this.mipmapEnabled            = settings.mipmapEnabled;
     this.sRGBTexture              = settings.sRGBTexture;
     this.fadeOut                  = settings.fadeOut;
     this.borderMipmap             = settings.borderMipmap;
     this.mipMapsPreserveCoverage  = settings.mipMapsPreserveCoverage;
     this.mipmapFadeDistanceStart  = settings.mipmapFadeDistanceStart;
     this.alphaTestReferenceValue  = settings.alphaTestReferenceValue;
     this.convertToNormalMap       = settings.convertToNormalMap;
     this.heightmapScale           = settings.heightmapScale;
     this.normalMapFilter          = settings.normalMapFilter;
     this.alphaSource              = settings.alphaSource;
     this.singleChannelComponent   = settings.singleChannelComponent;
     this.readable                 = settings.readable;
     this.streamingMipmaps         = settings.streamingMipmaps;
     this.streamingMipmapsPriority = settings.streamingMipmapsPriority;
     this.npotScale                = settings.npotScale;
     this.generateCubemap          = settings.generateCubemap;
     this.mipmapFadeDistanceEnd    = settings.mipmapFadeDistanceEnd;
 }
예제 #20
0
    public static Sprite CreateSpriteFromTexture2D(
        Texture2D SpriteTexture,
        int x,
        int y,
        int w,
        int h,
        float PixelsPerUnit       = 1.0f,
        SpriteMeshType spriteType = SpriteMeshType.Tight)
    {
        Sprite NewSprite = Sprite.Create(
            SpriteTexture,
            new Rect(x, y, w, h),
            new Vector2(0, 0),
            PixelsPerUnit,
            0,
            spriteType);

        return(NewSprite);
    }
예제 #21
0
    private void DisplaySpriteSettings()
    {
        spriteMode = (SpriteImportMode)EditorGUILayout.EnumPopup("Sprite Mode", spriteMode);
        EditorGUI.indentLevel++;
        packingTag    = EditorGUILayout.TextField("Packing Tag", packingTag);
        pixelsPerUnit = EditorGUILayout.FloatField("Pixels Per Unit", pixelsPerUnit);
        meshType      = (SpriteMeshType)EditorGUILayout.EnumPopup("Mesh Type", meshType);
        extrudeEdges  = EditorGUILayout.IntSlider("Extrude Edges", extrudeEdges, 0, 32);

        if (spriteMode == SpriteImportMode.Single)
        {
            pivot = (Pivot)EditorGUILayout.EnumPopup("Pivot", pivot);
            if (pivot == Pivot.Custom)
            {
                pivotPoint = EditorGUILayout.Vector2Field("Custom Pivot Point", pivotPoint);
            }
        }
        EditorGUI.indentLevel--;
    }
예제 #22
0
        public static Sprite ImportPathAsSprite(string tmxFolderPath, string relativeSourcePath, string storageFolder, int pixelsPerUnit)
        {
            string imageSourcePath;
            string imageTargetPath;

            CreateSingleImagePaths(relativeSourcePath, tmxFolderPath, storageFolder, out imageSourcePath, out imageTargetPath);
            TiledTSXImporter.CopyImages(new string[] { imageSourcePath }, new string[] { imageTargetPath });
            if (File.Exists(imageTargetPath))
            {
                TextureImporter ti = AssetImporter.GetAtPath(imageTargetPath) as TextureImporter;

                TextureImporterSettings textureSettings = new TextureImporterSettings();
                ti.ReadTextureSettings(textureSettings);

                SpriteMeshType  meshType   = SpriteMeshType.FullRect;
                SpriteAlignment alignment  = SpriteAlignment.TopLeft;
                FilterMode      filterMode = FilterMode.Point;

                if (textureSettings.spritePixelsPerUnit != pixelsPerUnit ||
                    textureSettings.spriteMeshType != meshType ||
                    textureSettings.spriteAlignment != (int)alignment ||
                    textureSettings.filterMode != filterMode)
                {
                    textureSettings.spritePixelsPerUnit = pixelsPerUnit;
                    textureSettings.spriteMeshType      = meshType;
                    textureSettings.spriteAlignment     = (int)alignment;
                    textureSettings.filterMode          = filterMode;
                    ti.SetTextureSettings(textureSettings);

                    EditorUtility.SetDirty(ti);
                    ti.SaveAndReimport();
                }
                Sprite newSprite = AssetDatabase.LoadAssetAtPath <Sprite> (imageTargetPath);
                Debug.Assert(newSprite != null);
                return(newSprite);
            }
            else
            {
                return(null);
            }
        }
예제 #23
0
        /// <summary>
        /// Load a sprite.
        /// </summary>
        /// <param name="filePath">Path of the sprite.</param>
        /// <param name="width">Width of the sprite.</param>
        /// <param name="height">Height of the sprite.</param>
        /// <param name="pixelsPerUnit">Pixels per unit.</param>
        /// <param name="spriteType">Type of sprite.</param>
        /// <returns></returns>
        public static Sprite LoadSprite(string filePath, int width, int height, float pixelsPerUnit = 100.0f,
                                        SpriteMeshType spriteType = SpriteMeshType.Tight)
        {
            if (File.Exists(filePath))
            {
                var fileData = File.ReadAllBytes(filePath);
                var tex2D    = new Texture2D(width, height);
                if (!tex2D.LoadImage(fileData))
                {
                    // Load the imagedata into the texture (size is set automatically)
                    Debug.Log("Error while loading image"); // If data = readable -> return texture
                }
                else
                {
                    return(Sprite.Create(tex2D, new Rect(0, 0, width, height), new Vector2(0, 0), pixelsPerUnit, 0,
                                         spriteType));
                }
            }

            Debug.Log("Invalid Path");
            return(null);
        }
예제 #24
0
    void Start()
    {
        float str2 = PlayerPrefs.GetFloat("DistanceTraveled");
        int   str3 = PlayerPrefs.GetInt("MyShot");

        DistanceText.text  = Mathf.Round(str2).ToString();
        ShotTakenText.text = str3.ToString();

        BinaryFormatter bf  = new BinaryFormatter();
        DirectoryInfo   dir = new DirectoryInfo(GetAndroidExternalStoragePath() + "/" + Application.productName + " Captures");

        if (!Directory.Exists(GetAndroidExternalStoragePath() + "/" + Application.productName + " Captures"))
        {
            var folder = Directory.CreateDirectory(GetAndroidExternalStoragePath() + "/" + Application.productName + " Captures");
        }

        var files = dir.GetFiles().Where(o => o.Name.EndsWith(".png")).ToArray();

        for (int i = 0; i < files.Length; i++)
        {
            float          PixelsPerUnit = 100.0f;
            SpriteMeshType spriteType    = SpriteMeshType.Tight;
            Texture2D      SpriteTexture = LoadTexture(files[i].FullName);
            Sprite         NewSprite     = Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0, 0), PixelsPerUnit, 0, spriteType);
            PhotoServices  imagefile     = new PhotoServices();
            imagefile.photosTexture = NewSprite;
            imagefile.photoId       = i;
            imagefile.photosName    = files[i].Name.ToString();
            imagefile.sharedPhotos  = false;
            PhotosLoaded.Add(imagefile);
            myPhotoPreview = Instantiate(PhotoPrefabs, GalleryManager.MyInstance.transform).GetComponent <GalerryView>();
            //AllFiles[i] = (FileModel)bf.Deserialize(fs);
            myPhotoPreview.PhotoMiniPreview.sprite = PhotosLoaded[i].photosTexture;
            myPhotoPreview.PhotoName.text          = PhotosLoaded[i].photosName.Replace(".png", "");
            myPhotoPreview.PhotoId      = PhotosLoaded[i].photoId;
            myPhotoPreview.sharedPhotos = PhotosLoaded[i].sharedPhotos;
        }
    }
예제 #25
0
    // Use this for initialization
    void Start()
    {
        textureManager = new TextureManager(256);
        textureManager.CreateTexture("hearts");
        textureManager.CreateTexture("diamond");
        textureManager.CreateTexture("clubs");
        textureManager.CreateTexture("spades");
        textureManager.CreateRoundedRectangle("base");
        textureManager.CreateRoundedRectangle("back");
        textureManager.PackTextures();
        SpriteMeshType spriteMeshType = SpriteMeshType.FullRect;
        Sprite         sprite         = Sprite.Create(textureManager.PackedTexture, textureManager.GetTextureRectByName("back"), new Vector2(0.5f, 0.5f), 1, 0, spriteMeshType);

        //Sprite sprite= Sprite.Create(textureManager.TilingTexture,new Rect(0,0,textureManager.TilingTexture.width,textureManager.TilingTexture.height),new Vector2(0.5f,0.5f),1,0,spriteMeshType);
        //Sprite sprite= Sprite.Create(textureManager.PackedTexture,new Rect(0,0,textureManager.PackedTexture.width,textureManager.PackedTexture.height),new Vector2(0.5f,0.5f),1);
        //Sprite sprite= Sprite.Create(textureManager.PackedTexture,textureManager.GetTextureRectByName("clubs"),new Vector2(0.5f,0.5f),1);

        spriteRenderer.sprite = sprite;
        spriteRenderer.size   = new Vector2(183, 256);

        CreateCard(Random.Range(1, 53));
        //CreateCard(10);
    }
예제 #26
0
        public static bool CreateTileSprite(string targetPath, int pixelsPerUnit, int cellWidth, int cellHeight, int imageWidth, int imageHeight)
        {
            TextureImporter ti = AssetImporter.GetAtPath(targetPath) as TextureImporter;

            TextureImporterSettings textureSettings = new TextureImporterSettings();

            ti.ReadTextureSettings(textureSettings);

            SpriteMeshType  meshType             = SpriteMeshType.FullRect;
            SpriteAlignment alignment            = SpriteAlignment.Custom;
            Vector2         pivot                = GetPivot(imageWidth, imageHeight, cellWidth, cellHeight);
            FilterMode      filterMode           = FilterMode.Point;
            bool            fallbackPhysicsShape = true;

            if (textureSettings.spritePixelsPerUnit != pixelsPerUnit ||
                textureSettings.spriteMeshType != meshType ||
                textureSettings.spriteAlignment != (int)alignment ||
                textureSettings.spritePivot != pivot ||
                textureSettings.filterMode != filterMode ||
                textureSettings.spriteGenerateFallbackPhysicsShape != fallbackPhysicsShape)
            {
                textureSettings.spritePixelsPerUnit = pixelsPerUnit;
                textureSettings.spriteMeshType      = meshType;
                textureSettings.spriteAlignment     = (int)alignment;
                textureSettings.spritePivot         = pivot;
                textureSettings.filterMode          = filterMode;
                textureSettings.spriteGenerateFallbackPhysicsShape = fallbackPhysicsShape;

                ti.SetTextureSettings(textureSettings);

                EditorUtility.SetDirty(ti);
                ti.SaveAndReimport();
            }

            return(true);
        }
예제 #27
0
    private void DrawTextureSettings(TextureImporterType textureType)
    {
        if (textureType != oldTextureType)
        {
            Reset();
        }
        switch (textureType)
        {
        case TextureImporterType.Image:
            if ((grayscaleToAlpha = EditorGUILayout.Toggle("Alpha from Grayscale", grayscaleToAlpha)))
            {
                alphaIsTransparency = EditorGUILayout.Toggle("Alpha is Transparency", alphaIsTransparency);
            }
            GUILayout.Space(8f);
            wrapMode = (TextureWrapMode)DrawPopup("Wrap Mode", (int)wrapMode, wrapModeString);
            if ((filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString)) != FilterMode.Point)
            {
                anisoLevel = EditorGUILayout.IntSlider("Aniso Level", anisoLevel, 0, 9);
            }
            break;

        case TextureImporterType.Bump:
            if (createFromGrayscale = EditorGUILayout.Toggle("(Invalid) Create from Grayscale", createFromGrayscale))
            {
                bumpiness = EditorGUILayout.Slider("(Invalid) Bumpiness", bumpiness, 0, 0.3f);
                filtering = DrawPopup("(Invalid) Filtering", filtering, filteringString);
            }
            GUILayout.Space(8f);
            wrapMode = (TextureWrapMode)DrawPopup("Wrap Mode", (int)wrapMode, wrapModeString);
            if ((filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString)) != FilterMode.Point)
            {
                anisoLevel = EditorGUILayout.IntSlider("Aniso Level", anisoLevel, 0, 9);
            }
            break;

        case TextureImporterType.GUI:
            GUILayout.Space(8f);
            filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString);
            break;

        case TextureImporterType.Sprite:
            spriteMode    = (SpriteImportMode)DrawPopup("Sprite Mode", (int)spriteMode, spriteModeString, spriteModeArray);
            packingTag    = EditorGUILayout.TextField("    Packing Tag", packingTag);
            pixelsToUnits = EditorGUILayout.FloatField("    Pixels To Units", pixelsToUnits);
            if (spriteMode == SpriteImportMode.Single)
            {
                if ((pivot = DrawPopup("    Pivot", pivot, pivotString, pivotArray)) == -1)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(EditorGUIUtility.labelWidth);
                    GUILayout.Label("X");
                    pivotX = EditorGUILayout.FloatField(pivotX);
                    GUILayout.Label("Y");
                    pivotY = EditorGUILayout.FloatField(pivotY);
                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.Space(8f);
            filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString);
            break;

        case TextureImporterType.Cursor:
            GUILayout.Space(8f);
            wrapMode   = (TextureWrapMode)DrawPopup("Wrap Mode", (int)wrapMode, wrapModeString);
            filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString);
            break;

        case TextureImporterType.Reflection:
            mapping        = DrawPopup("Mapping", mapping, mappingString);
            fixupEdgeSeams = EditorGUILayout.Toggle("Fixup Edge Seams", fixupEdgeSeams);
            GUILayout.Space(8f);
            if ((filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString)) != FilterMode.Point)
            {
                anisoLevel = EditorGUILayout.IntSlider("Aniso Level", anisoLevel, 0, 9);
            }
            break;

        case TextureImporterType.Cookie:
            if ((lightType = (LightType)DrawPopup("(Invalid) Light Type", (int)lightType, lightTypeString)) == LightType.Point)
            {
                mapping        = DrawPopup("(Invalid) Mapping", mapping, mappingString);
                fixupEdgeSeams = EditorGUILayout.Toggle("(Invalid) Fixup Edge Seams", fixupEdgeSeams);
            }
            grayscaleToAlpha = EditorGUILayout.Toggle("Alpha from Grayscale", grayscaleToAlpha);
            GUILayout.Space(8f);
            if ((filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString)) != FilterMode.Point)
            {
                anisoLevel = EditorGUILayout.IntSlider("Aniso Level", anisoLevel, 0, 9);
            }
            break;

        case TextureImporterType.Lightmap:
            GUILayout.Space(8f);
            if ((filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString)) != FilterMode.Point)
            {
                anisoLevel = EditorGUILayout.IntSlider("Aniso Level", anisoLevel, 0, 9);
            }
            break;

        case TextureImporterType.Advanced:
            nonPowerOf2      = (TextureImporterNPOTScale)DrawPopup("Non Power of 2", (int)nonPowerOf2, nonPowerOf2String);
            generateCubemap  = (TextureImporterGenerateCubemap)DrawPopup("Generate Cubemap", (int)generateCubemap, generateCubemapString);
            readWriteEnabled = EditorGUILayout.Toggle("Read/Write Enabled", readWriteEnabled);
            importType       = (TextureImporterType)DrawPopup("Import Type", (int)importType, importTypeString, importTypeArray);
            if (importType == TextureImporterType.Image)
            {
                grayscaleToAlpha    = EditorGUILayout.Toggle("    Alpha from Grayscale", grayscaleToAlpha);
                alphaIsTransparency = EditorGUILayout.Toggle("    Alpha is Transparency", alphaIsTransparency);
                bypassSRGBSampling  = EditorGUILayout.Toggle("    (Invalid) Bypass sRGB Sampling", bypassSRGBSampling);
                spriteMode          = (SpriteImportMode)DrawPopup("    Sprite Mode", (int)spriteMode, spriteModeStringFull);
                if (spriteMode != SpriteImportMode.None)
                {
                    packingTag    = EditorGUILayout.TextField("        Packing Tag", packingTag);
                    pixelsToUnits = EditorGUILayout.FloatField("        Pixels To Units", pixelsToUnits);
                    meshType      = (SpriteMeshType)DrawPopup("        Mesh Type", (int)meshType, meshTypeString);
                    extrudeEdges  = (uint)EditorGUILayout.IntSlider("        Extrude Edges", (int)extrudeEdges, 0, 32);
                    if (spriteMode == SpriteImportMode.Single)
                    {
                        if ((pivot = DrawPopup("        Pivot", pivot, pivotString, pivotArray)) == -1)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Space(EditorGUIUtility.labelWidth);
                            GUILayout.Label("X");
                            pivotX = EditorGUILayout.FloatField(pivotX);
                            GUILayout.Label("Y");
                            pivotY = EditorGUILayout.FloatField(pivotY);
                            GUILayout.EndHorizontal();
                        }
                    }
                }
            }
            else if (importType == TextureImporterType.Bump)
            {
                if (createFromGrayscale = EditorGUILayout.Toggle("    (Invalid) Create from Grayscale", createFromGrayscale))
                {
                    bumpiness = EditorGUILayout.Slider("    (Invalid) Bumpiness", bumpiness, 0, 0.3f);
                    filtering = DrawPopup("    Filtering", filtering, filteringString);
                }
            }
            GUILayout.Space(8f);
            if (generateMipMaps = EditorGUILayout.Toggle("Generate Mip Maps", generateMipMaps))
            {
                inLinearSpace   = EditorGUILayout.Toggle("    In Linear Space", inLinearSpace);
                borderMipMaps   = EditorGUILayout.Toggle("    Border Mip Maps", borderMipMaps);
                mipMapFiltering = (TextureImporterMipFilter)DrawPopup("    Mip Map Filtering", (int)mipMapFiltering, mipMapFilteringString);
                if (fadeoutMipMaps = EditorGUILayout.Toggle("    Fadeout Mip Maps", fadeoutMipMaps))
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("        Fade Range");
                    GUILayout.Space(43f);
                    EditorGUILayout.MinMaxSlider(ref fadeoutMin, ref fadeoutMax, 0, 10);
                    fadeoutMin = Mathf.RoundToInt(fadeoutMin);
                    fadeoutMax = Mathf.RoundToInt(fadeoutMax);
                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.Space(8f);
            wrapMode = (TextureWrapMode)DrawPopup("Wrap Mode", (int)wrapMode, wrapModeString);
            if ((filterMode = (FilterMode)DrawPopup("Filter Mode", (int)filterMode, filterModeString)) != FilterMode.Point)
            {
                anisoLevel = EditorGUILayout.IntSlider("Aniso Level", anisoLevel, 0, 9);
            }
            break;

        default:
            break;
        }
        GUILayout.Space(8f);
    }
예제 #28
0
    static int Create(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 3)
        {
            Texture2D arg0 = (Texture2D)LuaScriptMgr.GetUnityObject(L, 1, typeof(Texture2D));
            Rect      arg1 = (Rect)LuaScriptMgr.GetNetObject(L, 2, typeof(Rect));
            Vector2   arg2 = LuaScriptMgr.GetVector2(L, 3);
            Sprite    o    = Sprite.Create(arg0, arg1, arg2);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 4)
        {
            Texture2D arg0 = (Texture2D)LuaScriptMgr.GetUnityObject(L, 1, typeof(Texture2D));
            Rect      arg1 = (Rect)LuaScriptMgr.GetNetObject(L, 2, typeof(Rect));
            Vector2   arg2 = LuaScriptMgr.GetVector2(L, 3);
            float     arg3 = (float)LuaScriptMgr.GetNumber(L, 4);
            Sprite    o    = Sprite.Create(arg0, arg1, arg2, arg3);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 5)
        {
            Texture2D arg0 = (Texture2D)LuaScriptMgr.GetUnityObject(L, 1, typeof(Texture2D));
            Rect      arg1 = (Rect)LuaScriptMgr.GetNetObject(L, 2, typeof(Rect));
            Vector2   arg2 = LuaScriptMgr.GetVector2(L, 3);
            float     arg3 = (float)LuaScriptMgr.GetNumber(L, 4);
            uint      arg4 = (uint)LuaScriptMgr.GetNumber(L, 5);
            Sprite    o    = Sprite.Create(arg0, arg1, arg2, arg3, arg4);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 6)
        {
            Texture2D      arg0 = (Texture2D)LuaScriptMgr.GetUnityObject(L, 1, typeof(Texture2D));
            Rect           arg1 = (Rect)LuaScriptMgr.GetNetObject(L, 2, typeof(Rect));
            Vector2        arg2 = LuaScriptMgr.GetVector2(L, 3);
            float          arg3 = (float)LuaScriptMgr.GetNumber(L, 4);
            uint           arg4 = (uint)LuaScriptMgr.GetNumber(L, 5);
            SpriteMeshType arg5 = (SpriteMeshType)LuaScriptMgr.GetNetObject(L, 6, typeof(SpriteMeshType));
            Sprite         o    = Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 7)
        {
            Texture2D      arg0 = (Texture2D)LuaScriptMgr.GetUnityObject(L, 1, typeof(Texture2D));
            Rect           arg1 = (Rect)LuaScriptMgr.GetNetObject(L, 2, typeof(Rect));
            Vector2        arg2 = LuaScriptMgr.GetVector2(L, 3);
            float          arg3 = (float)LuaScriptMgr.GetNumber(L, 4);
            uint           arg4 = (uint)LuaScriptMgr.GetNumber(L, 5);
            SpriteMeshType arg5 = (SpriteMeshType)LuaScriptMgr.GetNetObject(L, 6, typeof(SpriteMeshType));
            Vector4        arg6 = LuaScriptMgr.GetVector4(L, 7);
            Sprite         o    = Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: Sprite.Create");
        }

        return(0);
    }
예제 #29
0
 public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType)
 {
   Vector4 zero = Vector4.zero;
   return Sprite.INTERNAL_CALL_Create(texture, ref rect, ref pivot, pixelsPerUnit, extrude, meshType, ref zero);
 }
예제 #30
0
 private static extern Sprite INTERNAL_CALL_Create(Texture2D texture, ref Rect rect, ref Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType, ref Vector4 border);
예제 #31
0
 public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType, Vector4 border) => default;                                            // 0x00000001808DC850-0x00000001808DC8B0
 public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType) => default;                                                            // 0x00000001808DCA50-0x00000001808DCB30
예제 #32
0
 internal static Sprite CreateSprite(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType, Vector4 border, bool generateFallbackPhysicsShape) => default; // 0x00000001808DC7C0-0x00000001808DC850
 public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType, Vector4 border, bool generateFallbackPhysicsShape) => default;         // 0x00000001808DCC10-0x00000001808DD0A0
예제 #33
0
        }                                                                                                                                                                                                                               // 0x00000001808DD280-0x00000001808DD2D0

        private static Sprite CreateSprite_Injected(Texture2D texture, ref Rect rect, ref Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType, ref Vector4 border, bool generateFallbackPhysicsShape) => default; // 0x00000001808DC740-0x00000001808DC7C0
예제 #34
0
 private SpritePackingMode GetPackingMode(string packingTag, SpriteMeshType meshType)
 {
     if (meshType == SpriteMeshType.Tight)
         if (IsTagPrefixed(packingTag) == AllowTightWhenTagged)
             return SpritePackingMode.Tight;
     return SpritePackingMode.Rectangle;
 }
 private SpritePackingMode GetPackingMode(string packingTag, SpriteMeshType meshType)
 {
   return meshType == SpriteMeshType.Tight && this.IsTagPrefixed(packingTag) == this.AllowTightWhenTagged ? SpritePackingMode.Tight : SpritePackingMode.Rectangle;
 }