Esempio n. 1
0
        private void FinishAction()
        {
            if (Mount.CurJob != null && Mount.CurJob.def == GUC_JobDefOf.Mounted)
            {
                ExtendedPawnData pawnData   = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(this.pawn);
                ExtendedPawnData animalData = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(Mount);

                pawnData.mount           = Mount;
                pawnData.drawOffsetCache = Vector3.zero;

                pawn.Rotation = Mount.Rotation;
                if (pawnData.drawOffset != -1)
                {
                    pawnData.drawOffsetCache.z = pawnData.drawOffset;
                }

                if (pawnData.mount.def.HasModExtension <DrawingOffsetPatch>())
                {
                    pawnData.drawOffsetCache += AddCustomOffsets(this.pawn, pawnData);
                }

                if (Mount.Rotation == Rot4.South)
                {
                    AnimalRecord value;
                    bool         found = Base.drawSelecter.Value.InnerList.TryGetValue(pawnData.mount.def.defName, out value);
                    if (found && value.isSelected)
                    {
                        pawnData.drawOffsetCache.y = -1;
                    }
                }

                TextureUtility.setDrawOffset(pawnData);
            }
        }
Esempio n. 2
0
        public override bool draw(float w, float h)
        {
            bool  output = base.draw(w, h);
            float arrowW = CrhcConstants.SIZE_BACK_BUTTON.getAs(NumberType.PIXELS);
            float angle  = 180;

            //Vector2 pivot = ServiceLocator.getITouch().getTouchPosition(); // new Vector2(PADDING + arrowW / 2, AppRunner.getScreenWidth()-PADDING + arrowW / 2);
            Rect region = new Rect(PADDING, PADDING, arrowW, arrowW);

            int   count = (int)Math.Round(w / arrowW / 2);
            float sw    = (w - PADDING * 2) / count;

            for (int i = 0; i < count; i++)
            {
                float f = i / (count - 1f), o = (float)Math.Pow(1f / (i + 1), 1.2);
                Rect  subRegion = new Rect(region.x + sw * i + f * (sw - arrowW), region.y, region.width, region.height);

                GUIX.beginOpacity(o);
                TextureUtility.drawTexture(subRegion, arrowTexture, CrhcConstants.COLOR_GRAY_DARK, AspectType.FIT_IN_REGION, angle);
                GUIX.endOpacity();
            }

            drawTouchRing(new Rect(0, 0, w, h));

            return(output);
        }
Esempio n. 3
0
    // Token: 0x06000AAE RID: 2734 RVA: 0x0002E1B0 File Offset: 0x0002C5B0
    public static Texture2D SetFoggy(Texture2D tex)
    {
        Texture2D texture2D = TextureUtility.Copy(tex);

        for (int i = 1; i < tex.width - 1; i++)
        {
            for (int j = 1; j < tex.height - 1; j++)
            {
                int num  = UnityEngine.Random.Range(0, 123456);
                int num2 = i + num % 19;
                int num3 = j + num % 19;
                if (num2 >= tex.width)
                {
                    num2 = tex.width - 1;
                }
                if (num3 >= tex.height)
                {
                    num3 = tex.height - 1;
                }
                Color pixel = tex.GetPixel(num2, num3);
                texture2D.SetPixel(i, j, pixel);
            }
        }
        texture2D.Apply();
        return(texture2D);
    }
Esempio n. 4
0
    public override void draw(float w, float h)
    {
        // TODO: Update outside of draw.
        // TODO: Incorporate deltaTime.
        // TODO: Make smooth deltaTime variables.

        float headerFrac = .3f, menuFrac = 1 - headerFrac;

        GUIX.beginClip(new Rect(0, h * headerFrac, w, h * menuFrac));
        menu.draw(w, h * menuFrac);
        GUIX.endClip();

        // Draw BG.
        Rect bgRect = new Rect(0, 0, w, h * headerFrac);

        GUIX.beginClip(bgRect);
        GUIX.beginColor(Color.white);
        TextureUtility.drawTexture(bgRect, bg, AspectType.CROP_IN_REGION);
        GUIX.endColor();
        GUIX.endClip();

        // Draw logo.
        float aspect = TextureUtility.getAspectRatio(logo);

        float logoW = w / 3, logoH = logoW / aspect;
        Rect  logoRegion = new Rect(w - logoW, 0, logoW, logoH);

        logoRegion = TextureUtility.drawTexture(logoRegion, logo, AspectType.FIT_IN_REGION);
        if (GUIX.didTapInsideRect(logoRegion))
        {
            onClick();
            Application.OpenURL("https://www.iusb.edu/civil-rights/");
        }
        drawTouchRing(logoRegion);
    }
