コード例 #1
0
        public static GameObject ImportIntoScene(FileTableContainer tableContainer, string filename = "", GameObject parent = null, bool applyPatch = true, string tableName = null, Stopwatch sw = null, ConvertOptions options = null)
        {
            sw ??= Stopwatch.StartNew();
            if (tableName == null && !string.IsNullOrEmpty(filename))
            {
                tableName = Path.GetFileNameWithoutExtension(filename);
            }

            // load table
            var loadedIn        = sw.ElapsedMilliseconds;
            var converter       = new VpxSceneConverter(tableContainer, filename, options);
            var tableGameObject = converter.Convert(applyPatch, tableName);
            var convertedIn     = sw.ElapsedMilliseconds;

            // if an object was selected in the editor, make it its parent
            if (parent != null)
            {
                GameObjectUtility.SetParentAndAlign(tableGameObject, parent);
            }

            // register undo system
            Undo.RegisterCreatedObjectUndo(tableGameObject, "Import VPX table file");

            // select imported object
            Selection.activeObject = tableGameObject;

            Logger.Info($"Imported {filename} in {convertedIn}ms (loaded after {loadedIn}ms).");

            return(tableGameObject);
        }
コード例 #2
0
        private GameObject CreateRenderable(IItem item)
        {
            var converter = new VpxSceneConverter(TableComponent);

            TableComponent.TableContainer.Refresh();
            return(converter.InstantiateAndPersistPrefab(item).GameObject);
        }
コード例 #3
0
        private void CreatePrefab <T>(string groupName, string path) where T : Component
        {
            var converter = new VpxSceneConverter(TableComponent);

            TableComponent.TableContainer.Refresh();

            var parentGo = converter.GetGroupParent(groupName);

            var prefab = Resources.Load <GameObject>(path);
            var go     = PrefabUtility.InstantiatePrefab(prefab) as GameObject;

            if (go)
            {
                go.name = GetNewPrefabName <T>(go.name);

                go.transform.SetParent(parentGo.transform, false);
            }

            Selection.activeGameObject = go;
        }
コード例 #4
0
        private void OnGUI()
        {
            const IconColor iconColor   = IconColor.Gray;
            var             iconSize    = position.width / 2f - 4.5f;
            var             buttonStyle = new GUIStyle(GUI.skin.button)
            {
                alignment     = TextAnchor.MiddleCenter,
                imagePosition = ImagePosition.ImageAbove
            };

            if (GUILayout.Button("New Table"))
            {
                var tableContainer = new FileTableContainer();
                var converter      = new VpxSceneConverter(tableContainer);
                var rootGameObj    = converter.Convert(false);
                Selection.activeGameObject = rootGameObj;
                Undo.RegisterCreatedObjectUndo(rootGameObj, "New Table");
            }

            if (TableComponent == null)
            {
                return;
            }

            EditorGUILayout.Space();
            GUILayout.Label(TableComponent.name, new GUIStyle(GUI.skin.label)
            {
                fontStyle = FontStyle.Bold
            });

            GUILayout.BeginHorizontal();

            if (CreateButton("Wall", Icons.Surface(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Surface.GetDefault, "Wall");
            }

            if (CreateButton("Gate", Icons.Gate(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Gate.GetDefault, "New Gate");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Ramp", Icons.Ramp(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Ramp.GetDefault, "New Ramp");
            }

            if (CreateButton("Flipper", Icons.Flipper(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Flipper.GetDefault, "New Flipper");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Plunger", Icons.Plunger(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Plunger.GetDefault, "New Plunger");
            }

            if (CreateButton("Bumper", Icons.Bumper(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Bumper.GetDefault, "New Bumper");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Spinner", Icons.Spinner(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Spinner.GetDefault, "New Spinner");
            }

            if (CreateButton("Trigger", Icons.Trigger(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Trigger.GetDefault, "New Trigger");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Kicker", Icons.Kicker(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Kicker.GetDefault, "New Kicker");
            }

            if (CreateButton("Light", Icons.Light(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Light.GetDefault, "New Light");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Hit Target", Icons.HitTarget(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(HitTarget.GetHitTarget, "New Hit Target");
            }

            if (CreateButton("Drop Target", Icons.DropTarget(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(HitTarget.GetDropTarget, "New Target");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Rubber", Icons.Rubber(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Rubber.GetDefault, "New Rubber");
            }

            if (CreateButton("Primitive", Icons.Primitive(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Primitive.GetDefault, "New Primitive");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Trough", Icons.Trough(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(Trough.GetDefault, "New Trough");
            }

            if (CreateButton("Drop Target\nBank", Icons.DropTargetBank(color: iconColor), iconSize, buttonStyle))
            {
                CreatePrefab <DropTargetBankComponent>("Drop Target Banks", "Prefabs/DropTargetBank");
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (CreateButton("Slingshot", Icons.Slingshot(color: iconColor), iconSize, buttonStyle))
            {
                CreatePrefab <SlingshotComponent>("Slingshots", "Prefabs/Slingshot");
            }

            if (CreateButton("Metal Wire\nGuide", Icons.MetalWireGuide(color: iconColor), iconSize, buttonStyle))
            {
                CreateItem(MetalWireGuide.GetDefault, "New MetalWireGuide");
            }


            GUILayout.EndHorizontal();
        }