コード例 #1
0
        internal override void Apply(VisualElement container)
        {
            /// <sample>
            // Get a reference to the field from UXML and assign it its value.
            var uxmlField = container.Q <LongField>("the-uxml-field");

            uxmlField.value = 42;

            // Create a new field, disable it, and give it a style class.
            var csharpField = new LongField("C# Field");

            csharpField.SetEnabled(false);
            csharpField.AddToClassList("some-styled-field");
            csharpField.value = uxmlField.value;
            container.Add(csharpField);

            // Mirror value of uxml field into the C# field.
            uxmlField.RegisterCallback <ChangeEvent <long> >((evt) =>
            {
                csharpField.value = evt.newValue;
            });
            /// </sample>
        }
コード例 #2
0
ファイル: NodeUtil.cs プロジェクト: Aspekt1024/HexCraft
        public static VisualElement CreateCostField(Currency cost, Action <Currency> costUpdateAction, bool isResearched = true, bool canAfford = true)
        {
            var costDisplay = new VisualElement();

            costDisplay.AddToClassList("action-cost");
            var suppliesCost = new LongField(3)
            {
                value = cost.supplies
            };

            suppliesCost.RegisterValueChangedCallback(
                newSupplies =>
            {
                cost.supplies = (int)newSupplies.newValue;
                costUpdateAction.Invoke(cost);
            });
            suppliesCost.AddToClassList("cost-field");

            var productionCost = new LongField(3)
            {
                value = cost.production
            };

            productionCost.RegisterValueChangedCallback(
                newProduction =>
            {
                cost.production = (int)newProduction.newValue;
                costUpdateAction.Invoke(cost);
            });
            productionCost.AddToClassList("cost-field");

            var populationCost = new LongField(3)
            {
                value = cost.population
            };

            populationCost.RegisterValueChangedCallback(
                newPopulation =>
            {
                cost.population = (int)newPopulation.newValue;
                costUpdateAction.Invoke(cost);
            });
            populationCost.AddToClassList("cost-field");

            costDisplay.Add(suppliesCost);
            costDisplay.Add(new Label("s "));
            costDisplay.Add(productionCost);
            costDisplay.Add(new Label("pd"));
            costDisplay.Add(populationCost);
            costDisplay.Add(new Label("pp"));

            if (isResearched)
            {
                costDisplay.AddToClassList("action-cost-researched");
            }
            else if (!canAfford)
            {
                costDisplay.AddToClassList("action-cost-unaffordable");
            }
            else
            {
                costDisplay.AddToClassList("action-cost-purchasable");
            }

            return(costDisplay);
        }