[UI] 초기 강화 화면 스크롤뷰 적용 및 배치

This commit is contained in:
Mingu
2017-07-19 03:08:01 +09:00
parent 57349fb48c
commit a2ce98a219
8 changed files with 10357 additions and 113 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fb2d794b390a5124d821975b3f85bf90
timeCreated: 1500375335
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View 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
View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 091bc9b94ff079e4a9bdde577e49aeb8
folderAsset: yes
timeCreated: 1500375492
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using UnityEngine;
using UnityEditor;
[CustomEditor( typeof(ScrollRectSnap))]
public sealed class ScrollRectSnapEditor : Editor {
public override void OnInspectorGUI(){
DrawDefaultInspector ();
}
}

View 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: