Skip to content

Commit

Permalink
feat. smooth UI rescale
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-Yulin committed Apr 3, 2024
1 parent 16564eb commit da24891
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 12 deletions.
60 changes: 48 additions & 12 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,10 @@ Transform:
m_GameObject: {fileID: 400244204}
m_LocalRotation: {x: 0.21263108, y: -0.67437977, z: -0.21263108, w: 0.67437977}
m_LocalPosition: {x: 0, y: 0, z: -0.01}
m_LocalScale: {x: 0.03, y: 0.03, z: 0.03}
m_LocalScale: {x: 0.029999997, y: 0.030000001, z: 0.03}
m_Children:
- {fileID: 278918740}
m_Father: {fileID: 1648845060}
m_Father: {fileID: 1549906063}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: -90, z: -35}
--- !u!135 &400244206
Expand Down Expand Up @@ -1173,7 +1173,6 @@ GameObject:
m_Component:
- component: {fileID: 661408668}
- component: {fileID: 661408670}
- component: {fileID: 661408669}
- component: {fileID: 661408671}
m_Layer: 0
m_Name: TextMeshPro
Expand Down Expand Up @@ -1201,14 +1200,6 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: -0.0109}
m_SizeDelta: {x: 0.032, y: 0.01}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &661408669
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 661408667}
m_CullTransparentMesh: 0
--- !u!23 &661408670
MeshRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1837,6 +1828,51 @@ Transform:
m_Father: {fileID: 2033680552}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1549906062
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1549906063}
- component: {fileID: 1549906064}
m_Layer: 0
m_Name: Menu
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1549906063
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1549906062}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 400244205}
m_Father: {fileID: 1648845060}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1549906064
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1549906062}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 28be8630190a51f4cb01ba2fa7142ab1, type: 3}
m_Name:
m_EditorClassIdentifier:
Coeff: -2
--- !u!1 &1603722573
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2085,7 +2121,7 @@ Transform:
m_LocalPosition: {x: 1.766, y: 0, z: 0.011}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 400244205}
- {fileID: 1549906063}
m_Father: {fileID: 600980682}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down
34 changes: 34 additions & 0 deletions Assets/Script/UI/HideOnFlip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HideOnFlip : MonoBehaviour
{
GameObject mainCamera;
GameObject child;

public float Coeff = -5;

void Start()
{
mainCamera = Camera.main.gameObject;
child = transform.GetChild(0).gameObject;
}

// Update is called once per frame
void Update()
{
float size = Vector3.Dot(mainCamera.transform.forward, transform.forward);
size *= Coeff;
size = Mathf.Clamp(size, 0.1f, 1);
if (size == 0.1f)
{
child.SetActive(false);
}
else
{
child.SetActive(true);
}
transform.localScale = size * Vector3.one;
}
}
11 changes: 11 additions & 0 deletions Assets/Script/UI/HideOnFlip.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da24891

Please sign in to comment.