UnityEngine.Sprite.Create(UnityEngine.Texture2D, UnityEngine.Rect, UnityEngine.Vector2)

Here are the examples of the csharp api UnityEngine.Sprite.Create(UnityEngine.Texture2D, UnityEngine.Rect, UnityEngine.Vector2) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

26 Examples 7

19 View Source File : Minimap.cs
License : GNU General Public License v3.0
Project Creator : aelariane

private void Initialize()
    {
        Vector3 v = new Vector3(0.5f, 0.5f);
        Texture2D texture2D = (Texture2D)RCManager.Load("icon");
        Rect rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Minimap.whiteIconSprite = UnityEngine.Sprite.Create(texture2D, rect, v);
        texture2D = (Texture2D)RCManager.Load("iconpointer");
        rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Minimap.pointerSprite = UnityEngine.Sprite.Create(texture2D, rect, v);
        texture2D = (Texture2D)RCManager.Load("supplyicon");
        rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Minimap.supplySprite = UnityEngine.Sprite.Create(texture2D, rect, v);
        texture2D = (Texture2D)RCManager.Load("mapborder");
        rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Vector4 border = new Vector4(5f, 5f, 5f, 5f);
        Minimap.borderSprite = UnityEngine.Sprite.Create(texture2D, rect, v, 100f, 1u, SpriteMeshType.FullRect, border);
        this.MINIMAP_ICON_SIZE = new Vector2((float)Minimap.whiteIconSprite.texture.width, (float)Minimap.whiteIconSprite.texture.height);
        this.MINIMAP_POINTER_SIZE = (float)(Minimap.pointerSprite.texture.width + Minimap.pointerSprite.texture.height) / 2f;
        this.MINIMAP_POINTER_DIST = (this.MINIMAP_ICON_SIZE.x + this.MINIMAP_ICON_SIZE.y) * 0.25f;
        this.MINIMAP_SUPPLY_SIZE = new Vector2((float)Minimap.supplySprite.texture.width, (float)Minimap.supplySprite.texture.height);
        this.replacedetsInitialized = true;
    }

19 View Source File : Minimap.cs
License : GNU General Public License v3.0
Project Creator : aelariane

private void Initialize()
    {
        Vector3 v = new Vector3(0.5f, 0.5f);
        Texture2D texture2D = (Texture2D)RCManager.Load("icon");
        Rect rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Minimap.whiteIconSprite = UnityEngine.Sprite.Create(texture2D, rect, v);
        texture2D = (Texture2D)RCManager.Load("iconpointer");
        rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Minimap.pointerSprite = UnityEngine.Sprite.Create(texture2D, rect, v);
        texture2D = (Texture2D)RCManager.Load("supplyicon");
        rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Minimap.supplySprite = UnityEngine.Sprite.Create(texture2D, rect, v);
        texture2D = (Texture2D)RCManager.Load("mapborder");
        rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
        Vector4 border = new Vector4(5f, 5f, 5f, 5f);
        Minimap.borderSprite = UnityEngine.Sprite.Create(texture2D, rect, v, 100f, 1u, SpriteMeshType.FullRect, border);
        this.MINIMAP_ICON_SIZE = new Vector2((float)Minimap.whiteIconSprite.texture.width, (float)Minimap.whiteIconSprite.texture.height);
        this.MINIMAP_POINTER_SIZE = (float)(Minimap.pointerSprite.texture.width + Minimap.pointerSprite.texture.height) / 2f;
        this.MINIMAP_POINTER_DIST = (this.MINIMAP_ICON_SIZE.x + this.MINIMAP_ICON_SIZE.y) * 0.25f;
        this.MINIMAP_SUPPLY_SIZE = new Vector2((float)Minimap.supplySprite.texture.width, (float)Minimap.supplySprite.texture.height);
        this.replacedetsInitialized = true;
    }

19 View Source File : Minimap.cs
License : GNU General Public License v3.0
Project Creator : aelariane

private void CreateUnityUI(Texture2D map, int minimapResolution)
    {
        GameObject gameObject = new GameObject("Canvas");
        gameObject.AddComponent<RectTransform>();
        this.canvas = gameObject.AddComponent<Canvas>();
        this.canvas.renderMode = RenderMode.ScreenSpaceOverlay;
        this.scaler = gameObject.AddComponent<Canvreplacedcaler>();
        this.scaler.uiScaleMode = Canvreplacedcaler.ScaleMode.ScaleWithScreenSize;
        this.scaler.referenceResolution = new Vector2(900f, 600f);
        this.scaler.screenMatchMode = Canvreplacedcaler.ScreenMatchMode.MatchWidthOrHeight;
        GameObject gameObject2 = new GameObject("CircleMask");
        gameObject2.transform.SetParent(gameObject.transform, false);
        this.minimapMaskT = gameObject2.AddComponent<RectTransform>();
        gameObject2.AddComponent<CanvasRenderer>();
        RectTransform rectTransform = this.minimapMaskT;
        Vector2 vector = this.minimapMaskT.anchorMax = Vector2.one;
        rectTransform.anchorMin = vector;
        float num = this.MINIMAP_CORNER_SIZE * 0.5f;
        this.cornerPosition = new Vector2(-(num + 5f), -(num + 70f));
        this.minimapMaskT.ancreplaceddPosition = this.cornerPosition;
        this.minimapMaskT.sizeDelta = new Vector2(this.MINIMAP_CORNER_SIZE, this.MINIMAP_CORNER_SIZE);
        GameObject gameObject3 = new GameObject("Minimap");
        gameObject3.transform.SetParent(this.minimapMaskT, false);
        this.minimap = gameObject3.AddComponent<RectTransform>();
        gameObject3.AddComponent<CanvasRenderer>();
        RectTransform rectTransform2 = this.minimap;
        RectTransform rectTransform3 = this.minimap;
        vector = new Vector2(0.5f, 0.5f);
        rectTransform3.anchorMax = vector;
        rectTransform2.anchorMin = vector;
        this.minimap.ancreplaceddPosition = Vector2.zero;
        this.minimap.sizeDelta = this.minimapMaskT.sizeDelta;
        Image image = gameObject3.AddComponent<Image>();
        Rect rect = new Rect(0f, 0f, (float)map.width, (float)map.height);
        image.sprite = UnityEngine.Sprite.Create(map, rect, new Vector3(0.5f, 0.5f));
        image.type = Image.Type.Simple;
    }

19 View Source File : Functions.cs
License : GNU General Public License v2.0
Project Creator : CheepYT

