备份CatanBuilding瘦身独立工程
This commit is contained in:
175
Assets/Scripts/SandDig/GameScript/GridPropItem.cs
Normal file
175
Assets/Scripts/SandDig/GameScript/GridPropItem.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using Game;
|
||||
using Script.RuntimeScript.Interface;
|
||||
using Script.RuntimeScript.model.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script.RuntimeScript.GameLogic
|
||||
{
|
||||
public class GridPropItem : MonoBehaviour, BroadEffectInterface
|
||||
{
|
||||
public int PlayEffectPriority { set; get; } = 1;
|
||||
/// <summary>
|
||||
/// 飞行动画
|
||||
/// </summary>
|
||||
private MoveWithCurve _effectScript;
|
||||
/// <summary>
|
||||
/// 展示动画
|
||||
/// </summary>
|
||||
private Animation _showEffect;
|
||||
GameObject DgSand;
|
||||
GameObject DgSandShadow;
|
||||
Transform fx_diggingitem_drop;
|
||||
public DiggingItemProp EffectType { get; set; }
|
||||
private GridPropData _data;
|
||||
Vector3 PositionRootLocalPos;
|
||||
public GridPropData Data
|
||||
{
|
||||
get { return _data; }
|
||||
set
|
||||
{
|
||||
_data = value;
|
||||
EffectType = _data.Config.DiggingType;
|
||||
}
|
||||
}
|
||||
bool isNormal = true;
|
||||
public async void Init(GridPropData data, float time)
|
||||
{
|
||||
Data = data;
|
||||
isNormal = EffectType is Normal;
|
||||
_effectScript = this.gameObject.GetComponent<MoveWithCurve>();
|
||||
PositionRootLocalPos = transform.Find("PositionRoot").localPosition;
|
||||
Transform animationRoot = transform.Find("PositionRoot/AnimationRoot");
|
||||
_showEffect = animationRoot.GetComponent<Animation>();
|
||||
if (isNormal)
|
||||
{
|
||||
DgSand = animationRoot.GetChild(0).gameObject;
|
||||
DgSandShadow = animationRoot.GetChild(1).gameObject;
|
||||
|
||||
fx_diggingitem_drop = animationRoot.Find("fx_diggingitem_drop");
|
||||
if (fx_diggingitem_drop != null)
|
||||
{
|
||||
fx_diggingitem_drop.localScale = Vector3.one * Data.Config.ItemFxScale;
|
||||
}
|
||||
SetShowShadow(true);
|
||||
if (_showEffect != null)
|
||||
{
|
||||
_showEffect.transform.localScale = Vector3.zero;
|
||||
await Awaiters.Seconds(time);
|
||||
_showEffect?.Play("propshow");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SetShowShadow(bool value)
|
||||
{
|
||||
if (isNormal)
|
||||
{
|
||||
DgSand.SetActive(!value);
|
||||
DgSandShadow.SetActive(value);
|
||||
}
|
||||
}
|
||||
public async void PlayEffect(bool overCheck)
|
||||
{
|
||||
int upDelay = SandDigEventConst.UpDelay;
|
||||
if (overCheck)
|
||||
{
|
||||
upDelay = SandDigEventConst.InUpDelay;
|
||||
}
|
||||
await System.Threading.Tasks.Task.Delay(upDelay);
|
||||
if (EffectType is Normal)
|
||||
{
|
||||
SetShowShadow(false);
|
||||
PlayNormalEffect(PlayNormalPropFly);
|
||||
}
|
||||
else if (EffectType is Resource)
|
||||
{
|
||||
PlayResourceEffect(PlayResourcePropFly);
|
||||
}
|
||||
}
|
||||
|
||||
private async void PlayNormalPropFly()
|
||||
{
|
||||
_showEffect?.Play("propshake");
|
||||
DiggingGameManager diggingGameManager = GContext.container.Resolve<DiggingGameManager>();
|
||||
diggingGameManager.ShowFX(Data.Config.Fx, false);
|
||||
diggingGameManager.ShowFX(Data.Config.Fx, true);
|
||||
await System.Threading.Tasks.Task.Delay(SandDigEventConst.UpWaitTime + SandDigEventConst.ShovelEffectTime);
|
||||
|
||||
if (Data.TargetPropItem == null)
|
||||
{
|
||||
DiggingGameManager.LogWarning("没找到目标 ,原地消失");
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
_effectScript.SetStartPosition(_effectScript.transform.position);
|
||||
_effectScript.EndPoint = Data.TargetPropItem.transform.position;
|
||||
//_effectScript.EndPoint.z += SandDigEventConst.TargetPropOffsetZ;
|
||||
_effectScript.Begin(() =>
|
||||
{
|
||||
GContext.Publish(new EventUISound("audio_ui_sanddig_itemdrop"));
|
||||
//隐藏目标道具
|
||||
Data.TargetPropItem.gameObject.SetActive(false);
|
||||
if (fx_diggingitem_drop != null)
|
||||
{
|
||||
fx_diggingitem_drop.gameObject.SetActive(true);
|
||||
}
|
||||
PropSparkItem propSparkItem = gameObject.AddComponent<PropSparkItem>();
|
||||
propSparkItem.Init(Data.Config.ItemFxScale);
|
||||
GContext.Publish(new GridPropEffectOver(Data.PropId, true));
|
||||
});
|
||||
this.transform.DOScale(SandDigEventConst.GetScale, 0.5f);
|
||||
}
|
||||
|
||||
private async void PlayResourcePropFly()
|
||||
{
|
||||
_showEffect?.Play("scale");
|
||||
await System.Threading.Tasks.Task.Delay(SandDigEventConst.ResourceEffectTime + SandDigEventConst.ShovelEffectTime);
|
||||
|
||||
this.gameObject.SetActive(false);
|
||||
GContext.Publish(new GridPropEffectOver(Data.PropId, true));
|
||||
|
||||
Vector3 worldPosition = this.transform.position;
|
||||
Vector3 screenPosition = ConvertTools.WorldToScreenPoint(worldPosition);
|
||||
screenPosition.z = 0;
|
||||
|
||||
Resource res = (EffectType as Resource);
|
||||
DiggingGameManager.LogError("添加道具:" + res.ItemID + " count:" + res.Param + " pos::" + screenPosition.ToString());
|
||||
GContext.Publish(new EventSandDigAddItem(res.ItemID, res.Param, screenPosition));
|
||||
}
|
||||
|
||||
|
||||
private void PlayNormalEffect(Action effectOver)
|
||||
{
|
||||
this.transform.DORotate(new Vector3(0, 0, 0), SandDigEventConst.UpTime)
|
||||
.SetLoops(-1, LoopType.Incremental)
|
||||
.SetEase(Ease.Linear);
|
||||
|
||||
Vector3 targetPositon = GContext.container.Resolve<DiggingGameManager>().ShowPropPositon.transform.position;
|
||||
Vector3 toPostion = new Vector3(targetPositon.x, targetPositon.y, SandDigEventConst.UpValue);
|
||||
Vector3 offstPosition = PositionRootLocalPos;
|
||||
offstPosition.x *= SandDigEventConst.UpScale;
|
||||
offstPosition.y *= SandDigEventConst.UpScale;
|
||||
offstPosition.z = 0;
|
||||
toPostion -= offstPosition;
|
||||
|
||||
GContext.Publish(new EventUISound("audio_ui_sanddig_itemfly"));
|
||||
|
||||
this.transform.DOMove(toPostion, SandDigEventConst.UpTime).OnComplete(() =>
|
||||
{
|
||||
GContext.Publish(new EventUISound("audio_ui_sanddig_itemshake"));
|
||||
this.transform.DOKill(); // 停止旋转动画
|
||||
this.transform.rotation = Quaternion.identity; // 角度变为0
|
||||
effectOver.Invoke();
|
||||
}).SetId(this);
|
||||
this.transform.DOScale(new Vector3(SandDigEventConst.UpScale, SandDigEventConst.UpScale, SandDigEventConst.UpScale), SandDigEventConst.UpTime);
|
||||
}
|
||||
|
||||
private void PlayResourceEffect(Action effectOver)
|
||||
{
|
||||
effectOver.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user