コード例 #1
0
ファイル: UI_UnitDisplay.cs プロジェクト: Epicguru/ProjectB
        private void DisplayUnits()
        {
            var selected = Unit.GetAllSelected();

            units.Clear();
            units.AddRange(selected);

            if (units.Count == 0)
            {
                return;
            }

            UI.Label($"Selected: {(units.Count == 1 ? units[0].Name : (units.Count + " units"))}.");
            UI.Label("Available actions:");

            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.ExpandHeight(false));

            int index = 0;

            foreach (var action in units.Count != 1 ? UnitAction.MergeActions(units) : units[0].GetAllActions())
            {
                if (UI.Button($"{action.Name} [{ActionKeys.Get(index)}]") || Input.GetKeyDown(ActionKeys.Get(index)))
                {
                    if (units.Count == 1)
                    {
                        string error = action.Run(units[0], null);
                        if (error != null)
                        {
                            Debug.LogWarning($"Action error: {error}");
                        }
                    }
                    else
                    {
                        foreach (var unit in units)
                        {
                            string error = action.Run(unit, null);
                            if (error != null)
                            {
                                Debug.LogWarning($"Action error: {error}");
                            }
                        }
                    }
                }
                index++;
            }

            GUILayout.EndScrollView();

            if (units.Count == 1)
            {
                DisplaySingleUnit(units[0]);
            }
        }