/// <summary> /// 创建一个ViewController /// </summary> /// <param name="param"></param> /// <returns></returns> public static PeViewController CreateViewController(ViewControllerParam param) { GameObject resGo = Resources.Load("Prefab/ViewController") as GameObject; if (resGo == null) { throw new Exception("Load view camera cursor prefab failed"); } PeViewController resController = resGo.GetComponent <PeViewController>(); if (resController == null) { throw new Exception("Load iso cursor prefab failed"); } PeViewController controller = PeViewController.Instantiate(resController); controller.transform.SetParent(Instance.transform); controller.transform.localPosition = Vector3.zero; controller.transform.localScale = Vector3.one; controller.transform.localRotation = Quaternion.identity; controller.SetParam(param); controller.ID = Instance.m_IDInitial; Instance.m_IDInitial++; return(controller); }
static Texture2D DoTakePhoto(GameObject cloneGo, int width, int height, Vector3 local_pos, Quaternion local_rot) { ViewControllerParam param = ViewControllerParam.DefaultPortrait; param.texWidth = width; param.texHeight = height; cloneGo.transform.localPosition = new Vector3(-500, 0, 0); Self._photoController.Set(cloneGo.transform, param); Self._photoController.SetLocalTrans(local_pos, local_rot); //Profiler.BeginSample ("Enable PhotoCtrl"); Self._photoController.gameObject.SetActive(true); //Profiler.EndSample (); Texture2D tex = Self._photoController.TakePhoto(); //Profiler.BeginSample ("Disable PhotoCtrl"); Self._photoController.gameObject.SetActive(false); //Profiler.EndSample (); cloneGo.SetActive(false); //Destroy(cloneGo); return(tex); }
public virtual void SetParam(ViewControllerParam param) { if (m_RenderTex == null) { m_RenderTex = new RenderTexture(param.texWidth, param.texHeight, 16, RenderTextureFormat.ARGB32); m_RenderTex.isCubemap = false; } else if (m_RenderTex.width != param.texWidth || m_RenderTex.height == param.texHeight) { m_RenderTex.Release(); RenderTexture.Destroy(m_RenderTex); m_RenderTex = new RenderTexture(param.texWidth, param.texHeight, 16, RenderTextureFormat.ARGB32); m_RenderTex.isCubemap = false; } _viewCam.targetTexture = m_RenderTex; _viewCam.nearClipPlane = param.camNearClip; _viewCam.farClipPlane = param.camFarClip; _viewCam.aspect = param.camAspect; _viewCam.fieldOfView = param.camFieldOfView; _viewCam.orthographic = param.orthographic; _viewCam.orthographicSize = param.orthographicSize; }
public void Set(Transform target, ViewControllerParam param) { SetTarget(target); SetParam(param); }