void CreateCanvas(CanvasInfo ci) { ci.mCanvas = new GameObject(CanvasName, typeof(RectTransform)); ci.mCanvas.layer = gameObject.layer; ci.mCanvas.hideFlags = HideFlags.HideAndDontSave; ci.mCanvas.transform.SetParent(ci.mCanvasParent.transform); #if UNITY_EDITOR // Workaround for Unity bug case Case 1004117 CanvasesAndTheirOwners.AddCanvas(ci.mCanvas, this); #endif var c = ci.mCanvasComponent = ci.mCanvas.AddComponent <Canvas>(); c.renderMode = (RenderMode)m_RenderMode; c.sortingOrder = m_SortingOrder; c.planeDistance = m_PlaneDistance; c.worldCamera = ci.mCanvasParent.OutputCamera; var go = new GameObject("Viewport", typeof(RectTransform)); go.transform.SetParent(ci.mCanvas.transform); ci.mViewport = (RectTransform)go.transform; go.AddComponent <UnityEngine.UI.RectMask2D>(); go = new GameObject("RawImage", typeof(RectTransform)); go.transform.SetParent(ci.mViewport.transform); ci.mRawImage = go.AddComponent <UnityEngine.UI.RawImage>(); }
void DestroyCanvas() { int numBrains = CinemachineCore.Instance.BrainCount; for (int i = 0; i < numBrains; ++i) { LocateMyCanvas(CinemachineCore.Instance.GetActiveBrain(i), false); if (mCanvas != null) { RuntimeUtility.DestroyObject(mCanvas); #if UNITY_EDITOR // Workaround for Unity bug case Case 1004117 CanvasesAndTheirOwners.RemoveCanvas(mCanvas); #endif } mCanvas = null; } }
void CreateCanvas(CanvasInfo ci) { ci.mCanvas = new GameObject(CanvasName, typeof(RectTransform)); ci.mCanvas.layer = gameObject.layer; ci.mCanvas.hideFlags = HideFlags.HideAndDontSave; ci.mCanvas.transform.SetParent(ci.mCanvasParent.transform); #if UNITY_EDITOR // Workaround for Unity bug case Case 1004117 CanvasesAndTheirOwners.AddCanvas(ci.mCanvas, this); #endif var c = ci.mCanvas.AddComponent <Canvas>(); c.renderMode = RenderMode.ScreenSpaceOverlay; var go = new GameObject("Viewport", typeof(RectTransform)); go.transform.SetParent(ci.mCanvas.transform); ci.mViewport = (RectTransform)go.transform; go.AddComponent <UnityEngine.UI.RectMask2D>(); go = new GameObject("RawImage", typeof(RectTransform)); go.transform.SetParent(ci.mViewport.transform); ci.mRawImage = go.AddComponent <UnityEngine.UI.RawImage>(); }
void DestroyCanvas() { int numBrains = CinemachineCore.Instance.BrainCount; for (int i = 0; i < numBrains; ++i) { var parent = CinemachineCore.Instance.GetActiveBrain(i); int numChildren = parent.transform.childCount; for (int j = 0; j < numChildren; ++j) { RectTransform child = parent.transform.GetChild(j) as RectTransform; if (child != null && child.name == CanvasName) { var canvas = child.gameObject; RuntimeUtility.DestroyObject(canvas); #if UNITY_EDITOR // Workaround for Unity bug case Case 1004117 CanvasesAndTheirOwners.RemoveCanvas(canvas); #endif } } } mCanvasInfo.Clear(); }