private void init() { this._headsetAdapter.onNewItemReceived += addNewDevice; this._headsetAdapter.onClearItems += clearDeviceAll; tempColor = fadeImage.color; canvasRect = rootCanvasScaler.GetComponent <RectTransform>(); if (canvasRect.rect.height < rootCanvasScaler.referenceResolution.y) { float ratio = canvasRect.rect.height / rootCanvasScaler.referenceResolution.y; float yPos = title.rectTransform.anchoredPosition.y * ratio; yPos = Mathf.Clamp(yPos, connectText.rectTransform.anchoredPosition.y + connectText.rectTransform.rect.height + title.rectTransform.rect.height, title.rectTransform.anchoredPosition.y); title.rectTransform.anchoredPosition = new Vector2(title.rectTransform.anchoredPosition.x, yPos); } }
// TODO set BackgroundImage.overrideSprite to sprite after Unity update https://issuetracker.unity3d.com/issues/image-color-cannot-be-changed-via-script-when-image-type-is-set-to-simple private void Start() { if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux) { SettingsPanel.SetActive(false); SettingsButton.SetActive(false); } else { SetDropdowns(); } origStartButtonText = StartButtonText.text; bgCanvasRT = BGCanvasScaler.GetComponent <RectTransform>(); fading = true; currentBGImageIndex = -1; StopAllCoroutines(); // TODO get bgSprites from DB if (BGSprites.Count > 0) { StartCoroutine(BGFadeSwitch()); } StartButton.onClick.AddListener(OnStartButtonClick); SetLoaderUIState(LoaderUIStateType.START); }
private void Awake() { rectTransform = GetComponent <RectTransform>(); canvasScaler = GetComponentInParent <CanvasScaler>(); canvas = canvasScaler.GetComponent <Canvas>(); if (IsDebugMode) { Debug.LogFormat("Screen width: {0}, height:{1}, resolution: {2}", Screen.width, Screen.height, Screen.currentResolution); var mainCamera = Camera.main; if (mainCamera != null) { Debug.LogFormat("Camera viewport: width {0}, height {1}", mainCamera.pixelWidth, mainCamera.pixelHeight); } } #if UNITY_EDITOR // 编辑器下对iPhoneX进行模拟 var safeArea = new Rect(132f, 63f, 2172f, 1062f); if (Screen.width == 2436 && Screen.height == 1125) { Simulate(safeArea); } #else var safeArea = Screen.safeArea; if (NeedFixCanvasScaler) { FixCanvasScaler(safeArea); } ApplySafeArea(safeArea, Screen.width, Screen.height); #endif }
void Start() { size = GetComponent <RectTransform>().sizeDelta; canvasScaler = GetComponentInParent <CanvasScaler>(); canvas = canvasScaler.GetComponent <Canvas>(); var refW = canvasScaler.referenceResolution.x; var refH = canvasScaler.referenceResolution.y; this.screenW = refW; this.screenH = refH; this.scaleX = Screen.width / refW; this.scaleY = Screen.height / refH; var n = this.name; this.keyX = "__" + n + "_win_x"; this.keyY = "__" + n + "_win_y"; var lp = transform.localPosition; var lpx = lp.x; var lpy = lp.y; if (PlayerPrefs.HasKey(keyX)) { lpx = PlayerPrefs.GetFloat(keyX); } if (PlayerPrefs.HasKey(keyY)) { lpy = PlayerPrefs.GetFloat(keyY); } this.transform.localPosition = new Vector3(lpx, lpy, lp.z); }
private void SetReferencePixelsPerUnit(float referencePixelsPerUnit, CanvasScaler scaler) { // if (referencePixelsPerUnit == m_PrevReferencePixelsPerUnit) // return; // m_Canvas.referencePixelsPerUnit = referencePixelsPerUnit; scaler.GetComponent <Canvas>().referencePixelsPerUnit = referencePixelsPerUnit; // m_PrevReferencePixelsPerUnit = referencePixelsPerUnit; }
private void SetScaleFactor(float scaleFactor, CanvasScaler scaler) { // if (scaleFactor == m_PrevScaleFactor) // return; // m_Canvas.scaleFactor = scaleFactor; scaler.GetComponent <Canvas>().scaleFactor = scaleFactor; // m_PrevScaleFactor = scaleFactor; }
// Update is called once per frame void Update() { if (screenWidth != Screen.width || screenHeight != Screen.height) { screenWidth = Screen.width; screenHeight = Screen.height; float designResolution = cs.referenceResolution.x / cs.referenceResolution.y; float realResolution = screenWidth / screenHeight; float aspect = realResolution / designResolution; if (aspect > 1) { cs.matchWidthOrHeight = 1; cs.GetComponent <Canvas>().worldCamera.orthographicSize = aspect; scaleFactor = cs.referenceResolution[1] / Screen.height; } else { cs.matchWidthOrHeight = 0; cs.GetComponent <Canvas>().worldCamera.orthographicSize = orthographicSize; scaleFactor = cs.referenceResolution[0] / Screen.width; } OnReaspectResolution?.Invoke(scaleFactor); } }
/// <summary> /// 키보드 사이즈 높이 /// 사용주의 : 코루틴으로 0.3초뒤 확인필요 /// </summary> /// <returns></returns> private float GetNativeKeyboardHeight() { // 실 기기에 적용된 UI해상도 알아 내기 if (_canvasScaler == null) { _canvasScaler = GetComponentInParent <CanvasScaler>(); } if (_canvasRect == null) { _canvasRect = _canvasScaler.GetComponent <RectTransform>(); } float height = 0; #if UNITY_ANDROID && !UNITY_EDITOR using (AndroidJavaClass unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { var unityPlayer = unityClass.GetStatic <AndroidJavaObject>("currentActivity").Get <AndroidJavaObject>("mUnityPlayer"); var view = unityPlayer.Call <AndroidJavaObject>("getView"); var dialog = unityPlayer.Get <AndroidJavaObject>("mSoftInputDialog"); if (view == null || dialog == null) { return(0); } using (AndroidJavaObject Rct = new AndroidJavaObject("android.graphics.Rect")) { view.Call("getWindowVisibleDisplayFrame", Rct); var keyboradNativeSize = Mathf.Round(Screen.height - Rct.Call <int>("height")); var per = keyboradNativeSize / Screen.height; height = _canvasRect.sizeDelta.y * per; // Debug.Log($"키보드 높이 : {height}"); return(height); } } #else height = Mathf.Round(TouchScreenKeyboard.area.height); // height = Screen.height * 0.5f - (height >= Display.main.systemHeight ? 0f : height); // Debug.Log($"키보드 높이 : {height}"); return(height); #endif }
// TODO set BackgroundImage.overrideSprite to sprite after Unity update https://issuetracker.unity3d.com/issues/image-color-cannot-be-changed-via-script-when-image-type-is-set-to-simple private void Start() { origStartButtonText = StartButtonText.text; bgCanvasRT = BGCanvasScaler.GetComponent <RectTransform>(); fading = true; currentBGImageIndex = -1; StopAllCoroutines(); // TODO get bgSprites from DB if (BGSprites.Count > 0) { StartCoroutine(BGFadeSwitch()); } StartButton.onClick.AddListener(OnStartButtonClick); SetLoaderUIState(LoaderUIStateType.START); }
public void Initialize() { if (Initialized) { return; } //Get the total time taken for all of this element's animation sections to finish hiding/showing. hidingTime = GetAllHidingTime(); showingTime = GetAllShowingTime(); myRT = GetComponent <RectTransform>(); parentCanvasScaler = GetComponentInParent <CanvasScaler>(); parentCanvasRT = parentCanvasScaler.GetComponent <RectTransform>(); if (transform.parent) { directParentRT = transform.parent.GetComponent <RectTransform>(); } Vector2 canvasLossyScale = parentCanvasRT.lossyScale; canvasHalfWidth = canvasLossyScale.x * parentCanvasRT.rect.width / 2; canvasHalfHeight = canvasLossyScale.y * parentCanvasRT.rect.height / 2; if (directParentRT) { dParentHalfWidth = canvasLossyScale.x * directParentRT.rect.width / 2; dParentHalfHeight = canvasLossyScale.y * directParentRT.rect.height / 2; } myRTWidth = canvasLossyScale.x * myRT.rect.width; myRTHeight = canvasLossyScale.y * myRT.rect.height; MovementSection.startVectorValue = myRT.position; outOfScreenPos = GetHidingPosition(HidingPosition, EdgeGap, MovementSection.WantedVectorValue, LocalCustomPosition); RotationSection.startVectorValue = myRT.eulerAngles; ScaleSection.startVectorValue = myRT.localScale; FindTargetFader(); FindSliceImage(); Initialized = true; }
public void Initialize() { if (Initialized) { return; } if (DeactivateWhileInvisible) { OnHideComplete.AddListener(() => { if (!Visible) { gameObject.SetActive(Visible); } }); } hidingTime = GetAllHidingTime(); showingTime = GetAllShowingTime(); selfRectTransform = GetComponent <RectTransform>(); parentCanvasScaler = GetComponentInParent <CanvasScaler>(); parentCanvasRectTransform = parentCanvasScaler.GetComponent <RectTransform>(); if (transform.parent) { directParentRectTransform = transform.parent.GetComponent <RectTransform>(); } Vector2 canvasLossyScale = parentCanvasRectTransform.lossyScale; canvasHalfWidth = canvasLossyScale.x * parentCanvasRectTransform.rect.width / 2; canvasHalfHeight = canvasLossyScale.y * parentCanvasRectTransform.rect.height / 2; if (directParentRectTransform) { directParentHalfWidth = canvasLossyScale.x * directParentRectTransform.rect.width / 2; directParentHalfHeight = canvasLossyScale.y * directParentRectTransform.rect.height / 2; } selfRectTransformWidth = canvasLossyScale.x * selfRectTransform.rect.width; selfRectTransformHeight = canvasLossyScale.y * selfRectTransform.rect.height; MovementSection.startVectorValue = selfRectTransform.position; outOfScreenPos = GetHidingPosition(HidingPosition, EdgeGap, MovementSection.WantedVectorValue, LocalCustomPosition); RotationSection.startVectorValue = selfRectTransform.eulerAngles; ScaleSection.startVectorValue = selfRectTransform.localScale; FindTargetFader(); FindSliceImage(); Initialized = true; }
/* * Private. */ private void Initialize() { if (_initialized) { return; } if (!rectTransform) { rectTransform = GetComponent <RectTransform>(); } rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.pivot = new Vector2(0.5F, 0.5F); _canvasScaler = GetComponentInParent <CanvasScaler>(); _canvasScalerRectTransform = _canvasScaler.GetComponent <RectTransform>(); _initialized = true; }
// TODO set BackgroundImage.overrideSprite to sprite after Unity update https://issuetracker.unity3d.com/issues/image-color-cannot-be-changed-via-script-when-image-type-is-set-to-simple private void Start() { if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux) { SettingsPanel.SetActive(false); SettingsButton.SetActive(false); } else { SetDropdowns(); } bgCanvasRT = BGCanvasScaler.GetComponent <RectTransform>(); fading = true; currentBGImageIndex = -1; StopAllCoroutines(); // TODO get bgSprites from DB if (BGSprites.Count > 0) { StartCoroutine(BGFadeSwitch()); } }
// Call this whenever the contents of the panel list has changed private void InitializeStack() { // Do not call this from Awake, it is too early to obtain valid data from the canvas Debug.Log("InitializeStack:" + System.DateTime.Now.ToString()); Canvas canvas = GetComponentInParent <Canvas>(); // TODO: If this fails it should be an error if (canvas != null) { // Check if there is a canvas scaler being used CanvasScaler canvasScaler = GetComponentInParent <CanvasScaler>(); // When there is a canvas scaler we need to extract the post scaled dimensions from it. // Otherwise we can just read the dimensions directly from the canvas rect. RectTransform canvasRectTransform = (canvasScaler != null) ? canvasScaler.GetComponent <RectTransform>() : canvas.GetComponent <RectTransform>(); // TODO: If this fails it should be an error if (canvasRectTransform != null) { m_PanelWidth = canvasRectTransform.rect.width; m_PanelHeight = canvasRectTransform.rect.height; RectTransform rectTransform; int index = 0; foreach (ScreenPanel screenPanel in m_PanelList) { rectTransform = screenPanel.GetComponent <RectTransform>(); if (rectTransform != null) { // Set the anchor info rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(0, 0); rectTransform.pivot = new Vector2(0, 0); rectTransform.anchoredPosition = new Vector2(0, m_PanelHeight * index); ++index; // Set the dimensions rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, m_PanelHeight); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, m_PanelWidth); } // Ensure all child panels begin as disabled ScreenPanel panel = screenPanel.GetComponent <ScreenPanel>(); if (panel != null) { panel.Enabled = false; } } // Set up this parent panel based on the number of children rectTransform = GetComponent <RectTransform>(); if (rectTransform != null) { // Set the anchor info rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(0, 0); rectTransform.pivot = new Vector2(0, 0); rectTransform.anchoredPosition = new Vector2(0, 0); // Set the dimensions rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, m_PanelHeight * index); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, m_PanelWidth); } // Reset the stack to the default position m_CurrentIndex = 0; m_TargetIndex = 0; m_TransitionValue = 0.0f; // Set the default panel as enabled m_PanelList[m_CurrentIndex].Enabled = true; } } }
public override void OnInspectorGUI() { if (CanvasScalerEditor.s_Styles == null) { CanvasScalerEditor.s_Styles = new CanvasScalerEditor.Styles(); } bool flag = true; bool flag2 = false; bool flag3 = (base.target as CanvasScaler).GetComponent <Canvas>().renderMode == RenderMode.WorldSpace; for (int i = 0; i < base.targets.Length; i++) { CanvasScaler canvasScaler = base.targets[i] as CanvasScaler; Canvas component = canvasScaler.GetComponent <Canvas>(); if (!component.isRootCanvas) { flag = false; break; } if ((flag3 && component.renderMode != RenderMode.WorldSpace) || (!flag3 && component.renderMode == RenderMode.WorldSpace)) { flag2 = true; break; } } if (!flag) { EditorGUILayout.HelpBox("Non-root Canvases will not be scaled.", MessageType.Warning); } else { base.serializedObject.Update(); EditorGUI.showMixedValue = flag2; using (new EditorGUI.DisabledScope(flag3 || flag2)) { if (flag3 || flag2) { EditorGUILayout.Popup(CanvasScalerEditor.s_Styles.uiScaleModeContent.text, 0, new string[] { "World" }, new GUILayoutOption[0]); } else { EditorGUILayout.PropertyField(this.m_UiScaleMode, CanvasScalerEditor.s_Styles.uiScaleModeContent, new GUILayoutOption[0]); } } EditorGUI.showMixedValue = false; if (!flag2 && (flag3 || !this.m_UiScaleMode.hasMultipleDifferentValues)) { EditorGUILayout.Space(); if (flag3) { EditorGUILayout.PropertyField(this.m_DynamicPixelsPerUnit, new GUILayoutOption[0]); } else if (this.m_UiScaleMode.enumValueIndex == 0) { EditorGUILayout.PropertyField(this.m_ScaleFactor, new GUILayoutOption[0]); } else if (this.m_UiScaleMode.enumValueIndex == 1) { EditorGUILayout.PropertyField(this.m_ReferenceResolution, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_ScreenMatchMode, new GUILayoutOption[0]); if (this.m_ScreenMatchMode.enumValueIndex == 0 && !this.m_ScreenMatchMode.hasMultipleDifferentValues) { Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 12f, new GUILayoutOption[0]); CanvasScalerEditor.DualLabeledSlider(controlRect, this.m_MatchWidthOrHeight, CanvasScalerEditor.s_Styles.matchContent, CanvasScalerEditor.s_Styles.widthContent, CanvasScalerEditor.s_Styles.heightContent); } } else if (this.m_UiScaleMode.enumValueIndex == 2) { EditorGUILayout.PropertyField(this.m_PhysicalUnit, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_FallbackScreenDPI, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_DefaultSpriteDPI, new GUILayoutOption[0]); } EditorGUILayout.PropertyField(this.m_ReferencePixelsPerUnit, new GUILayoutOption[0]); } base.serializedObject.ApplyModifiedProperties(); } }
public void InitSafeArea() { SafeInit(); //UI TODO: Find a Callback instead of Calling this every frame. Vector4 v_safeArea = GetSafePadding(); // or Screen.safeArea if you use a version of Unity that supports it //#if IN_GAME // Common.HobaDebuger.Log("[UI] InitSafeArea " + v_safeArea + SystemInfo.deviceModel); //#else // Debug.Log("[UI] InitSafeArea " + v_safeArea + SystemInfo.deviceModel); //#endif #if !UNITY_EDITOR if (v_safeArea == Vector4.zero) { enabled = false; } #endif if (!_ShouldBeEnable) { return; } float scale = 1; #if IN_GAME && UNITY_IOS || IN_GAME && UNITY_ANDROID || UNITY_EDITOR CanvasScaler cs = GetComponentInParent <CanvasScaler>(); if (cs == null) { return; } else { RectTransform rt = cs.GetComponent <RectTransform>(); if (rt != null) { scale = rt.rect.width / Screen.width; } } #endif Vector4 v_result = new Vector4(); int i_platform = 0; #if UNITY_EDITOR v_result = v_safeArea * VDensity; #elif IN_GAME && UNITY_IOS v_result = new Vector4(v_safeArea.x, 0, 0, 0); Debug.Log("Safe padding " + v_result + " , " + " , " + scale); i_platform = 1; #elif IN_GAME && UNITY_ANDROID float d = AndroidUtil.GetDensity(); v_result = v_safeArea * d; Debug.Log("Safe padding " + v_result + " , " + d + " , " + scale); i_platform = 2; #endif #if IN_GAME object[] float4_results = LuaScriptMgr.Instance.CallLuaFunction("ConfirmSafeArea", v_result.x, v_result.y, v_result.z, v_result.w, SystemInfo.deviceModel, i_platform); if (float4_results != null) { CurSafePadding = new Vector4((float)(double)float4_results[0], (float)(double)float4_results[1], (float)(double)float4_results[2], (float)(double)float4_results[3]) * scale; } #else CurSafePadding = v_result * scale; #endif }
private static void DrawCanvasScaler(CanvasScaler canvasScaler) { if (canvasScaler.GetComponent <Canvas>().renderMode == RenderMode.WorldSpace) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Dynamic Pixels Per Unit", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.dynamicPixelsPerUnit = NitroxGUILayout.FloatField(canvasScaler.dynamicPixelsPerUnit); } } else { using (new GUILayout.HorizontalScope()) { GUILayout.Label("UI Scale Mode", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.uiScaleMode = NitroxGUILayout.EnumPopup(canvasScaler.uiScaleMode); } if (canvasScaler.uiScaleMode == CanvasScaler.ScaleMode.ConstantPixelSize) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Scale Factor", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.scaleFactor = NitroxGUILayout.FloatField(canvasScaler.scaleFactor); } } else if (canvasScaler.uiScaleMode == CanvasScaler.ScaleMode.ScaleWithScreenSize) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Reference Resolution", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.referenceResolution = VectorDrawer.DrawVector2(canvasScaler.referenceResolution); } using (new GUILayout.HorizontalScope()) { GUILayout.Label("Screen Match Mode", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.screenMatchMode = NitroxGUILayout.EnumPopup(canvasScaler.screenMatchMode); } using (new GUILayout.HorizontalScope()) { GUILayout.Label("Match", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); float newMatchValue = NitroxGUILayout.FloatField(canvasScaler.matchWidthOrHeight); canvasScaler.matchWidthOrHeight = Mathf.Max(0, Mathf.Min(newMatchValue, 1)); } } else { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Physical Unit", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.physicalUnit = NitroxGUILayout.EnumPopup(canvasScaler.physicalUnit); } using (new GUILayout.HorizontalScope()) { GUILayout.Label("Fallback Screen DPI", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.matchWidthOrHeight = NitroxGUILayout.FloatField(canvasScaler.fallbackScreenDPI); } using (new GUILayout.HorizontalScope()) { GUILayout.Label("Default Sprite DPI", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); float newDefaultSpriteDPI = NitroxGUILayout.FloatField(canvasScaler.defaultSpriteDPI); canvasScaler.defaultSpriteDPI = Mathf.Max(1, newDefaultSpriteDPI); } } } using (new GUILayout.HorizontalScope()) { GUILayout.Label("Reference Pixels Per Unit", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH)); NitroxGUILayout.Separator(); canvasScaler.referencePixelsPerUnit = NitroxGUILayout.FloatField(canvasScaler.referencePixelsPerUnit); } }
public override void OnSingletonInit() { m_CanvasScaler = UIMgr.S.uiRoot.rootCanvas.GetComponent <CanvasScaler>(); m_CanvasRoot = m_CanvasScaler.GetComponent <RectTransform>(); }
// Start is called before the first frame update void Start() { cs = GetComponent <CanvasScaler>(); orthographicSize = cs.GetComponent <Canvas>().worldCamera.orthographicSize; }
public override void OnInspectorGUI() { if (s_Styles == null) { s_Styles = new Styles(); } bool allAreRoot = true; bool showWorldDiffers = false; bool showWorld = ((target as CanvasScaler).GetComponent <Canvas>().renderMode == RenderMode.WorldSpace); for (int i = 0; i < targets.Length; i++) { CanvasScaler scaler = targets[i] as CanvasScaler; Canvas canvas = scaler.GetComponent <Canvas>(); if (!canvas.isRootCanvas) { allAreRoot = false; break; } if (showWorld && canvas.renderMode != RenderMode.WorldSpace || !showWorld && canvas.renderMode == RenderMode.WorldSpace) { showWorldDiffers = true; break; } } if (!allAreRoot) { EditorGUILayout.HelpBox("Non-root Canvases will not be scaled.", MessageType.Warning); return; } serializedObject.Update(); EditorGUI.showMixedValue = showWorldDiffers; using (new EditorGUI.DisabledScope(showWorld || showWorldDiffers)) { if (showWorld || showWorldDiffers) { EditorGUILayout.Popup(s_Styles.uiScaleModeContent.text, 0, new[] { "World" }); } else { EditorGUILayout.PropertyField(m_UiScaleMode, s_Styles.uiScaleModeContent); } } EditorGUI.showMixedValue = false; if (!showWorldDiffers && !(!showWorld && m_UiScaleMode.hasMultipleDifferentValues)) { EditorGUILayout.Space(); // World Canvas if (showWorld) { EditorGUILayout.PropertyField(m_DynamicPixelsPerUnit); } // Constant pixel size else if (m_UiScaleMode.enumValueIndex == (int)CanvasScaler.ScaleMode.ConstantPixelSize) { EditorGUILayout.PropertyField(m_ScaleFactor); } // Scale with screen size else if (m_UiScaleMode.enumValueIndex == (int)CanvasScaler.ScaleMode.ScaleWithScreenSize) { EditorGUILayout.PropertyField(m_ReferenceResolution); EditorGUILayout.PropertyField(m_ScreenMatchMode); if (m_ScreenMatchMode.enumValueIndex == (int)CanvasScaler.ScreenMatchMode.MatchWidthOrHeight && !m_ScreenMatchMode.hasMultipleDifferentValues) { Rect r = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + kSliderEndpointLabelsHeight); DualLabeledSlider(r, m_MatchWidthOrHeight, s_Styles.matchContent, s_Styles.widthContent, s_Styles.heightContent); } } // Constant physical size else if (m_UiScaleMode.enumValueIndex == (int)CanvasScaler.ScaleMode.ConstantPhysicalSize) { EditorGUILayout.PropertyField(m_PhysicalUnit); EditorGUILayout.PropertyField(m_FallbackScreenDPI); EditorGUILayout.PropertyField(m_DefaultSpriteDPI); } EditorGUILayout.PropertyField(m_ReferencePixelsPerUnit); } serializedObject.ApplyModifiedProperties(); }
public void Apply_Effect(int index) { TweenConfig config = tweenConfigs[index]; LTDescr tweenDescr = null; Vector3 v3a, v3b; switch (config.type) { case TweenType.None: break; case TweenType.Move: switch (config.para) { case TweenPara.None: break; case TweenPara.Zero_To_One: break; case TweenPara.One_To_Zero: break; case TweenPara.FloatA_To_FloatB: break; case TweenPara.VectA_To_VectB: if (!config.use_curVal_as_A) { transform.position = config.vec_A; } tweenDescr = LeanTween.move(gameObject, config.vec_B, config.duration); break; case TweenPara.ColA_To_ColB: break; case TweenPara.ViewA_To_ViewB: if (!config.use_curVal_as_A) { v3a = Cam.ViewportToWorldPoint(config.vPrt_A); v3a.z = transform.position.z; transform.position = v3a; } v3b = Cam.ViewportToWorldPoint(config.vPrt_B); v3b.z = transform.position.z; tweenDescr = LeanTween.move(gameObject, v3b, config.duration).setEase(config.curve); break; default: break; } break; case TweenType.MoveUI: RectTransform rt = GetComponent <RectTransform>(); switch (config.para) { case TweenPara.None: break; case TweenPara.Zero_To_One: break; case TweenPara.One_To_Zero: break; case TweenPara.FloatA_To_FloatB: break; case TweenPara.VectA_To_VectB: if (!config.use_curVal_as_A) { transform.position = config.vec_A; } tweenDescr = LeanTween.move(gameObject, config.vec_B, config.duration); break; case TweenPara.ColA_To_ColB: break; case TweenPara.ViewA_To_ViewB: CanvasScaler cs = GetComponentInParent <CanvasScaler>(); RectTransform crt = cs.GetComponent <RectTransform>(); if (!config.use_curVal_as_A) { v3a.x = crt.rect.width * config.vPrt_A.x * crt.localScale.x; v3a.y = crt.rect.height * config.vPrt_A.y * crt.localScale.y; v3a.z = transform.position.z; transform.position = v3a; } v3b.x = crt.rect.width * config.vPrt_B.x * crt.localScale.x; v3b.y = crt.rect.height * config.vPrt_B.y * crt.localScale.y; v3b.z = transform.position.z; tweenDescr = LeanTween.move(gameObject, v3b, config.duration).setEase(config.curve); break; default: break; } break; case TweenType.Rotate: break; case TweenType.Scale: break; case TweenType.ColorMat: break; case TweenType.ColorVtx: break; default: break; } if (tweenDescr != null) { tweenDescr.setOnStart(() => { config.onStart.Invoke(); }); tweenDescr.setOnComplete(() => { config.onComplete.Invoke(); }); } }