diff --git a/meng_yao/Assets/Scenes/scene_Main.unity b/meng_yao/Assets/Scenes/scene_Main.unity index d7cc74fc..502155b5 100644 --- a/meng_yao/Assets/Scenes/scene_Main.unity +++ b/meng_yao/Assets/Scenes/scene_Main.unity @@ -1967,7 +1967,7 @@ RectTransform: - {fileID: 1870468089} - {fileID: 1377878409} - {fileID: 1896852796} - - {fileID: 1037673228} + - {fileID: 688806162} - {fileID: 2110946833} - {fileID: 1000392733} - {fileID: 1777185130} @@ -19816,6 +19816,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 831700dc083b97641a10c7fcf7e532b4, type: 3} m_Name: m_EditorClassIdentifier: + spinSpeed: 500 + numberOfSegments: 6 + spinDuration: 3 + decelerationDuration: 1 + multipleRotations: 3 + targetPrizeID: 3 rewardlist: - {fileID: 1194945822} - {fileID: 164182623} @@ -19824,7 +19830,7 @@ MonoBehaviour: - {fileID: 488469915} - {fileID: 2029355234} PlayerBtn: {fileID: 2110946834} - PlayerPointer: {fileID: 1037673229} + PlayerPointer: {fileID: 688806162} GetNumber: {fileID: 1023722784} AdvertiseBtn: {fileID: 1182210765} --- !u!1 &225881885 @@ -60722,6 +60728,43 @@ RectTransform: m_AnchoredPosition: {x: 489, y: -186.8906} m_SizeDelta: {x: 100, y: 100} m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &688806161 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 688806162} + m_Layer: 5 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &688806162 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 688806161} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1037673228} + m_Father: {fileID: 28427002} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -1, y: -0} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &691481648 GameObject: m_ObjectHideFlags: 0 @@ -90163,17 +90206,17 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1037673227} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 28427002} - m_RootOrder: 3 + m_Father: {fileID: 688806162} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 38} + m_AnchoredPosition: {x: 1, y: 38} m_SizeDelta: {x: 332, y: 406} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1037673229 diff --git a/meng_yao/Assets/script/scene_Main/Scene_main_jiekou.cs b/meng_yao/Assets/script/scene_Main/Scene_main_jiekou.cs index 4c13986c..3df5cae3 100644 --- a/meng_yao/Assets/script/scene_Main/Scene_main_jiekou.cs +++ b/meng_yao/Assets/script/scene_Main/Scene_main_jiekou.cs @@ -48,7 +48,8 @@ public class Scene_main_jiekou :MonoBehaviour treebonusrank treebonusrank = new treebonusrank(); userinviteconfig userinviteconfig = new userinviteconfig(); treeluckywheel treeluckywheel = new treeluckywheel(); - + treeluckywheeldraw treeluckywheeldraw = new treeluckywheeldraw(); + treeluckywheeladvert treeluckywheeladvert = new treeluckywheeladvert(); public static Scene_main_jiekou instance; //public PlayerInfoData infoData; @@ -332,4 +333,18 @@ public class Scene_main_jiekou :MonoBehaviour { return await treeluckywheel.TreeluckyWheel(); } + + public async Task treeluckywheeldraws()//幸运转盘抽奖 + { + return await treeluckywheeldraw.Treeluckywheeldraws(); + } + + public async Task Treeluckywheeldraws(string transid)//幸运转盘广告 + { + treeluckywheeladvertBody body = new treeluckywheeladvertBody(); + body.trans_id = transid; + return await treeluckywheeladvert.Treeluckywheeladverts(body); + + } + } diff --git a/meng_yao/Assets/script/scene_Main/ui/ZhuanpanPanel.cs b/meng_yao/Assets/script/scene_Main/ui/ZhuanpanPanel.cs index 28c32f26..bef7f2c6 100644 --- a/meng_yao/Assets/script/scene_Main/ui/ZhuanpanPanel.cs +++ b/meng_yao/Assets/script/scene_Main/ui/ZhuanpanPanel.cs @@ -1,16 +1,31 @@ +using DG.Tweening; using System.Collections; using System.Collections.Generic; +using System.Reflection; using UnityEngine; using UnityEngine.UI; public class ZhuanpanPanel : MonoBehaviour { - + public float spinSpeed = 500f; // 旋转指针的速度 + public int numberOfSegments = 6; // 转盘分段的数量 + + public float spinDuration = 3f; // 总共旋转的时间(包括加速和减速) + public float decelerationDuration = 1f; // 减速的持续时间 + List prizeNames =new List(); // 奖品的id + public float multipleRotations = 3f; // 转盘旋转的圈数 + + private float targetAngle; // 目标角度 + private bool isSpinning = false; // 是否正在旋转 + + // 设置目标 ID(根据 ID 停在哪个奖项上) + public int targetPrizeID; public List rewardlist; public Button PlayerBtn; - public Image PlayerPointer; + public RectTransform PlayerPointer; + public Text GetNumber; @@ -19,28 +34,83 @@ public class ZhuanpanPanel : MonoBehaviour async void Start() { - TreeluckywheelResponse response = await Scene_main_jiekou.instance.TreeluckyWheels(); - for (int i = 0; i < response.data.items.Length; i++) - { - rewardlist[i].text = response.data.items[i].amount+"g"; - } - GetNumber.text ="看广告获得抽奖次数"+ response.data.count_watch +"/10"; + Init(); PlayerBtn.onClick.AddListener(PlayerClick); AdvertiseBtn.onClick.AddListener(AdvertiseClick); } + async void AdvertiseClick() + { + + bool issucceffull = await Scene_main_jiekou.instance.Treeluckywheeldraws("string"); + if (issucceffull) + { + Init(); + } + } + async void PlayerClick() + { + treeluckywheeldrawResponse response = await Scene_main_jiekou.instance.treeluckywheeldraws(); + if (response.code == 200) + { + for (int i = 0; i < prizeNames.Count; i++) + { + if (response.data.uid == prizeNames[i]) + { + targetPrizeID = i + 1; + break; + } + } + targetAngle = (360f / numberOfSegments * targetPrizeID) - 60f; + StartRotation();//启用协程 + } + else + { + Promptmgr.Instance.PromptBubble(response.message); + } + - void PlayerClick() - { - } - void AdvertiseClick() - { - + private async void Init() + { + TreeluckywheelResponse response = await Scene_main_jiekou.instance.TreeluckyWheels(); + for (int i = 0; i < response.data.items.Length; i++) + { + rewardlist[i].text = response.data.items[i].amount + "g"; + prizeNames.Add(response.data.items[i].uid); + } + GetNumber.text = "看广告获得抽奖次数" + response.data.count_watch + "/10"; } + public void StartRotation() + { + if (isSpinning) return; // 如果正在旋转中,则不执行 + isSpinning = true; + + // 先清除之前的所有动画,确保不会产生二次旋转 + DOTween.Kill(PlayerPointer); + + // 调用 DoTween 旋转函数 + SpinWheelWithDotween(); + } + + // 使用 DoTween 来旋转转盘 + private void SpinWheelWithDotween() + { + // 计算目标旋转角度,包括额外的多圈旋转 + float totalRotation = targetAngle + 360 * multipleRotations; + + // 通过 DoTween 旋转转盘,目标角度加上多个圈 + PlayerPointer.DORotate( + new Vector3(0, 0, -totalRotation), // 目标旋转角度 + spinDuration, // 动画时长 + RotateMode.FastBeyond360 // 允许快速旋转超过360度 + ) + .SetEase(Ease.InOutCubic) // 使用缓动函数控制加速与减速 + .OnKill(() => { // 动画结束时 + + }); + } - // Update is called once per frame - } diff --git a/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeladvert.cs b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeladvert.cs new file mode 100644 index 00000000..c12f1590 --- /dev/null +++ b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeladvert.cs @@ -0,0 +1,38 @@ +using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +public class treeluckywheeladvert : MonoBehaviour +{ + public Dictionary CreateHeaders() + { + if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.Data.access_token)) + { + Debug.LogWarning("尝试创建请求头时,token 未设置。"); + return new Dictionary(); + } + return new Dictionary + { + + { "Authorization","Bearer "+MyGlobal.global.loginResponse.Data.access_token }, + { "client-info", "{\"platform\":\"ios\",\"phone_product\":\"apple\",\"phone_model\":\"iPhone_8\",\"system_version\":\"12.0\",\"screen_size\":\"750*1334\",\"device_no\":\"e3e277810fff9d955ebdd7037eff51a8\",\"version\":\"1.0.0\"}" } + }; + } + + public async Task Treeluckywheeladverts(treeluckywheeladvertBody body) + { + string response = await myWeb.SendRequest(myWeb.URL + "/api/tree/lucky_wheel_advert", "POST", JsonConvert.SerializeObject(body), CreateHeaders()); + Debug.Log("幸运转盘" + response); + myResponse response1 = JsonConvert.DeserializeObject(response); + bool succeffull; + if (response1.code == 200) { succeffull = true; } else { succeffull = false; } + return succeffull; + } +} + +public class treeluckywheeladvertBody +{ + public string trans_id; +} diff --git a/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeladvert.cs.meta b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeladvert.cs.meta new file mode 100644 index 00000000..fa2f48b2 --- /dev/null +++ b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeladvert.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f8f9bbe986bf9474587233fe228e3e15 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeldraw.cs b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeldraw.cs new file mode 100644 index 00000000..686703b2 --- /dev/null +++ b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeldraw.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +public class treeluckywheeldraw : MonoBehaviour +{ + + public Dictionary CreateHeaders() + { + if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.Data.access_token)) + { + Debug.LogWarning("尝试创建请求头时,token 未设置。"); + return new Dictionary(); + } + return new Dictionary + { + + { "Authorization","Bearer "+MyGlobal.global.loginResponse.Data.access_token }, + { "client-info", "{\"platform\":\"ios\",\"phone_product\":\"apple\",\"phone_model\":\"iPhone_8\",\"system_version\":\"12.0\",\"screen_size\":\"750*1334\",\"device_no\":\"e3e277810fff9d955ebdd7037eff51a8\",\"version\":\"1.0.0\"}" } + }; + } + + public async Task Treeluckywheeldraws() + { + string response = await myWeb.SendRequest(myWeb.URL + "/api/tree/lucky_wheel_draw", "POST", "{}", CreateHeaders()); + Debug.Log("幸运转盘" + response); + treeluckywheeldrawResponse treeluckywheeldrawresponse = JsonConvert.DeserializeObject(response); + return treeluckywheeldrawresponse; + } + +} + +public class treeluckywheeldrawResponse:myResponse +{ + public treeluckywheeldrawData data; +} + +[System.Serializable] +public class treeluckywheeldrawData +{ + public string uid; // 物品的唯一标识符 + public string name; // 物品的名称 + public int amount; // 物品的数量 +} + diff --git a/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeldraw.cs.meta b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeldraw.cs.meta new file mode 100644 index 00000000..d7a7bbe1 --- /dev/null +++ b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/treeluckywheeldraw.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7b330c5ea85c1b44086cb0f4254d8d22 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/userinviteconfig.cs b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/userinviteconfig.cs index 376dac46..508f7af9 100644 --- a/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/userinviteconfig.cs +++ b/meng_yao/Assets/script/serveTestScript/treeModule/treeModuleNew/userinviteconfig.cs @@ -30,8 +30,6 @@ public class userinviteconfig : MonoBehaviour return userinviteconfigresponse; } - - } [Serializable]