public static Sprite LoadSpriteFromFile(string filepath)
        {
            var tex = LoadTextureFromFile(filepath);

            return Sprite.Create(
                tex,
                new Rect(0, 0, tex.width, tex.height),
                new Vector2(0.5f, 0.5f)
            );
        }

19 View Source File : Functions.cs
License : GNU General Public License v2.0
Project Creator : CheepYT

public static Sprite LoadSpriteFromreplacedemblyResource(replacedembly replacedembly, string resource)
        {
            var tex = LoadTextureFromreplacedemblyResource(replacedembly, resource);

            return Sprite.Create(
                tex,
                new Rect(0, 0, tex.width, tex.height),
                new Vector2(0.5f, 0.5f)
            );
        }

19 View Source File : G_CUIColorPicker.cs
License : GNU General Public License v3.0
Project Creator : Cytoid

private void Setup( Color inputColor )
        {
            alphaSlider.value = inputColor.a;
            alphaSliderBGImage.color = inputColor;
            
            var satvalGO = GO( "SaturationValue" );
            var satvalKnob = GO( "SaturationValue/Knob" );
            var hueGO = GO( "Hue" );
            var hueKnob = GO( "Hue/Knob" );
            var result = GO( "Result" );
            var hueColors = new Color [] 
            {
                Color.red,
                Color.yellow,
                Color.green,
                Color.cyan,
                Color.blue,
                Color.magenta,
            };
            
            var satvalColors = new Color [] 
            {
                new Color( 0, 0, 0 ),
                new Color( 0, 0, 0 ),
                new Color( 1, 1, 1 ),
                hueColors[0],
            };
            
            var hueTex = new Texture2D( 1, 7 );
            
            for ( int i = 0; i < 7; i++ ) {
                hueTex.SetPixel( 0, i, hueColors[i % 6] );
            }
            
            hueTex.Apply();
            hueGO.GetComponent<Image>().sprite = Sprite.Create( hueTex, new Rect( 0, 0.5f, 1, 6 ), new Vector2( 0.5f, 0.5f ) );
            var hueSz = GetWidgetSize( hueGO );
            var satvalTex = new Texture2D(2,2);
            satvalGO.GetComponent<Image>().sprite = Sprite.Create( satvalTex, new Rect( 0.5f, 0.5f, 1, 1 ), new Vector2( 0.5f, 0.5f ) );

            System.Action resetSatValTexture = () => {
                for ( int j = 0; j < 2; j++ ) {
                    for ( int i = 0; i < 2; i++ ) {
                        satvalTex.SetPixel( i, j, satvalColors[i + j * 2] );
                    }
                }
                satvalTex.Apply();
            };
            
            var satvalSz = GetWidgetSize( satvalGO );
            float Hue, Saturation, Value;
            RGBToHSV( inputColor, out Hue, out Saturation, out Value );

            System.Action applyHue = () => 
            {
                var i0 = Mathf.Clamp( ( int )Hue, 0, 5 );
                var i1 = ( i0 + 1 ) % 6;
                var resultColor = Color.Lerp( hueColors[i0], hueColors[i1], Hue - i0 );
                satvalColors[3] = resultColor;
                resetSatValTexture();
            };

            System.Action applySaturationValue = () => 
            {
                var sv = new Vector2( Saturation, Value );
                var isv = new Vector2( 1 - sv.x, 1 - sv.y );
                var c0 = isv.x * isv.y * satvalColors[0];
                var c1 = sv.x * isv.y * satvalColors[1];
                var c2 = isv.x * sv.y * satvalColors[2];
                var c3 = sv.x * sv.y * satvalColors[3];
                var resultColor = c0 + c1 + c2 + c3;
                var resImg = result.GetComponent<Image>();
                resImg.color = resultColor;
                if ( _color != resultColor )
                {
                    resultColor = new Color(resultColor.r, resultColor.g, resultColor.b, alphaSlider.value);
                    
                    if ( _onValueChange != null ) 
                    {
                        _onValueChange( resultColor );
                    }
                    _color = resultColor;
                    
                    alphaSliderBGImage.color = _color;
                }
            };
            applyHue();
            applySaturationValue();
            satvalKnob.transform.localPosition = new Vector2( Saturation * satvalSz.x, Value * satvalSz.y );
            hueKnob.transform.localPosition = new Vector2( hueKnob.transform.localPosition.x, Hue / 6 * satvalSz.y );
            System.Action dragH = null;
            System.Action dragSV = null;
            System.Action idle = () => {
                if ( Input.GetMouseButtonDown( 0 ) ) {
                    Vector2 mp;
                    if ( GetLocalMouse( hueGO, out mp ) ) {
                        _update = dragH;
                    } else if ( GetLocalMouse( satvalGO, out mp ) ) {
                        _update = dragSV;
                    }
                }
            };
            dragH = () => {
                Vector2 mp;
                GetLocalMouse( hueGO, out mp );
                Hue = mp.y / hueSz.y * 6;
                applyHue();
                applySaturationValue();
                hueKnob.transform.localPosition = new Vector2( hueKnob.transform.localPosition.x, mp.y );
                if ( Input.GetMouseButtonUp( 0 ) ) {
                    _update = idle;
                }
            };
            dragSV = () => {
                Vector2 mp;
                GetLocalMouse( satvalGO, out mp );
                Saturation = mp.x / satvalSz.x;
                Value = mp.y / satvalSz.y;
                applySaturationValue();
                satvalKnob.transform.localPosition = mp;
                if ( Input.GetMouseButtonUp( 0 ) ) {
                    _update = idle;
                }
            };
            _update = idle;
        }

19 View Source File : UnityExtensions.cs
License : MIT License
Project Creator : DonnYep

public static Sprite ConvertToSprite(this Texture2D texture)
        {
            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
            return sprite;
        }

19 View Source File : Utility.Unity.cs
License : MIT License
Project Creator : DonnYep

public static Sprite CameraScreenshotreplacedpriteRGBA(Camera camera)
            {
                var texture2D = CameraScreenshotAsTextureRGBA(camera);
                var sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.zero);
                return sprite;
            }

19 View Source File : Utility.Unity.cs
License : MIT License
Project Creator : DonnYep

public static Sprite CameraScreenshotreplacedpriteRGB(Camera camera)
            {
                var texture2D = CameraScreenshotAsTextureRGB(camera);
                var sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.zero);
                return sprite;
            }

19 View Source File : Utility.Unity.cs
License : MIT License
Project Creator : DonnYep

public static Sprite CameraScreenshotreplacedprite(Camera camera, TextureFormat textureFormat)
            {
                var texture2D = CameraScreenshotAsTexture(camera, textureFormat);
                var sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.zero);
                return sprite;
            }

