406 lines
20 KiB
C#
406 lines
20 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
namespace TKS.OutGame
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 포트레이트 대화 장치(첫 실행 흐름 · PD 2026-11-24 · 요청서 §2-2) — 왼쪽 아래 포트레이트 + 오른쪽 말풍선(이름표 · 다음 표시) ·
|
||
|
|
/// talk = 화면 전체 어둡게(터치 = 다음) · point = 대상만 밝게(눌리지 않음 · 터치 = 다음) · press = 대상만 밝게 + 금빛 테 + 손가락(그 대상만 눌림).
|
||
|
|
/// 대상이 대화 칸과 겹치면 대화 칸이 대상 위로 올라간다(와이어프레임 wire_sortie · wire_recruit).
|
||
|
|
/// 캔버스(P41): 루트 = Static · Dim(어두운 판 4장 + 구멍 막이 = 줄이 바뀔 때만) · Talk(포트레이트 · 말풍선 · 이름표 = 줄이 바뀔 때만) ·
|
||
|
|
/// 대사 글자 · 다음 표시 = 말풍선 안 중첩 Frame · Fx(금빛 테 숨쉬기 · 손가락 까딱임) = Frame.
|
||
|
|
/// 그림 = 다시 씀(연의 말풍선 Scenario/bubble · name_tag · 학습 안내 손가락 tut_hand) · 좌표 · 크기 · 색 = 표 first_flow_config.
|
||
|
|
/// </summary>
|
||
|
|
public class FirstFlowGuide : MonoBehaviour
|
||
|
|
{
|
||
|
|
public class Request
|
||
|
|
{
|
||
|
|
public string mode = FirstFlowData.Talk;
|
||
|
|
public string name = "";
|
||
|
|
public Color tagTint = Color.gray;
|
||
|
|
public Color plate = Color.white;
|
||
|
|
public Sprite portrait;
|
||
|
|
public string text = "";
|
||
|
|
public List<RectTransform> targets;
|
||
|
|
}
|
||
|
|
|
||
|
|
const float DesignW = 1080f;
|
||
|
|
|
||
|
|
RectTransform root;
|
||
|
|
RectTransform dimLayer;
|
||
|
|
RectTransform talkLayer;
|
||
|
|
RectTransform fxLayer;
|
||
|
|
readonly Image[] dims = new Image[4];
|
||
|
|
Image holeBlock;
|
||
|
|
RectTransform block;
|
||
|
|
Image plate;
|
||
|
|
Image portrait;
|
||
|
|
Image bubble;
|
||
|
|
Image nameTag;
|
||
|
|
Text nameText;
|
||
|
|
Text body;
|
||
|
|
Text nextMark;
|
||
|
|
readonly Image[] frame = new Image[4];
|
||
|
|
Image finger;
|
||
|
|
|
||
|
|
Request req;
|
||
|
|
float shownChars;
|
||
|
|
float charsPerSec = 40f;
|
||
|
|
float clock;
|
||
|
|
Rect hole;
|
||
|
|
bool hasHole;
|
||
|
|
float nextPeriod = 0.9f;
|
||
|
|
float framePeriod = 1f, frameMin = 0.5f;
|
||
|
|
float fingerBob = 16f, fingerPeriod = 0.7f;
|
||
|
|
Vector2 fingerHome;
|
||
|
|
Color frameColor = Color.yellow;
|
||
|
|
|
||
|
|
/// <summary>대사 칸이 떠 있는가.</summary>
|
||
|
|
public bool Shown { get; private set; }
|
||
|
|
/// <summary>지금 줄의 방식 · 말하는 이 · 전체 대사(테스트 · 캡처).</summary>
|
||
|
|
public string Mode { get { return req != null ? req.mode : ""; } }
|
||
|
|
public string SpeakerName { get { return req != null ? req.name : ""; } }
|
||
|
|
public string FullText { get { return req != null ? req.text : ""; } }
|
||
|
|
/// <summary>대사가 아직 한 글자씩 나오는 중인가.</summary>
|
||
|
|
public bool Typing { get { return Shown && req != null && shownChars < req.text.Length; } }
|
||
|
|
/// <summary>대사가 다 나온 뒤의 화면 누름 수(지휘 쪽이 읽고 0 으로 돌린다).</summary>
|
||
|
|
public int Taps;
|
||
|
|
/// <summary>밝게 남긴 칸(루트 좌표 · 없으면 null · 테스트).</summary>
|
||
|
|
public Rect? Hole { get { return hasHole ? hole : (Rect?)null; } }
|
||
|
|
public bool FingerShown { get { return finger != null && finger.gameObject.activeSelf; } }
|
||
|
|
public bool PortraitShown { get { return portrait != null && portrait.sprite != null; } }
|
||
|
|
|
||
|
|
public static FirstFlowGuide Create(Transform parent, Camera cam)
|
||
|
|
{
|
||
|
|
var go = new GameObject("FirstFlowGuide");
|
||
|
|
go.transform.SetParent(parent, false);
|
||
|
|
var g = go.AddComponent<FirstFlowGuide>();
|
||
|
|
g.Build(cam);
|
||
|
|
go.SetActive(false);
|
||
|
|
return g;
|
||
|
|
}
|
||
|
|
|
||
|
|
static string[] L(string key)
|
||
|
|
{
|
||
|
|
return FirstFlowData.List(key);
|
||
|
|
}
|
||
|
|
|
||
|
|
static float At(string[] a, int i, float def)
|
||
|
|
{
|
||
|
|
return ScreenTable.At(a, i, def);
|
||
|
|
}
|
||
|
|
|
||
|
|
void Build(Camera cam)
|
||
|
|
{
|
||
|
|
var cv = L("canvas");
|
||
|
|
UiLayer.Root(gameObject, cam, (int)At(cv, 0, 470f), At(cv, 1, 0.33f), UiLayer.Reference, UiRate.Static);
|
||
|
|
root = (RectTransform)transform;
|
||
|
|
|
||
|
|
// 어두운 판 4장(대상 둘레) + 구멍 막이(가리키기 = 대상도 눌리지 않게) — 눌림 = 대사 넘김
|
||
|
|
dimLayer = UiLayer.Group("Dim", root, UiRate.Event, true);
|
||
|
|
var dimCol = FirstFlowData.Col("dim", new Color(0f, 0f, 0f, 0.62f));
|
||
|
|
for (int i = 0; i < 4; i++) dims[i] = Panel("Dim" + i, dimLayer, dimCol);
|
||
|
|
holeBlock = Panel("HoleBlock", dimLayer, new Color(0f, 0f, 0f, 0f));
|
||
|
|
holeBlock.canvasRenderer.cullTransparentMesh = true; // 누름만 · 그리지 않음
|
||
|
|
|
||
|
|
// 금빛 테 · 손가락(매 프레임 움직임)
|
||
|
|
fxLayer = UiLayer.Group("Fx", root, UiRate.Frame, false);
|
||
|
|
var ff = L("focus_frame"); // 여백 | 테 굵기 | 색 | 숨쉬기 주기 | 가장 흐릴 때
|
||
|
|
frameColor = ScreenTable.Col(ff, 2, new Color(0.95f, 0.7f, 0.24f));
|
||
|
|
framePeriod = Mathf.Max(0.1f, At(ff, 3, 1f));
|
||
|
|
frameMin = Mathf.Clamp01(At(ff, 4, 0.55f));
|
||
|
|
for (int i = 0; i < 4; i++)
|
||
|
|
{
|
||
|
|
frame[i] = UiKit.Rect("Frame" + i, fxLayer, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero).gameObject.AddComponent<Image>();
|
||
|
|
frame[i].color = frameColor;
|
||
|
|
frame[i].raycastTarget = false;
|
||
|
|
}
|
||
|
|
var fg = L("finger"); // 크기 | 대상 가운데에서 x(폭 비율) | y(높이 비율) | 까딱임 px | 주기
|
||
|
|
float fs = At(fg, 0, 150f);
|
||
|
|
finger = UiKit.Rect("Finger", fxLayer, new Vector2(0.5f, 0.5f), new Vector2(0.12f, 0.85f), Vector2.zero, new Vector2(fs, fs)).gameObject.AddComponent<Image>(); // 피벗 = 손가락 끝(학습 안내와 같음)
|
||
|
|
finger.sprite = UISkin.Icon("tut_hand");
|
||
|
|
if (finger.sprite == null)
|
||
|
|
{
|
||
|
|
finger.sprite = UiKit.Circle;
|
||
|
|
finger.rectTransform.pivot = new Vector2(0.5f, 0.5f);
|
||
|
|
finger.rectTransform.sizeDelta = new Vector2(fs * 0.45f, fs * 0.45f);
|
||
|
|
}
|
||
|
|
finger.raycastTarget = false;
|
||
|
|
fingerBob = At(fg, 3, 16f);
|
||
|
|
fingerPeriod = Mathf.Max(0.1f, At(fg, 4, 0.7f));
|
||
|
|
|
||
|
|
// 대화 칸(화면 아래 가운데 · 설계 폭 1080 기준 좌표)
|
||
|
|
talkLayer = UiLayer.Group("Talk", root, UiRate.Event, true);
|
||
|
|
block = UiKit.Rect("Block", talkLayer, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), Vector2.zero, new Vector2(DesignW, 10f));
|
||
|
|
plate = UiKit.Rect("Plate", block, Vector2.zero, new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero).gameObject.AddComponent<Image>();
|
||
|
|
plate.sprite = UiKit.Circle;
|
||
|
|
plate.raycastTarget = false;
|
||
|
|
portrait = UiKit.Rect("Portrait", block, Vector2.zero, new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero).gameObject.AddComponent<Image>();
|
||
|
|
portrait.preserveAspect = true;
|
||
|
|
portrait.raycastTarget = false;
|
||
|
|
bubble = UiKit.Rect("Bubble", block, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero).gameObject.AddComponent<Image>();
|
||
|
|
bubble.sprite = Resources.Load<Sprite>("Scenario/bubble");
|
||
|
|
bubble.type = bubble.sprite != null ? Image.Type.Sliced : Image.Type.Simple;
|
||
|
|
bubble.raycastTarget = true;
|
||
|
|
Clickable(bubble);
|
||
|
|
var bt = L("bubble_text"); // 글자 | 최소 글자 | 색 | 좌우 여백 | 위 여백 | 아래 여백 | 줄 간격 | 초당 글자 수
|
||
|
|
body = UiKit.Title(UiKit.FillLabel(bubble.transform, "", (int)At(bt, 0, 38f), ScreenTable.Col(bt, 2, new Color(0.24f, 0.13f, 0.07f)), TextAnchor.MiddleLeft, false));
|
||
|
|
body.rectTransform.offsetMin = new Vector2(At(bt, 3, 44f), At(bt, 5, 34f));
|
||
|
|
body.rectTransform.offsetMax = new Vector2(-At(bt, 3, 44f), -At(bt, 4, 40f));
|
||
|
|
body.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||
|
|
body.verticalOverflow = VerticalWrapMode.Truncate;
|
||
|
|
body.resizeTextForBestFit = true;
|
||
|
|
body.resizeTextMinSize = (int)At(bt, 1, 28f);
|
||
|
|
body.resizeTextMaxSize = (int)At(bt, 0, 38f);
|
||
|
|
body.lineSpacing = At(bt, 6, 1.15f);
|
||
|
|
body.raycastTarget = false;
|
||
|
|
charsPerSec = Mathf.Max(1f, At(bt, 7, 40f));
|
||
|
|
UiLayer.Nest(body.gameObject, UiRate.Frame, false); // 한 글자씩 나오는 동안만 바뀜 — 포트레이트 · 말풍선을 다시 묶지 않게
|
||
|
|
var nm = L("next_mark"); // 글자 크기 | 말풍선 오른쪽에서 x | 아래에서 y | 색 | 깜박임 주기
|
||
|
|
nextMark = UiKit.Label(bubble.transform, "▼", (int)At(nm, 0, 34f), ScreenTable.Col(nm, 3, new Color(0.72f, 0.26f, 0.23f)), TextAnchor.MiddleCenter,
|
||
|
|
new Vector2(1f, 0f), new Vector2(0.5f, 0.5f), new Vector2(At(nm, 1, -44f), At(nm, 2, 34f)), new Vector2(60f, 60f));
|
||
|
|
nextMark.raycastTarget = false;
|
||
|
|
nextPeriod = Mathf.Max(0.1f, At(nm, 4, 0.9f));
|
||
|
|
UiLayer.Nest(nextMark.gameObject, UiRate.Frame, false);
|
||
|
|
var nt = L("name_tag"); // 말풍선 왼쪽에서 x | 말풍선 위끝에서 y(가운데) | 높이 | 글자 | 좌우 여백 | 글자 색
|
||
|
|
nameTag = UiKit.Rect("NameTag", bubble.transform, new Vector2(0f, 1f), new Vector2(0f, 0.5f), new Vector2(At(nt, 0, 40f), At(nt, 1, 0f)), new Vector2(200f, At(nt, 2, 56f))).gameObject.AddComponent<Image>();
|
||
|
|
nameTag.sprite = Resources.Load<Sprite>("Scenario/name_tag");
|
||
|
|
nameTag.type = nameTag.sprite != null ? Image.Type.Sliced : Image.Type.Simple;
|
||
|
|
nameTag.raycastTarget = false;
|
||
|
|
nameText = UiKit.Title(UiKit.FillLabel(nameTag.transform, "", (int)At(nt, 3, 30f), ScreenTable.Col(nt, 5, Color.white)), true);
|
||
|
|
nameText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||
|
|
nameText.raycastTarget = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
Image Panel(string name, Transform parent, Color c)
|
||
|
|
{
|
||
|
|
var img = UiKit.Rect(name, parent, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero).gameObject.AddComponent<Image>();
|
||
|
|
img.color = c;
|
||
|
|
img.raycastTarget = true;
|
||
|
|
Clickable(img);
|
||
|
|
return img;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Clickable(Image img)
|
||
|
|
{
|
||
|
|
var b = img.gameObject.AddComponent<Button>();
|
||
|
|
b.transition = Selectable.Transition.None;
|
||
|
|
b.onClick.AddListener(Tap);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---------- 보이기 · 숨기기 ----------
|
||
|
|
|
||
|
|
public void Show(Request q)
|
||
|
|
{
|
||
|
|
req = q ?? new Request();
|
||
|
|
Shown = true;
|
||
|
|
Taps = 0;
|
||
|
|
shownChars = 0f;
|
||
|
|
clock = 0f;
|
||
|
|
gameObject.SetActive(true);
|
||
|
|
|
||
|
|
bool small = req.mode != FirstFlowData.Talk;
|
||
|
|
var bb = L(small ? "bubble_small" : "bubble"); // 왼 x | 폭 | 높이 | 아래에서 y
|
||
|
|
if (bb.Length < 3) bb = L("bubble");
|
||
|
|
var pt = L(small ? "portrait_small" : "portrait"); // 가운데 x | 가운데 y | 그림 크기 | 받침 크기
|
||
|
|
float bx = At(bb, 0, 430f), bw = At(bb, 1, 620f), bh = At(bb, 2, 250f), by = At(bb, 3, 0f);
|
||
|
|
var brt = bubble.rectTransform;
|
||
|
|
brt.anchoredPosition = new Vector2(bx, by);
|
||
|
|
brt.sizeDelta = new Vector2(bw, bh);
|
||
|
|
float pc = At(pt, 2, 400f), pp = At(pt, 3, 340f);
|
||
|
|
var pos = new Vector2(At(pt, 0, 250f), At(pt, 1, 170f));
|
||
|
|
portrait.rectTransform.anchoredPosition = pos;
|
||
|
|
portrait.rectTransform.sizeDelta = new Vector2(pc, pc);
|
||
|
|
portrait.sprite = req.portrait;
|
||
|
|
portrait.enabled = req.portrait != null;
|
||
|
|
plate.rectTransform.anchoredPosition = pos;
|
||
|
|
plate.rectTransform.sizeDelta = new Vector2(pp, pp);
|
||
|
|
plate.color = req.plate;
|
||
|
|
plate.enabled = req.plate.a > 0.01f;
|
||
|
|
float top = Mathf.Max(by + bh + nameTag.rectTransform.sizeDelta.y * 0.5f, pos.y + Mathf.Max(pc, pp) * 0.5f);
|
||
|
|
block.sizeDelta = new Vector2(DesignW, top);
|
||
|
|
|
||
|
|
nameTag.gameObject.SetActive(req.name.Length > 0);
|
||
|
|
nameTag.color = req.tagTint;
|
||
|
|
nameText.text = req.name;
|
||
|
|
var nt = L("name_tag");
|
||
|
|
nameTag.rectTransform.sizeDelta = new Vector2(Mathf.Ceil(nameText.preferredWidth) + 2f * At(nt, 4, 26f), nameTag.rectTransform.sizeDelta.y);
|
||
|
|
body.text = "";
|
||
|
|
nextMark.gameObject.SetActive(false);
|
||
|
|
|
||
|
|
hasHole = false;
|
||
|
|
Refit(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Hide()
|
||
|
|
{
|
||
|
|
Shown = false;
|
||
|
|
req = null;
|
||
|
|
hasHole = false;
|
||
|
|
Taps = 0;
|
||
|
|
if (gameObject.activeSelf) gameObject.SetActive(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>화면 누름(어두운 판 · 말풍선 · 테스트) — 대사가 나오는 중이면 전부 보여 주고, 다 나왔으면 누름 수를 더한다.</summary>
|
||
|
|
public void Tap()
|
||
|
|
{
|
||
|
|
if (!Shown || req == null) return;
|
||
|
|
if (Typing)
|
||
|
|
{
|
||
|
|
shownChars = req.text.Length;
|
||
|
|
body.text = req.text;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
Taps++;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---------- 매 프레임 ----------
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
if (!Shown || req == null) return;
|
||
|
|
float dt = Time.unscaledDeltaTime;
|
||
|
|
clock += dt;
|
||
|
|
if (shownChars < req.text.Length)
|
||
|
|
{
|
||
|
|
shownChars = Mathf.Min(req.text.Length, shownChars + charsPerSec * dt);
|
||
|
|
string s = req.text.Substring(0, Mathf.FloorToInt(shownChars));
|
||
|
|
if (body.text != s) body.text = s;
|
||
|
|
}
|
||
|
|
// 다음 표시(▼) = 대사가 다 나온 뒤 · 누르게 하는 줄에는 없음
|
||
|
|
bool mark = !Typing && req.mode != FirstFlowData.Press;
|
||
|
|
if (nextMark.gameObject.activeSelf != mark) nextMark.gameObject.SetActive(mark);
|
||
|
|
if (mark)
|
||
|
|
{
|
||
|
|
var c = nextMark.color;
|
||
|
|
c.a = 0.35f + 0.65f * (0.5f + 0.5f * Mathf.Cos(clock / nextPeriod * Mathf.PI * 2f));
|
||
|
|
nextMark.color = c;
|
||
|
|
}
|
||
|
|
if (hasHole && req.mode == FirstFlowData.Press)
|
||
|
|
{
|
||
|
|
float a = Mathf.Lerp(frameMin, 1f, 0.5f + 0.5f * Mathf.Cos(clock / framePeriod * Mathf.PI * 2f));
|
||
|
|
var fc = new Color(frameColor.r, frameColor.g, frameColor.b, frameColor.a * a);
|
||
|
|
for (int i = 0; i < 4; i++) frame[i].color = fc;
|
||
|
|
float bob = fingerBob * (0.5f + 0.5f * Mathf.Sin(clock / fingerPeriod * Mathf.PI * 2f));
|
||
|
|
finger.rectTransform.anchoredPosition = fingerHome + new Vector2(bob, -bob); // 손가락 끝이 대상 쪽(왼쪽 위)을 까딱까딱 가리킴
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void LateUpdate()
|
||
|
|
{
|
||
|
|
if (Shown && req != null) Refit(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>대상 칸을 다시 재고(화면 전환 · 스크롤로 움직였을 때만) 어두운 판 · 테 · 손가락 · 대화 칸 자리를 맞춘다.</summary>
|
||
|
|
void Refit(bool force)
|
||
|
|
{
|
||
|
|
Rect h;
|
||
|
|
bool has = TargetRect(out h);
|
||
|
|
if (!force && has == hasHole && (!has || Near(h, hole))) return;
|
||
|
|
hasHole = has;
|
||
|
|
hole = h;
|
||
|
|
Layout();
|
||
|
|
}
|
||
|
|
|
||
|
|
static bool Near(Rect a, Rect b)
|
||
|
|
{
|
||
|
|
return Mathf.Abs(a.xMin - b.xMin) < 0.5f && Mathf.Abs(a.yMin - b.yMin) < 0.5f && Mathf.Abs(a.xMax - b.xMax) < 0.5f && Mathf.Abs(a.yMax - b.yMax) < 0.5f;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>대상들을 합친 칸(루트 좌표 · 자식 그림까지 · 표 focus_frame 의 여백만큼 넓힘) — 대상이 없거나 꺼져 있으면 false.</summary>
|
||
|
|
bool TargetRect(out Rect r)
|
||
|
|
{
|
||
|
|
r = new Rect();
|
||
|
|
if (req == null || req.targets == null || req.mode == FirstFlowData.Talk) return false;
|
||
|
|
bool any = false;
|
||
|
|
var b = new Bounds();
|
||
|
|
foreach (var t in req.targets)
|
||
|
|
{
|
||
|
|
if (t == null || !t.gameObject.activeInHierarchy) continue;
|
||
|
|
var tb = RectTransformUtility.CalculateRelativeRectTransformBounds(root, t);
|
||
|
|
if (tb.size.x < 1f && tb.size.y < 1f) continue;
|
||
|
|
if (!any) b = tb;
|
||
|
|
else b.Encapsulate(tb);
|
||
|
|
any = true;
|
||
|
|
}
|
||
|
|
if (!any) return false;
|
||
|
|
float pad = At(L("focus_frame"), 0, 10f);
|
||
|
|
var full = root.rect;
|
||
|
|
r = Rect.MinMaxRect(Mathf.Max(full.xMin, b.min.x - pad), Mathf.Max(full.yMin, b.min.y - pad), Mathf.Min(full.xMax, b.max.x + pad), Mathf.Min(full.yMax, b.max.y + pad));
|
||
|
|
return r.width > 1f && r.height > 1f;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Layout()
|
||
|
|
{
|
||
|
|
var full = root.rect;
|
||
|
|
if (!hasHole)
|
||
|
|
{
|
||
|
|
Place(dims[0], full);
|
||
|
|
for (int i = 1; i < 4; i++) dims[i].gameObject.SetActive(false);
|
||
|
|
dims[0].gameObject.SetActive(true);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Place(dims[0], Rect.MinMaxRect(full.xMin, hole.yMax, full.xMax, full.yMax)); // 위
|
||
|
|
Place(dims[1], Rect.MinMaxRect(full.xMin, full.yMin, full.xMax, hole.yMin)); // 아래
|
||
|
|
Place(dims[2], Rect.MinMaxRect(full.xMin, hole.yMin, hole.xMin, hole.yMax)); // 왼쪽
|
||
|
|
Place(dims[3], Rect.MinMaxRect(hole.xMax, hole.yMin, full.xMax, hole.yMax)); // 오른쪽
|
||
|
|
for (int i = 0; i < 4; i++) dims[i].gameObject.SetActive(true);
|
||
|
|
}
|
||
|
|
bool point = hasHole && req.mode == FirstFlowData.Point;
|
||
|
|
holeBlock.gameObject.SetActive(point);
|
||
|
|
if (point) Place(holeBlock, hole);
|
||
|
|
|
||
|
|
bool press = hasHole && req.mode == FirstFlowData.Press;
|
||
|
|
bool lit = hasHole && req.mode != FirstFlowData.Talk;
|
||
|
|
float w = At(L("focus_frame"), 1, 8f);
|
||
|
|
for (int i = 0; i < 4; i++) frame[i].gameObject.SetActive(lit);
|
||
|
|
if (lit)
|
||
|
|
{
|
||
|
|
Place(frame[0], Rect.MinMaxRect(hole.xMin - w, hole.yMax, hole.xMax + w, hole.yMax + w));
|
||
|
|
Place(frame[1], Rect.MinMaxRect(hole.xMin - w, hole.yMin - w, hole.xMax + w, hole.yMin));
|
||
|
|
Place(frame[2], Rect.MinMaxRect(hole.xMin - w, hole.yMin, hole.xMin, hole.yMax));
|
||
|
|
Place(frame[3], Rect.MinMaxRect(hole.xMax, hole.yMin, hole.xMax + w, hole.yMax));
|
||
|
|
for (int i = 0; i < 4; i++) frame[i].color = frameColor;
|
||
|
|
}
|
||
|
|
finger.gameObject.SetActive(press);
|
||
|
|
if (press)
|
||
|
|
{
|
||
|
|
var fg = L("finger");
|
||
|
|
fingerHome = hole.center + new Vector2(hole.width * At(fg, 1, 0.22f), hole.height * At(fg, 2, -0.18f));
|
||
|
|
// 손 그림(손가락 끝 = 피벗 · 그림은 오른쪽 아래로 뻗음)이 화면 밖으로 잘리지 않게 끝 자리를 안쪽으로
|
||
|
|
var frt = finger.rectTransform;
|
||
|
|
float right = frt.sizeDelta.x * (1f - frt.pivot.x) + fingerBob, down = frt.sizeDelta.y * frt.pivot.y + fingerBob;
|
||
|
|
fingerHome.x = Mathf.Min(fingerHome.x, full.xMax - right);
|
||
|
|
fingerHome.y = Mathf.Max(fingerHome.y, full.yMin + down);
|
||
|
|
frt.anchoredPosition = fingerHome;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 대화 칸 = 화면 아래 · 대상과 겹치면 대상 위(자리가 없으면 대상 아래)
|
||
|
|
var tk = L("talk"); // 아래에서 y | 대상과의 간격 | 화면 위끝 여백
|
||
|
|
float bottom = At(tk, 0, 190f), gap = At(tk, 1, 40f), topPad = At(tk, 2, 150f);
|
||
|
|
float hgt = block.sizeDelta.y;
|
||
|
|
float y = bottom;
|
||
|
|
if (hasHole)
|
||
|
|
{
|
||
|
|
float h0 = hole.yMin - full.yMin, h1 = hole.yMax - full.yMin; // 화면 아래에서 잰 대상의 아래 · 위
|
||
|
|
if (h1 + gap > y && h0 - gap < y + hgt)
|
||
|
|
{
|
||
|
|
float above = h1 + gap + w;
|
||
|
|
if (above + hgt <= full.height - topPad) y = above;
|
||
|
|
else if (h0 - gap - w - hgt >= 0f) y = h0 - gap - w - hgt;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
block.anchoredPosition = new Vector2(0f, y);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void Place(Image img, Rect r)
|
||
|
|
{
|
||
|
|
var rt = img.rectTransform;
|
||
|
|
rt.anchoredPosition = r.center;
|
||
|
|
rt.sizeDelta = new Vector2(Mathf.Max(0f, r.width), Mathf.Max(0f, r.height));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|