using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using Unity.VisualScripting; using UnityEngine; using UnityEngine.U2D; using UnityEngine.UI; using static UnityEditor.PlayerSettings; [System.Serializable] public struct Register { public string Phone; } [Serializable] public struct AddGold { public int Gold; } [Serializable] public struct Login { public string Phone; } [Serializable] public struct GetListByPhone { public string Phone; } [Serializable] public class Item//道具数据item { public int Id; public int Num; public int Type; public string Name; public float ActivateValue; public float StoreValue; public float Yield; public int Limit; public int EndureTime; public int RemainEndureTime; public List ReferrerBouns; public string CreateDateTime; } [Serializable] public class BuyuItem//捕鱼精灵数据item { public int Id; public int Num; public int Type; public string Name; public float ActivateValue; public float GenerateValue; public float GainOdds; public int EndureTime; public List ReferrerBouns; public string CreateDateTime; } [Serializable] public class BuyuList { public BuyuItem[] List; } [Serializable] public class VoucherItem//返回的代金卷数据 { public string Id; public int Num; public int Type; public string OwnerId; public string GeneratorId; public float ActivateValue; public float GenerateValue; public float AlreadyGenerateValue; public float RemainEndureTime; public float EndureTime; public string CreateDateTime; } /*[Serializable] public class JinshaItem//返回的精灵数据 { public string Id; public int Num; public int Type; public string OwnerId; public float StoreValue; public float AlreadyGenerateValue; public float GenerateValue; public float RemainEndureTime; public float EndureTime; public string CreateDateTime; } public class JInshalist { public JInshalist[] List; } */ [Serializable] public class Use_daijinjuan { public string Id; } [Serializable] public class Mining_Wizard_ID //挖矿精灵id { public string[] Ids; } [Serializable] public class Giveaway //赠送代金卷 { public string[] Ids; public string GiftTargetId; } [Serializable] public class AllVocherItem //所有代金卷数据 { public string Id; public string GeneratorId; public string OwnerId; public float Type; public float Num; public bool IsUsed; public bool IsAdmin; public string UsedDateTime; public string CreateDateTime; } [Serializable] public class Res//消息返回类 { public int ErrorCode; public string ErrorMessage; } [Serializable] public class AllVocherItemRes : Res { public AllVocherItem[] List; } [Serializable] public class Response : Res//挖矿精灵数据 { public Item[] List; } [Serializable] public class ResponseVoucher : Res//渔夫数据 { public VoucherItem[] List; } [Serializable] public class GenerateForFisherElf //渔夫购买数据 { public int Num; public int Count; } [Serializable] public class Use //使用道具 { public string Id; } [Serializable] public class ids:Res { public List Ids; } [Serializable] public class ItmeBuy//购买道具 { public int Num; public int Count; public int Type; } [System.Serializable] public class ItemData//道具类 所有的道具都是这个结构体 { public int Num; public string Name; public int Hp; public float HpUpMul; public int Attack; public float AttackUpMul; public int Defense; public float DefenseUpMul; public int AttackSpeed; public float AttackSpeedUpMul; public int Move; public float MoveUpMul; public int[] Skill; public int Attribute; public string LevelUpNeedThingsJson; public string Expand; public int Type; public int Rarity; public string WeaponBulletEffectPath; public string WeaponBulletHitEffectPath; public int UltimateSkill; public int Access; public int[] SellDate; public int Cash; public float CashDiscount; public int Gold; public float GoldDiscount; public int Gem; public float GemDiscount; public int IsSell; public string IconPath; public int IconAtlasLocation; } public class mount : MonoBehaviour { //图片缓存机制 public static Dictionary SpriteDic = new Dictionary(); public static Dictionary SpriteSheetDic = new Dictionary(); //游戏道具加载缓存 public Dictionary itemDataList = new Dictionary(); // 加载图片或图集中的某个Sprite的静态方法 public static Sprite LoadSprite(string path, int index = -1) { if (index == -1) { // 如果字典中已存在该图片,则直接返回缓存的纹理 if (SpriteDic.ContainsKey(path)) { return SpriteDic[path]; } // 从指定路径加载纹理 Sprite texture = Resources.Load(path); if (texture != null) { // 加载成功,将其缓存到字典中 SpriteDic[path] = texture; return texture; } else { Debug.LogError("加载纹理失败,路径:" + path); return null; } } else { // 如果字典中已存在该图集,则直接从缓存中返回 if (SpriteSheetDic.ContainsKey(path)) { Sprite[] sprites = SpriteSheetDic[path]; if (index >= 0 && index < sprites.Length) { return sprites[index]; } else { Debug.LogError("索引超出范围,路径:" + path); return null; } } // 从指定路径加载图集 Sprite[] spriteSheet = Resources.LoadAll(path); if (spriteSheet != null && spriteSheet.Length > 0) { // 加载成功,将其缓存到字典中 SpriteSheetDic[path] = spriteSheet; if (index >= 0 && index < spriteSheet.Length) { return spriteSheet[index]; } else { Debug.LogError("索引超出范围,路径:" + path); return null; } } else { Debug.LogError("加载图集失败,路径:" + path); return null; } } } public void LoadAllJsonFiles() { // 加载 Resources/json 文件夹内的所有 JSON 文件 TextAsset[] jsonFiles = Resources.LoadAll("json"); foreach (TextAsset jsonFile in jsonFiles) { // 使用 JsonUtility 解析每个 JSON 文件 ItemData itemData = JsonUtility.FromJson(jsonFile.text); itemDataList.Add(itemData.Num, itemData); } Debug.Log("物品json配置加载完成"); } public static mount mountitem; // Start is called before the first frame update public virtual void Awake() { DontDestroyOnLoad(this); //mountitem.login_screen(); } private void Start() { mountitem = this; LoadAllJsonFiles(); //game.GetComponent().sprite = LoadSprite("animation/miner_new/miner_stand_6",11); //give_firend(); } public GameObject add_pop_up(bool is_force = false)//添加弹窗 { GameObject prefab = Resources.Load("preform/gui/pop_up_ui"); GameObject ranking_list_item = Instantiate(prefab, this.transform); ranking_list_item.GetComponent().is_force = is_force; return ranking_list_item; } //0 输入框 //1 输入框带按钮 //2 取消按钮 确定按钮 //3 购买人才item //4 购买人才文字消息 public void login_screen()//注册界面 { List boxTypes = new List(); boxTypes.Add(new BoxType { Name = "account_number", textName = " 手机号", prompt= "请输入手机号", Type = 1, is_required = true }); boxTypes.Add(new BoxType { Name = "verification_code", textName = " 验证码 ", prompt = "请输入验证码", Type = 0, is_required = true }); boxTypes.Add(new BoxType { Name = "submit", textName = " 取消确定 ",Type = 2}); GameObject gameObject = add_pop_up(true);//生成弹窗母体 List gameObjects = gameObject.GetComponent().updateUI(boxTypes, "注册");//测试输入框回调处理 gameObjects[0].GetComponent().register_click((BoxType boxType,int type) =>//手机号获取验证码点击 { if (boxType.is_required && string.IsNullOrWhiteSpace(boxType.content)) { Promptmgr.Instance.PromptBubble("请不要" + boxType.textName + "为空"); return; } Debug.Log("获取验证码"); }); gameObjects[2].GetComponent().register_click(async (BoxType boxType, int type) =>//登录确定或取消 { if (type == 0){ gameObject.GetComponent().destroy(); } else if (type == 1){ Register register = new Register(); register.Phone = boxTypes[0].content; //register.Code = boxTypes[0].content; string jsonString = JsonUtility.ToJson(register); string response = await web.SendRequest("http://47.109.133.52/Player/Register", "POST", jsonString); Debug.Log(response); } }); } }