227 lines
9.0 KiB
C#
227 lines
9.0 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using Game;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FishingStart : MonoBehaviour
|
|
{
|
|
public List<Image> barList;
|
|
GameObject old_bar;
|
|
public Image bar_light;
|
|
public List<RectTransform> lineList;
|
|
GameObject old_line;
|
|
public RectTransform line_light;
|
|
public RectTransform lineheight;
|
|
public RectTransform zhizhen;
|
|
float height;
|
|
RodWaitingZone waitingZone;
|
|
RodWaitingSequence waitingSequence;
|
|
public int curIndex;
|
|
List<float> ZoneScale;
|
|
[Header("进度条上端空余比例")]
|
|
public float top = 0.04784689f;
|
|
[Header("进度条下端空余比例")]
|
|
public float bottom = 0.05502392f;
|
|
[Header("高亮空余比例")]
|
|
public float bottomH = 0.07177033f;
|
|
private void Awake()
|
|
{
|
|
height = lineheight.rect.height;
|
|
}
|
|
public void SetBar(RodWaitingZone waitingZone, List<float> StrengthToScale)
|
|
{
|
|
IUIService uIService = GContext.container.Resolve<IUIService>();
|
|
GContext.Publish(new VibrationData(HapticTypes.Warning));
|
|
this.waitingZone = waitingZone;
|
|
ZoneScale = new List<float>();
|
|
for (int i = 0; i < waitingZone.ZoneScale.Count; i++)
|
|
{
|
|
ZoneScale.Add(waitingZone.ZoneScale[i] * (1 + StrengthToScale[i]));
|
|
}
|
|
float allScale = ZoneScale.Sum();
|
|
float curScale = 0;
|
|
string spriteName;
|
|
for (int i = waitingZone.ZoneSequence.Count - 1; i >= 0; i--)
|
|
{
|
|
curScale += ZoneScale[i];
|
|
int index = waitingZone.ZoneSequence[i];
|
|
barList[index].transform.SetSiblingIndex(i);
|
|
float fillAmount = (curScale / allScale) * (1 - top - bottom) + bottom;
|
|
barList[index].fillAmount = fillAmount;
|
|
if (index > 0)
|
|
{
|
|
int a = waitingZone.ZoneSequence[i - 1];
|
|
int b = waitingZone.ZoneSequence[i];
|
|
if (a > b)
|
|
{
|
|
spriteName = $"line_battle_start_{b}{a}";
|
|
lineList[i - 1].localScale = new Vector3(1, -1, 1);
|
|
}
|
|
else
|
|
{
|
|
spriteName = $"line_battle_start_{a}{b}";
|
|
lineList[i - 1].localScale = Vector3.one;
|
|
}
|
|
Image image = lineList[i - 1].GetComponent<Image>();
|
|
uIService.SetImageSprite(image, spriteName, "FishingPanel");
|
|
lineList[i - 1].gameObject.SetActive(waitingZone.ZoneScale[i] != 0);
|
|
lineList[i - 1].anchoredPosition = new Vector2(0, height * fillAmount);
|
|
|
|
if (index == 3)
|
|
{
|
|
old_bar = barList[index].gameObject;
|
|
old_line = lineList[i - 1].gameObject;
|
|
bar_light.transform.SetSiblingIndex(i);
|
|
bar_light.fillAmount = fillAmount - bottomH;
|
|
spriteName = spriteName + "_light";
|
|
|
|
if (a > b)
|
|
{
|
|
line_light.localScale = new Vector3(1, -1, 1);
|
|
}
|
|
else
|
|
{
|
|
line_light.localScale = Vector3.one;
|
|
}
|
|
image = line_light.GetComponent<Image>();
|
|
uIService.SetImageSprite(image, spriteName, "FishingPanel");
|
|
line_light.gameObject.SetActive(waitingZone.ZoneScale[i] != 0);
|
|
line_light.anchoredPosition = new Vector2(0, height * fillAmount);
|
|
}
|
|
}
|
|
}
|
|
if (waitingZone.ZoneScale[0] == 0)
|
|
{
|
|
lineList[0].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
void ShowLight(bool value)
|
|
{
|
|
old_bar.SetActive(!value);
|
|
old_line.SetActive(!value);
|
|
bar_light.gameObject.SetActive(value);
|
|
line_light.gameObject.SetActive(value);
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
StopAllCoroutines();
|
|
}
|
|
public void StopMove()
|
|
{
|
|
StopAllCoroutines();
|
|
}
|
|
public int GetCurPos()
|
|
{
|
|
float allScale = ZoneScale.Sum();
|
|
float curScale = 0;
|
|
float zhizhenPos = (zhizhen.anchoredPosition.y - height * bottom) / (height * (1 - top - bottom)) - 0.0001f;
|
|
if (zhizhenPos >= 1)
|
|
{
|
|
zhizhenPos = 0.9999f;
|
|
}
|
|
for (int i = waitingZone.ZoneSequence.Count - 1; i >= 0; i--)
|
|
{
|
|
curScale += ZoneScale[i];
|
|
if (zhizhenPos <= curScale / allScale)
|
|
{
|
|
return waitingZone.ZoneSequence[i];
|
|
}
|
|
}
|
|
return waitingZone.ZoneSequence[^1];
|
|
}
|
|
public void StartMoveCo(List<int> waitingSequenceIDList, float FishVigilanceToTime, float RodVigilanceToTime)
|
|
{
|
|
StartCoroutine(StartMove(waitingSequenceIDList, FishVigilanceToTime, RodVigilanceToTime));
|
|
}
|
|
IEnumerator StartMove(List<int> waitingSequenceIDList, float FishVigilanceToTime, float RodVigilanceToTime)
|
|
{
|
|
ShowLight(false);
|
|
int waitingSequenceID = waitingSequenceIDList[Random.Range(0, waitingSequenceIDList.Count)];
|
|
zhizhen.DOKill();
|
|
zhizhen.anchoredPosition = new Vector2(0, height * (1 - top));
|
|
waitingSequence = GContext.container.Resolve<Tables>().TbRodWaitingSequence.GetOrDefault(waitingSequenceID);
|
|
List<float> moveTime = new List<float>();
|
|
List<float> stayTime = new List<float>();
|
|
float VigilanceToTime;
|
|
for (int i = 0; i < waitingSequence.MoveTime.Count; i++)
|
|
{
|
|
VigilanceToTime = (1 - RodVigilanceToTime) / (1 + FishVigilanceToTime);
|
|
moveTime.Add(waitingSequence.MoveTime[i] * VigilanceToTime);
|
|
stayTime.Add(waitingSequence.StayTime[i] * VigilanceToTime);
|
|
}
|
|
do
|
|
{
|
|
for (int i = 0; i < waitingSequence.StayMoveCount.Count; i++)
|
|
{
|
|
int oldIndex = curIndex;
|
|
curIndex = (int)waitingSequence.ZoneWeight[i];
|
|
float endPos = barList[curIndex].fillAmount;
|
|
float startPos = bottom;
|
|
int index = waitingZone.ZoneSequence.IndexOf(curIndex);//当前bar在ZoneSequence中的index
|
|
if (index < waitingZone.ZoneSequence.Count - 1)
|
|
{
|
|
index = waitingZone.ZoneSequence[index + 1];//下一层bar的index
|
|
startPos = barList[index].fillAmount;
|
|
}
|
|
float middle = (startPos + endPos) / 2;
|
|
float offset = Mathf.Abs(startPos - endPos) / 2 * height;
|
|
float target = middle * height;
|
|
float distance = Mathf.Abs(zhizhen.anchoredPosition.y - target);
|
|
zhizhen.DOAnchorPosY(target, moveTime[i]).SetEase(Ease.Linear);
|
|
if (curIndex == 3 || oldIndex == 3)
|
|
{
|
|
if (distance > 0.001f && offset < distance)
|
|
{
|
|
float moveOutTime = offset / distance * moveTime[i];
|
|
yield return new WaitForSeconds(moveTime[i] - moveOutTime);
|
|
ShowLight(curIndex == 3);
|
|
yield return new WaitForSeconds(moveOutTime);
|
|
}
|
|
else
|
|
{
|
|
ShowLight(curIndex == 3);
|
|
yield return new WaitForSeconds(moveTime[i]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
yield return new WaitForSeconds(moveTime[i]);
|
|
}
|
|
IsShowGuidance isShowGuidance = new IsShowGuidance();
|
|
GContext.Publish(isShowGuidance);
|
|
if (isShowGuidance.isShow && curIndex == 3)
|
|
{
|
|
yield break;
|
|
}
|
|
GContext.Publish(new EventFishingSound(SoundType.audio_fishing_piercing));
|
|
GContext.Publish(new VibrationData(HapticTypes.Vibrate));
|
|
yield return StartCoroutine(StayTime(stayTime[i], startPos, middle, endPos, (int)waitingSequence.StayMoveCount[i]));
|
|
|
|
}
|
|
zhizhen.DOAnchorPosY(height * (1 - top), 0.5f).SetEase(Ease.Linear);
|
|
yield return new WaitForSeconds(0.5f);
|
|
} while (waitingZone.ZoneScale[0] == 0);
|
|
curIndex = -1;
|
|
}
|
|
IEnumerator StayTime(float time, float startPos, float middle, float endPos, int count)
|
|
{
|
|
float pos1 = (endPos - startPos) / 3;
|
|
float pos = UnityEngine.Random.Range(startPos, endPos);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (pos > middle)
|
|
pos = UnityEngine.Random.Range(startPos, pos - pos1);
|
|
else
|
|
pos = UnityEngine.Random.Range(pos + pos1, endPos);
|
|
zhizhen.DOAnchorPosY(pos * height, time / count).SetEase(Ease.Linear);
|
|
yield return new WaitForSeconds(time / count);
|
|
GContext.Publish(new EventFishingSound(SoundType.audio_fishing_piercing));
|
|
}
|
|
}
|
|
}
|