ball 项目提交
This commit is contained in:
@@ -0,0 +1,209 @@
|
||||
using FairyGUI;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[Flags]
|
||||
public enum RewardDisplayType
|
||||
{
|
||||
None = 0b_0000_0000,
|
||||
|
||||
|
||||
Number = 0b_0000_0001,
|
||||
|
||||
|
||||
ValueChange = 0b_0000_0010,
|
||||
|
||||
|
||||
Dialog = 0b_0000_0100,
|
||||
|
||||
|
||||
RewardFly = 0b_0000_1000,
|
||||
}
|
||||
|
||||
|
||||
public enum RewardOrigin
|
||||
{
|
||||
None,
|
||||
GameWin,
|
||||
H5Icon,
|
||||
LuckyWheel,
|
||||
SignIn,
|
||||
AdTask,
|
||||
Play,
|
||||
Achievement,
|
||||
H5Fly101,
|
||||
H5Fly102,
|
||||
Passview,
|
||||
}
|
||||
|
||||
public enum RewardCondition
|
||||
{
|
||||
None,
|
||||
AD,
|
||||
}
|
||||
|
||||
|
||||
public class RewardSingleData
|
||||
{
|
||||
public int id;
|
||||
public int type;
|
||||
public decimal value;
|
||||
public decimal multiRate;
|
||||
public decimal rate;
|
||||
|
||||
public decimal GetTotalValue()
|
||||
{
|
||||
return Math.Round(value * rate, 2);
|
||||
}
|
||||
|
||||
public RewardOrigin origin;
|
||||
public Vector2 startPosition;
|
||||
public Vector2 endPosition;
|
||||
public int index;
|
||||
public RewardSingleData(int id, decimal value, RewardOrigin origin, int index = 0)
|
||||
{
|
||||
this.id = id;
|
||||
this.value = value;
|
||||
this.origin = origin;
|
||||
this.index = index;
|
||||
InitData();
|
||||
}
|
||||
|
||||
private void InitData()
|
||||
{
|
||||
InitRate();
|
||||
InitMultiRate();
|
||||
}
|
||||
|
||||
private void InitRate()
|
||||
{
|
||||
if (rate == 0)
|
||||
{
|
||||
rate = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitMultiRate()
|
||||
{
|
||||
if (multiRate == 0)
|
||||
{
|
||||
multiRate = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void InitFlyPosition()
|
||||
{
|
||||
InitStartPosition();
|
||||
InitEndPosition();
|
||||
}
|
||||
|
||||
private void InitStartPosition()
|
||||
{
|
||||
if (startPosition == Vector2.zero)
|
||||
{
|
||||
startPosition = GRoot.inst.size / 2;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitEndPosition()
|
||||
{
|
||||
if (endPosition == Vector2.zero && id != 0)
|
||||
{
|
||||
var itemUI = GameHelper.GetItemUI(id);
|
||||
var gObject = itemUI?.GetChildAt(1);
|
||||
if (gObject != null)
|
||||
{
|
||||
endPosition = itemUI.LocalToRoot((Vector2)gObject.position + gObject.size / 2, GRoot.inst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCanFly()
|
||||
{
|
||||
return IsCanFly(id);
|
||||
}
|
||||
|
||||
public static bool IsCanFly(int id)
|
||||
{
|
||||
return id == 101 || id == 102 || id == 111;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class RewardData
|
||||
{
|
||||
private List<RewardSingleData> rewardDataList;
|
||||
|
||||
public RewardDisplayType displayType;
|
||||
|
||||
public RewardCondition condition;
|
||||
|
||||
private Action<bool> mOnCompleted;
|
||||
|
||||
public bool isSingle;
|
||||
|
||||
public decimal ctRate;
|
||||
|
||||
public RewardData()
|
||||
{
|
||||
InitData();
|
||||
}
|
||||
|
||||
public void AddCompleted(Action<bool> onCompleted)
|
||||
{
|
||||
mOnCompleted += onCompleted;
|
||||
}
|
||||
|
||||
|
||||
public void OnCompleted(bool isSuccess)
|
||||
{
|
||||
mOnCompleted?.Invoke(isSuccess);
|
||||
}
|
||||
|
||||
public void AddReward(RewardSingleData rewardSingleData)
|
||||
{
|
||||
rewardDataList ??= new List<RewardSingleData>();
|
||||
|
||||
var isNeedAdd = true;
|
||||
|
||||
foreach (var data in rewardDataList.Where(data => data.id == rewardSingleData.id))
|
||||
{
|
||||
data.value += rewardSingleData.value;
|
||||
isNeedAdd = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isNeedAdd)
|
||||
{
|
||||
rewardDataList.Add(rewardSingleData);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitData()
|
||||
{
|
||||
if (rewardDataList != null)
|
||||
{
|
||||
rewardDataList.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardDataList = new List<RewardSingleData>();
|
||||
}
|
||||
}
|
||||
|
||||
public List<RewardSingleData> GetRewardDataList()
|
||||
{
|
||||
return rewardDataList;
|
||||
}
|
||||
|
||||
public int GetRewardFlyCount()
|
||||
{
|
||||
return GetRewardDataList().Count(rewardSingleData => rewardSingleData.IsCanFly());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ab2c0def1063b543b89fed5d33423d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class RewardDisplayData
|
||||
{
|
||||
public RewardSingleData rewardSingleData;
|
||||
public bool isPlayAudio;
|
||||
public string audioName;
|
||||
public bool isNeedFly;
|
||||
public bool isNeedValueChange;
|
||||
public event Action<decimal> UpdateCb;
|
||||
public event Action EndEventCb;
|
||||
public event Action UICloseEventCb;
|
||||
private decimal coinAddTime = 0.45m;
|
||||
public bool isSingle;
|
||||
private decimal showValue;
|
||||
private decimal showAddValue;
|
||||
private bool isCompleted;
|
||||
|
||||
public RewardDisplayData(RewardSingleData rewardSingleData)
|
||||
{
|
||||
this.rewardSingleData = rewardSingleData;
|
||||
showValue = rewardSingleData.GetTotalValue();
|
||||
showAddValue = showValue;
|
||||
}
|
||||
|
||||
public void SetUpdate(Action<decimal> updateCb)
|
||||
{
|
||||
UpdateCb = updateCb;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (isCompleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var val = showValue * Convert.ToDecimal(Time.deltaTime) / coinAddTime;
|
||||
if (showAddValue >= val)
|
||||
{
|
||||
showAddValue -= val;
|
||||
if (isNeedValueChange)
|
||||
{
|
||||
UpdateCb?.Invoke(val);
|
||||
}
|
||||
}
|
||||
else if (showAddValue > 0)
|
||||
{
|
||||
if (isNeedValueChange)
|
||||
{
|
||||
UpdateCb?.Invoke(showAddValue);
|
||||
}
|
||||
|
||||
showAddValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetUpdateComplete(Action endEventCb)
|
||||
{
|
||||
EndEventCb = endEventCb;
|
||||
}
|
||||
|
||||
public void EndEvent()
|
||||
{
|
||||
EndEventCb?.Invoke();
|
||||
EndEventCb = null;
|
||||
isCompleted = true;
|
||||
}
|
||||
|
||||
public void UICloseEvent()
|
||||
{
|
||||
UICloseEventCb?.Invoke();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UpdateCb = null;
|
||||
EndEventCb = null;
|
||||
UICloseEventCb = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96c535e1964438c499609fb7a2376428
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user