示例#1
0
        public override void OnInspectorGUI()
        {
            if (!_tableAuthoring)
            {
                EditorGUILayout.HelpBox($"Cannot find table. The gamelogic engine must be applied to a table object or one of its children.", MessageType.Error);
                return;
            }

            var pos = EditorGUILayout.GetControlRect(true, 18f);

            pos = EditorGUI.PrefixLabel(pos, new GUIContent("Machine Folder"));

            if (GUI.Button(pos, _mpfEngine.machineFolder, EditorStyles.objectField))
            {
                var path = EditorUtility.OpenFolderPanel("Mission Pinball Framework: Choose machine folder", _mpfEngine.machineFolder, "");
                if (!string.IsNullOrWhiteSpace(path))
                {
                    _mpfEngine.machineFolder = path;
                }
            }

            if (GUILayout.Button("Get Machine Description"))
            {
                if (!Directory.Exists(_mpfEngine.machineFolder))
                {
                    EditorUtility.DisplayDialog("Mission Pinball Framework", "Gotta choose a valid machine folder first!", "Okay");
                }
                else if (!Directory.Exists(Path.Combine(_mpfEngine.machineFolder, "config")))
                {
                    EditorUtility.DisplayDialog("Mission Pinball Framework", $"{_mpfEngine.machineFolder} doesn't seem a valid machine folder. We expect a \"config\" subfolder in there!", "Okay");
                }
                else
                {
                    _mpfEngine.GetMachineDescription();
                }
            }

            EditorGUI.BeginDisabledGroup(!HasData);
            if (GUILayout.Button("Populate Hardware"))
            {
                if (EditorUtility.DisplayDialog("Mission Pinball Framework", "This will clear all linked switches, coils and lamps and re-populate them. You sure you want to do that?", "Yes", "No"))
                {
                    _tableAuthoring.RepopulateHardware(_mpfEngine);
                    TableSelector.Instance.TableUpdated();
                    SceneView.RepaintAll();
                }
            }
            EditorGUI.EndDisabledGroup();


            var naStyle = new GUIStyle(GUI.skin.label)
            {
                fontStyle = FontStyle.Italic
            };

            // list switches, coils and lamps
            if (_mpfEngine.AvailableCoils.Length + _mpfEngine.AvailableSwitches.Length + _mpfEngine.AvailableLamps.Length > 0)
            {
                if (_foldoutSwitches = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutSwitches, "Switches"))
                {
                    foreach (var sw in _mpfEngine.AvailableSwitches)
                    {
                        EditorGUILayout.LabelField(new GUIContent($"  [{sw.InternalId}] {sw.Id} ", Icons.Switch(sw.NormallyClosed, IconSize.Small)));
                    }
                    if (_mpfEngine.AvailableSwitches.Length == 0)
                    {
                        EditorGUILayout.LabelField("No switches in this machine.", naStyle);
                    }
                }
                EditorGUILayout.EndFoldoutHeaderGroup();

                if (_foldoutCoils = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutCoils, "Coils"))
                {
                    foreach (var sw in _mpfEngine.AvailableCoils)
                    {
                        EditorGUILayout.LabelField(new GUIContent($"  [{sw.InternalId}] {sw.Id} ", Icons.Coil(IconSize.Small)));
                    }
                    if (_mpfEngine.AvailableCoils.Length == 0)
                    {
                        EditorGUILayout.LabelField("No coils in this machine.", naStyle);
                    }
                }
                EditorGUILayout.EndFoldoutHeaderGroup();

                if (_foldoutLamps = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutLamps, "Lamps"))
                {
                    foreach (var sw in _mpfEngine.AvailableLamps)
                    {
                        EditorGUILayout.LabelField(new GUIContent($"  [{sw.InternalId}] {sw.Id} ", Icons.Light(IconSize.Small)));
                    }
                    if (_mpfEngine.AvailableLamps.Length == 0)
                    {
                        EditorGUILayout.LabelField("No lamps in this machine.", naStyle);
                    }
                }
                EditorGUILayout.EndFoldoutHeaderGroup();
            }
        }