public void Apply(UnityEngine.UI.CanvasScaler canvasScaler) { canvasScaler.scaleFactor = this.canvasScalerData.scaleFactor; canvasScaler.physicalUnit = this.canvasScalerData.physicalUnit; canvasScaler.referenceResolution = this.canvasScalerData.referenceResolution; canvasScaler.screenMatchMode = this.canvasScalerData.screenMatchMode; canvasScaler.uiScaleMode = this.canvasScalerData.uiScaleMode; canvasScaler.dynamicPixelsPerUnit = this.canvasScalerData.dynamicPixelsPerUnit; canvasScaler.matchWidthOrHeight = this.canvasScalerData.matchWidthOrHeight; canvasScaler.referencePixelsPerUnit = this.canvasScalerData.referencePixelsPerUnit; canvasScaler.defaultSpriteDPI = this.canvasScalerData.defaultSpriteDPI; canvasScaler.fallbackScreenDPI = this.canvasScalerData.fallbackScreenDPI; }
static StackObject *get_referenceResolution_4(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.UI.CanvasScaler instance_of_this_method = (UnityEngine.UI.CanvasScaler) typeof(UnityEngine.UI.CanvasScaler).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.referenceResolution; return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
public static Canvas InitEnviroment(RouleObject arg, Vector2 uiSize) { rouleObject = arg; var canvasPfb = rouleObject.prefabs.Find(x => x.groupType == GroupType.CANVAS).prefab; canvas = GameObject.Instantiate(canvasPfb).GetComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; UnityEngine.UI.CanvasScaler scaler = PSDImportUtility.canvas.GetComponent <UnityEngine.UI.CanvasScaler>(); scaler.referenceResolution = new Vector2(uiSize.x, uiSize.y); uinode = new UGUINode(PSDImportUtility.canvas.transform, null); return(canvas); }
public override void ValidateEditor() { base.ValidateEditor(); this.canvas = this.GetComponent <Canvas>(); this.canvasScaler = this.GetComponent <UnityEngine.UI.CanvasScaler>(); var prevElements = this.layoutElements; this.layoutElements = this.GetComponentsInChildren <WindowLayoutElement>(true); this.canvas.renderMode = WindowSystem.GetSettings().canvas.renderMode; this.ApplyTags(prevElements); }
static StackObject *get_dynamicPixelsPerUnit_18(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.UI.CanvasScaler instance_of_this_method = (UnityEngine.UI.CanvasScaler) typeof(UnityEngine.UI.CanvasScaler).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.dynamicPixelsPerUnit; __ret->ObjectType = ObjectTypes.Float; *(float *)&__ret->Value = result_of_this_method; return(__ret + 1); }
static StackObject *set_matchWidthOrHeight_3(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Single @value = *(float *)&ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); UnityEngine.UI.CanvasScaler instance_of_this_method = (UnityEngine.UI.CanvasScaler) typeof(UnityEngine.UI.CanvasScaler).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); instance_of_this_method.matchWidthOrHeight = value; return(__ret); }
private void InitCanvas() { EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);// EditorApplication.NewScene (); Canvas temp = AssetDatabase.LoadAssetAtPath(PSDImporterConst.ASSET_PATH_CANVAS, typeof(Canvas)) as Canvas; PSDImportUtility.canvas = GameObject.Instantiate(temp) as Canvas; PSDImportUtility.canvas.renderMode = RenderMode.ScreenSpaceOverlay; UnityEngine.UI.CanvasScaler scaler = PSDImportUtility.canvas.GetComponent <UnityEngine.UI.CanvasScaler>(); scaler.screenMatchMode = UnityEngine.UI.CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; scaler.matchWidthOrHeight = 1f; scaler.referenceResolution = new Vector2(psdUI.psdSize.width, psdUI.psdSize.height); GameObject go = AssetDatabase.LoadAssetAtPath(PSDImporterConst.ASSET_PATH_EVENTSYSTEM, typeof(GameObject)) as GameObject; PSDImportUtility.eventSys = GameObject.Instantiate(go) as GameObject; }
static StackObject *set_screenMatchMode_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.UI.CanvasScaler.ScreenMatchMode @value = (UnityEngine.UI.CanvasScaler.ScreenMatchMode) typeof(UnityEngine.UI.CanvasScaler.ScreenMatchMode).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); UnityEngine.UI.CanvasScaler instance_of_this_method = (UnityEngine.UI.CanvasScaler) typeof(UnityEngine.UI.CanvasScaler).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); instance_of_this_method.screenMatchMode = value; return(__ret); }
static StackObject *set_physicalUnit_13(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.UI.CanvasScaler.Unit @value = (UnityEngine.UI.CanvasScaler.Unit) typeof(UnityEngine.UI.CanvasScaler.Unit).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); UnityEngine.UI.CanvasScaler instance_of_this_method = (UnityEngine.UI.CanvasScaler) typeof(UnityEngine.UI.CanvasScaler).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); instance_of_this_method.physicalUnit = value; return(__ret); }
public override void ReadFrom(object obj) { base.ReadFrom(obj); if (obj == null) { return; } UnityEngine.UI.CanvasScaler o = (UnityEngine.UI.CanvasScaler)obj; uiScaleMode = (uint)o.uiScaleMode; referencePixelsPerUnit = o.referencePixelsPerUnit; scaleFactor = o.scaleFactor; referenceResolution = o.referenceResolution; screenMatchMode = (uint)o.screenMatchMode; matchWidthOrHeight = o.matchWidthOrHeight; physicalUnit = (uint)o.physicalUnit; fallbackScreenDPI = o.fallbackScreenDPI; defaultSpriteDPI = o.defaultSpriteDPI; dynamicPixelsPerUnit = o.dynamicPixelsPerUnit; }
/// <summary> /// Write the specified value using the writer. /// </summary> /// <param name="value">Value.</param> /// <param name="writer">Writer.</param> public override void Write(object value, ISaveGameWriter writer) { UnityEngine.UI.CanvasScaler canvasScaler = (UnityEngine.UI.CanvasScaler)value; writer.WriteProperty("uiScaleMode", canvasScaler.uiScaleMode); writer.WriteProperty("referencePixelsPerUnit", canvasScaler.referencePixelsPerUnit); writer.WriteProperty("scaleFactor", canvasScaler.scaleFactor); writer.WriteProperty("referenceResolution", canvasScaler.referenceResolution); writer.WriteProperty("screenMatchMode", canvasScaler.screenMatchMode); writer.WriteProperty("matchWidthOrHeight", canvasScaler.matchWidthOrHeight); writer.WriteProperty("physicalUnit", canvasScaler.physicalUnit); writer.WriteProperty("fallbackScreenDPI", canvasScaler.fallbackScreenDPI); writer.WriteProperty("defaultSpriteDPI", canvasScaler.defaultSpriteDPI); writer.WriteProperty("dynamicPixelsPerUnit", canvasScaler.dynamicPixelsPerUnit); writer.WriteProperty("useGUILayout", canvasScaler.useGUILayout); writer.WriteProperty("enabled", canvasScaler.enabled); writer.WriteProperty("tag", canvasScaler.tag); writer.WriteProperty("name", canvasScaler.name); writer.WriteProperty("hideFlags", canvasScaler.hideFlags); }
UnityEngine.UI.Image CreateToolsCanvas() { var actS = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); var actS2 = UnityEngine.SceneManagement.SceneManager.GetSceneByBuildIndex(0); if (actS2 != null) { UnityEngine.SceneManagement.SceneManager.SetActiveScene(actS2); } GameObject canvasGo = new GameObject(); canvasGo.name = "[Interface]"; Canvas canvas = canvasGo.AddComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; UnityEngine.UI.CanvasScaler canvasScaler = canvasGo.AddComponent <UnityEngine.UI.CanvasScaler>(); UnityEngine.UI.GraphicRaycaster canvasRaycaster = canvasGo.AddComponent <UnityEngine.UI.GraphicRaycaster>(); GameObject backgroundGo = new GameObject(); backgroundGo.name = "fx-background"; backgroundGo.transform.SetParent(canvasGo.transform); RectTransform rectTr = backgroundGo.AddComponent <RectTransform>(); rectTr.anchorMin = new Vector2(0, 0); rectTr.anchorMax = new Vector2(1, 1); rectTr.pivot = new Vector2(0.5f, 0.5f); rectTr.anchoredPosition = new Vector2(0, 0); rectTr.sizeDelta = Vector2.zero; rectTr.ForceUpdateRectTransforms(); CanvasRenderer canvasRenderer = backgroundGo.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image image = backgroundGo.AddComponent <UnityEngine.UI.Image>(); image.enabled = false; canvasGo.transform.SetAsLastSibling(); if (actS != null) { UnityEngine.SceneManagement.SceneManager.SetActiveScene(actS); } return(image); }
public override object WriteTo(object obj, System.Collections.Generic.Dictionary <long, UnityEngine.Object> objects) { obj = base.WriteTo(obj, objects); if (obj == null) { return(null); } UnityEngine.UI.CanvasScaler o = (UnityEngine.UI.CanvasScaler)obj; o.uiScaleMode = (UnityEngine.UI.CanvasScaler.ScaleMode)uiScaleMode; o.referencePixelsPerUnit = referencePixelsPerUnit; o.scaleFactor = scaleFactor; o.referenceResolution = referenceResolution; o.screenMatchMode = (UnityEngine.UI.CanvasScaler.ScreenMatchMode)screenMatchMode; o.matchWidthOrHeight = matchWidthOrHeight; o.physicalUnit = (UnityEngine.UI.CanvasScaler.Unit)physicalUnit; o.fallbackScreenDPI = fallbackScreenDPI; o.defaultSpriteDPI = defaultSpriteDPI; o.dynamicPixelsPerUnit = dynamicPixelsPerUnit; return(o); }
public static void SetCamFOVByScreen(Camera cam) { if (cam.orthographic) { float designedSize = 34f; UnityEngine.UI.CanvasScaler canvasScaler2dUI = DoozyUI.UIManager.GetUiContainer.GetComponent <UnityEngine.UI.CanvasScaler>(); float desginedAspect = canvasScaler2dUI.referenceResolution.x / canvasScaler2dUI.referenceResolution.y; float actualAspect = (float)cam.pixelWidth / cam.pixelHeight; cam.orthographicSize = (designedSize / actualAspect) * desginedAspect; } else { float designedVFOV = 60f; UnityEngine.UI.CanvasScaler canvasScaler2dUI = DoozyUI.UIManager.GetUiContainer.GetComponent <UnityEngine.UI.CanvasScaler>(); float desginedAspect = canvasScaler2dUI.referenceResolution.x / canvasScaler2dUI.referenceResolution.y; float actualAspect = (float)cam.pixelWidth / cam.pixelHeight; float newVFOVInRads = 2 * Mathf.Atan(desginedAspect / actualAspect * Mathf.Tan(designedVFOV * Mathf.Deg2Rad * 0.5f)); cam.fieldOfView = newVFOVInRads * Mathf.Rad2Deg; } }
private void CreateUIRoot() { mUIRoot = new GameObject("UIRoot"); GameObject.DontDestroyOnLoad(mUIRoot); mLowUIRoot = mUIRoot.CreateChild("LowUIRoot", typeof(Canvas), typeof(UnityEngine.UI.CanvasScaler), typeof(UnityEngine.UI.GraphicRaycaster)); Camera _cm0 = mLowUIRoot.CreateChild("Camera", typeof(Camera)).GetComponent <Camera>(); _cm0.orthographic = true; _cm0.clearFlags = CameraClearFlags.Depth; _cm0.nearClipPlane = -100; _cm0.farClipPlane = 100; _cm0.orthographicSize = 20; Canvas _ca0 = mLowUIRoot.GetComponent <Canvas>(); _ca0.renderMode = RenderMode.ScreenSpaceCamera; _ca0.worldCamera = _cm0; _ca0.sortingOrder = 0; UnityEngine.UI.CanvasScaler _cs0 = mLowUIRoot.GetComponent <UnityEngine.UI.CanvasScaler>(); _cs0.uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize; _cs0.referenceResolution = mViewSzie; //_cs0.screenMatchMode = UnityEngine.UI.CanvasScaler.ScreenMatchMode.Expand; _cs0.matchWidthOrHeight = mMatch; mNormalUIRoot = mUIRoot.CreateChild("NormalUIRoot", typeof(Canvas), typeof(UnityEngine.UI.CanvasScaler), typeof(UnityEngine.UI.GraphicRaycaster)); Camera _cm1 = mNormalUIRoot.CreateChild("Camera", typeof(Camera)).GetComponent <Camera>(); _cm1.orthographic = true; _cm1.clearFlags = CameraClearFlags.Depth; _cm1.nearClipPlane = -100; _cm1.farClipPlane = 100; _cm1.orthographicSize = 20; Canvas _ca1 = mNormalUIRoot.GetComponent <Canvas>(); _ca1.renderMode = RenderMode.ScreenSpaceCamera; _ca1.worldCamera = _cm1; _ca1.sortingOrder = 1; UnityEngine.UI.CanvasScaler _cs1 = mNormalUIRoot.GetComponent <UnityEngine.UI.CanvasScaler>(); _cs1.uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize; _cs1.referenceResolution = mViewSzie; // _cs1.screenMatchMode = UnityEngine.UI.CanvasScaler.ScreenMatchMode.Expand; _cs1.matchWidthOrHeight = mMatch; mHightUIRoot = mUIRoot.CreateChild("HightUIRoot", typeof(Canvas), typeof(UnityEngine.UI.CanvasScaler), typeof(UnityEngine.UI.GraphicRaycaster)); Camera _cm2 = mHightUIRoot.CreateChild("Camera", typeof(Camera)).GetComponent <Camera>(); _cm2.orthographic = true; _cm2.clearFlags = CameraClearFlags.Depth; _cm2.nearClipPlane = -100; _cm2.farClipPlane = 100; _cm2.orthographicSize = 20; Canvas _ca2 = mHightUIRoot.GetComponent <Canvas>(); _ca2.renderMode = RenderMode.ScreenSpaceCamera; _ca2.worldCamera = _cm2; _ca2.sortingOrder = 2; UnityEngine.UI.CanvasScaler _cs2 = mHightUIRoot.GetComponent <UnityEngine.UI.CanvasScaler>(); _cs2.uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize; _cs2.referenceResolution = mViewSzie; //_cs2.screenMatchMode = UnityEngine.UI.CanvasScaler.ScreenMatchMode.Expand; _cs2.matchWidthOrHeight = mMatch; GameObject EventSystem = mUIRoot.CreateChild("EventSystem", typeof(UnityEngine.EventSystems.EventSystem), typeof(UnityEngine.EventSystems.StandaloneInputModule)); }
/// <summary> /// Read the data using the reader. /// </summary> /// <param name="reader">Reader.</param> public override object Read(ISaveGameReader reader) { UnityEngine.UI.CanvasScaler canvasScaler = SaveGameType.CreateComponent <UnityEngine.UI.CanvasScaler> (); ReadInto(canvasScaler, reader); return(canvasScaler); }
/// <summary> /// Read the data into the specified value. /// </summary> /// <param name="value">Value.</param> /// <param name="reader">Reader.</param> public override void ReadInto(object value, ISaveGameReader reader) { UnityEngine.UI.CanvasScaler canvasScaler = (UnityEngine.UI.CanvasScaler)value; foreach (string property in reader.Properties) { switch (property) { case "uiScaleMode": canvasScaler.uiScaleMode = reader.ReadProperty <UnityEngine.UI.CanvasScaler.ScaleMode> (); break; case "referencePixelsPerUnit": canvasScaler.referencePixelsPerUnit = reader.ReadProperty <System.Single> (); break; case "scaleFactor": canvasScaler.scaleFactor = reader.ReadProperty <System.Single> (); break; case "referenceResolution": canvasScaler.referenceResolution = reader.ReadProperty <UnityEngine.Vector2> (); break; case "screenMatchMode": canvasScaler.screenMatchMode = reader.ReadProperty <UnityEngine.UI.CanvasScaler.ScreenMatchMode> (); break; case "matchWidthOrHeight": canvasScaler.matchWidthOrHeight = reader.ReadProperty <System.Single> (); break; case "physicalUnit": canvasScaler.physicalUnit = reader.ReadProperty <UnityEngine.UI.CanvasScaler.Unit> (); break; case "fallbackScreenDPI": canvasScaler.fallbackScreenDPI = reader.ReadProperty <System.Single> (); break; case "defaultSpriteDPI": canvasScaler.defaultSpriteDPI = reader.ReadProperty <System.Single> (); break; case "dynamicPixelsPerUnit": canvasScaler.dynamicPixelsPerUnit = reader.ReadProperty <System.Single> (); break; case "useGUILayout": canvasScaler.useGUILayout = reader.ReadProperty <System.Boolean> (); break; case "enabled": canvasScaler.enabled = reader.ReadProperty <System.Boolean> (); break; case "tag": canvasScaler.tag = reader.ReadProperty <System.String> (); break; case "name": canvasScaler.name = reader.ReadProperty <System.String> (); break; case "hideFlags": canvasScaler.hideFlags = reader.ReadProperty <UnityEngine.HideFlags> (); break; } } }
void Start() { m_started = true; m_canvasScaler = GetComponentInParent <UnityEngine.UI.CanvasScaler>(); Fit(); }
private static void SetUnsupportedFields(UnityEngine.Canvas canvas, UnityEngine.UI.CanvasScaler scaler) { canvas.renderMode = UnityEngine.RenderMode.ScreenSpaceCamera; canvas.pixelPerfect = false; scaler.referencePixelsPerUnit = 1; }