CabinetArtwork.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace Fateforge.Editor
  5. {
  6. public static class CabinetArtwork
  7. {
  8. const string Art = "Assets/Fateforge/Art/PhysicalCasino/";
  9. const string Shop = "Assets/Fateforge/Resources/Fateforge/Art/assets/graphics/sprites/kit_ui_shop_interface/";
  10. const string Audio = "Assets/Fateforge/Resources/Fateforge/Audio/sfx/";
  11. public static void Load(UiTheme theme)
  12. {
  13. theme.coinSprite = AssetDatabase.LoadAssetAtPath<Sprite>(Art + "CoinStack.png");
  14. theme.helpBadge = AssetDatabase.LoadAssetAtPath<Sprite>(Art + "HelpBadge.png");
  15. theme.leverHub = AssetDatabase.LoadAssetAtPath<Sprite>(Art + "LeverHub.png");
  16. theme.leverRod = AssetDatabase.LoadAssetAtPath<Sprite>(Art + "LeverRod.png");
  17. theme.leverKnob = AssetDatabase.LoadAssetAtPath<Sprite>(Art + "LeverKnob.png");
  18. theme.unlockSprite = AssetDatabase.LoadAssetAtPath<Sprite>(Art + "UnlockPlus.png");
  19. theme.rerollSprite = AssetDatabase.LoadAssetAtPath<Sprite>(Shop + "reroll_button_normal.png");
  20. theme.ticketRip = AssetDatabase.LoadAssetAtPath<AudioClip>(Audio + "RS_ticket_rip_1.ogg");
  21. theme.defeatStinger = AssetDatabase.LoadAssetAtPath<AudioClip>(Audio + "CHA_MUS_STINGER_DEFEAT_03.ogg");
  22. theme.scoreTick = AssetDatabase.LoadAssetAtPath<AudioClip>(Audio + "score/RS_score_ratchet_1.ogg");
  23. theme.scoreImpact = AssetDatabase.LoadAssetAtPath<AudioClip>(Audio + "score/RS_score_impact.ogg");
  24. theme.defeatArt=AssetDatabase.LoadAssetAtPath<Sprite>(Art+"AfterHours.png");
  25. theme.magnetActivation=AssetDatabase.LoadAssetAtPath<AudioClip>(Audio+"combinations/RS_magnet_electric_activation_1.ogg");
  26. EditorUtility.SetDirty(theme);
  27. }
  28. // Also upgrades an already authored scene without rebuilding unrelated assets.
  29. public static void Apply(ViewBindings view)
  30. {
  31. Load(view.theme);
  32. SetCoin(view.play.Find("CoinIcon"), view.theme);
  33. var help = (Image)view.help.targetGraphic;
  34. help.sprite = view.theme.helpBadge;
  35. help.color = Color.white;
  36. var helpLabel=view.help.GetComponentInChildren<TMPro.TMP_Text>(true);
  37. helpLabel.text="";
  38. helpLabel.enabled=false;
  39. string path = AssetDatabase.GetAssetPath(view.offerPrefab);
  40. var root = PrefabUtility.LoadPrefabContents(path);
  41. try
  42. {
  43. var offer = root.GetComponent<OfferView>();
  44. offer.priceCoin = SetCoin(offer.buy.transform.Find("PriceCoin"), view.theme);
  45. PrefabUtility.SaveAsPrefabAsset(root, path);
  46. }
  47. finally { PrefabUtility.UnloadPrefabContents(root); }
  48. }
  49. static Image SetCoin(Transform node, UiTheme theme)
  50. {
  51. if (node.TryGetComponent<UiGlyph>(out var old)) Object.DestroyImmediate(old);
  52. if (!node.TryGetComponent<Image>(out var image)) image = node.gameObject.AddComponent<Image>();
  53. image.sprite = theme.coinSprite;
  54. image.color = Color.white;
  55. image.preserveAspect = true;
  56. image.raycastTarget = false;
  57. return image;
  58. }
  59. }
  60. }