示例#1
0
    public static Sprite LoadSpriteFromFile(string p_file)
    {
        FileSprite loaded = m_loadedSprites.Find(fs => fs.Name == Path.GetFileNameWithoutExtension(p_file));

        if (loaded != null && loaded.Sprite)
        {
            return(loaded.Sprite);
        }

        Texture2D texture = LoadTexture(p_file);

        if (texture == null)
        {
            return(null);
        }

        texture.filterMode = FilterMode.Point;

        Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), 100f, 0, SpriteMeshType.Tight);

        sprite.name = Path.GetFileNameWithoutExtension(p_file);

        m_loadedSprites.Add(new FileSprite(p_file, sprite));

        return(sprite);
    }
示例#2
0
 public bool Update(TimeSpan deltaTime)
 {
     for (int e = 0; e < _entities.Count; ++e)
     {
         Transform  trans  = _transforms[_entities[e].ComponentIndices[0]];
         FileSprite sprite = _sprites[_entities[e].ComponentIndices[1]];
         _renderer.AddSprite(sprite.CharacterBuffer, sprite.ForeColor, sprite.BackColor, trans.LocalLeft, trans.LocalTop);
     }
     return(true);
 }
示例#3
0
    public static Sprite LoadSpriteFromResources(string p_name)
    {
        FileSprite loaded = m_loadedSprites.Find(fs => fs.Name == p_name);

        if (loaded != null && loaded.Sprite)
        {
            return(loaded.Sprite);
        }

        Sprite sprite = Resources.Load <Sprite>("Sprites/" + p_name);

        sprite.texture.filterMode = FilterMode.Point;

        m_loadedSprites.Add(new FileSprite(p_name, sprite));

        return(sprite);
    }
示例#4
0
    public void Load()
    {
        List <FileSprite> sprites = new List <FileSprite>();

        m_currentIndex = 0;

        if (!MenuHandler.Instance || MenuHandler.Instance.m_handlingPlayer == null)
        {
            return;
        }

        string loadedCursor = Game.m_options.Get("CursorSprite", MenuHandler.Instance.m_handlingPlayer.id).GetString();

        foreach (string file in Directory.GetFiles(Application.dataPath + "/Data/Cursors/"))
        {
            if (file.ToLower().EndsWith(".png"))
            {
                string name = Path.GetFileNameWithoutExtension(file);

                try {
                    FileSprite existingSprite = m_sprites.Find(fs => fs.Name.Equals(name));
                    sprites.Add(existingSprite);
                } catch (NullReferenceException) {
                    Sprite sprite = SpriteUtils.LoadSpriteFromFile(file);

                    if (sprite == null)
                    {
                        continue;
                    }

                    sprites.Add(new FileSprite(name, sprite));
                }
            }
        }

        m_sprites      = sprites;
        m_currentIndex = m_sprites.FindIndex(fs => fs.Name.Equals(loadedCursor));

        Display(m_currentIndex);
    }