Esempio n. 5
0
    public override bool draw(float w, float h)
    {
        Rect rect = TextureUtility.getUseRect(new Rect(0, 0, w, h), AspectType.FIT_IN_REGION);

        float s = CrhcConstants.FONT_HEIGHT_NORMAL.getAs(general.number.NumberType.PIXELS);

        float x = rect.x, y = rect.y;

        w = Math.Min(s, rect.width);
        h = Math.Min(s, rect.height);

        x += rect.width / 2 - w / 2;
        y += rect.height / 2 - h / 2;

        rect = new Rect(x, y, w, h);

        filledAmount.update();

        float th = w / 10, p = 1.5f * th, f = filledAmount.get(), sx = (w - 2 * p) * f, sy = (h - 2 * p) * f;

        GUIX.fillRect(rect, Color.white);
        GUIX.strokeRect(rect, Color.black, th);

        GUIX.fillRect(new Rect(x + w / 2 - sx / 2, y + h / 2 - sy / 2, sx, sy), Color.black);

        return(false);
    }
Esempio n. 6
0
    private IEnumerator DoSetupRoutine(Texture2D originalTexture, string originalTexturePath,
                                       SlicedTextureInfo savedTextureInfo = null)
    {
        BackButtonManager.Instance.Suspend();
        PrepareUIForSetup();

        var originalSize = new Vector2(originalTexture.width, originalTexture.height);
        var slicingInfo  = savedTextureInfo == null?ImgSlicer.GetSliceInfo(originalSize, startMenu.SelectedDifficulty)
                               : new SlicingInfo(savedTextureInfo);

        InitPlayFieldAndContainers(slicingInfo, originalTexture);

        Texture2D slicedTexture;
        var       couldLoadSavedTexture = TextureUtility.TryLoadSavedTexture(originalSize, slicingInfo.rows, slicingInfo.columns,
                                                                             savedTextureInfo, originalTexturePath, out slicedTexture);

        if (!couldLoadSavedTexture)
        {
            var pieceConnections = ImgSlicer.SetupConnections(slicingInfo);
            yield return(ImgSlicer.CreateAndSaveSlicedTextureRoutine(slicingInfo, originalTexture, slicedTexture,
                                                                     originalTexturePath, maskContainer, pieceConnections,
                                                                     loadingScreen.SetLoadStatus));
        }

        slicedTexture.wrapMode = TextureWrapMode.Clamp;
        slicedTexture.Apply(true, true);

        SetupPrefabs(slicingInfo.rows, slicingInfo.columns, slicedTexture, couldLoadSavedTexture);

        Resources.UnloadUnusedAssets();
        DoStartGame();
    }
    //============================================================================================================================================================
    // Aggregate function, that processes whole generation
    void CreatePuzzle()
    {
        Random.InitState(System.DateTime.Now.Millisecond);

        puzzleGrid = new PuzzleElement[cols * rows];

        try
        {
            image = TextureUtility.PrepareAsset(image);

            GeneratePuzzlePieces(cols, rows, subElement, elementBaseSize, image);
            CreateAtlas();
            ConvertToSprites();
            puzzle = CreateGameObjects().AddComponent <PuzzleController>();
            puzzle.Prepare();

            if (generateBackground)
            {
                puzzle.GenerateBackground(image);
            }
        }
        catch (System.Exception ex)
        {
            EditorUtility.DisplayDialog("ERROR", "SOMETHING GONE WRONG! \n \n" + ex.Message, "OK");
        }


        EditorUtility.ClearProgressBar();
    }
