This commit is contained in:
hyskai 2024-11-03 01:11:55 +08:00
parent a2cf1f4f49
commit d7823281af
10 changed files with 455 additions and 133 deletions

View File

@ -300,7 +300,6 @@ GameObject:
m_Component:
- component: {fileID: 56346249}
- component: {fileID: 56346250}
- component: {fileID: 56346251}
m_Layer: 0
m_Name: top3
m_TagString: Untagged
@ -355,48 +354,6 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 6.8632345, y: 4.257353}
m_EdgeRadius: 0
--- !u!114 &56346251
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 56346248}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9aea6b85491b20b4ea34c75ad09c4ec9, type: 3}
m_Name:
m_EditorClassIdentifier:
fishManPrefab: {fileID: 9155457817904467836, guid: 12cf12d921b09b343bdadb6638b7447c, type: 3}
startPos: {fileID: 423906224}
type: 2
isbuy: 0
isGoldLand: 1
paths:
- pathPoints:
- {fileID: 78513529}
- {fileID: 1127531261}
- {fileID: 2043484084}
- {fileID: 1863374491}
- {fileID: 323654385}
- pathPoints:
- {fileID: 964032477}
- {fileID: 1935800548}
- {fileID: 258516099}
- {fileID: 1004232774}
- {fileID: 2133241629}
- {fileID: 2024839349}
- {fileID: 874517737}
pathsNeedTimer: 30
fishingNeedTimer: 30
restTimer: 5
getgoldnumber: 100
goldshop: {fileID: 1621691472}
goldnumer: 0
goldNumerTextPro: {fileID: 1113669198}
HightLight: {fileID: 102276561}
Btntrans: {fileID: 56346249}
FishPrice: 0
--- !u!1 &78513528
GameObject:
m_ObjectHideFlags: 0
@ -2319,7 +2276,6 @@ GameObject:
m_Component:
- component: {fileID: 559443431}
- component: {fileID: 559443433}
- component: {fileID: 559443432}
m_Layer: 0
m_Name: top1
m_TagString: Untagged
@ -2348,48 +2304,6 @@ Transform:
m_Father: {fileID: 787643888}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &559443432
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 559443430}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9aea6b85491b20b4ea34c75ad09c4ec9, type: 3}
m_Name:
m_EditorClassIdentifier:
fishManPrefab: {fileID: 8759413356347716201, guid: 895559f95d4ca3b47a49156ec979e40c, type: 3}
startPos: {fileID: 1734571546}
type: 0
isbuy: 0
isGoldLand: 1
paths:
- pathPoints:
- {fileID: 1752358036}
- {fileID: 1082195120}
- {fileID: 2147345441}
- {fileID: 1445626387}
- {fileID: 339905144}
- pathPoints:
- {fileID: 211894328}
- {fileID: 1607578808}
- {fileID: 207042482}
- {fileID: 56093340}
- {fileID: 1086483495}
- {fileID: 258008391}
- {fileID: 1576490689}
pathsNeedTimer: 30
fishingNeedTimer: 30
restTimer: 3
getgoldnumber: 100
goldshop: {fileID: 1780327002}
goldnumer: 0
goldNumerTextPro: {fileID: 979148971}
HightLight: {fileID: 1504197550}
Btntrans: {fileID: 559443431}
FishPrice: 0
--- !u!61 &559443433
BoxCollider2D:
m_ObjectHideFlags: 0
@ -3864,7 +3778,6 @@ GameObject:
m_Component:
- component: {fileID: 1048058358}
- component: {fileID: 1048058359}
- component: {fileID: 1048058360}
m_Layer: 0
m_Name: top2
m_TagString: Untagged
@ -3919,48 +3832,6 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 5.8965707, y: 4.327156}
m_EdgeRadius: 0
--- !u!114 &1048058360
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1048058357}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9aea6b85491b20b4ea34c75ad09c4ec9, type: 3}
m_Name:
m_EditorClassIdentifier:
fishManPrefab: {fileID: 9027535534103199909, guid: 930941387799a9d479889a373bafdc8e, type: 3}
startPos: {fileID: 1067588907}
type: 1
isbuy: 0
isGoldLand: 1
paths:
- pathPoints:
- {fileID: 199805572}
- {fileID: 827362920}
- {fileID: 1332269050}
- {fileID: 1626887113}
- {fileID: 729948191}
- pathPoints:
- {fileID: 914569106}
- {fileID: 499830626}
- {fileID: 2063902009}
- {fileID: 1585686091}
- {fileID: 1328318913}
- {fileID: 2034494837}
- {fileID: 318175897}
pathsNeedTimer: 30
fishingNeedTimer: 30
restTimer: 5
getgoldnumber: 100
goldshop: {fileID: 784479835}
goldnumer: 0
goldNumerTextPro: {fileID: 1634093115}
HightLight: {fileID: 579933540}
Btntrans: {fileID: 1048058358}
FishPrice: 0
--- !u!1 &1067588906
GameObject:
m_ObjectHideFlags: 0
@ -6784,7 +6655,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1883297442}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.00003862381, y: 0.00182724, z: -24.20161}
m_LocalPosition: {x: 0.014378071, y: 0.0022006035, z: -24.20161}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []

