Beispiel #1
0
            public int GetIndex(string guid, out bool alreadyContained)
            {
                if (string.IsNullOrEmpty(guid))
                {
                    alreadyContained = false;
                    return(-1);
                }

                if (texDict.ContainsKey(guid) && texDict[guid].usedCount > 0)
                {
                    TextureIdentifier ident = texDict[guid];
                    ident.usedCount++;
                    texDict[guid]    = ident;
                    alreadyContained = true;
                    return(ident.belonged);
                }
                else
                {
                    TextureIdentifier ident;
                    ident.usedCount = 1;
                    if (avaiableTexs.Length <= 0)
                    {
                        throw new Exception("No available texture lefted!");
                    }
                    ident.belonged = avaiableTexs[avaiableTexs.Length - 1];

                    avaiableTexs.RemoveLast();
                    texDict[guid]    = ident;
                    alreadyContained = false;
                    return(ident.belonged);
                }
            }
Beispiel #2
0
            public int GetLightmapIndex(string guid, out bool alreadyContained)
            {
                if (lightmapDict.ContainsKey(guid) && lightmapDict[guid].usedCount > 0)
                {
                    TextureIdentifier ident = lightmapDict[guid];
                    ident.usedCount++;
                    lightmapDict[guid] = ident;
                    alreadyContained   = true;
                    return(ident.belonged);
                }
                else
                {
                    TextureIdentifier ident;
                    ident.usedCount = 1;
                    if (avaiableLightmap.Length <= 0)
                    {
                        throw new Exception("No available lightmap lefted!");
                    }
                    ident.belonged = avaiableLightmap[avaiableLightmap.Length - 1];

                    avaiableLightmap.RemoveLast();
                    lightmapDict[guid] = ident;
                    alreadyContained   = false;
                    return(ident.belonged);
                }
            }
Beispiel #3
0
 public void RemoveLightmap(string guid)
 {
     if (lightmapDict.ContainsKey(guid))
     {
         TextureIdentifier ident = lightmapDict[guid];
         ident.usedCount--;
         if (ident.usedCount <= 0)
         {
             lightmapDict.Remove(guid);
             avaiableLightmap.Add(ident.belonged);
         }
         else
         {
             lightmapDict[guid] = ident;
         }
     }
 }
Beispiel #4
0
 public void RemoveTex(string guid)
 {
     if (texDict.ContainsKey(guid))
     {
         TextureIdentifier ident = texDict[guid];
         ident.usedCount--;
         if (ident.usedCount <= 0)
         {
             texDict.Remove(guid);
             avaiableTexs.Add(ident.belonged);
         }
         else
         {
             texDict[guid] = ident;
         }
     }
 }
Beispiel #5
0
        public static void SetStyleBorder(GUIStyle style, Color foregroundColor, Color backgroundColor)
        {
            var identifier = new TextureIdentifier(foregroundColor, backgroundColor);

            Texture2D tex;

            if (TextureRecords.ContainsKey(identifier))
            {
                tex = TextureRecords[identifier];
            }
            else
            {
                var texSize = 16;

                tex = new Texture2D(texSize, texSize, TextureFormat.ARGB32, false, true);

                for (int y = 0; y < texSize; y++)
                {
                    for (int x = 0; x < texSize; x++)
                    {
                        if (x == 0 || y == 0 || x == texSize - 1 || y == texSize - 1)
                        {
                            tex.SetPixel(x, y, foregroundColor);
                        }
                        else
                        {
                            tex.SetPixel(x, y, backgroundColor);
                        }
                    }
                }

                tex.Apply(false);

                style.border = new RectOffset(4, 4, 4, 4);
            }

            style.normal.background  = tex;
            style.active.background  = tex;
            style.hover.background   = tex;
            style.focused.background = tex;
        }
        public static PowerupFlyweight GetFlyweight(TextureIdentifier textureIdentifier, IPowerUpStrategy strategy)
        {
            String key = getKey(textureIdentifier, strategy);

            if (_powerupFlyweights.ContainsKey(key))
            {
                //OurLogger.Log($"Reusing flyweight {key}");
                GameApplication.defaultLogger.LogMessage(10, $"Reusing flyweight {key}");
                return(_powerupFlyweights[key]);
            }
            else
            {
                //OurLogger.Log($"Creating new flyweight {key}");
                GameApplication.defaultLogger.LogMessage(10, $"Creating flyweight {key}");

                PowerupFlyweight powerupFlyweight = new PowerupFlyweight(ResourceHolderFacade.GetInstance().Textures.Get(textureIdentifier), strategy);

                _powerupFlyweights.Add(key, powerupFlyweight);

                return(_powerupFlyweights[key]);
            }
        }
 public static String getKey(TextureIdentifier textureIdentifier, IPowerUpStrategy strategy)
 {
     return(String.Format("{0}__{1}", textureIdentifier.ToString(), strategy.GetType().Name));
 }