185 lines
4.1 KiB
C#
185 lines
4.1 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-09-15
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "StoryWindow.View" company="KUNPO"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using DG.Tweening;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class StoryWindow
|
|
{
|
|
#region Field
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
GameObject _goL;
|
|
[KUIFlag]
|
|
GameObject _goR;
|
|
[KUIFlag]
|
|
Image _imgL;
|
|
[KUIFlag]
|
|
Image _imgR;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpLName;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpRName;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpContent;
|
|
[KUIFlag]
|
|
Button _btnFrame;
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
bool _autoStory;
|
|
float _storyTimer;
|
|
StoryAction _storyAction;
|
|
Tweener _storyTweener;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void InitView()
|
|
{
|
|
SetViewData();
|
|
|
|
_btnFrame.onClick.AddListener(this.OnFrameBtnClick);
|
|
}
|
|
|
|
public void RefreshView()
|
|
{
|
|
if (this.data is StoryAction storyAction)
|
|
{
|
|
DoAction(storyAction);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void DoAction(StoryAction storyAction)
|
|
{
|
|
if (_storyAction != null || storyAction == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_storyAction = storyAction;
|
|
if (_storyAction != null)
|
|
{
|
|
_goL.SetActive(false);
|
|
_goR.SetActive(false);
|
|
_tmpContent.text = "";
|
|
|
|
if (_storyAction.type == 2)
|
|
{
|
|
var talkers = _storyAction.item.talker;
|
|
for (int i = 0; i < talkers.Length; i++)
|
|
{
|
|
var talker = talkers[i];
|
|
if (talker[0] == 1)
|
|
{
|
|
_goL.SetActive(true);
|
|
var npc = ItemProxy.Instance.GetStaticItem<ItemNpc>(talker[1]);
|
|
if (npc != null)
|
|
{
|
|
_tmpLName.text = npc.name;
|
|
if (!string.IsNullOrEmpty(npc.picture))
|
|
IconProxy.Instance.SetSpriteAsync(_imgL, npc.picture);
|
|
else if (npc.icon != null && npc.icon.Length > 0)
|
|
IconProxy.Instance.SetSprite(_imgL, npc.icon);
|
|
}
|
|
_imgL.color = talker[3] == 1 ? Color.white : Color.black;
|
|
}
|
|
else
|
|
{
|
|
_goR.SetActive(true);
|
|
var npc = ItemProxy.Instance.GetStaticItem<ItemNpc>(talker[1]);
|
|
if (npc != null)
|
|
{
|
|
_tmpRName.text = npc.name;
|
|
if (!string.IsNullOrEmpty(npc.picture))
|
|
IconProxy.Instance.SetSpriteAsync(_imgR, npc.picture);
|
|
else if (npc.icon != null && npc.icon.Length > 0)
|
|
IconProxy.Instance.SetSprite(_imgR, npc.icon);
|
|
}
|
|
_imgR.color = talker[3] == 1 ? Color.white : Color.black;
|
|
}
|
|
|
|
_storyTweener = _tmpContent.DOText(_storyAction.item.talkings, 2f).OnComplete(() =>
|
|
{
|
|
_storyTweener = null;
|
|
});
|
|
}
|
|
}
|
|
else if (_storyAction.type == 5)
|
|
{
|
|
_goL.SetActive(false);
|
|
_goR.SetActive(false);
|
|
_storyTweener = _tmpContent.DOText(_storyAction.item.talkings, 2f).OnComplete(() =>
|
|
{
|
|
_storyTweener = null;
|
|
});
|
|
}
|
|
_storyTimer = _storyAction.item.autoTime * 0.001f;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void UpdateView()
|
|
{
|
|
if (_autoStory && _storyTimer > 0)
|
|
{
|
|
_storyTimer -= 1f;
|
|
if (_storyTimer <= 0)
|
|
{
|
|
if (_storyAction != null)
|
|
{
|
|
_storyAction.Complete();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private float _lastClickTime;
|
|
private void OnFrameBtnClick()
|
|
{
|
|
if (Time.time - _lastClickTime < 0.2f)
|
|
return;
|
|
|
|
_lastClickTime = Time.time;
|
|
if (_storyTweener != null)
|
|
{
|
|
_storyTweener.Kill(true);
|
|
_storyTweener = null;
|
|
return;
|
|
}
|
|
|
|
if (_storyAction != null)
|
|
{
|
|
_storyAction.Complete();
|
|
_storyAction = null;
|
|
}
|
|
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|