19 View Source File : TranslationHooks.cs
License : The Unlicense
Project Creator : ghorsington

public static void OnTranslateSprite(ref Sprite sprite)
        {
            if (sprite == null)
                return;

            string spriteName = sprite.name;
            bool previouslyTranslated;
            if (string.IsNullOrEmpty(spriteName) || (previouslyTranslated = spriteName.StartsWith("!")))
                return;

            var args = new TextureTranslationEventArgs(sprite.name, "SPRITE") {OriginalTexture = sprite.texture};

            SpriteLoad?.Invoke(null, args);

            if (args.Data == null)
                return;

            var newSprite = Sprite.Create(args.Data.CreateTexture2D(), sprite.rect, sprite.pivot);
            newSprite.name = previouslyTranslated ? spriteName : "!" + spriteName;
            sprite = newSprite;
        }

19 View Source File : BetterSceneLoader.cs
License : GNU General Public License v3.0
Project Creator : Keelhauled

void MakeBetterSceneLoader()
        {
            UISystem = UIUtility.CreateNewUISystem("BetterSceneLoaderCanvas");
            UISystem.GetComponent<Canvreplacedcaler>().referenceResolution = new Vector2(1920f / UIScale, 1080f / UIScale);
            UISystem.gameObject.SetActive(false);
            UISystem.gameObject.transform.SetParent(transform);

            mainPanel = UIUtility.CreatePanel("Panel", UISystem.transform);
            mainPanel.color = backgroundColor;
            UIUtility.AddOutlineToObject(mainPanel.transform, outlineColor);

            var drag = UIUtility.CreatePanel("Draggable", mainPanel.transform);
            drag.transform.SetRect(0f, 1f, 1f, 1f, 0f, -headerSize);
            drag.color = dragColor;
            UIUtility.MakeObjectDraggable(drag.rectTransform, mainPanel.rectTransform);

            nametext = UIUtility.CreateText("Nametext", drag.transform, "Scenes");
            nametext.transform.SetRect(0f, 0f, 1f, 1f, 340f, 0f, -buttonSize * 2f);
            nametext.alignment = TextAnchor.MiddleCenter;

            var close = UIUtility.CreateButton("CloseButton", drag.transform, "");
            close.transform.SetRect(1f, 0f, 1f, 1f, -buttonSize * 2f);
            close.onClick.AddListener(() => UISystem.gameObject.SetActive(false));
            Utils.AddCloseSymbol(close);
            
            category = UIUtility.CreateDropdown("Dropdown", drag.transform, "Categories");
            category.transform.SetRect(0f, 0f, 0f, 1f, 0f, 0f, 100f);
            category.captionText.transform.SetRect(0f, 0f, 1f, 1f, 0f, 2f, -15f, -2f);
            category.captionText.alignment = TextAnchor.MiddleCenter;
            category.options = GetCategories();
            category.onValueChanged.AddListener((x) =>
            {
                imagelist.content.GetComponentInChildren<Image>().gameObject.SetActive(false);
                imagelist.content.ancreplaceddPosition = new Vector2(0f, 0f);
                PopulateGrid();
            });

            var refresh = UIUtility.CreateButton("RefreshButton", drag.transform, "Refresh");
            refresh.transform.SetRect(0f, 0f, 0f, 1f, 100f, 0f, 180f);
            refresh.onClick.AddListener(() => ReloadImages());

            var save = UIUtility.CreateButton("SaveButton", drag.transform, "Save");
            save.transform.SetRect(0f, 0f, 0f, 1f, 180f, 0f, 260f);
            save.onClick.AddListener(() => SaveScene());

            var folder = UIUtility.CreateButton("FolderButton", drag.transform, "Folder");
            folder.transform.SetRect(0f, 0f, 0f, 1f, 260f, 0f, 340f);
            folder.onClick.AddListener(() => Process.Start(scenePath));

            var loadingPanel = UIUtility.CreatePanel("LoadingIconPanel", drag.transform);
            loadingPanel.transform.SetRect(0f, 0f, 0f, 1f, 340f, 0f, 340f + headerSize);
            loadingPanel.color = new Color(0f, 0f, 0f, 0f);
            var loadingIcon = UIUtility.CreatePanel("LoadingIcon", loadingPanel.transform);
            loadingIcon.transform.SetRect(0.1f, 0.1f, 0.9f, 0.9f);
            var texture = Utils.LoadTexture(Properties.Resources.loadicon);
            loadingIcon.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            LoadingIcon.Init(loadingIcon, -5f);

            imagelist = UIUtility.CreateScrollView("Imagelist", mainPanel.transform);
            imagelist.transform.SetRect(0f, 0f, 1f, 1f, marginSize, marginSize, -marginSize, -headerSize - marginSize / 2f);
            imagelist.gameObject.AddComponent<Mask>();
            imagelist.content.gameObject.AddComponent<VerticalLayoutGroup>();
            imagelist.content.gameObject.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            imagelist.verticalScrollbar.GetComponent<RectTransform>().offsetMin = new Vector2(scrollOffsetX, 0f);
            imagelist.viewport.offsetMax = new Vector2(scrollOffsetX, 0f);
            imagelist.movementType = ScrollRect.MovementType.Clamped;

            optionspanel = UIUtility.CreatePanel("ButtonPanel", imagelist.transform);
            optionspanel.gameObject.SetActive(false);

            confirmpanel = UIUtility.CreatePanel("ConfirmPanel", imagelist.transform);
            confirmpanel.gameObject.SetActive(false);

            yesbutton = UIUtility.CreateButton("YesButton", confirmpanel.transform, "Y");
            yesbutton.transform.SetRect(0f, 0f, 0.5f, 1f);
            yesbutton.onClick.AddListener(() => DeleteScene(currentPath));

            nobutton = UIUtility.CreateButton("NoButton", confirmpanel.transform, "N");
            nobutton.transform.SetRect(0.5f, 0f, 1f, 1f);
            nobutton.onClick.AddListener(() => confirmpanel.gameObject.SetActive(false));

            var loadbutton = UIUtility.CreateButton("LoadButton", optionspanel.transform, "Load");
            loadbutton.transform.SetRect(0f, 0f, 0.3f, 1f);
            loadbutton.onClick.AddListener(() => LoadScene(currentPath));

            var importbutton = UIUtility.CreateButton("ImportButton", optionspanel.transform, "Import");
            importbutton.transform.SetRect(0.35f, 0f, 0.65f, 1f);
            importbutton.onClick.AddListener(() => ImportScene(currentPath));

            var deletebutton = UIUtility.CreateButton("DeleteButton", optionspanel.transform, "Delete");
            deletebutton.transform.SetRect(0.7f, 0f, 1f, 1f);
            deletebutton.onClick.AddListener(() => confirmpanel.gameObject.SetActive(true));

            PopulateGrid();
        }

