bool RecycleObject(string resName, GameObject go) { if (_instancePool.ContainsKey(resName) == false) { UDebug.LogWarning("res:" + resName + " doesn't have a Object Pool"); return(false); } Queue <GameObject> pool = _instancePool[resName]; go.transform.SetParent(null); go.SetActive(false); pool.Enqueue(go); return(true); }
public bool UnloadResource(Object obj, bool forceUnload = false) { if (obj == null) { return(false); } int id = obj.GetInstanceID(); if (_resNameOfObject.ContainsKey(id)) { return(UnloadResource(_resNameOfObject[id], obj, forceUnload)); } else { if (obj is GameObject) { GameObject.Destroy(obj); } UDebug.LogWarning("Object:" + obj + " is not in the Dic"); return(false); } }
public void DrawGraphics(Control control, Point delta, PaintEventArgs e) { if (TextureID.HasValue) { GL.DeleteTexture(TextureID.Value); } TextureID = GL.GenTexture(); if (controlImage == null || controlImage.Size != FormToShow.Size) { controlImage = new Bitmap(FormToShow.Width, FormToShow.Height); using (Graphics tempG = Graphics.FromImage(controlImage)) { tempG.FillRectangle(new SolidBrush(FormToShow.BackColor), new Rectangle(0, 0, FormToShow.Width, FormToShow.Height)); } } //FormToShow.DrawToBitmap(controlImage, new Rectangle(0, 0, FormToShow.Width, FormToShow.Height)); using (Bitmap temp = new Bitmap(control.Width, control.Height)) { try { control.DrawToBitmap(temp, new Rectangle(0, 0, control.Width, control.Height)); } catch (ArgumentException ex) { UDebug.LogWarning(String.Format("Exception drawing {0} control...", control.Name)); } using (Graphics g = Graphics.FromImage(controlImage)) g.DrawImage(temp, delta); using (Bitmap tempRotation = new Bitmap(controlImage)) { tempRotation.RotateFlip(RotateFlipType.RotateNoneFlipY); System.Drawing.Imaging.BitmapData TextureData = tempRotation.LockBits( new Rectangle(0, 0, tempRotation.Width, tempRotation.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); GL.BindTexture(TextureTarget.Texture2D, TextureID.Value); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, tempRotation.Width, tempRotation.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, TextureData.Scan0); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); tempRotation.UnlockBits(TextureData); FormTexture = new Texture_t(); FormTexture.eType = ETextureType.OpenGL; FormTexture.eColorSpace = EColorSpace.Auto; FormTexture.handle = (IntPtr)TextureID.Value; if (Controller != null) { OpenVR.Overlay.SetOverlayTexture(this.Handle, ref FormTexture); } } System.GC.Collect(); //Not really optimized } }