| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- using System;
- using System.Collections;
- using DiamondArrow.Platform;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace DiamondArrow
- {
- public sealed partial class DiamondArrowGame : MonoBehaviour
- {
- public TextAsset levelData;
- public NeonTheme theme;
- public HomeLayoutView homeLayout;
- public VictoryView victoryLayout;
- public LevelBook Book { get; private set; }
- public PlayerSave Save { get; private set; }
- public GameSession Run { get; private set; }
- public string CurrentScreen { get; private set; }
- public string CurrentModal { get; private set; }
- SaveStore store;
- RectTransform canvasRect,root,screen,modal,toastRoot;
- Sprite[] icons,avatarSprites;
- ArrowBoard board;
- Text gemsText,timeText,heartsText,leftText,toastText;
- Image heartIcon;int lastHearts=-1;
- RectTransform timeFill;
- readonly Text[] toolCounts=new Text[3];
- readonly Button[] toolButtons=new Button[3];
- float toastEnd,readyAt;
- bool appPaused,resultScheduled,chestBusy;
- int tutorialStep;
- RectTransform tutorialBubble;
- GameAudio gameAudio;
- int lastCountdownSecond=-1;
- static readonly Color TileTop = Neon.Hex("#372544");
- static readonly Color TileBottom = Neon.Hex("#190E24");
- static readonly Color ArmedTop = Neon.Hex("#78365F");
- readonly System.Random random=new System.Random();
- PlatformServices platform;
- Text profileName, chestActionText;
- Image profilePortrait;
- HomeLayoutView lobby;
- VictoryView victory;
- Button chestAction;
- bool rewardPending;
- long lastChestDisplaySecond = -1;
- string DisplayName => string.IsNullOrWhiteSpace(platform.PlayerName) ? Save.name : platform.PlayerName;
- string Today=>DateTime.Now.ToString("yyyy-MM-dd");
- Font Font=>theme.font!=null?theme.font:Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
- void Awake()
- {
- Application.targetFrameRate=60;
- #if UNITY_IOS
- Screen.orientation=ScreenOrientation.Portrait;
- #endif
- #if UNITY_EDITOR
- Application.runInBackground=true;
- #endif
- Book=LevelBook.Parse(levelData.text);var issues=Book.Validate();if(issues.Count>0)throw new InvalidOperationException(string.Join("; ",issues));
- store=new SaveStore(Application.persistentDataPath);Save=store.Load();
- icons=new Sprite[16];float cell=theme.icons.width/4f;
- for(int i=0;i<16;i++)icons[i]=Sprite.Create(theme.icons,new Rect(i%4*cell,theme.icons.height-(i/4+1)*cell,cell,cell),new Vector2(.5f,.5f),100);
- if(!theme.avatarAtlas)Debug.LogError("Diamond Arrow: avatar atlas is unassigned. Run Diamond Arrow/Refresh avatar portraits.",this);
- if(theme.avatarAtlas){avatarSprites=new Sprite[AvatarCatalog.NewCount];float aw=theme.avatarAtlas.width/3f,ah=theme.avatarAtlas.height/2f;for(int i=0;i<avatarSprites.Length;i++)avatarSprites[i]=Sprite.Create(theme.avatarAtlas,new Rect(i%3*aw,theme.avatarAtlas.height-(i/3+1)*ah,aw,ah),new Vector2(.5f,.5f),100);}
- BuildCanvas();CreateAudio();ShowLoading();
- if (Save.InitializeGuest(random)) Persist();
- var services = new GameObject("DiamondServices-" + Guid.NewGuid().ToString("N"));
- services.transform.SetParent(transform, false);
- platform = services.AddComponent<PlatformServices>();
- platform.ProfileChanged += RefreshIdentity;
- AppRuntimesEvents.OnPlatformOpen += OnPlatformOpen;
- platform.Initialize();
- }
- void OnDestroy(){AppRuntimesEvents.OnPlatformOpen-=OnPlatformOpen;if(platform)platform.ProfileChanged-=RefreshIdentity;if(icons!=null)foreach(var s in icons)if(s!=null)Destroy(s);if(avatarSprites!=null)foreach(var s in avatarSprites)if(s)Destroy(s);}
- void OnPlatformOpen()
- {
- Save.music = false;
- gameAudio.StopMusic();
- Persist();
- if (CurrentModal == "SETTINGS") ShowSettings();
- }
- void Update()
- {
- if (CurrentScreen == "Lobby") RefreshChestControls(DateTimeOffset.Now);
- if(toastRoot&&Time.unscaledTime>toastEnd)toastRoot.gameObject.SetActive(false);
- if(Run!=null&&CurrentScreen=="Game"&&Run.Status==RunStatus.Playing&&modal==null&&tutorialStep==0&&!appPaused&&Time.unscaledTime>=readyAt)
- { Run.Tick(Time.unscaledDeltaTime);UpdateGameHud();CountdownAudio();if(Run.Status!=RunStatus.Playing)ScheduleOutcome(); }
- if(!rewardPending && Input.GetKeyDown(KeyCode.Escape)) { if(modal!=null&&!chestBusy&&CurrentModal!="Result"&&CurrentModal!="Fail")CloseModal();else if(CurrentScreen=="Game")ShowQuit(); }
- }
- void OnApplicationPause(bool paused){appPaused=paused;if(gameAudio)gameAudio.SetSuspended(paused);if(paused)Persist();}
- void OnApplicationFocus(bool focused){appPaused=!focused;}
- void OnApplicationQuit(){if(Save!=null)Persist();}
- void Persist(){if(store==null||Save==null)return;if(!store.Save(Save))Toast("Unable to save progress on this device");}
- void BuildCanvas()
- {
- var go=new GameObject("DiamondArrowCanvas",typeof(RectTransform),typeof(Canvas),typeof(CanvasScaler),typeof(GraphicRaycaster));go.transform.SetParent(transform,false);
- var canvas=go.GetComponent<Canvas>();canvas.renderMode=RenderMode.ScreenSpaceCamera;canvas.worldCamera=Camera.main;canvas.planeDistance=10;canvas.sortingOrder=10;canvas.additionalShaderChannels=AdditionalCanvasShaderChannels.TexCoord1|AdditionalCanvasShaderChannels.TexCoord2|AdditionalCanvasShaderChannels.TexCoord3;
- var scaler=go.GetComponent<CanvasScaler>();scaler.uiScaleMode=CanvasScaler.ScaleMode.ScaleWithScreenSize;scaler.referenceResolution=new Vector2(750,1334);scaler.matchWidthOrHeight=.5f;
- canvasRect=(RectTransform)go.transform;
- var backdrop = Node(canvasRect, "Background", 0, 0, 750, 1334);
- backdrop.pivot = new Vector2(.5f, .5f);
- var image = backdrop.gameObject.AddComponent<Image>();
- image.sprite = theme.background;
- image.raycastTarget = false;
- var aspect = backdrop.gameObject.AddComponent<AspectRatioFitter>();
- aspect.aspectRatio = image.sprite.rect.width / image.sprite.rect.height;
- aspect.aspectMode = AspectRatioFitter.AspectMode.EnvelopeParent;
- root=Node(canvasRect,"SafeArea",0,0,750,1334);root.anchorMin=root.anchorMax=root.pivot=new Vector2(.5f,.5f);root.anchoredPosition=Vector2.zero;
- var safe=go.AddComponent<SafeCanvas>();safe.content=root;safe.Apply();
- if(EventSystem.current==null)new GameObject("DiamondArrowEventSystem",typeof(EventSystem),typeof(StandaloneInputModule)).transform.SetParent(transform);
- toastRoot=Panel(root,"Toast",65,1125,620,70,false);toastRoot.anchorMin=toastRoot.anchorMax=new Vector2(.5f,0);toastRoot.anchoredPosition=new Vector2(-310,209);toastText=Label(toastRoot,"",18,12,584,46,22,Neon.Ice);toastRoot.gameObject.SetActive(false);
- }
- public void Toast(string message){if(!toastRoot)return;toastText.text=message;toastRoot.gameObject.SetActive(true);toastRoot.SetAsLastSibling();toastEnd=Time.unscaledTime+2.8f;}
- void ClearScreen(string name)
- {
- StopAllCoroutines();CloseModal();if(screen){screen.gameObject.SetActive(false);Destroy(screen.gameObject);}board=null;gemsText=null;tutorialStep=0;tutorialBubble=null;resultScheduled=false;chestBusy=false;
- lobby = null;
- CurrentScreen=name;if(gameAudio)gameAudio.SetGameplay(name=="Game");screen=Node(root,name,0,0,750,1334);screen.SetAsFirstSibling();
- if (name == "Lobby") Stretch(screen);
- else Center(screen);
- }
- static void Stretch(RectTransform rect)
- {
- rect.anchorMin = Vector2.zero;
- rect.anchorMax = Vector2.one;
- rect.offsetMin = rect.offsetMax = Vector2.zero;
- }
- static void Center(RectTransform rect)
- {
- rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(.5f, .5f);
- rect.anchoredPosition = Vector2.zero;
- }
- void ShowLoading(){ClearScreen("Loading");Logo(screen,70,360,610,210);Label(screen,"OPENING THE VAULT",100,640,550,40,22,Neon.Ice);var fill=Panel(screen,"Loading bar",120,710,510,12,false);StartCoroutine(Loading(fill));}
- IEnumerator Loading(RectTransform bar){for(float t=0;t<1.1f;t+=Time.unscaledDeltaTime){bar.sizeDelta=new Vector2(510*t/1.1f,12);yield return null;}ShowStart();}
- public void ShowStart()
- {
- ClearScreen("Start");
- Logo(screen, 60, 368, 630, 216);
- Button(screen, "Start playing", 140, 918, 470, 104, "PLAY", () => {
- Save.seen = true;
- Persist();
- ShowLobby();
- }, true, 14);
- if (store.Warning != null) Toast(store.Warning);
- }
- Sprite PlayerPortrait()
- {
- int index = Save.avatar - AvatarCatalog.LegacyCount;
- Sprite local = avatarSprites != null && index >= 0 && index < avatarSprites.Length ? avatarSprites[index] : icons[0];
- return platform.Portrait ? platform.Portrait : local;
- }
- static void SetPortrait(RawImage portrait, Sprite sprite)
- {
- var texture = sprite.texture;
- var rect = sprite.rect;
- portrait.texture = texture;
- portrait.uvRect = new Rect(rect.x / texture.width, rect.y / texture.height,
- rect.width / texture.width, rect.height / texture.height);
- }
- void RefreshIdentity()
- {
- if (lobby)
- {
- lobby.nickname.text = DisplayName;
- SetPortrait(lobby.portrait, PlayerPortrait());
- }
- if (profileName) profileName.text = DisplayName;
- if (victory)
- {
- victory.playerName.text = DisplayName;
- SetPortrait(victory.portrait, PlayerPortrait());
- }
- if (profilePortrait) profilePortrait.sprite = PlayerPortrait();
- }
- Text FittedLabel(Text label)
- {
- label.supportRichText = false;
- label.resizeTextForBestFit = true;
- label.resizeTextMinSize = 12;
- label.resizeTextMaxSize = label.fontSize;
- return label;
- }
- public void ShowLobby()
- {
- ClearScreen("Lobby");
- Run = null;
- lobby = Instantiate(homeLayout, screen, false);
- // The persistent canvas backdrop extends beyond the lobby's safe area.
- lobby.previewBackground.SetActive(false);
- Stretch((RectTransform)lobby.transform);
- int number = Save.NextLevel;
- var level = Book.GetLevel(number);
- lobby.board.Configure(level);
- lobby.chapter.text = Book.Chapter(number).ToUpperInvariant();
- lobby.levelNumber.text = "LEVEL " + number;
- lobby.details.text = level.arrows.Length + " arrows · " + level.size + "×" + level.size + " · " + Clock(level.seconds);
- lobby.totalStars.text = Save.TotalStars.ToString();
- gemsText = lobby.balance;
- gemsText.text = Save.gems.ToString();
- RefreshIdentity();
- RefreshChestControls(DateTimeOffset.Now, true);
- BindAction(lobby.settings, ShowSettings);
- BindAction(lobby.diamonds, ShowDiamonds);
- BindAction(lobby.dailyChest, ShowChest);
- BindAction(lobby.checkIn, ShowCheckin);
- BindAction(lobby.shop, ShowShop);
- BindAction(lobby.help, ShowHelp);
- BindAction(lobby.play, () => StartLevel(number));
- }
- void BindAction(Button button, Action action)
- {
- button.onClick.AddListener(() => {
- Sound(SoundCue.Tap);
- action();
- });
- }
- public void StartLevel(int number)
- {
- if(!Save.Unlocked(number)){Toast("Clear the previous level first");return;}
- ClearScreen("Game");lastCountdownSecond=-1;Run=new GameSession(Book.GetLevel(number));readyAt=Time.unscaledTime+.65f;GameHeader();
- Label(screen,"STAGE",36,142,170,30,19,Neon.Muted,TextAnchor.MiddleLeft);Label(screen,number.ToString("00"),34,167,180,66,52,Color.white,TextAnchor.MiddleLeft);
- Label(screen,Book.Chapter(number),220,146,490,40,27,Neon.Ice,TextAnchor.MiddleRight);Label(screen,Run.Remaining+" arrows · "+Run.Level.size+"×"+Run.Level.size,260,194,450,30,20,Neon.Muted,TextAnchor.MiddleRight);
- timeText=Label(screen,"",32,234,132,42,27,Neon.Ice);var rail=Panel(screen,"Timer rail",180,247,530,13,false);rail.GetComponent<NeonPanel>().top=Neon.Hex("#251235");timeFill=Panel(rail,"Time remaining",0,0,530,13,false);timeFill.GetComponent<NeonPanel>().top=Neon.Ice;timeFill.GetComponent<NeonPanel>().bottom=Neon.Purple;
- var frame=Panel(screen,"Puzzle board",30,295,690,690);var viewport=Node(frame,"Arrow viewport",16,16,658,658);viewport.gameObject.AddComponent<RectMask2D>();var ar=Node(viewport,"Arrows",0,0,658,658);board=ar.gameObject.AddComponent<ArrowBoard>();board.Configure(Run.Level,Run);board.clicked=TapArrow;
- leftText=Label(screen,"",36,1000,678,42,23,Neon.Ice);
- BuildPowerUps();
- UpdateGameHud();
- if(number==1&&!Save.tutorial){tutorialStep=1;board.TutorialArrow=Run.FreeArrows()[0];TutorialBubble();}
- }
- void BuildPowerUps()
- {
- Label(screen, "POWER-UPS", 36, 1058, 678, 30, 18, Neon.Muted, TextAnchor.MiddleLeft);
- string[] names = { "Spotlight", "Hammer", "+1 Heart" };
- const float gap = 24, width = 214;
- for (int i = 0; i < names.Length; i++)
- {
- int tool = i;
- var item = TileButton(screen, names[i], 30 + i * (width + gap), 1104, width, 164, () => UseTool(tool));
- toolButtons[i] = item.GetComponent<Button>();
- item.gameObject.AddComponent<CanvasGroup>();
- Icon(item, 10 + i, 26, 20, 72);
- toolCounts[i] = FittedLabel(Label(item, "", 107, 32, 82, 44, 24, Neon.Ice));
- Label(item, names[i], 16, 108, width - 32, 40, 24, Color.white);
- }
- }
- RectTransform TileButton(Transform parent, string name, float x, float y, float width, float height, Action action)
- {
- var item = Button(parent, name, x, y, width, height, "", action, false, false);
- var face = item.GetComponent<NeonPanel>();
- face.top = TileTop;
- face.bottom = TileBottom;
- return item;
- }
- public void TapArrow(int index)
- {
- if(Run==null||modal!=null||Run.Status!=RunStatus.Playing||Time.unscaledTime<readyAt||tutorialStep>1)return;
- if(tutorialStep==1&&index!=board.TutorialArrow){Toast("Tap the gold arrow inside the ring");return;}
- int blocker=Run.Blocker(index);bool armed=Run.HammerArmed;var result=Run.Tap(index);
- if(result==TapResult.Ignored)return;
- if(result==TapResult.Blocked){board.Flash(index,blocker);Sound(SoundCue.Blocked);Buzz();}
- else{if(armed){Save.hammer--;Persist();}board.AnimateExit(index,result==TapResult.Smashed);Sound(result==TapResult.Smashed?SoundCue.Hammer:SoundCue.Slide);if(tutorialStep==1){tutorialStep=2;board.TutorialArrow=-1;TutorialBubble();}}
- UpdateGameHud();if(Run.Status!=RunStatus.Playing)ScheduleOutcome();
- }
- void UseTool(int tool)
- {
- if(Run==null||Run.Status!=RunStatus.Playing||tutorialStep!=0||modal!=null)return;
- if(tool==0){if(Save.spotlight<=0){Toast("Out of Spotlight · visit the shop");return;}var free=Run.FreeArrows();if(free.Count==0)return;Save.spotlight--;board.highlight=free[random.Next(free.Count)];board.highlightUntil=Time.unscaledTime+4.2f;Toast("Follow the golden glow");Sound(SoundCue.Hint);}
- if(tool==1){if(Save.hammer<=0){Toast("Out of Hammer · visit the shop");return;}Run.HammerArmed=!Run.HammerArmed;Toast(Run.HammerArmed?"Tap an arrow to smash it":"Hammer cancelled");}
- if(tool==2){if(Save.heart<=0){Toast("Out of Heart refills · visit the shop");return;}if(!Run.RefillHeart()){Toast("Hearts are full");return;}Save.heart--;Toast("+1 heart");Sound(SoundCue.Heart);}
- Persist();UpdateGameHud();
- }
- void UpdateGameHud()
- {
- if(Run==null||!timeText)return;timeText.text=Clock(Run.TimeLeft);float ratio=Run.TimeLeft/Run.Level.seconds;timeText.color=ratio<=.16f?Color.red:ratio<=.42f?Neon.Gold:Neon.Ice;timeFill.sizeDelta=new Vector2(530*Mathf.Clamp01(ratio),13);
- heartsText.text="× "+Run.Hearts;heartsText.color=Run.Hearts<=1?Neon.Pink:Color.white;if(lastHearts!=Run.Hearts){lastHearts=Run.Hearts;heartIcon.color=Run.Hearts==0?new Color(.6f,.45f,.65f,.5f):Color.white;}leftText.text=Run.Remaining+" LEFT ━ "+Run.Mistakes+" mistakes";
- toolCounts[0].text = "× " + Save.spotlight;
- toolCounts[1].text = Run.HammerArmed ? "ON" : "× " + Save.hammer;
- toolCounts[2].text = "× " + Save.heart;
- bool[] available={Save.spotlight>0,Save.hammer>0,Save.heart>0&&Run.Hearts<5};
- for(int i=0;i<3;i++)if(toolButtons[i]){toolButtons[i].interactable=available[i];toolButtons[i].GetComponent<CanvasGroup>().alpha=available[i]?1:.38f;}
- var hammerFace = toolButtons[1].GetComponent<NeonPanel>();
- Color hammerColor = Run.HammerArmed ? ArmedTop : TileTop;
- if (hammerFace.top != hammerColor) { hammerFace.top = hammerColor; hammerFace.SetVerticesDirty(); }
- }
- void ScheduleOutcome(){if(resultScheduled)return;resultScheduled=true;StartCoroutine(Outcome());}
- IEnumerator Outcome(){yield return new WaitForSecondsRealtime(.42f);while(board&&board.HasActiveExits)yield return null;yield return new WaitForSecondsRealtime(.1f);if(Run.Status==RunStatus.Cleared)ShowResult();else ShowFail();}
- void TutorialBubble()
- {
- if(tutorialBubble){tutorialBubble.gameObject.SetActive(false);Destroy(tutorialBubble.gameObject);}tutorialBubble=Panel(screen,"Tutorial",50,1050,650,272);
- string[] title={"","TAP THE GOLD ARROW","BLOCKED ARROWS COST A HEART","CLEAR THE WHOLE BOARD"};string[] body={"","The ring marks its tip.\nTap anywhere on the gold arrow to slide it out.","Another arrow in the path? You lose a heart.\nYou have three. Look before you tap.","Remove every arrow before time runs out.\nNo mistakes earns three stars."};
- Label(tutorialBubble,title[tutorialStep],15,18,620,35,23,Neon.Ice);Label(tutorialBubble,body[tutorialStep],22,67,606,90,22,Color.white);
- if(tutorialStep>1)Button(tutorialBubble,"Tutorial next",175,168,300,88,tutorialStep==2?"GOT IT":"START",()=>{if(tutorialStep==2){tutorialStep=3;TutorialBubble();}else{tutorialStep=0;Save.tutorial=true;Persist();tutorialBubble.gameObject.SetActive(false);Destroy(tutorialBubble.gameObject);tutorialBubble=null;readyAt=Time.unscaledTime+.2f;}},true);
- }
- void GameHeader()
- {
- var back=Button(screen,"Back",30,38,80,80,"",ShowQuit,false);Icon(back,15,14,14,52);Logo(screen,122,12,418,139);
- var health=Panel(screen,"Lives",552,38,168,82);health.GetComponent<NeonPanel>().accent=Neon.Pink;heartIcon=Icon(health,12,5,3,76);heartsText=Label(health,"",78,18,82,46,32,Color.white);lastHearts=-1;
- }
- static string Clock(float sec){int s=Mathf.CeilToInt(Mathf.Max(0,sec));return s/60+":"+(s%60).ToString("00");}
- RectTransform Node(Transform parent,string name,float x,float y,float w,float h)
- {
- var r=new GameObject(name,typeof(RectTransform)).GetComponent<RectTransform>();r.SetParent(parent,false);r.anchorMin=r.anchorMax=new Vector2(0,1);r.pivot=new Vector2(0,1);r.anchoredPosition=new Vector2(x,-y);r.sizeDelta=new Vector2(w,h);return r;
- }
- RectTransform Panel(Transform parent,string name,float x,float y,float w,float h,bool frame=true)
- {var r=Node(parent,name,x,y,w,h);var p=r.gameObject.AddComponent<NeonPanel>();p.material=theme.surfaceMaterial;p.frame=frame;p.raycastTarget=false;p.top=Neon.Hex("#29163D");p.bottom=Neon.Hex("#0A0514");if(name=="Puzzle board"||name=="Board frame"){p.surface=5;p.accent=Neon.Hex("#9B64D1");}return r;}
- Text Label(Transform parent,string content,float x,float y,float w,float h,int size,Color color,TextAnchor alignment=TextAnchor.MiddleCenter)
- {
- var r=Node(parent,string.IsNullOrEmpty(content)?"Text":content,x,y,w,h);var text=r.gameObject.AddComponent<Text>();text.font=Font;text.text=content;text.fontSize=size;text.fontStyle=FontStyle.Bold;text.color=color;text.alignment=alignment;text.raycastTarget=false;text.horizontalOverflow=HorizontalWrapMode.Wrap;text.verticalOverflow=VerticalWrapMode.Truncate;if(size>=24){var shadow=r.gameObject.AddComponent<Shadow>();shadow.effectColor=new Color(.015f,0,.035f,.6f);shadow.effectDistance=new Vector2(0,-2);}return text;
- }
- RectTransform Button(Transform parent,string name,float x,float y,float w,float h,string title,Action action,bool primary=false,int icon=-1)
- {return MakeButton(parent,name,x,y,w,h,title,action,primary,true,icon);}
- RectTransform Button(Transform parent,string name,float x,float y,float w,float h,string title,Action action,bool primary,bool frame)
- {return MakeButton(parent,name,x,y,w,h,title,action,primary,frame,-1);}
- RectTransform MakeButton(Transform parent,string name,float x,float y,float w,float h,string title,Action action,bool primary,bool frame,int icon)
- {
- if(frame&&!string.IsNullOrEmpty(title)){h=Mathf.Max(88,h);w=Mathf.Max(88,w);}
- var r=Panel(parent,name,x,y,w,h,frame);var graphic=r.GetComponent<NeonPanel>();graphic.raycastTarget=true;graphic.surface=primary?3:4;if(primary){graphic.top=Neon.Hex("#ED259F");graphic.bottom=Neon.Hex("#850057");}else if(!frame){graphic.top=new Color(0,0,0,0);graphic.bottom=graphic.top;}
- var b=r.gameObject.AddComponent<UnityEngine.UI.Button>();b.targetGraphic=graphic;r.gameObject.AddComponent<ButtonDepth>();var colors=b.colors;colors.highlightedColor=new Color(1,.9f,1);colors.pressedColor=new Color(.65f,.5f,.75f);b.colors=colors;b.onClick.AddListener(()=>{Sound(SoundCue.Tap);action?.Invoke();});
- if(!string.IsNullOrEmpty(title))Label(r,title,icon>=0?42:10,4,w-(icon>=0?58:20),h-8,primary?32:25,Color.white);
- if(icon>=0)Icon(r,icon,w*.24f,Mathf.Max(6,(h-36)/2),36);return r;
- }
- Image Icon(Transform parent,int id,float x,float y,float size,Color? tint=null){var r=Node(parent,"Icon "+id,x,y,size,size);var im=r.gameObject.AddComponent<Image>();im.sprite=icons[id];im.preserveAspect=true;im.color=tint??Color.white;im.raycastTarget=false;return im;}
- void Logo(Transform parent,float x,float y,float w,float h){var r=Node(parent,"Logo",x,y,w,h);var im=r.gameObject.AddComponent<Image>();im.sprite=theme.logo;im.preserveAspect=true;im.raycastTarget=false;}
- void Rule(Transform parent,float x,float y,float w,Color color,float h=1){var line=Panel(parent,"Etched separator",x,y,w,h,false);var g=line.GetComponent<NeonPanel>();g.radius=0;g.top=new Color(color.r,color.g,color.b,.4f);g.bottom=g.top;}
- public void DebugShowLobby(){ShowLobby();}
- }
- }
|