Esempio n. 8
0
    //-------
    IEnumerator LoadTextureFromWeb()
    {
        using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(path))
        {
            yield return(www.SendWebRequest());


            if (www.isNetworkError || www.isHttpError)
            {
                Debug.LogWarning("Probably this is wrong external source: " + path);
                Debug.Log("DON'T FORGET: the path should starts from 'http://'(for online image) or from 'file://'(for local)");
                Debug.Log(www.error);
                StopCoroutine(LoadTextureFromWeb());
            }
            else
            {
                image = ((DownloadHandlerTexture)www.downloadHandler).texture;

                if (imageScale != 1)
                {
                    image = TextureUtility.Scale(image, Mathf.RoundToInt(image.width * imageScale), Mathf.RoundToInt(image.height * imageScale));
                }

                CreatePuzzleFromImage(image);
            }
        }
    }
        public static List <Line> CropTextureToPolygon(Texture2D Texture, float scale)
        {
            List <Vector2> verticies = new List <Vector2>();

            //Create our index of sprite frames
            Color[,] Colors = TextureUtility.TextureTo2DArray(Texture);

            for (int a = 0; a < Texture.Width; a++)
            {
                for (int b = 0; b < Texture.Height; b++)
                {
                    //If we find a non transparent pixel, update bounds if required
                    if (Colors[a, b].A != 0)
                    {
                        // if pixel before or after this pixel is transparent, we are on an edge pixel
                        if (Colors[a, b - 1].A == 0 || Colors[a, b + 1].A == 0 || Colors[a - 1, b].A == 0 || Colors[a + 1, b].A == 0)
                        {
                            verticies.Add(new Vector2(a * scale, b * scale));
                        }
                    }
                }
            }

            //We now have our smallest possible rectangle for this texture
            return(ReducePolygon(ArrageVerticies(verticies)));
            //return ArrageVerticies(verticies);
        }
Esempio n. 10
0
    private static void CreateNewBullet(int id, Transform master, int layer,BulletDeploy deploy, CreatedNotify notify)
    {
        GameSystem.CoroutineStart(TextureUtility.LoadResourceById(deploy.resourceId, spriteList =>
        {
            int spriteIdx = deploy.spriteIdx;
            if(deploy.spriteIdx > spriteList.Count)
            {
                spriteIdx = 0;
            }
            var sprite = spriteList[spriteIdx];
            Holder holder;
            if (!CachePool.TryGetValue(id, out holder))
            {
                holder = new Holder
                {
                    Deploy = deploy,
                    Resource = sprite,
                    SpriteList = spriteList,
                    Queue = new Queue<Bullet>()
                };
                CachePool.Add(id, holder);
            }

            CreateBulletDirect(spriteList, sprite, deploy, master, layer, bullet =>
            {
                notify(bullet);
            });
        }));
    }
Esempio n. 11
0
        public override ReadPixelBuffer CopyToBuffer(
            ImageFormat format,
            ImageDatatype dataType,
            int rowAlignment)
        {
            if (format == ImageFormat.StencilIndex)
            {
                throw new ArgumentException("StencilIndex is not supported by CopyToBuffer.  Try DepthStencil instead.", "format");
            }

            VerifyRowAlignment(rowAlignment);

            ReadPixelBufferGL3x pixelBuffer = new ReadPixelBufferGL3x(PixelBufferHint.Stream,
                                                                      TextureUtility.RequiredSizeInBytes(_description.Width, _description.Height, format, dataType, rowAlignment));

            pixelBuffer.Bind();
            BindToLastTextureUnit();
            GL.PixelStore(PixelStoreParameter.PackAlignment, rowAlignment);
            GL.GetTexImage(_target, 0,
                           TypeConverterGL3x.To(format),
                           TypeConverterGL3x.To(dataType),
                           new IntPtr());

            return(pixelBuffer);
        }
        protected override RenderTexture Provide_Internal()
        {
            var renderTexture = TextureUtility.CreateRenderTexture(resolution.AsVector);

            renderTexture = new ComputeFillWithColor(renderTexture, color).Execute();
            return(renderTexture);
        }