19 View Source File : ModMenuManager.cs
License : GNU General Public License v3.0
Project Creator : Keelhauled

IEnumerator MakeUI()
        {
            for(int i = 0; i < 2; i++) yield return null; // wait for other UI

            var elements = XElement.Load(Environment.CurrentDirectory + menuFolder + menuFile).Elements();
            var gameObjects = Resources.FindObjectsOfTypeAll<GameObject>().Where(x => x.GetComponent<RectTransform>()).ToList();
            modinfolist = new List<ModInfo>();
            foreach(var item in elements)
            {
                string itemName = (string)item.Element("name");
                var match = gameObjects.Where(x => itemName == x.name).ToList();
                if(match.Count > 0)
                {
                    if(match.Count > 1) Console.WriteLine("[{0}] More than one GameObject found with the name \"{1}\"", GetType().Name, itemName);
                    modinfolist.Add(new ModInfo(itemName, (string)item.Element("icon"), match[0]));
                }
            }

            int itemLimit = 4;
            float width = 59f;
            float height = ((width + spacingY / 2f) * Mathf.Clamp(modinfolist.Count, 1, itemLimit) + headerSize + marginSizeBig) / 2f + 1f;

            UISystem = UIUtility.CreateNewUISystem("ModMenuManagerCanvas");
            UISystem.GetComponent<Canvreplacedcaler>().referenceResolution = new Vector2(1920f / UIScale, 1080f / UIScale);
            UISystem.gameObject.SetActive(false);
            UISystem.transform.SetAsLastSibling();
            UISystem.GetComponent<Canvas>().sortingOrder = 5;

            var panel = UIUtility.CreatePanel("Panel", UISystem.transform);
            panel.transform.SetRect(1f, 0.4f, 1f, 0.4f, -width, -height, 0f, height);
            panel.color = transparentColor;

            var drag = UIUtility.CreatePanel("Draggable", panel.transform);
            drag.transform.SetRect(0f, 1f, 1f, 1f, 0f, -headerSize);
            drag.color = dragColor;
            UIUtility.MakeObjectDraggable(drag.rectTransform, panel.rectTransform);

            var modlist = UIUtility.CreateScrollView("Modlist", panel.transform);
            modlist.transform.SetRect(0f, 0f, 1f, 1f, marginSizeBig, marginSizeBig, -marginSizeBig, -headerSize - marginSizeBig);
            modlist.gameObject.AddComponent<Mask>();
            modlist.content.gameObject.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            modlist.GetComponent<Image>().color = new Color(0f, 0f, 0f, 0.01f);
            modlist.movementType = ScrollRect.MovementType.Clamped;
            Destroy(modlist.verticalScrollbar.gameObject);
            modlist.scrollSensitivity = 50f;

            var autogrid = modlist.content.gameObject.AddComponent<AutoGridLayout>();
            autogrid.aspectRatio = 1;
            autogrid.m_IsColumn = true;
            autogrid.m_Column = 1;
            autogrid.spacing = new Vector2(0f, spacingY);

            foreach(var modinfo in modinfolist)
            {
                var button = UIUtility.CreateButton("Button", modlist.content.transform, "");
                button.transform.SetRect(0f, 0f, 1f, 1f, marginSizeSmall, marginSizeSmall, -marginSizeSmall, -marginSizeSmall);
                button.gameObject.AddComponent<Image>();

                string iconPath = Environment.CurrentDirectory + menuFolder + "icons/" + modinfo.Icon;
                if(File.Exists(iconPath))
                {
                    var texture = Pngreplacedist.LoadTexture(iconPath);
                    var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
                    button.transform.gameObject.AddComponent<Image>();
                    var image = button.transform.gameObject.GetComponent<Image>();
                    image.sprite = sprite;
                }
                else
                {
                    button.GetComponentInChildren<Text>().text = modinfo.Name.Substring(0, 1);
                }

                //modinfo.Canvas.AddComponent<ManageSortingOrder>();

                button.onClick.AddListener(() =>
                {
                    modinfo.Canvas.SetActive(!modinfo.Canvas.activeSelf);
                    SetSortingOrder(modinfo);
                });
            }

            // hack for AutoGridLayout
            yield return null;
            UISystem.gameObject.SetActive(true);
        }

19 View Source File : SceneLoaderUI.cs
License : GNU General Public License v3.0
Project Creator : Keelhauled

