初始化仓库
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using DataTable;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class RoleItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private CommonButton _button = null;
|
||||
[SerializeField] private Image _roleImage = null;
|
||||
private SelectRoleForm _selectRoleForm = null;
|
||||
private DRRole _role = null;
|
||||
|
||||
public void OnInit(SelectRoleForm selectRoleForm, DRRole role)
|
||||
{
|
||||
this._selectRoleForm = selectRoleForm;
|
||||
this._role = role;
|
||||
GameEntry.SpriteCache.GetSprite(role.IconName, sprite => _roleImage.sprite = sprite);
|
||||
|
||||
_button.RegisterAction(0, OnPointerEnter);
|
||||
_button.RegisterAction(1, OnPointerClick);
|
||||
_button.RegisterAction(2, OnPointerExit);
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
this._selectRoleForm = null;
|
||||
this._role = null;
|
||||
|
||||
_button.UnRegisterAction(0, OnPointerEnter);
|
||||
_button.UnRegisterAction(1, OnPointerClick);
|
||||
_button.UnRegisterAction(2, OnPointerExit);
|
||||
}
|
||||
|
||||
private void OnPointerEnter()
|
||||
{
|
||||
_selectRoleForm.UpdateShowRole(_role);
|
||||
}
|
||||
|
||||
private void OnPointerClick()
|
||||
{
|
||||
_selectRoleForm.StartGame();
|
||||
}
|
||||
|
||||
private void OnPointerExit()
|
||||
{
|
||||
_selectRoleForm.UpdateShowRole(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35de2974f065de547952f8d5cbb9f6fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Text;
|
||||
using DataTable;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class RolePropertyArea : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text _roleNameText;
|
||||
|
||||
[SerializeField] private RawImage _roleAvatar;
|
||||
|
||||
[SerializeField] private TMP_Text _roleInitialPropertyText;
|
||||
|
||||
[SerializeField] private Transform _roleInitialItemParent;
|
||||
|
||||
public void OnInit(DRRole role)
|
||||
{
|
||||
_roleNameText.text = role.RoleName;
|
||||
// _roleAvatar.texture = AssetUtility.GetUITextureIcon(role.IconName);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (role.InitialProperties != null)
|
||||
{
|
||||
foreach (var modifier in role.InitialProperties)
|
||||
{
|
||||
sb.Append($"{modifier.ToString()}\n");
|
||||
}
|
||||
}
|
||||
_roleInitialPropertyText.text = sb.ToString();
|
||||
|
||||
|
||||
// foreach (var item in role.InitialItemIds)
|
||||
// {
|
||||
// var itemGO = Instantiate(_roleInitialItemParent.GetChild(0), _roleInitialItemParent);
|
||||
// itemGO.GetComponent<RoleItem>().OnInit(item.Key, item.Value);
|
||||
// }
|
||||
}
|
||||
|
||||
public void OnReset(object userData = null)
|
||||
{
|
||||
// _roleNameText.text = string.Empty;
|
||||
// _roleAvatar.texture = null;
|
||||
// _roleInitialPropertyText.text = string.Empty;
|
||||
// foreach (Transform item in _roleInitialItemParent)
|
||||
// {
|
||||
// Destroy(item.gameObject);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e82dc413a4cd277429ec1e3f2de69434
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
using System.Linq;
|
||||
using DataTable;
|
||||
using GameFramework.DataTable;
|
||||
using Procedure;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class SelectRoleForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private GameObject _randomRoleCard = null;
|
||||
|
||||
[SerializeField] private GameObject _roleCard = null;
|
||||
|
||||
[SerializeField] private RolePropertyArea _propertyArea = null;
|
||||
|
||||
private DRRole _currentRole = null;
|
||||
private IDataTable<DRRole> _roleDataTable = null;
|
||||
private DRRole[] _roleList = null;
|
||||
private RoleItem[] _roleItems = null;
|
||||
|
||||
private ProcedureStartMenu _procedure;
|
||||
|
||||
#region FSM
|
||||
|
||||
protected override void OnInit(object userData)
|
||||
{
|
||||
base.OnInit(userData);
|
||||
|
||||
if (userData is ProcedureStartMenu procedure)
|
||||
{
|
||||
_procedure = procedure;
|
||||
}
|
||||
|
||||
_roleDataTable = GameEntry.DataTable.GetDataTable<DRRole>();
|
||||
_roleItems = this.transform.GetComponentsInChildren<RoleItem>();
|
||||
_roleList = _roleDataTable.GetAllDataRows();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
Log.Debug($"{_roleList.Length} || {_roleItems.Length}");
|
||||
for (int i = 0; i < _roleItems.Length; i++)
|
||||
{
|
||||
if (i < _roleList.Length)
|
||||
{
|
||||
_roleItems[i].gameObject.SetActive(true);
|
||||
_roleItems[i].OnInit(this, _roleList[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_roleItems[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
base.OnClose(isShutdown, userData);
|
||||
|
||||
foreach (var item in _roleItems)
|
||||
{
|
||||
item.OnReset();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void OnReturnButtonClick()
|
||||
{
|
||||
GameEntry.UI.CloseUIForm(this);
|
||||
}
|
||||
|
||||
public void UpdateShowRole(DRRole role)
|
||||
{
|
||||
_currentRole = role;
|
||||
|
||||
if (role == null)
|
||||
{
|
||||
_randomRoleCard.SetActive(true);
|
||||
_roleCard.SetActive(false);
|
||||
_propertyArea.OnReset();
|
||||
}
|
||||
else
|
||||
{
|
||||
_randomRoleCard.SetActive(false);
|
||||
_propertyArea.OnInit(role);
|
||||
_roleCard.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
if (_currentRole == null)
|
||||
{
|
||||
int roleIndex = Random.Range(0, _roleList.Length);
|
||||
_currentRole = _roleList[roleIndex];
|
||||
}
|
||||
|
||||
_procedure?.StartGame(_currentRole.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 665710bc9ed5c5547a40f0cc2d92ba2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user