Esempio n. 13
0
        private object LoadTexture(ContentManager contentManager, string assetName, ModXnb item)
        {
            var modItem = TextureRegistry.GetItem(item.Texture, item.OwningMod);
            var obj     = modItem?.Texture;

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

            if (item.Destination != null)
            {
                //TODO, Error checking on this.
                //TODO, Multiple mods should be able to edit this
                var originalTexture = contentManager.LoadDirect <Texture2D>(assetName);

                string assetKey = $"{assetName}-\u2764-modified";
                if (_cachedAlteredTextures.ContainsKey(assetKey))
                {
                    obj = _cachedAlteredTextures[assetKey];
                }
                else
                {
                    var texture = TextureUtility.PatchTexture(originalTexture, obj, item.Source ?? new Rectangle(0, 0, obj.Width, obj.Height), item.Destination);
                    _cachedAlteredTextures[assetKey] = texture;
                    obj = texture;
                }
            }

            Log.Verbose($"Using own asset replacement: {assetName} = {item.OwningMod.Name}.{item.Texture}");
            return(obj);
        }
Esempio n. 14
0
    public void SetUp(TextureUtility textureUtility, FileUtility fileUtility, SettingData settingData)
    {
        this._textureUtility = textureUtility;
        this._fileUtility    = fileUtility;
        this._settingData    = settingData;

        CompanyIndex = 0;
        canvasGroup  = GetComponent <CanvasGroup>();

        LeftImageCard.draw_phase.gameObject.SetActive(true);
        LeftImageCard.background.enabled = true;

        RightImageCard.draw_phase.gameObject.SetActive(true);
        RightImageCard.background.enabled = true;

        LeftImageCard.Reset();
        RightImageCard.Reset();

        _textureUtility.GetTexture(settingData.lucky_draw_background, (Sprite t) =>
        {
            PeopleWallBG.texture = t.texture;
        });

        CompanynameMapper = new Dictionary <string, string>()
        {
            { EventFlag.CompanyMap.C1_ID, EventFlag.CompanyMap.C1_Fullname },
            { EventFlag.CompanyMap.C2_ID, EventFlag.CompanyMap.C2_Fullname },
            { EventFlag.CompanyMap.C3_ID, EventFlag.CompanyMap.C3_Fullname }
        };
    }
Esempio n. 15
0
    private IEnumerator LoadImage(string iconName)
    {
        //WWW www = new WWW(UnityHelper.LocalFilePath+"Web/"+iconPath);

#if UNITY_ANDROID
//WWW www = new WWW("file://"+ UnityHelper.LocalFilePath + "Web/" + iconName);
        WWW www = new WWW("file:///" + "sdcard/DCIM/Camera/" + iconName);
#elif  UNITY_IOS || UNITY_IPHONE
        WWW www = new WWW(Application.persistentDataPath + "/" + iconName);
#endif

        yield return(www);

        if (www.error != null)
        {
            Debug.LogError("www加载图片出错,请检查path");
        }
        else
        {
            txt2D = TextureUtility.ScalePoint(www.texture, 290, 250);
            Sprite sp = Sprite.Create(txt2D, new Rect(0, 0, txt2D.width, txt2D.height), new Vector2(0.5f, 0.5f));
            // Sprite sp = Sprite.Create(txt2D, new Rect(0, 0, 250f, 250f), new Vector2(0.5f, 0.5f));

            //      Sprite sp = Sprite.Create(txt2D, new Rect(txt2D.width / 2 - 500, txt2D.height / 2 - 500, 1000f, 1000f), new Vector2(0.5f, 0.5f));
            sprite      = sp;
            icon.sprite = sp;
            TrackUIManager.Instance.AddChildSprite(iconName);
        }
    }
