Exemplo n.º 1
0
    /** Sets the cursor to cursor of given name. */
    public static void SetCursor(string name, Vector2 hotspot = default(Vector2))
    {
        //stupid webgl is bugged and I can't used custom cursors without cursor corruption.  Forcing software is terraible so I don't do that either.
        if (isWebGL)
        {
            return;
        }

        string fullPath = "Mouse Cursors/" + name;

        Sprite standardCursor = ResourceManager.GetSprite(fullPath);
        Sprite largeCursor    = ResourceManager.GetSprite(fullPath + "@x2") ?? standardCursor;

        if (standardCursor == null)
        {
            Trace.LogWarning("Invalid cursor name {0}, not found.", fullPath);
            return;
        }

        bool useLargeCursor = Screen.width >= 1920;

        Texture2D cursorTexture = (useLargeCursor ? largeCursor.texture : standardCursor.texture);

        Util.Assert(TextureMagic.IsReadable(cursorTexture), "Cursor texture must be readwrite enabled.");

        Cursor.SetCursor(cursorTexture, hotspot * (useLargeCursor ? 2 : 1), CursorMode.Auto);
    }
Exemplo n.º 2
0
    /** Process the source texture by remapping the colors, write to destination as output */
    private void Process()
    {
        Refresh = false;

        CreateDestinationTexture();

        if ((Source == null) || (Destination == null))
        {
            return;
        }

        Trace.Log("Processing texture " + Source);

        if (!TextureMagic.IsReadable(Source))
        {
            throw new UnityException("Can not read from source texture.");
        }

        data = Source.GetPixels32();

        for (int ylp = 0; ylp < Source.height; ylp++)
        {
            for (int xlp = 0; xlp < Source.width; xlp++)
            {
                Color32 col = Color.red;

                switch (GetTexelType(xlp, ylp))
                {
                case TexelType.Background:
                    col = BackgroundColor;
                    break;

                case TexelType.Edge:
                    col = EdgeColor;
                    break;

                case TexelType.Normal:
                    col = GetTexel(xlp, ylp);
                    break;

                case TexelType.Shadow:
                    col = ShadowColor;
                    break;
                }
                Destination.SetPixel(xlp, ylp, col);
            }
        }

        Destination.Apply();
        TextureMagic.SaveTextureToFile(Destination, DestinationPath);

        Trace.Log("Saved " + DestinationPath);

        data = null;
    }
Exemplo n.º 3
0
Arquivo: CoM.cs Projeto: bsimser/CoM
    /** Finds and organises all the sprites required to display the gui. */
    public static void LoadGraphics()
    {
        DateTime startTime = DateTime.Now;

        Trace.Log("Loading graphic resources:");

        Instance.MiscSprites      = LoadGraphicResources(MiscAtlasPath);
        Instance.MonsterSprites   = LoadGraphicResources(MonsterAtlasPath);
        Instance.MapIconSprites   = LoadGraphicResources(MapIconsAtlasPath);
        Instance.ItemIconSprites  = LoadGraphicResources(ItemIconsAtlasPath);
        Instance.SpellIconSprites = LoadGraphicResources(SpellIconsAtlasPath);
        Instance.IconSprites      = LoadGraphicResources(IconsAtlasPath, "NotFound");
        Instance.Portraits        = SpriteLibrary.FromXML(PortraitsXMLPath);

        Util.Assert(TextureMagic.IsReadable(Instance.MapIconSprites[0].texture), "Map sprites atlas needs to be set to readable under import settings (advanced).");

        Trace.Log("Graphic resource loading completed in " + (DateTime.Now - startTime).TotalMilliseconds.ToString("0.0") + "ms.");

        _graphicsLoaded = true;
    }