View File

@ -223,7 +223,7 @@ public class mount : MonoBehaviour
public static mount mountitem;
// Start is called before the first frame update
public virtual void Awake()
public virtual void Awake()
{
DontDestroyOnLoad(this);
@ -232,7 +232,7 @@ public class mount : MonoBehaviour
//mountitem.login_screen();
}
public virtual void Start()
private void Start()
{
mountitem = this;
LoadAllJsonFiles();

View File

@ -8,7 +8,13 @@ public class boy : mount
public int currencType = 0;//货币类型
public List<GameObject> listgameobject = new List<GameObject>();
public Dictionary<float, int> ActivateValues = new Dictionary<float, int>();
public override async void Start()
public override void Awake()
{
}
private async void Start()
{
//测试用
Login login = new Login();

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 27bd589a37ed62a4fb108e150abd2d36
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEditor.Progress;
public class boy_jinsha:mount
{
public int currencType = 0;//货币类型
public List<GameObject> listgameobject = new List<GameObject>();
public Dictionary<float, int> ActivateValues = new Dictionary<float, int>();
public override void Awake()
{
}
private async void Start()
{
//测试用
Login login = new Login();
login.Phone = "test1";
await web.SendRequest(web.URL + "/Player/Login", "POST", JsonUtility.ToJson(login));
string userponse = await web.SendRequest(web.URL + "/FisherElf/GetList", "POST");
Response itemList = JsonUtility.FromJson<Response>(userponse);
foreach (Item item in itemList.List)
{ //处理给过来的渔夫数据,只保留对应货币的渔夫
if (item.Type == currencType)
{
if (!ActivateValues.ContainsKey(item.ActivateValue))
{
ActivateValues.Add(item.ActivateValue, item.Num);
}
}
}
UpShipTimer();
}
public async void UpShipTimer()
{
int index = 0;
foreach (int key in ActivateValues.Keys)
{
listgameobject[index].GetComponent<landContorl>().ActivateValue = key;
listgameobject[index].GetComponent<landContorl>().Num = ActivateValues[key];
index++;
}
string allfisherman = "";
if (currencType == 0)//金币
{
allfisherman = await web.SendRequest(web.URL + "/FisherElfActive/GetListOfGold", "POST");
}
else//宝石
{
allfisherman = await web.SendRequest(web.URL + "/FisherElfActive/GetListOfGem", "POST");
}
//Debug.Log(allfisherman);
Response allfishermanres = JsonUtility.FromJson<Response>(allfisherman);
//Debug.Log(Struct.StructToString(allfishermanres, 1));
foreach (Item item in allfishermanres.List)
{
if (item.Type == currencType)
{
foreach (GameObject gameObject in listgameobject)
{
if (gameObject.GetComponent<landContorl>().ActivateValue == item.ActivateValue)//如果价格一致
{
Debug.Log(item.RemainEndureTime.ToString() + '/' + item.EndureTime.ToString());
gameObject.GetComponent<landContorl>().add_fish(item.RemainEndureTime.ToString() + '/' + item.EndureTime.ToString());
//gameObject.GetComponent<landContorl>().add_fish();
}
}
}
}
}
}

View File

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

View File

@ -0,0 +1,333 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using TMPro;
public class landContorl_jinsha : MonoBehaviour
{
public GameObject fishManPrefab;
private GameObject fishMan;
private shipcontorl fishManShipContorl;
public Transform startPos;
public Transform endPos;
public int type;
public bool isbuy = false;
public bool isGoldLand = false;
public float ActivateValue = 0;
public int Num = 0;
public int Type = 0;
//路径
public List<Path> paths;
//航行时间
public float pathsNeedTimer = 30f;
//捕鱼时间
public float fishingNeedTimer = 30f;
//休息时间
public float restTimer = 5f;
//每次获得的金币数量默认100
public int getgoldnumber = 100;
public GameObject goldshop;
public TextMeshPro goldNumerTextPro;
public GameObject HightLight;//高亮
public Transform Btntrans;
public float FishPrice;
public GameObject map;
// Start is called before the first frame update
private void Start()
{
FishPrice = 10;
if (goldshop == null)
{
Debug.LogError("goldshop==null");
return;
}
HightLight.SetActive(false);
if (!isGoldLand) return;
shopman.instance.OnType += addman;
}
private void Update()
{
goldNumerTextPro.text = ActivateValue.ToString();
}
private void OnDisable()
{
if (!isGoldLand) return;
shopman.instance.OnType -= addman;
}
void addman(int type, int number)
{
if (type == this.type)
{
if (isbuy == false)
{
isbuy = true;
PlayerManager.Instance.SetMoney(MoneyType.Coins, -FishPrice);
Promptmgr.Instance.PromptBubble("购买成功", Color.black, Color.blue);
}
else
{
Promptmgr.Instance.PromptBubble("已经购买了", Color.black, Color.red);
}
}
}
private void OnMouseDown()
{
if (fishMan != null)
{
Promptmgr.Instance.PromptBubble("已经有船了", Color.black, Color.red);
return;
}
OnClick();
}
private void OnTouch()
{
if (fishMan != null)
{
Promptmgr.Instance.PromptBubble("已经有船了", Color.black, Color.red);
return;
}
OnClick();
}
async void OnClick()
{
GenerateForFisherElf generateForFisherElf = new GenerateForFisherElf(); // 购买渔夫
generateForFisherElf.Num = Num;
generateForFisherElf.Count = 1;
string userponse = await web.SendRequest(web.URL + "/Voucher/GenerateForFisherElf", "POST", JsonUtility.ToJson(generateForFisherElf));
ids itemList = JsonUtility.FromJson<ids>(userponse);
if (itemList.ErrorCode == 0) // 如果购买成功
{
foreach (string item in itemList.Ids)
{
Use use = new Use(); // 使用渔夫
use.Id = item;
string rect = await web.SendRequest(web.URL + "/Voucher/Use", "POST", JsonUtility.ToJson(use));
Res res = JsonUtility.FromJson<ids>(userponse);
if (res.ErrorCode == 0)
{
Promptmgr.Instance.PromptBubble("购买成功", Color.black, Color.red);
ScaleAni(Btntrans);
add_fish();
map.GetComponent<boy>().UpShipTimer();
}
else
{
Promptmgr.Instance.PromptBubble(res.ErrorMessage, Color.black, Color.red);
}
}
}
else// 如果购买失败
{
Promptmgr.Instance.PromptBubble("购买失败", Color.black, Color.red);
}
Debug.Log(Struct.StructToString(itemList, 3));
}
public void add_fish(string timerStr = null)//生成船只
{
//倒计时
// fishManShipContorl.UpShowTimer("测试");
if (fishMan != null)
{
fishManShipContorl.UpShowTimer(timerStr);
return;
}
if (timerStr != null)
{
fishMan = GameObject.Instantiate(fishManPrefab);
fishMan.transform.position = endPos.position;
fishManShipContorl = fishMan.GetComponent<shipcontorl>();
MoveToStartPos();
return;
}
fishMan = GameObject.Instantiate(fishManPrefab);
fishMan.transform.position = startPos.position;
fishManShipContorl = fishMan.GetComponent<shipcontorl>();
MoveToFishingPos();
}
void MoveToFishingPos()
{
// 随机选择一条路径
Path selectedPath = paths[Random.Range(0, paths.Count)];
// 移动到捕鱼点
StartCoroutine(MoveToFishingPoint(fishMan, selectedPath.pathPoints));
}
public void ScaleAni(Transform transform)
{
HightLight.SetActive(true);
transform.DOScale(1.1f, 0.2f)
.SetEase(Ease.InOutSine)
.OnComplete(() => {
transform.DOScale(1f, 0.2f).SetEase(Ease.InOutSine);
HightLight.SetActive(false);
});
}
IEnumerator MoveToFishingPoint(GameObject man, List<Transform> path)
{
// 将路径点转换为 Vector3 数组
Vector3[] pathPoints = new Vector3[path.Count];
for (int i = 0; i < path.Count; i++)
{
pathPoints[i] = path[i].position;
}
ChangeShipLook(pathPoints[0], pathPoints[path.Count - 1]);
// 创建一个摆动效果的 Tween
//注意 ,摆动动的是船,移动移动是根节点
var swayTween = fishManShipContorl.Man.transform.DOLocalRotate(new Vector3(0, 0, 10), 1f, RotateMode.LocalAxisAdd) // 每次摆动角度
.SetEase(Ease.InOutSine)
.SetLoops(-1, LoopType.Yoyo); // 无限往复
man.GetComponent<shipcontorl>().SetState(ShipState.move);
// 使用 DOPath 沿着路径移动到捕鱼点,并禁用旋转变化
yield return man.transform.DOPath(pathPoints, pathsNeedTimer, PathType.CatmullRom)
.SetOptions(false) // 禁用旋转
.SetEase(Ease.InOutSine)
.WaitForCompletion();
// 停止摆动效果
swayTween.Kill();
StartCoroutine(Fishing());
}
IEnumerator Fishing()
{
fishMan.GetComponent<shipcontorl>().SetState(ShipState.shipthrow);
yield return new WaitForSeconds(1f);
fishMan.GetComponent<shipcontorl>().SetState(ShipState.stand);
// 等待捕鱼指定时间
yield return new WaitForSeconds(fishingNeedTimer - 1f);
// 返回起点
MoveToStartPos();
}
void MoveToStartPos()
{
// 随机选择一条路径
Path selectedPath = paths[Random.Range(0, paths.Count)];
// 移动到捕鱼点
StartCoroutine(MoveToStartPos(fishMan, selectedPath.pathPoints));
}
IEnumerator MoveToStartPos(GameObject man, List<Transform> path)
{
// 创建路径点数组,长度为路径点数量 + 1
Vector3[] pathPoints = new Vector3[path.Count + 1];
// 设置最后一个点为起始位置
pathPoints[path.Count] = startPos.position;
// 反向赋值路径点
for (int i = 0; i < path.Count; i++)
{
pathPoints[i] = path[path.Count - 1 - i].position; // 从最后一个点开始赋值
}
ChangeShipLook(pathPoints[0], pathPoints[path.Count]);
// 创建一个摆动效果的 Tween
//注意 ,摆动动的是船,移动移动是根节点
var swayTween = fishManShipContorl.Man.transform.DOLocalRotate(new Vector3(0, 0, 10), 1f, RotateMode.LocalAxisAdd) // 每次摆动角度
.SetEase(Ease.InOutSine)
.SetLoops(-1, LoopType.Yoyo); // 无限往复
man.GetComponent<shipcontorl>().SetState(ShipState.move);
// 使用 DOPath 沿着路径移动到捕鱼点,并禁用旋转变化
yield return man.transform.DOPath(pathPoints, pathsNeedTimer, PathType.CatmullRom)
.SetOptions(false) // 禁用旋转
.SetEase(Ease.InOutSine)
.WaitForCompletion();
//加钱
AddGold();
// 等待捕鱼指定时间
yield return new WaitForSeconds(restTimer);
// 停止摆动效果
swayTween.Kill();
//循环
MoveToFishingPos();
}
//根据前后位置改变朝向
void ChangeShipLook(Vector3 startpos, Vector3 endpos)
{
if (startpos.x > endpos.x)
{
fishMan.GetComponent<shipcontorl>().ChangeLookat(0f); // 朝向右边
}
else
{
fishMan.GetComponent<shipcontorl>().ChangeLookat(180f); // 朝向左边
}
}
void AddGold()
{
Debug.LogError("返航完成,开始:真·摸-鱼,加钱");
goldNumerTextPro.text = ActivateValue.ToString();
fishMan.GetComponent<shipcontorl>().SetState(ShipState.draw);
}
}

View File

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