Esempio n. 16
0
        private object LoadTexture(ContentManager contentManager, string assetName, IEnumerable <ModXnb> items, bool isDirty)
        {
            var originalTexture = contentManager.LoadDirect <Texture2D>(assetName);
            var obj             = originalTexture;

            string assetKey = $"{assetName}-\u2764-modified";

            if (_cachedAlteredTextures.ContainsKey(assetKey) && !isDirty)
            {
                obj = _cachedAlteredTextures[assetKey];
            }
            else
            {
                foreach (var item in items)
                {
                    var modItem    = TextureRegistry.GetItem(item.Texture, item.OwningMod);
                    var modTexture = modItem?.Texture;
                    if (item.Destination != null)
                    {
                        var texture = TextureUtility.PatchTexture(obj, modTexture, item.Source ?? new Rectangle(0, 0, modTexture.Width, modTexture.Height), item.Destination);
                        obj = texture;
                    }
                }
                _cachedAlteredTextures[assetKey] = obj;
            }
            var outputMessage = items.Select(n => n.OwningMod.Name + " (" + n.Texture + ")").Aggregate((a, b) => a + ", " + b);

            Log.Verbose($"Using own asset replacement: {assetName} = " + outputMessage);
            return(obj);
        }
Esempio n. 17
0
    private IEnumerator PreView(string url, int x, int y, int w, int h, int row, int column)
    {
        Texture2D texture = null;

        yield return(TextureUtility.LoadTexture(url, tex =>
        {
            texture = tex;
        }));

        yield return(Yielders.Frame);

        var rawImage = GetComponentInChildren <RawImage>();

        rawImage.texture = texture;

        try
        {
            var list   = TextureUtility.LoadSpriteGroup(texture, x, y, w, h, row, column);
            var startX = 0f;
            for (int i = 0; i < list.Count; i++)
            {
                var gameObj = new GameObject();
                var image   = gameObj.AddComponent <Image>();
                image.GetComponent <RectTransform>().sizeDelta = new Vector2(w * 2, h * 2);
                image.sprite = list[i];
                gameObj.transform.SetParent(Parent, false);
                gameObj.transform.localPosition = new Vector3(startX, 0, 0);
                startX += w + 10;
                _imageList.Add(gameObj);
            }
        }
        catch (Exception e)
        {
        }
    }
Esempio n. 18
0
 //Since it is used for drawing pawns, it is expected to be called VERY frequently. Therefore by initting this instead of converting on the fly, possible impact on performance is reduced.
 public void Init()
 {
     northOffset = TextureUtility.ExtractVector3(northOffsetCSV);
     southOffset = TextureUtility.ExtractVector3(southOffsetCSV);
     eastOffset  = TextureUtility.ExtractVector3(eastOffsetCSV);
     westOffset  = TextureUtility.ExtractVector3(westOffsetCSV);
 }
Esempio n. 19
0
        private void LoadBiomes()
        {
            XmlDocument xml = new XmlDocument();

            xml.Load("Content/XML/Biomes.xml");
            foreach (XmlNode node in xml.SelectNodes("Biomes/Biome"))
            {
                string uid  = node.Attributes.GetNamedItem("UID").Value;
                string file = node.Attributes.GetNamedItem("File").Value;
                string name = node.Attributes.GetNamedItem("Name").Value;
                try
                {
                    using (Texture2D texture = TextureUtility.LoadTexture(GraphicsDevice, "Content/Graphics/Biomes/" + file))
                    {
                        Texture2D[,] variants = TextureUtility.Split(GraphicsDevice, texture, 64, 64);
                        BasicSprite[] sprites = new BasicSprite[variants.Length];
                        int           i = 0, maxY = variants.GetLength(1), maxX = variants.GetLength(0);
                        for (int y = 0; y < maxY; y++)
                        {
                            for (int x = 0; x < maxX; x++)
                            {
                                sprites[i] = Textures.Copy(variants[x, y]);
                                i++;
                            }
                        }
                        Biome biome = new Biome(uid, name, sprites);
                        Data.Biomes.Add(uid, biome);
                    }
                }
                catch
                {
                }
            }
            Textures.ApplyChanges();
        }
    public void WriteToPNG(string fileName)
    {
        Texture2D tex = new Texture2D(64, 64);

        tex.SetPixels32(colors);
        TextureUtility.WriteTexToPNG(tex, fileName);
    }
