public void InstantiateRCFishInAquarium() { RenderTextureCamera renderTextureCamera = fishPrefab.transform.parent.GetComponent <ColoringTrackingHandler>().RC.GetComponent <RenderTextureCamera>(); GameObject fish = (GameObject)Instantiate(fishPrefab, fishPrefab.transform.position, fishPrefab.transform.rotation); fish.transform.parent = aquariumBehavior.fishHolder.transform; fish.transform.localPosition = new Vector3(Random.Range(-0.3f, 0.3f), Random.Range(0.08f, 0.3f), Random.Range(-0.18f, 0.15f)); while (Vector3.Distance(fish.transform.localPosition, aquariumBehavior.forbiddenArea.transform.localPosition) < 0.2f) { fish.transform.localPosition = new Vector3(Random.Range(-0.3f, 0.3f), Random.Range(0.08f, 0.3f), Random.Range(-0.18f, 0.15f)); } fish.transform.localScale = new Vector3(1f, 1f, 1f); fish.transform.Rotate(fish.transform.up * Random.Range(20f, 200f)); //Texture2D tex2D = new Texture2D(renderTextureCamera.GetRenderTexture().width, renderTextureCamera.GetRenderTexture().height); //tex2D.ReadPixels(RenderTextureCamera.ARCamera_Camera.rect, 0, 0); //tex2D.Apply(); fish.GetComponentInChildren <GetTexture>().enabled = false; Texture2D FrameTexture = new Texture2D(renderTextureCamera.GetRenderTexture().width, renderTextureCamera.GetRenderTexture().height, TextureFormat.RGB24, false); RenderTexture.active = renderTextureCamera.GetRenderTexture(); FrameTexture.ReadPixels(new Rect(0, 0, renderTextureCamera.GetRenderTexture().width, renderTextureCamera.GetRenderTexture().height), 0, 0); RenderTexture.active = null; FrameTexture.Apply(); Material newMat = Resources.Load("FishMat", typeof(Material)) as Material; newMat.EnableKeyword("_MainTex"); newMat.SetTexture("_MainTex", FrameTexture); fish.GetComponentInChildren <SkinnedMeshRenderer>().material = newMat; //GetComponentInChildren<SkinnedMeshRenderer>().material.SetTexture("_MainTex", FrameTexture); FishMovement fishMovement = fish.AddComponent <FishMovement>(); fishMovement.aquariumBehavior = aquariumBehavior; fishMovement.SetPassPoints(passPoints); //fishMovement.movementType = (FishMovement.MovementType)Random.Range(0, 2); }
IEnumerator TakeScreen() { yield return(new WaitForEndOfFrame()); _rt = RenderCamera.GetRenderTexture(); screenShot = new Texture2D(_rt.width, _rt.height, TextureFormat.RGBA32, false); RenderTexture.active = _rt; screenShot.ReadPixels(new Rect(0, 0, _rt.width, _rt.height), 0, 0); RenderTexture.active = null; screenShot.Apply(); }
public void OnClickScan() { RenderTexture RendTex = rtc.GetRenderTexture(); FrameTexture = new Texture2D(RendTex.width, RendTex.height, TextureFormat.RGB24, false); RenderTexture.active = RendTex; FrameTexture.ReadPixels(new Rect(0, 0, RendTex.width, RendTex.height), 0, 0); RenderTexture.active = null; FrameTexture.Apply(); }
IEnumerator TakeScreen() { yield return(new WaitForEndOfFrame()); if (RenderCamera == null) { yield return(0); } _rt = RenderCamera.GetRenderTexture(); // Debug.Log(_rt.width+"||"+_rt.height); if (screenShot == null || screenShot.width != _rt.width) { screenShot = new Texture2D(_rt.width, _rt.height, TextureFormat.BGRA32, false); } RenderTexture.active = _rt; screenShot.ReadPixels(new Rect(0, 0, _rt.width, _rt.height), 0, 0); RenderTexture.active = null; screenShot.Apply(); rawImage.texture = screenShot; }