public void CreateUI()
        {
            UISystem = UIUtility.CreateNewUISystem("BetterSceneLoaderCanvas");
            UISystem.GetComponent<Canvreplacedcaler>().referenceResolution = new Vector2(1920f / UIScale, 1080f / UIScale);
            ShowWindow(false);

            mainPanel = UIUtility.CreatePanel("Panel", UISystem.transform);
            mainPanel.color = backgroundColor;
            UIUtility.AddOutlineToObject(mainPanel.transform, outlineColor);

            var drag = UIUtility.CreatePanel("Draggable", mainPanel.transform);
            drag.transform.SetRect(0f, 1f, 1f, 1f, 0f, -headerSize);
            drag.color = dragColor;
            UIUtility.MakeObjectDraggable(drag.rectTransform, mainPanel.rectTransform);

            nametext = UIUtility.CreateText("Nametext", drag.transform, "Scenes");
            nametext.transform.SetRect(0f, 0f, 1f, 1f, 340f, 0f, -buttonSize * 2f);
            nametext.alignment = TextAnchor.MiddleCenter;

            var close = UIUtility.CreateButton("CloseButton", drag.transform, "");
            close.transform.SetRect(1f, 0f, 1f, 1f, -buttonSize * 2f);
            close.onClick.AddListener(() => ShowWindow(false));

            var x1 = UIUtility.CreatePanel("x1", close.transform);
            x1.transform.SetRect(0f, 0f, 1f, 1f, 8f, 0f, -8f);
            x1.rectTransform.eulerAngles = new Vector3(0f, 0f, 45f);
            x1.color = new Color(0f, 0f, 0f, 1f);
            var x2 = UIUtility.CreatePanel("x2", close.transform);
            x2.transform.SetRect(0f, 0f, 1f, 1f, 8f, 0f, -8f);
            x2.rectTransform.eulerAngles = new Vector3(0f, 0f, -45f);
            x2.color = new Color(0f, 0f, 0f, 1f);

            var category = UIUtility.CreateDropdown("Dropdown", drag.transform, "Categories");
            category.transform.SetRect(0f, 0f, 0f, 1f, 0f, 0f, 100f);
            category.captionText.transform.SetRect(0f, 0f, 1f, 1f, 0f, 2f, -15f, -2f);
            category.captionText.alignment = TextAnchor.MiddleCenter;
            category.options = GetCategories();
            category.onValueChanged.AddListener(x =>
            {
                currentCategoryFolder = CategoryFolders[category.options[x].text];
                imagelist.content.GetComponentInChildren<Image>().gameObject.SetActive(false);
                imagelist.content.ancreplaceddPosition = new Vector2(0f, 0f);
                PopulateGrid();
            });

            var refresh = UIUtility.CreateButton("RefreshButton", drag.transform, "Refresh");
            refresh.transform.SetRect(0f, 0f, 0f, 1f, 100f, 0f, 180f);
            refresh.onClick.AddListener(ReloadImages);

            var save = UIUtility.CreateButton("SaveButton", drag.transform, "Save");
            save.transform.SetRect(0f, 0f, 0f, 1f, 180f, 0f, 260f);
            save.interactable = false;
            save.onClick.AddListener(() =>
            {
                string path = Path.Combine(currentCategoryFolder, DateTime.Now.ToString("yyyy_MMdd_HHmm_ss_fff") + ".png");
                OnSaveButtonClick(path);
                var button = CreateSceneButton(imagelist.content.GetComponentInChildren<Image>().transform, Pngreplacedist.LoadTexture(path), path);
                button.transform.SetAsFirstSibling();
            });

            var folder = UIUtility.CreateButton("FolderButton", drag.transform, "Folder");
            folder.transform.SetRect(0f, 0f, 0f, 1f, 260f, 0f, 340f);
            folder.onClick.AddListener(() => OnFolderButtonClick(scenePath));

            var loadingPanel = UIUtility.CreatePanel("LoadingIconPanel", drag.transform);
            loadingPanel.transform.SetRect(0f, 0f, 0f, 1f, 340f, 0f, 340f + headerSize);
            loadingPanel.color = new Color(0f, 0f, 0f, 0f);
            var loadingIcon = UIUtility.CreatePanel("LoadingIcon", loadingPanel.transform);
            loadingIcon.transform.SetRect(0.1f, 0.1f, 0.9f, 0.9f);
            var loadiconTex = Pngreplacedist.ChangeTextureFromByte(Resource.GetResourceAsBytes(typeof(SceneLoaderUI).replacedembly, "Resources.loadicon"));
            loadingIcon.sprite = Sprite.Create(loadiconTex, new Rect(0, 0, loadiconTex.width, loadiconTex.height), new Vector2(0.5f, 0.5f));
            LoadingIcon.Init(loadingIcon, -5f);

            imagelist = UIUtility.CreateScrollView("Imagelist", mainPanel.transform);
            imagelist.transform.SetRect(0f, 0f, 1f, 1f, marginSize, marginSize, -marginSize, -headerSize - marginSize / 2f);
            imagelist.gameObject.AddComponent<Mask>();
            imagelist.content.gameObject.AddComponent<VerticalLayoutGroup>();
            imagelist.content.gameObject.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            imagelist.verticalScrollbar.GetComponent<RectTransform>().offsetMin = new Vector2(scrollOffsetX, 0f);
            imagelist.viewport.offsetMax = new Vector2(scrollOffsetX, 0f);
            imagelist.movementType = ScrollRect.MovementType.Clamped;

            optionspanel = UIUtility.CreatePanel("ButtonPanel", imagelist.transform);
            optionspanel.gameObject.SetActive(false);

            confirmpanel = UIUtility.CreatePanel("ConfirmPanel", imagelist.transform);
            confirmpanel.gameObject.SetActive(false);

            yesbutton = UIUtility.CreateButton("YesButton", confirmpanel.transform, "Y");
            yesbutton.transform.SetRect(0f, 0f, 0.5f, 1f);
            yesbutton.onClick.AddListener(() => OnDeleteButtonClick(currentPath));

            nobutton = UIUtility.CreateButton("NoButton", confirmpanel.transform, "N");
            nobutton.transform.SetRect(0.5f, 0f, 1f, 1f);
            nobutton.onClick.AddListener(() => confirmpanel.gameObject.SetActive(false));

            var loadbutton = UIUtility.CreateButton("LoadButton", optionspanel.transform, "Load");
            loadbutton.transform.SetRect(0f, 0f, 0.3f, 1f);
            loadbutton.onClick.AddListener(() =>
            {
                confirmpanel.gameObject.SetActive(false);
                optionspanel.gameObject.SetActive(false);
                OnLoadButtonClick(currentPath);
                if(BetterSceneLoaderCore.AutoClose.Value)
                    ShowWindow(false);
            });

            var importbutton = UIUtility.CreateButton("ImportButton", optionspanel.transform, "Import");
            importbutton.transform.SetRect(0.35f, 0f, 0.65f, 1f);
            importbutton.onClick.AddListener(() =>
            {
                OnImportButtonClick(currentPath);
                confirmpanel.gameObject.SetActive(false);
                optionspanel.gameObject.SetActive(false);
            });

            var deletebutton = UIUtility.CreateButton("DeleteButton", optionspanel.transform, "Delete");
            deletebutton.transform.SetRect(0.7f, 0f, 1f, 1f);
            deletebutton.onClick.AddListener(() =>
            {
                confirmpanel.gameObject.SetActive(true);
                currentButton.gameObject.SetActive(false);
                confirmpanel.gameObject.SetActive(false);
                optionspanel.gameObject.SetActive(false);
            });

            var pluginiconTex = Pngreplacedist.ChangeTextureFromByte(Resource.GetResourceAsBytes(typeof(SceneLoaderUI).replacedembly, "Resources.pluginicon"));
            toolbarToggle = CustomToolbarButtons.AddLeftToolbarToggle(pluginiconTex, false, ShowWindow);

            UpdateWindow();
            PopulateGrid();
        }

19 View Source File : BetterSceneLoader.cs
License : GNU General Public License v3.0
Project Creator : Keelhauled