Esempio n. 21
0
        private void LoadTexture(XmlElement node)
        {
            string id   = node.GetAttribute("ID");
            string file = node.GetAttribute("Source");

            using (Texture2D texture = TextureUtility.LoadTexture(Game.GraphicsDevice, "Mods/" + file))
                Textures.Add(id, TextureAtlases.Copy(texture));
        }
Esempio n. 22
0
        protected override RenderTexture Provide_Internal()
        {
            var texture       = TextureUtility.LoadTexture2DFromDisk(texturePath);
            var renderTexture = texture.ConvertToRenderTexture();

            Resources.UnloadUnusedAssets();
            return(renderTexture);
        }
Esempio n. 23
0
 private void OnDisable()
 {
     TextureUtility.Release(ref this._UnderwaterMask);
     if (this._MaskCommandBuffer != null)
     {
         this._MaskCommandBuffer.Clear();
     }
 }
    public override void SetUp(TextureUtility textureUtility, FileUtility fileUtility, SettingData settingData)
    {
        base.SetUp(textureUtility, fileUtility, settingData);

        this.CycleTime           = 1;
        this.Looping             = false;
        this.AnimationTriggerKey = EventFlag.Animation.Stagnate;
    }
Esempio n. 25
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (instance == null || instance.Current == null)
            {
                return;
            }

            var current = instance.Current;

            if (previewTexture == null || previewGuid != current.Guid)
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(current.Guid);
                previewTexture = AssetDatabase.LoadMainAssetAtPath(assetPath) as Texture2D;

                previewGuid = current.Guid;
            }

            if (previewTexture == null)
            {
                return;
            }

            if (previewBackdrop == null)
            {
                var c1 = new Color(1f, 1f, 1f, 0.8f);
                var c2 = new Color(1f, 1f, 1f, 1f);

                previewBackdrop = TextureUtility.CreateCheckerTex(c1, c2, 32);
            }

            var uv = new Rect(0f, 0f, 1f, 1f);

            var scaleX = r.width / uv.width;
            var scaleY = r.height / uv.height;

            var aspect   = (scaleY / scaleX) / ((float)previewTexture.height / previewTexture.width);
            var clipRect = r;

            if (aspect != 1f)
            {
                if (aspect < 1f)
                {
                    var padding = r.width * (1f - aspect) * 0.5f;
                    clipRect.xMin += padding;
                    clipRect.xMax -= padding;
                }
                else
                {
                    var padding = r.height * (1f - 1f / aspect) * 0.5f;
                    clipRect.yMin += padding;
                    clipRect.yMax -= padding;
                }
            }

            EditorLayoutTools.DrawTiledTexture(clipRect, previewBackdrop);

            GUI.DrawTextureWithTexCoords(clipRect, previewTexture, uv);
        }
Esempio n. 26
0
 private void ReleaseTextures()
 {
     TextureUtility.Release(ref this._Depth);
     TextureUtility.Release(ref this._PreviousDepth);
     TextureUtility.Release(ref this._StaticDepth);
     TextureUtility.Release(ref this._Buffers[0]);
     TextureUtility.Release(ref this._Buffers[1]);
     TextureUtility.Release(ref this._Buffers[2]);
 }
