生态树抽奖所有接口的接入

This commit is contained in:
liuliang 2025-01-03 22:12:00 +08:00
parent 1ade8f23c6
commit e69d499263
8 changed files with 258 additions and 25 deletions

View File

@ -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

View File

@ -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<treeluckywheeldrawResponse> treeluckywheeldraws()//幸运转盘抽奖
{
return await treeluckywheeldraw.Treeluckywheeldraws();
}
public async Task<bool> Treeluckywheeldraws(string transid)//幸运转盘广告
{
treeluckywheeladvertBody body = new treeluckywheeladvertBody();
body.trans_id = transid;
return await treeluckywheeladvert.Treeluckywheeladverts(body);
}
}

View File

@ -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<string> prizeNames =new List<string>(); // 奖品的id
public float multipleRotations = 3f; // 转盘旋转的圈数
private float targetAngle; // 目标角度
private bool isSpinning = false; // 是否正在旋转
// 设置目标 ID根据 ID 停在哪个奖项上)
public int targetPrizeID;
public List<Text> 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
}

View File

@ -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<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.Data.access_token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "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<bool> 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<myResponse>(response);
bool succeffull;
if (response1.code == 200) { succeffull = true; } else { succeffull = false; }
return succeffull;
}
}
public class treeluckywheeladvertBody
{
public string trans_id;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f8f9bbe986bf9474587233fe228e3e15
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.Data.access_token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "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<treeluckywheeldrawResponse> Treeluckywheeldraws()
{
string response = await myWeb.SendRequest(myWeb.URL + "/api/tree/lucky_wheel_draw", "POST", "{}", CreateHeaders());
Debug.Log("幸运转盘" + response);
treeluckywheeldrawResponse treeluckywheeldrawresponse = JsonConvert.DeserializeObject<treeluckywheeldrawResponse>(response);
return treeluckywheeldrawresponse;
}
}
public class treeluckywheeldrawResponse:myResponse
{
public treeluckywheeldrawData data;
}
[System.Serializable]
public class treeluckywheeldrawData
{
public string uid; // 物品的唯一标识符
public string name; // 物品的名称
public int amount; // 物品的数量
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b330c5ea85c1b44086cb0f4254d8d22
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -30,8 +30,6 @@ public class userinviteconfig : MonoBehaviour
return userinviteconfigresponse;
}
}
[Serializable]