Button CreateSceneButton(Transform parent, Texture2D texture, string path)
        {
            var button = UIUtility.CreateButton("ImageButton", parent, "");
            button.onClick.AddListener(() =>
            {
                currentButton = button;
                currentPath = path;

                if(optionspanel.transform.parent != button.transform)
                {
                    optionspanel.transform.SetParent(button.transform);
                    optionspanel.transform.SetRect(0f, 0f, 1f, 0.15f);
                    optionspanel.gameObject.SetActive(true);

                    confirmpanel.transform.SetParent(button.transform);
                    confirmpanel.transform.SetRect(0.4f, 0.4f, 0.6f, 0.6f);
                }
                else
                {
                    optionspanel.gameObject.SetActive(!optionspanel.gameObject.activeSelf);
                }

                confirmpanel.gameObject.SetActive(false);
            });
            
            var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            button.gameObject.GetComponent<Image>().sprite = sprite;

            return button;
        }

19 View Source File : SceneLoaderUI.cs
License : GNU General Public License v3.0
Project Creator : Keelhauled

private Button CreateSceneButton(Transform parent, Texture2D texture, string path)
        {
            var button = UIUtility.CreateButton("ImageButton", parent, "");
            button.onClick.AddListener(() =>
            {
                currentButton = button;
                currentPath = path;

                if(optionspanel.transform.parent != button.transform)
                {
                    optionspanel.transform.SetParent(button.transform);
                    optionspanel.transform.SetRect(0f, 0f, 1f, 0.15f);
                    optionspanel.gameObject.SetActive(true);

                    confirmpanel.transform.SetParent(button.transform);
                    confirmpanel.transform.SetRect(0.4f, 0.4f, 0.6f, 0.6f);
                }
                else
                {
                    optionspanel.gameObject.SetActive(!optionspanel.gameObject.activeSelf);
                }

                confirmpanel.gameObject.SetActive(false);
            });

            var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            button.gameObject.GetComponent<Image>().sprite = sprite;

            return button;
        }

19 View Source File : AppUI.cs
License : MIT License
Project Creator : NRatel

public void SetImage(Texture2D texture)
        {
            this.m_Go_BigImageBg.gameObject.SetActive(true);

            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
            this.m_Image_BigImage.sprite = sprite;
            RectTransform rt = this.m_Image_BigImage.GetComponent<RectTransform>();
            rt.sizeDelta = new Vector2(texture.width, texture.height);

            //缩放至屏幕可直接显示的大小
            float minRate = Mathf.Min(600.0f / texture.width, 600.0f/ texture.height);
            if (minRate < 1)
            {
                rt.localScale = new Vector2(minRate, minRate);
            }
            else {
                rt.localScale = Vector2.one;
            }
        }

19 View Source File : Grid.cs
License : MIT License
Project Creator : peteschmitz

private void BuildGrid()
    {
        this.truncatedColumns = 0;
        this.truncatedRows = 0;

        var boxWidth = GameContext.PixelPerUnit;
        var boxHeight = (int)(Ground.groundHeightUnits * GameContext.PixelPerUnit);
        var requestedColumns = this.columns + this.boxBufferWidth * 2;
        if (requestedColumns > WarehouseManager.MaxSize)
        {
            this.truncatedColumns = requestedColumns - WarehouseManager.MaxSize;
            requestedColumns -= this.truncatedColumns;
        }
        var requestedRows = this.rows + this.boxBufferHeight * 2;
        if (requestedRows > WarehouseManager.MaxSize)
        {
            this.truncatedRows = requestedRows - WarehouseManager.MaxSize;
            requestedRows -= this.truncatedRows;
        }
        this.texture = new Texture2D(boxWidth * requestedColumns, boxHeight * requestedRows);
        this.texture.requestedMipmapLevel = 0;
        this.texture.filterMode = FilterMode.Point;
        this.sprite = Sprite.Create(this.texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, GameContext.PixelPerUnit);
        this.spriteRenderer.sprite = this.sprite;
        for (var x = 0; x < requestedColumns + 1; ++x)
        {
            var pixelsX = (x == requestedColumns ? texture.width - this.borderSize : x * boxWidth);
            var pixelsHeight = boxHeight * requestedRows;
            var colors = Enumerable.Repeat(this.borderColor, this.borderSize * pixelsHeight).ToArray();
            this.texture.SetPixels(pixelsX, 0, this.borderSize, pixelsHeight, colors);
        }
        for (var y = 0; y < requestedRows + 1; ++y)
        {
            var pixelsY = (y == requestedRows ? texture.height - this.borderSize : y * boxHeight);
            var pixelsWidth = boxWidth * requestedColumns;
            var colors = Enumerable.Repeat(this.borderColor, this.borderSize * pixelsWidth).ToArray();
            this.texture.SetPixels(0, pixelsY, pixelsWidth, this.borderSize, colors);
        }
        this.texture.Apply(true);
        this.boxCollider.size = this.sprite.bounds.size;
        this.boxCollider.offset = new Vector2(this.boxCollider.size.x * 0.5f, this.boxCollider.size.y * 0.5f);
        this.CenterOn(requestedColumns, requestedRows);
    }

19 View Source File : ThumbnailBuilder.cs
License : MIT License
Project Creator : peteschmitz

public Sprite GetSprite(Ground[][] grounds)
    {
        var scaledTileSize = (int)(scale * TileSize);
        var region = this.GetRegion(grounds);
        var texture = new Texture2D(region.Length * scaledTileSize + pixelPadding * 2, region[0].Length * scaledTileSize + pixelPadding * 2);
        texture.requestedMipmapLevel = 0;
        texture.filterMode = FilterMode.Point;
        texture.SetPixels(Enumerable.Repeat(this.background, texture.width * texture.height).ToArray());
        for (var column = 0; column < region.Length; ++column)
        {
            for (var row = 0; row < region.Length; ++row)
            {
                var ground = region[column][row];
                Texture2D scaledTexture = null;
                if (ground?.occupant != null)
                {
                    scaledTexture = this.GetScaledTexture(ground.occupant, scaledTileSize);
                }
                else if (ground != null)
                {
                    scaledTexture = this.GetScaledTexture(ground, scaledTileSize);
                }
                if (scaledTexture != null)
                {
                    texture.SetPixels(pixelPadding + column * scaledTileSize, pixelPadding + row * scaledTileSize, scaledTexture.width, scaledTexture.height, scaledTexture.GetPixels());
                }
            }
        }
        texture.Apply();
        var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, GameContext.PixelPerUnit);
        return sprite;
    }

19 View Source File : InternalAsyncEmojiRect.cs
License : MIT License
Project Creator : sassembla

