mirror of
https://github.com/byeongyupKim/dlfqks.git
synced 2026-02-04 12:02:59 +09:00
[UI] 초기 강화 화면 스크롤뷰 적용 및 배치
This commit is contained in:
File diff suppressed because it is too large
Load Diff
3920
Assets/1. Scenes/ScrollViewSample.unity
Normal file
3920
Assets/1. Scenes/ScrollViewSample.unity
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/1. Scenes/ScrollViewSample.unity.meta
Normal file
8
Assets/1. Scenes/ScrollViewSample.unity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb2d794b390a5124d821975b3f85bf90
|
||||
timeCreated: 1500375335
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
69
Assets/2. Scripts/ScrollRectSnap.cs
Normal file
69
Assets/2. Scripts/ScrollRectSnap.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class ScrollRectSnap : ScrollRect {
|
||||
public int horizontalPages = 3; // horizontalの分割数
|
||||
public int verticalPages = 3; // verticalの分割数
|
||||
|
||||
[SerializeField] private float smooth = 10f; // スナップ係数
|
||||
private Vector2 targetPosition; // スナップ先座標
|
||||
private bool isDrag = false; // フラグ
|
||||
|
||||
protected override void Start(){
|
||||
base.Start ();
|
||||
normalizedPosition = content.GetComponent<RectTransform> ().pivot;
|
||||
targetPosition = GetSnapPosition ();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (!isDrag && normalizedPosition != targetPosition) {
|
||||
normalizedPosition = Vector2.Lerp (normalizedPosition, targetPosition, smooth * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnBeginDrag(PointerEventData eventData){
|
||||
base.OnBeginDrag (eventData);
|
||||
isDrag = true;
|
||||
}
|
||||
|
||||
public override void OnEndDrag(PointerEventData eventData){
|
||||
base.OnEndDrag (eventData);
|
||||
targetPosition = GetSnapPosition ();
|
||||
isDrag = false;
|
||||
}
|
||||
|
||||
// スナップ先座標を取得する
|
||||
Vector2 GetSnapPosition(){
|
||||
float x = 0, y = 0;
|
||||
Vector2 center;
|
||||
|
||||
if(horizontal){
|
||||
if(horizontalPages > 1){
|
||||
for (int page = 0; page < horizontalPages; page ++) {
|
||||
center.x = (2f * page - 1f) / ((horizontalPages - 1f) * 2f);
|
||||
if(horizontalNormalizedPosition >= center.x){
|
||||
x = page / (horizontalPages - 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
x = horizontalNormalizedPosition;
|
||||
}
|
||||
|
||||
if(vertical){
|
||||
if(verticalPages > 1){
|
||||
for (int page = 0; page < verticalPages; page ++) {
|
||||
center.y = (2f * page - 1f) / ((verticalPages - 1f) * 2f);
|
||||
if(verticalNormalizedPosition >= center.y){
|
||||
y = page / (verticalPages - 1f) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
y = verticalNormalizedPosition;
|
||||
}
|
||||
return new Vector2 (x, y);
|
||||
}
|
||||
}
|
||||
12
Assets/2. Scripts/ScrollRectSnap.cs.meta
Normal file
12
Assets/2. Scripts/ScrollRectSnap.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c698f9ce753239646b084427564dc7c9
|
||||
timeCreated: 1500375496
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Editor.meta
Normal file
9
Assets/Editor.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 091bc9b94ff079e4a9bdde577e49aeb8
|
||||
folderAsset: yes
|
||||
timeCreated: 1500375492
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Editor/ScrollRectSnapEditor.cs
Normal file
10
Assets/Editor/ScrollRectSnapEditor.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor( typeof(ScrollRectSnap))]
|
||||
public sealed class ScrollRectSnapEditor : Editor {
|
||||
|
||||
public override void OnInspectorGUI(){
|
||||
DrawDefaultInspector ();
|
||||
}
|
||||
}
|
||||
12
Assets/Editor/ScrollRectSnapEditor.cs.meta
Normal file
12
Assets/Editor/ScrollRectSnapEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92a730efb00d040f084ba97552a53eeb
|
||||
timeCreated: 1464137933
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user