备份CatanBuilding瘦身独立工程
This commit is contained in:
254
Assets/Scripts/UI/Fishing/FishingWeighBar.cs
Normal file
254
Assets/Scripts/UI/Fishing/FishingWeighBar.cs
Normal file
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using cfg;
|
||||
using asap.core;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
public class FishingWeighBar : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
public class Medal
|
||||
{
|
||||
public float Len;
|
||||
public float Point {
|
||||
get {
|
||||
return _isSpecalMedal? SpPoint:NormalPoint;
|
||||
}
|
||||
}
|
||||
public float NormalPoint;
|
||||
public float SpPoint;
|
||||
public string medalName;
|
||||
public Transform Parent;
|
||||
|
||||
private GameObject _go;
|
||||
public bool _isSpecalMedal;
|
||||
|
||||
public void IsSpecialMedal(bool isSpecial)
|
||||
{
|
||||
_isSpecalMedal = isSpecial;
|
||||
}
|
||||
|
||||
public async void CreateMedal()
|
||||
{
|
||||
if(_go == null)
|
||||
_go = await Addressables.InstantiateAsync(medalName, Parent.GetChild(0)).Task;
|
||||
}
|
||||
public void ActivateVFX()
|
||||
{
|
||||
_go.transform.Find("fx_fishingreward_iconrate_glow").gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Medal> _medals = new();
|
||||
private Tables _tables;
|
||||
public RectTransform rect_ruler;
|
||||
public RectTransform rect_medals;
|
||||
|
||||
|
||||
public Dictionary<int, string> MedalPrefabs = new();
|
||||
|
||||
[SerializeField]
|
||||
private Transform
|
||||
tran_medalParent;
|
||||
|
||||
private int curMedalIndex;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
curMedalIndex = 0;
|
||||
MedalPrefabs.Add(0, "fishing_rate_d");
|
||||
MedalPrefabs.Add(1, "fishing_rate_c");
|
||||
MedalPrefabs.Add(2, "fishing_rate_c+");
|
||||
MedalPrefabs.Add(3, "fishing_rate_b");
|
||||
MedalPrefabs.Add(4, "fishing_rate_b+");
|
||||
MedalPrefabs.Add(5, "fishing_rate_a");
|
||||
MedalPrefabs.Add(6, "fishing_rate_a+");
|
||||
MedalPrefabs.Add(7, "fishing_rate_s");
|
||||
MedalPrefabs.Add(8, "fishing_rate_ss");
|
||||
MedalPrefabs.Add(9, "fishing_rate_sss");
|
||||
MedalPrefabs.Add(10, "fishing_rate_x");
|
||||
MedalPrefabs.Add(11, "fishing_rate_xx");
|
||||
MedalPrefabs.Add(12, "fishing_rate_xxx");
|
||||
|
||||
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
var ranks = _tables.TbGlobalConfig.Rank;
|
||||
var spRanks = _tables.TbGlobalConfig.RankForSpFish;
|
||||
|
||||
//¸øÃ¿¸ö½±Õ¸³·ÖÊý
|
||||
for ( int i = 0; i < tran_medalParent.childCount; i++ )
|
||||
{
|
||||
var parent = tran_medalParent.GetChild(i);
|
||||
var rect = parent.GetComponent<RectTransform>();
|
||||
var medal = new Medal
|
||||
{
|
||||
Len = rect.sizeDelta.y / 2 - rect.anchoredPosition.y,
|
||||
medalName = MedalPrefabs[i],
|
||||
NormalPoint= ranks[i],
|
||||
SpPoint = spRanks[i],
|
||||
Parent = parent,
|
||||
};
|
||||
medal.CreateMedal();
|
||||
// Debug.Log($" {parent.name} {rect.sizeDelta.y} / 2 - {rect.anchoredPosition.y}");
|
||||
_medals.Add(medal);
|
||||
}
|
||||
// _medals[0].CreateMedal();
|
||||
// _medals[1].CreateMedal();
|
||||
}
|
||||
|
||||
public void IsSpecialSettlement(bool isSpecial)
|
||||
{
|
||||
Debug.Log("IsSpecialSettlement :" + isSpecial);
|
||||
foreach (var medal in _medals)
|
||||
{
|
||||
medal.IsSpecialMedal(isSpecial);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetPointByLen(float curLen,bool isSpecialFish=false)
|
||||
{
|
||||
Medal preMedal = null;
|
||||
Medal nextMedal = null;
|
||||
|
||||
float curScore = 0f;
|
||||
|
||||
for ( int i = 0; i < _medals.Count - 1; i++ )
|
||||
{
|
||||
var lastMedal1 = _medals[i];
|
||||
var endMedal1 = _medals[i + 1];
|
||||
if ( lastMedal1.Len >= curLen&&i==0 )
|
||||
{
|
||||
preMedal = null;
|
||||
nextMedal = endMedal1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( lastMedal1.Len < curLen && endMedal1.Len >= curLen )
|
||||
{
|
||||
preMedal = lastMedal1;
|
||||
nextMedal = endMedal1;
|
||||
// Debug.Log("ÄãºÃ");
|
||||
break;
|
||||
}
|
||||
|
||||
if ( endMedal1.Len <= curLen && i == _medals.Count - 2 )
|
||||
{
|
||||
preMedal = endMedal1;
|
||||
nextMedal = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if ( _medals[0].Len > curLen )
|
||||
// {
|
||||
// nextMedal = _medals[0];
|
||||
// }
|
||||
// if ( _medals[_medals.Count - 1].Len < curLen )
|
||||
// {
|
||||
// preMedal = _medals[_medals.Count - 1];
|
||||
// }
|
||||
|
||||
if ( preMedal == null )
|
||||
{
|
||||
//0-1
|
||||
curScore = nextMedal.Point * curLen / nextMedal.Len;
|
||||
}
|
||||
else if ( nextMedal == null )
|
||||
{
|
||||
//max
|
||||
// Debug.LogError("max!!");
|
||||
curScore = preMedal.Point+0.01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
//center
|
||||
var score = nextMedal.Point - preMedal.Point;
|
||||
var len = nextMedal.Len - preMedal.Len;
|
||||
|
||||
curScore = preMedal.Point + score * ( curLen - preMedal.Len ) / len;
|
||||
}
|
||||
return curScore;
|
||||
|
||||
}
|
||||
public float GetLenByPoint(float curScore)
|
||||
{
|
||||
Medal preMedal = null;
|
||||
Medal nextMedal = null;
|
||||
|
||||
float curLen = 0f;
|
||||
for ( int i = 0; i < _medals.Count - 1; i++ )
|
||||
{
|
||||
var lastMedal1 = _medals[i];
|
||||
var endMedal1 = _medals[i + 1];
|
||||
if ( lastMedal1.Point>= curScore && i == 0 )
|
||||
{
|
||||
preMedal = null;
|
||||
nextMedal = endMedal1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( lastMedal1.Point < curScore && endMedal1.Point >= curScore )
|
||||
{
|
||||
preMedal = lastMedal1;
|
||||
nextMedal = endMedal1;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( endMedal1.Point <= curScore && i == _medals.Count - 2 )
|
||||
{
|
||||
preMedal = endMedal1;
|
||||
nextMedal = null;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// _medals[curMedalIndex + 1].CreateMedal();
|
||||
// _medals[curMedalIndex + 2].CreateMedal();
|
||||
//
|
||||
// if ( _medals[0].Point >= curScore )
|
||||
// {
|
||||
// nextMedal = _medals[0];
|
||||
// }
|
||||
// if ( _medals[_medals.Count - 1].Point <= curScore )
|
||||
// {
|
||||
// preMedal = _medals[_medals.Count - 1];
|
||||
// }
|
||||
|
||||
if ( preMedal == null )
|
||||
{
|
||||
//0-1
|
||||
curLen = nextMedal.Len * curScore / nextMedal.Point;
|
||||
}
|
||||
else if ( nextMedal == null )
|
||||
{
|
||||
//max
|
||||
// Debug.LogError("max!!");
|
||||
curLen = preMedal.Len+0.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
//center
|
||||
var score = nextMedal.Point - preMedal.Point;
|
||||
var len = nextMedal.Len - preMedal.Len;
|
||||
|
||||
curLen=preMedal.Len + len * ( curScore - preMedal.Point ) / score;
|
||||
}
|
||||
return curLen;
|
||||
|
||||
}
|
||||
public void CheckIfTouchScore(float curLen)
|
||||
{
|
||||
if ( curLen >= _medals[curMedalIndex].Len-0.01f )
|
||||
{
|
||||
_medals[curMedalIndex].ActivateVFX();
|
||||
curMedalIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user