public static InternalAsyncEmojiRect New<T, U>(T parentTextElement, Char[] chars) where T : LTAsyncElement, ILayoutableText where U : IMissingSpriteCache, new()
        {
            var emojiOrMarkStr = new string(chars);

            var go = parentTextElement.GenerateGO(emojiOrMarkStr);

            // TMProのレイアウトをするためには、ここでCanvasに乗っている親要素の上に載せるしかない。
            go.transform.SetParent(parentTextElement.transform, false);


            var emojiRect = go.AddComponent<InternalAsyncEmojiRect>();

            // 文字をセットする場所としてRectTransformを取得、レイアウトのために高さに無限値をセット
            var rectTrans = go.GetComponent<RectTransform>();
            // フォント情報を取得するためにT型をセットし、そこからTMProのcomponentを取り出す。そこに絵文字をセットし、絵文字画像を得る。
            var textComponent = go.GetComponent<TextMeshProUGUI>();

            textComponent.enableWordWrapping = true;
            textComponent.text = emojiOrMarkStr;
            rectTrans.sizeDelta = Vector2.positiveInfinity;
            var textInfos = textComponent.GetTextInfo(emojiOrMarkStr);
            textComponent.enableWordWrapping = false;

            var lines = textInfos.lineCount;
            if (lines != 1)
            {
                throw new Exception("unsupported emoji/mark pattern.");
            }

            var lineInfo = textInfos.lineInfo[0];
            var lineWidth = lineInfo.length;
            var lineHeight = lineInfo.lineHeight;

            // サイズの更新
            var size = new Vector2(lineWidth, lineHeight);

            // 絵文字/記号部分を左上アンカーにすると、高さがNanにならずに絵文字/記号スプライトが表示される。
            if (0 < rectTrans.childCount)
            {
                var emojiRectTrans = rectTrans.GetChild(0).GetComponent<RectTransform>();
                emojiRectTrans.pivot = new Vector2(0, 1);
                emojiRectTrans.anchorMin = new Vector2(0, 1);
                emojiRectTrans.anchorMax = new Vector2(0, 1);
                emojiRectTrans.ancreplaceddPosition = Vector2.zero;
            }

            // この文字オブジェクト自体の位置、サイズを規定する
            rectTrans.ancreplaceddPosition = Vector2.zero;
            rectTrans.sizeDelta = size;

            // サイズを一旦TMProの情報をもとに決定する
            emojiRect.Size = size;

            var (isExist, codePoint) = TextLayoutDefinitions.TMPro_ChechIfEmojiOrMarkExist(emojiOrMarkStr);
            if (isExist)
            {
                // 最低一つ要素が作られているはずなので、そのSpreplacedeの位置情報をレイアウト後に合致するように調整する。
                if (rectTrans.childCount == 1)
                {
                    var emojiRectTrans = rectTrans.GetChild(0).GetComponent<RectTransform>();
                    emojiRectTrans.pivot = new Vector2(0, 1);
                    emojiRectTrans.anchorMin = new Vector2(0, 1);
                    emojiRectTrans.anchorMax = new Vector2(0, 1);
                    emojiRectTrans.ancreplaceddPosition = Vector2.zero;
                }
                else
                {
                    Debug.LogWarning("絵文字かマークがある状態だが、このcodePointの文字を示すspriteがロードされない codePoint:" + codePoint);
                }
            }
            else
            {
                // ローディングフラグを立てる
                emojiRect.IsLoading = true;

                /*
                    ポイント数
                    フォント名
                    表示幅
                    表示高さ
                    コードポイント
                */
                var fontName = textComponent.font.name;
                var fontSize = textComponent.fontSize;
                var requestWidth = size.x;
                var requestHeight = size.y;

                var cacheInstance = InternalCachePool.Get<U>();

                cacheInstance.LoadMissingEmoji(
                    fontName,
                    fontSize,
                    requestWidth,
                    requestHeight,
                    codePoint,
                    cor =>
                    {
                        emojiRect.StartCoroutine(cor);
                    },
                    data =>
                    {
                        emojiRect.IsLoading = false;

                        var spr = Sprite.Create(data, new Rect(0, 0, data.width, data.height), Vector2.zero);

                        // サイズを更新
                        rectTrans.sizeDelta = new Vector2(data.width, data.height);

                        // tmProのコンポーネントを排除する(子供があるとそれを描画しようとしてエラーが出る)
                        GameObject.Destroy(textComponent);

                        if (0 < rectTrans.childCount)
                        {
                            // TMProの文字(カラ)が置いてあるコンポーネントを削除する
                            var emojiChild = rectTrans.GetChild(0);
                            GameObject.Destroy(emojiChild.gameObject);
                        }

                        // スプライトを作って入れる
                        var spriteObject = new GameObject("sprite");
                        var spriteComponent = spriteObject.AddComponent<Image>();

                        var childRectTrans = spriteComponent.GetComponent<RectTransform>();
                        childRectTrans.pivot = new Vector2(0, 1);
                        childRectTrans.anchorMin = new Vector2(0, 1);
                        childRectTrans.anchorMax = new Vector2(0, 1);
                        spriteComponent.transform.SetParent(rectTrans, false);

                        spriteComponent.sprite = spr;
                        spriteComponent.SetNativeSize();

                        // 決定後のサイズを入力する
                        emojiRect.Size = rectTrans.sizeDelta;
                    },
                    () =>
                    {
                        emojiRect.IsLoading = false;
                    }
                );
            }

            return emojiRect;
        }

19 View Source File : InternalAsyncMissingTextRect.cs
License : MIT License
Project Creator : sassembla

