Created
July 22, 2012 19:06
-
-
Save flarb/3160727 to your computer and use it in GitHub Desktop.
Unity3d GPU Pre-loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
using System.Collections.Generic; | |
public class AssetGPULoader : MonoBehaviour { | |
public Camera activeCamera; | |
RenderTexture _rt; | |
void Awake() | |
{ | |
_rt = new RenderTexture(32, 32, 24); | |
_rt.Create(); | |
activeCamera.targetTexture = _rt; | |
} | |
// Use this for initialization | |
void Start () { | |
} | |
public void PreLoadObject(GameObject obj) | |
{ | |
SnapshotObject(obj); | |
} | |
void SnapshotObject(GameObject obj) | |
{ | |
//move camera into position | |
Vector3 pos = obj.transform.position; | |
pos += new Vector3(0f, .5f, 0f); | |
activeCamera.transform.position = pos; | |
activeCamera.transform.LookAt(obj.transform.position); | |
activeCamera.Render(); | |
RenderTexture.active = _rt; | |
activeCamera.targetTexture = null; | |
RenderTexture.active = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment