一款基于卡牌的塔防游戏,类似于 Supercell 的《皇室战争》的游戏玩法(简化形式), 可以与“非智能”AI 进行比赛。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

67 行
2.1 KiB

using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
class PopupControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public PopupControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new PopupControlView(m_Label, node, propertyInfo);
}
}
[Serializable]
struct PopupList
{
public int selectedEntry;
public List<string> popupEntries;
}
class PopupControlView : VisualElement
{
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
PopupField<string> m_PopupField;
public PopupControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/PopupControlView"));
m_Node = node;
m_PropertyInfo = propertyInfo;
Type type = propertyInfo.PropertyType;
if (type != typeof(PopupList))
{
throw new ArgumentException("Property must be a PopupList.", "propertyInfo");
}
Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
var value = (PopupList)propertyInfo.GetValue(m_Node, null);
m_PopupField = new PopupField<string>(value.popupEntries, value.selectedEntry);
m_PopupField.RegisterValueChangedCallback(OnValueChanged);
Add(m_PopupField);
}
void OnValueChanged(ChangeEvent<string> evt)
{
var value = (PopupList)m_PropertyInfo.GetValue(m_Node, null);
value.selectedEntry = m_PopupField.index;
m_PropertyInfo.SetValue(m_Node, value, null);
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
}
}
}