public static InternalAsyncMissingTextRect New<T, U>(T parentTextElement, string text) where T : LTAsyncElement, ILayoutableText where U : IMissingSpriteCache, new()
        {
            var go = parentTextElement.GenerateGO(text);

            // TMProのレイアウトをするためには、ここでCanvasに乗っている親要素の上に載せるしかない。
            go.transform.SetParent(parentTextElement.transform, false);

            var missingTextRect = go.AddComponent<InternalAsyncMissingTextRect>();

            // 文字をセットする場所としてRectTransformを取得、レイアウトのために高さに無限値をセット
            var rectTrans = go.GetComponent<RectTransform>();
            // フォント情報を取得するためにT型をセットし、そこからTMProのcomponentを取り出す。そこに絵文字をセットし、絵文字画像を得る。
            var textComponent = go.GetComponent<TextMeshProUGUI>();

            textComponent.enableWordWrapping = true;
            textComponent.text = text;
            rectTrans.sizeDelta = Vector2.positiveInfinity;
            var textInfos = textComponent.GetTextInfo(text);
            textComponent.enableWordWrapping = false;

            var lines = textInfos.lineCount;
            if (lines != 1)
            {
                throw new Exception("unsupported emoji/mark pattern.");
            }

            var lineInfo = textInfos.lineInfo[0];
            var lineWidth = lineInfo.length;
            var lineHeight = lineInfo.lineHeight;

            // サイズの更新
            var size = new Vector2(lineWidth, lineHeight);

            // この文字オブジェクト自体の位置、サイズを規定する
            rectTrans.ancreplaceddPosition = Vector2.zero;
            rectTrans.sizeDelta = size;

            // サイズを一旦TMProの情報をもとに決定する
            missingTextRect.Size = size;

            // ローディングフラグを立てる
            missingTextRect.IsLoading = true;

            /*
                フォント名
                ポイント数
                表示幅
                表示高さ
                文字
            */
            var fontName = textComponent.font.name;
            var fontSize = textComponent.fontSize;
            var requestWidth = size.x;
            var requestHeight = size.y;

            var cacheInstance = InternalCachePool.Get<U>();

            cacheInstance.LoadMissingText(
                fontName,
                fontSize,
                requestWidth,
                requestHeight,
                text,
                cor =>
                {
                    missingTextRect.StartCoroutine(cor);
                },
                data =>
                {
                    missingTextRect.IsLoading = false;

                    var spr = Sprite.Create(data, new Rect(0, 0, data.width, data.height), Vector2.zero);

                    // サイズを更新
                    rectTrans.sizeDelta = new Vector2(data.width, data.height);

                    // tmProのコンポーネントを排除する(子供があるとそれを描画しようとしてエラーが出る)
                    GameObject.Destroy(textComponent);

                    if (0 < rectTrans.childCount)
                    {
                        // TMProの文字(カラ)が置いてあるコンポーネントを削除する
                        var emojiChild = rectTrans.GetChild(0);
                        GameObject.Destroy(emojiChild.gameObject);
                    }

                    // スプライトを作って入れる
                    var spriteObject = new GameObject("sprite");
                    var spriteComponent = spriteObject.AddComponent<Image>();

                    var childRectTrans = spriteComponent.GetComponent<RectTransform>();
                    childRectTrans.pivot = new Vector2(0, 1);
                    childRectTrans.anchorMin = new Vector2(0, 1);
                    childRectTrans.anchorMax = new Vector2(0, 1);
                    spriteComponent.transform.SetParent(rectTrans, false);

                    spriteComponent.sprite = spr;
                    spriteComponent.SetNativeSize();

                    // 決定後のサイズを入力する
                    missingTextRect.Size = rectTrans.sizeDelta;
                },
                () =>
                {
                    missingTextRect.IsLoading = false;
                }
            );

            return missingTextRect;
        }

19 View Source File : AssetLoader.cs
License : MIT License
Project Creator : Vek17

public static Sprite Create(string filePath) {
                var bytes = File.ReadAllBytes(icons_folder + filePath);
                var texture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
                _ = texture.LoadImage(bytes);
                var sprite = Sprite.Create(texture, new Rect(0, 0, 64, 64), new Vector2(0, 0));
                return sprite;
            }

19 View Source File : WalletConnect.cs
License : MIT License
Project Creator : WalletConnect

private IEnumerator DownloadImagesFor(string id, string[] sizes = null)
        {
            if (sizes == null)
            {
                sizes = new string[] {"sm", "md", "lg"};
            }
            
            var data = SupportedWallets[id];

            foreach (var size in sizes)
            {
                var url = "https://registry.walletconnect.org/logo/" + size + "/" + id + ".jpeg";

                using (UnityWebRequest imageRequest = UnityWebRequestTexture.GetTexture(url))
                {
                    yield return imageRequest.SendWebRequest();

                    if (imageRequest.isNetworkError)
                    {
                        Debug.Log("Error Getting Wallet Icon: " + imageRequest.error);
                    }
                    else
                    {
                        var texture = ((DownloadHandlerTexture) imageRequest.downloadHandler).texture;
                        var sprite = Sprite.Create(texture,
                            new Rect(0.0f, 0.0f, texture.width, texture.height),
                            new Vector2(0.5f, 0.5f), 100.0f);

                        if (size == "sm")
                        {
                            data.smallIcon = sprite;
                        }
                        else if (size == "md")
                        {
                            data.medimumIcon = sprite;
                        }
                        else if (size == "lg")
                        {
                            data.largeIcon = sprite;
                        }
                    }
                }
            }
        }

19 View Source File : UnityEngine_SpriteWrap.cs
License : MIT License
Project Creator : XINCGer

[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
	static int Create(IntPtr L)
	{
		try
		{
			int count = LuaDLL.lua_gettop(L);

			if (count == 3)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 4)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 5)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 6)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 7)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
				UnityEngine.Vector4 arg6 = ToLua.ToVector4(L, 7);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 8)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
				UnityEngine.Vector4 arg6 = ToLua.ToVector4(L, 7);
				bool arg7 = LuaDLL.luaL_checkboolean(L, 8);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else
			{
				return LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Sprite.Create");
			}
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}

19 View Source File : UnityEngine_SpriteWrap.cs
License : MIT License
Project Creator : XINCGer

[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
	static int Create(IntPtr L)
	{
		try
		{
			int count = LuaDLL.lua_gettop(L);

			if (count == 3)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 4)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 5)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 6)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 7)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
				UnityEngine.Vector4 arg6 = ToLua.ToVector4(L, 7);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else if (count == 8)
			{
				UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
				UnityEngine.Rect arg1 = StackTraits<UnityEngine.Rect>.Check(L, 2);
				UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
				float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
				uint arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
				UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
				UnityEngine.Vector4 arg6 = ToLua.ToVector4(L, 7);
				bool arg7 = LuaDLL.luaL_checkboolean(L, 8);
				UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
				ToLua.PushSealed(L, o);
				return 1;
			}
			else
			{
				return LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Sprite.Create");
			}
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}

19 View Source File : CommonHelper.cs
License : MIT License
Project Creator : XINCGer

public static Sprite SliceTextureToSprite(Texture2D texture2D, float x, float y, float width, float height)
    {
        if (null != texture2D)
        {
            if (x + width > texture2D.width)
            {
                width = texture2D.width - x;
                Debug.LogWarning("the width is larger then texture2D width!");
            }
            if (y + height > texture2D.height)
            {
                height = texture2D.height - y;
                Debug.LogWarning("the height is larger then texture2D height!");
            }

            Sprite sprite = Sprite.Create(texture2D, new Rect(x, y, width, height), new Vector2(0.5f, 0.5f));
            return sprite;
        }
        Debug.LogWarning("Texture2D 不能为空!");
        return null;
    }