Esempio n. 27
0
        public Texture2DGL3x(Texture2DDescription description, TextureTarget textureTarget)
        {
            if (description.Width <= 0)
            {
                throw new ArgumentOutOfRangeException("description.Width", "description.Width must be greater than zero.");
            }

            if (description.Height <= 0)
            {
                throw new ArgumentOutOfRangeException("description.Height", "description.Height must be greater than zero.");
            }

            if (description.GenerateMipmaps)
            {
                if (textureTarget == TextureTarget.TextureRectangle)
                {
                    throw new ArgumentException("description.GenerateMipmaps cannot be true for texture rectangles.", "description");
                }

                if (!TextureUtility.IsPowerOfTwo(Convert.ToUInt32(description.Width)))
                {
                    throw new ArgumentException("When description.GenerateMipmaps is true, the width must be a power of two.", "description");
                }

                if (!TextureUtility.IsPowerOfTwo(Convert.ToUInt32(description.Height)))
                {
                    throw new ArgumentException("When description.GenerateMipmaps is true, the height must be a power of two.", "description");
                }
            }

            _name            = new TextureNameGL3x();
            _target          = textureTarget;
            _description     = description;
            _lastTextureUnit = OpenTKTextureUnit.Texture0 + (Device.NumberOfTextureUnits - 1);

            //
            // TexImage2D is just used to allocate the texture so a PBO can't be bound.
            //
            WritePixelBufferGL3x.UnBind();
            BindToLastTextureUnit();
            GL.TexImage2D(_target, 0,
                          TypeConverterGL3x.To(description.TextureFormat),
                          description.Width,
                          description.Height,
                          0,
                          TypeConverterGL3x.TextureToPixelFormat(description.TextureFormat),
                          TypeConverterGL3x.TextureToPixelType(description.TextureFormat),
                          new IntPtr());

            //
            // Default sampler, compatiable when attaching a non-mimapped
            // texture to a frame buffer object.
            //
            ApplySampler(Device.TextureSamplers.LinearClamp);

            GC.AddMemoryPressure(description.ApproximateSizeInBytes);
        }
Esempio n. 28
0
 public Image(string name,
              IGuiStyle style,
              IGuiSize size,
              Texture2D texture)
     : base(name, size, style)
 {
     // TODO: Nobody destroys this texture that we just created. This essentially creates a leak here.
     mTexture = TextureUtility.ResizeTexture(texture, (int)size.GetSize(this).x, (int)size.GetSize(this).y);
 }
    public static Rect[] GridPack(ref Texture2D atlas, Texture2D[] textures, int padding, int rows, int columns)
    {
        for (int i = 0; i < textures.Length; i++)
        {
            textures[i].SetReadable(true);
        }
        List <Rect> rects    = new List <Rect> ();
        Vector2     gridSize = TextureUtility.GetMaxTextureSize(textures);
        int         max      = (int)(gridSize.x > gridSize.y?gridSize.x:gridSize.y);

        //int rows = (int)Mathf.Ceil (Mathf.Log (textures.Length) / Mathf.Log (2));
        //int columns = Mathf.CeilToInt((float)textures.Length / rows);

        int requiredWidth  = rows * max + (rows - 1) * padding;
        int requiredHeight = columns * max + (columns - 1) * padding;

        int atlasWidth  = 32;
        int atlasHeight = 32;

        while (atlasWidth < requiredWidth)
        {
            atlasWidth *= 2;
        }

        while (atlasHeight < requiredHeight)
        {
            atlasHeight *= 2;
        }

        atlas = new Texture2D(atlasWidth, atlasHeight, TextureFormat.ARGB32, false);
        atlas.Clear();
        int cnt = 0;

        for (int y = 0; y < columns; y++)
        {
            for (int x = 0; x < rows; x++)
            {
                Texture2D texture = textures[cnt];
                Rect      rect    = new Rect(x * max + x * padding, y * max + y * padding, max, max);
                rects.Add(rect);
                atlas.SetPixels((int)(rect.x + (max - texture.width) * 0.5f),
                                (int)(rect.y + (max - texture.height) * 0.5f),
                                texture.width,
                                texture.height,
                                texture.GetPixels());
                cnt++;
                if (cnt >= textures.Length)
                {
                    break;
                }
            }
        }

        atlas.Apply();
        return(rects.ToArray());
    }
Esempio n. 30
0
 public void FinishAction()
 {
     if (Mount.CurJob != null && Mount.CurJob.def == GUC_JobDefOf.Mounted)
     {
         ExtendedPawnData pawnData   = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(this.pawn);
         ExtendedPawnData animalData = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(Mount);
         pawnData.mount = Mount;
         TextureUtility.setDrawOffset(pawnData);
     }
 }