Esempio n. 1
0
        /**
         * <summary>Unsets the values of all script variables, so that they can be re-assigned to the correct scene if multiple scenes are open.</summary>
         */
        public void ClearVariables()
        {
            playerPrefab = null;
            mainCameraPrefab = null;
            persistentEnginePrefab = null;
            gameEnginePrefab = null;

            // Managers
            sceneManagerPrefab = null;
            settingsManagerPrefab = null;
            actionsManagerPrefab = null;
            variablesManagerPrefab = null;
            inventoryManagerPrefab = null;
            speechManagerPrefab = null;
            cursorManagerPrefab = null;
            menuManagerPrefab = null;

            // PersistentEngine components
            optionsComponent = null;
            runtimeInventoryComponent = null;
            runtimeVariablesComponent = null;
            playerMenusComponent = null;
            stateHandlerComponent = null;
            sceneChangerComponent = null;
            saveSystemComponent = null;
            levelStorageComponent = null;
            runtimeLanguagesComponent = null;

            // GameEngine components
            menuSystemComponent = null;
            dialogComponent = null;
            playerInputComponent = null;
            playerInteractionComponent = null;
            playerMovementComponent = null;
            playerCursorComponent = null;
            playerQTEComponent = null;
            sceneSettingsComponent = null;
            navigationManagerComponent = null;
            actionListManagerComponent = null;
            localVariablesComponent = null;
            menuPreviewComponent = null;

            SetGameEngine ();
        }
Esempio n. 2
0
        private void Update()
        {
            if (!Application.isPlaying)
            {
                if (AdvGame.GetReferences ())
                {
                    menuManager = AdvGame.GetReferences ().menuManager;

                    if (menuManager)
                    {
                        if (menuManager.GetSelectedMenu () != null)
                        {
                            AC.Menu menu = menuManager.GetSelectedMenu ();

                            foreach (MenuElement element in menu.visibleElements)
                            {
                                for (int i=0; i<element.GetNumSlots (); i++)
                                {
                                    if (menuManager.GetSelectedElement () == element && element.isClickable && i == 0)
                                    {
                                        element.PreDisplay (i, 0, false);
                                    }

                                    else
                                    {
                                        element.PreDisplay (i, 0, false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void OnGUI()
        {
            if (!Application.isPlaying)
            {
                if (AdvGame.GetReferences ())
                {
                    menuManager = AdvGame.GetReferences ().menuManager;

                    if (menuManager && menuManager.drawInEditor && AdvGame.GetReferences ().viewingMenuManager)
                    {
                        if (menuManager.GetSelectedMenu () != null)
                        {
                            AC.Menu menu = menuManager.GetSelectedMenu ();

                            if (menu.IsUnityUI ())
                            {
                                return;
                            }

                            CheckScreenSize (menu);

                            if ((menu.appearType == AppearType.Manual || menu.appearType == AppearType.OnInputKey) && menu.pauseWhenEnabled && menuManager.pauseTexture)
                            {
                                GUI.DrawTexture (AdvGame.GUIRect (0.5f, 0.5f, 1f, 1f), menuManager.pauseTexture, ScaleMode.ScaleToFit, true, 0f);
                            }

                            if ((menu.positionType == AC_PositionType.FollowCursor || menu.positionType == AC_PositionType.AppearAtCursorAndFreeze || menu.positionType == AC_PositionType.OnHotspot || menu.positionType == AC_PositionType.AboveSpeakingCharacter || menu.positionType == AC_PositionType.AbovePlayer) && AdvGame.GetReferences ().cursorManager && AdvGame.GetReferences ().cursorManager.pointerIcon.texture)
                            {
                                CursorIconBase icon = AdvGame.GetReferences ().cursorManager.pointerIcon;
                                GUI.DrawTexture (AdvGame.GUIBox (new Vector2 (AdvGame.GetMainGameViewSize ().x / 2f, AdvGame.GetMainGameViewSize ().y / 2f), icon.size), icon.texture, ScaleMode.ScaleToFit, true, 0f);
                            }

                            menu.StartDisplay ();

                            foreach (MenuElement element in menu.visibleElements)
                            {
                                SetStyles (element);

                                for (int i=0; i<element.GetNumSlots (); i++)
                                {
                                    if (menuManager.GetSelectedElement () == element && element.isClickable && i == 0)
                                    {
                                    //	element.PreDisplay (i, true, 0);
                                        element.Display (highlightedStyle, i, 1f, true);
                                    }

                                    else
                                    {
                                    //	element.PreDisplay (i, true, 0);
                                        element.Display (normalStyle, i, 1f, false);
                                    }
                                }

                                if (menu.IsPointerOverSlot (element, 0, Event.current.mousePosition + new Vector2 (menu.GetRect ().x, menu.GetRect ().y)))
                                {
                                    menuManager.SelectElementFromPreview (menu, element);
                                }
                            }

                            menu.EndDisplay ();

                            if (menuManager.drawOutlines)
                            {
                                menu.DrawOutline (menuManager.GetSelectedElement ());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
		private void OnDestroy ()
		{
			actionListManager = null;
			dialog = null;
			playerInput = null;
			playerInteraction = null;
			menuSystem = null;
			stateHandler = null;
			options = null;
			menus = null;
			runtimeInventory = null;
			settingsManager = null;
			cursorManager = null;
			speechManager = null;
			menuManager = null;
			sceneSettings = null;
		}
        /**
         * <summary>Rebuilds the game's Menus, either from the existing MenuManager asset, or from a new one.</summary>
         * <param name = "menuManager">The Menu Manager to use for Menu generation. If left empty, the default Menu Manager will be used.</param>
         */
        public void RebuildMenus(MenuManager menuManager = null)
        {
            if (menuManager != null)
            {
                KickStarter.menuManager = menuManager;
            }

            foreach (Menu menu in menus)
            {
                if (menu.menuSource == MenuSource.UnityUiPrefab && menu.canvas != null && menu.canvas.gameObject != null)
                {
                    Destroy (menu.canvas.gameObject);
                }
            }

            menus = new List<Menu>();

            if (KickStarter.menuManager)
            {
                pauseTexture = KickStarter.menuManager.pauseTexture;
                foreach (AC.Menu _menu in KickStarter.menuManager.menus)
                {
                    Menu newMenu = ScriptableObject.CreateInstance <Menu>();
                    newMenu.Copy (_menu);

                    if (_menu.appearType == AppearType.WhenSpeechPlays && _menu.oneMenuPerSpeech)
                    {
                        // Don't make canvas object yet!
                    }
                    else if (newMenu.IsUnityUI ())
                    {
                        newMenu.LoadUnityUI ();
                    }
                    newMenu.Initalise ();
                    menus.Add (newMenu);
                }
            }

            CreateEventSystem ();

            foreach (AC.Menu menu in menus)
            {
                menu.Recalculate ();
            }

            #if UNITY_WEBPLAYER && !UNITY_EDITOR
            // WebPlayer takes another second to get the correct screen dimensions
            foreach (AC.Menu menu in menus)
            {
                menu.Recalculate ();
            }
            #endif
        }
Esempio n. 6
0
        private void ShowPage()
        {
            GUI.skin.label.wordWrap = true;

            if (pageNumber == 0)
            {
                if (Resource.ACLogo)
                {
                    GUI.DrawTexture(new Rect(82, 25, 256, 128), Resource.ACLogo);
                }
                GUILayout.Space(140f);
                GUILayout.Label("New Game Wizard", CustomStyles.managerHeader);

                GUILayout.Space(5f);
                GUILayout.Label("This window can help you get started with making a new Adventure Creator game.");
                GUILayout.Label("To begin, click 'Next'. Changes will not be implemented until you are finished.");
            }

            else if (pageNumber == 1)
            {
                GUILayout.Label("Enter a name for your game. This will be used for filenames, so alphanumeric characters only.");
                gameName = GUILayout.TextField(gameName);
            }

            else if (pageNumber == 2)
            {
                GUILayout.Label("What kind of perspective will your game have?");
                cameraPerspective_int = EditorGUILayout.Popup(cameraPerspective_int, cameraPerspective_list);

                if (cameraPerspective_int == 0)
                {
                    GUILayout.Space(5f);
                    GUILayout.Label("By default, 2D games are built entirely in the X-Z plane, and characters are scaled to achieve a depth effect.\nIf you prefer, you can position your characters in 3D space, so that they scale accurately due to camera perspective.");
                    screenSpace = EditorGUILayout.ToggleLeft("I'll position my characters in 3D space", screenSpace);
                }
                else if (cameraPerspective_int == 1)
                {
                    GUILayout.Space(5f);
                    GUILayout.Label("2.5D games mixes 3D characters with 2D backgrounds. By default, 2.5D games group several backgrounds into one scene, and swap them out according to the camera angle.\nIf you prefer, you can work with just one background in a scene, to create a more traditional 2D-like adventure.");
                    oneScenePerBackground = EditorGUILayout.ToggleLeft("I'll work with one background per scene", oneScenePerBackground);
                }
                else if (cameraPerspective_int == 2)
                {
                    GUILayout.Label("3D games can still have sprite-based Characters, but having a true 3D environment is more flexible so far as Player control goes. How should your Player character be controlled?");
                    movementMethod = (MovementMethod)EditorGUILayout.EnumPopup(movementMethod);
                }
            }

            else if (pageNumber == 3)
            {
                if (cameraPerspective_int == 1 && !oneScenePerBackground)
                {
                    GUILayout.Label("Do you want to play the game ONLY with a keyboard or controller?");
                    directControl = EditorGUILayout.ToggleLeft("Yes", directControl);
                    GUILayout.Space(5f);
                }
                else if (cameraPerspective_int == 2 && movementMethod == MovementMethod.Drag)
                {
                    GUILayout.Label("Is your game designed for Touch-screen devices?");
                    touchScreen = EditorGUILayout.ToggleLeft("Yes", touchScreen);
                    GUILayout.Space(5f);
                }

                GUILayout.Label("How do you want to interact with Hotspots?");
                interactionMethod = (AC_InteractionMethod)EditorGUILayout.EnumPopup(interactionMethod);
                if (interactionMethod == AC_InteractionMethod.ContextSensitive)
                {
                    EditorGUILayout.HelpBox("This method simplifies interactions to either Use, Examine, or Use Inventory. Hotspots can be interacted with in just one click.", MessageType.Info);
                }
                else if (interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot)
                {
                    EditorGUILayout.HelpBox("This method emulates the classic 'Sierra-style' interface, in which the player chooses from a list of verbs, and then the Hotspot they wish to interact with.", MessageType.Info);
                }
                else if (interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction)
                {
                    EditorGUILayout.HelpBox("This method involves first choosing a Hotspot, and then from a range of available interactions, which can be customised in the Editor.", MessageType.Info);
                }
                else if (interactionMethod == AC_InteractionMethod.CustomScript)
                {
                    EditorGUILayout.HelpBox("See the Manual's 'Custom interaction systems' section for information on how to trigger Hotspots and inventory items.", MessageType.Info);
                }
            }

            else if (pageNumber == 4)
            {
                GUILayout.Label("Please choose what interface you would like to start with. It can be changed at any time - this is just to help you get started.");
                wizardMenu = (WizardMenu)EditorGUILayout.EnumPopup(wizardMenu);

                if (wizardMenu == WizardMenu.DefaultAC || wizardMenu == WizardMenu.DefaultUnityUI)
                {
                    MenuManager    defaultMenuManager    = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_MenuManager.asset", typeof(MenuManager)) as MenuManager;
                    CursorManager  defaultCursorManager  = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_CursorManager.asset", typeof(CursorManager)) as CursorManager;
                    ActionsManager defaultActionsManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_ActionsManager.asset", typeof(ActionsManager)) as ActionsManager;

                    if (defaultMenuManager == null || defaultCursorManager == null || defaultActionsManager == null)
                    {
                        EditorGUILayout.HelpBox("Unable to locate the default Manager assets in '" + Resource.MainFolderPath + "/Default'. These assets must be imported in order to start with the default interface.", MessageType.Warning);
                    }
                }

                if (wizardMenu == WizardMenu.Blank)
                {
                    EditorGUILayout.HelpBox("Your interface will be completely blank - no cursor icons will exist either.\r\n\r\nThis option is not recommended for those still learning how to use AC.", MessageType.Info);
                }
                else if (wizardMenu == WizardMenu.DefaultAC)
                {
                    EditorGUILayout.HelpBox("This mode uses AC's built-in Menu system and not Unity UI.\r\n\r\nUnity UI prefabs will also be created for each Menu, however, so that you can make use of them later if you choose.", MessageType.Info);
                }
                else if (wizardMenu == WizardMenu.DefaultUnityUI)
                {
                    EditorGUILayout.HelpBox("This mode relies on Unity UI to handle the interface.\r\n\r\nCopies of the UI prefabs will be stored in a UI subdirectory, for you to edit.", MessageType.Info);
                }
            }

            else if (pageNumber == 5)
            {
                GUILayout.Label("The following values have been set based on your choices. Please review them and amend if necessary, then click 'Finish' to create your game template.");
                GUILayout.Space(5f);

                gameName = EditorGUILayout.TextField("Game name:", gameName);
                cameraPerspective_int = (int)cameraPerspective;
                cameraPerspective_int = EditorGUILayout.Popup("Camera perspective:", cameraPerspective_int, cameraPerspective_list);
                cameraPerspective     = (CameraPerspective)cameraPerspective_int;

                if (cameraPerspective == CameraPerspective.TwoD)
                {
                    movingTurning = (MovingTurning)EditorGUILayout.EnumPopup("Moving and turning:", movingTurning);
                }

                movementMethod    = (MovementMethod)EditorGUILayout.EnumPopup("Movement method:", movementMethod);
                inputMethod       = (InputMethod)EditorGUILayout.EnumPopup("Input method:", inputMethod);
                interactionMethod = (AC_InteractionMethod)EditorGUILayout.EnumPopup("Interaction method:", interactionMethod);
                hotspotDetection  = (HotspotDetection)EditorGUILayout.EnumPopup("Hotspot detection method:", hotspotDetection);

                wizardMenu = (WizardMenu)EditorGUILayout.EnumPopup("GUI type:", wizardMenu);
            }

            else if (pageNumber == 6)
            {
                GUILayout.Label("Your game's Managers have been set up!");
                GUILayout.Space(5f);
                GUILayout.Label("Your next step is to create and set your Player prefab, which you can do using the Character Wizard.");
            }
        }
Esempio n. 7
0
		private void GetReferences ()
		{
			settingsManager = AdvGame.GetReferences ().settingsManager;
			if (settingsManager.IsInLoadingScene ())
			{
				return;
			}
			
			speechManager = AdvGame.GetReferences ().speechManager;
			cursorManager = AdvGame.GetReferences ().cursorManager;
			menuManager = AdvGame.GetReferences ().menuManager;
			
			playerCursor = GameObject.FindWithTag (Tags.gameEngine).GetComponent <PlayerCursor>();
			actionListManager = playerCursor.GetComponent <ActionListManager>();
			playerInput = playerCursor.GetComponent <PlayerInput>();
			playerInteraction = playerCursor.GetComponent <PlayerInteraction>();
			menuSystem = playerCursor.GetComponent <MenuSystem>();
			dialog = playerCursor.GetComponent <Dialog>();
			sceneSettings = playerCursor.GetComponent <SceneSettings>();
			
			stateHandler = this.GetComponent <StateHandler>();
			options = this.GetComponent <Options>();
			runtimeInventory = this.GetComponent <RuntimeInventory>();
		}
Esempio n. 8
0
        private void Finish()
        {
            if (!references)
            {
                GetReferences();
            }

            if (!references)
            {
                return;
            }

            string managerPath = gameName + "/Managers";

            try
            {
                System.IO.Directory.CreateDirectory(Application.dataPath + "/" + managerPath);
            }
            catch (System.Exception e)
            {
                ACDebug.LogError("Wizard aborted - Could not create directory: " + Application.dataPath + "/" + managerPath + ". Please make sure the Assets direcrory is writeable, and that the intended game name contains no special characters.");
                Debug.LogException(e, this);
                pageNumber--;
                return;
            }

            try
            {
                ScriptableObject t = CustomAssetUtility.CreateAsset <SceneManager> ("SceneManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SceneManager.asset", gameName + "_SceneManager");
                references.sceneManager = (SceneManager)t;

                t = CustomAssetUtility.CreateAsset <SettingsManager> ("SettingsManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SettingsManager.asset", gameName + "_SettingsManager");
                references.settingsManager = (SettingsManager)t;

                references.settingsManager.saveFileName      = gameName;
                references.settingsManager.cameraPerspective = cameraPerspective;
                references.settingsManager.movingTurning     = movingTurning;
                references.settingsManager.movementMethod    = movementMethod;
                references.settingsManager.inputMethod       = inputMethod;
                references.settingsManager.interactionMethod = interactionMethod;
                references.settingsManager.hotspotDetection  = hotspotDetection;
                if (cameraPerspective == CameraPerspective.TwoPointFiveD)
                {
                    references.settingsManager.forceAspectRatio = true;
                }

                t = CustomAssetUtility.CreateAsset <ActionsManager> ("ActionsManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/ActionsManager.asset", gameName + "_ActionsManager");
                references.actionsManager = (ActionsManager)t;
                AdventureCreator.RefreshActions();
                ActionsManager defaultActionsManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_ActionsManager.asset", typeof(ActionsManager)) as ActionsManager;
                if (defaultActionsManager != null)
                {
                    references.actionsManager.defaultClass     = defaultActionsManager.defaultClass;
                    references.actionsManager.defaultClassName = defaultActionsManager.defaultClassName;
                }

                t = CustomAssetUtility.CreateAsset <VariablesManager> ("VariablesManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/VariablesManager.asset", gameName + "_VariablesManager");
                references.variablesManager = (VariablesManager)t;

                t = CustomAssetUtility.CreateAsset <InventoryManager> ("InventoryManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/InventoryManager.asset", gameName + "_InventoryManager");
                references.inventoryManager = (InventoryManager)t;

                t = CustomAssetUtility.CreateAsset <SpeechManager> ("SpeechManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SpeechManager.asset", gameName + "_SpeechManager");
                references.speechManager = (SpeechManager)t;

                references.speechManager.ClearLanguages();

                t = CustomAssetUtility.CreateAsset <CursorManager> ("CursorManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/CursorManager.asset", gameName + "_CursorManager");
                references.cursorManager = (CursorManager)t;

                t = CustomAssetUtility.CreateAsset <MenuManager> ("MenuManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/MenuManager.asset", gameName + "_MenuManager");
                references.menuManager = (MenuManager)t;

                CursorManager defaultCursorManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_CursorManager.asset", typeof(CursorManager)) as CursorManager;
                if (wizardMenu == WizardMenu.Blank)
                {
                    if (defaultCursorManager != null)
                    {
                        CursorIcon useIcon = new CursorIcon();
                        useIcon.Copy(defaultCursorManager.cursorIcons[0]);
                        references.cursorManager.cursorIcons.Add(useIcon);
                        EditorUtility.SetDirty(references.cursorManager);
                    }
                }
                else
                {
                    if (defaultCursorManager != null)
                    {
                        foreach (CursorIcon defaultIcon in defaultCursorManager.cursorIcons)
                        {
                            CursorIcon newIcon = new CursorIcon();
                            newIcon.Copy(defaultIcon);
                            references.cursorManager.cursorIcons.Add(newIcon);
                        }

                        CursorIconBase pointerIcon = new CursorIconBase();
                        pointerIcon.Copy(defaultCursorManager.pointerIcon);
                        references.cursorManager.pointerIcon = pointerIcon;
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot find Default_CursorManager asset to copy from!");
                    }
                    references.cursorManager.allowMainCursor = true;
                    EditorUtility.SetDirty(references.cursorManager);

                    MenuManager defaultMenuManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_MenuManager.asset", typeof(MenuManager)) as MenuManager;
                    if (defaultMenuManager != null)
                    {
                                                #if UNITY_EDITOR
                        references.menuManager.drawOutlines = defaultMenuManager.drawOutlines;
                        references.menuManager.drawInEditor = defaultMenuManager.drawInEditor;
                                                #endif
                        references.menuManager.pauseTexture = defaultMenuManager.pauseTexture;

                        if (wizardMenu != WizardMenu.Blank)
                        {
                            System.IO.Directory.CreateDirectory(Application.dataPath + "/" + gameName + "/UI");
                        }
                        foreach (Menu defaultMenu in defaultMenuManager.menus)
                        {
                            Menu newMenu = ScriptableObject.CreateInstance <Menu>();
                            newMenu.Copy(defaultMenu, true, true);
                            newMenu.Recalculate();

                            if (wizardMenu == WizardMenu.DefaultAC)
                            {
                                newMenu.menuSource = MenuSource.AdventureCreator;
                            }
                            else if (wizardMenu == WizardMenu.DefaultUnityUI)
                            {
                                newMenu.menuSource = MenuSource.UnityUiPrefab;
                            }

                            if (defaultMenu.canvas)
                            {
                                string oldPath = AssetDatabase.GetAssetPath(defaultMenu.canvas.gameObject);
                                string newPath = "Assets/" + gameName + "/UI/" + defaultMenu.canvas.name + ".prefab";

                                if (AssetDatabase.CopyAsset(oldPath, newPath))
                                {
                                    AssetDatabase.ImportAsset(newPath);
                                    GameObject canvasObNewPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(newPath, typeof(GameObject));
                                    newMenu.canvas = canvasObNewPrefab.GetComponent <Canvas>();
                                }
                                else
                                {
                                    newMenu.canvas = null;
                                    ACDebug.LogWarning("Could not copy asset " + oldPath + " to " + newPath, defaultMenu.canvas.gameObject);
                                }
                                newMenu.rectTransform = null;
                            }

                            foreach (MenuElement newElement in newMenu.elements)
                            {
                                if (newElement != null)
                                {
                                    AssetDatabase.AddObjectToAsset(newElement, references.menuManager);
                                    newElement.hideFlags = HideFlags.HideInHierarchy;
                                }
                                else
                                {
                                    ACDebug.LogWarning("Null element found in " + newMenu.title + " - the interface may not be set up correctly.");
                                }
                            }
                            AssetDatabase.AddObjectToAsset(newMenu, references.menuManager);
                            newMenu.hideFlags = HideFlags.HideInHierarchy;

                            references.menuManager.menus.Add(newMenu);
                        }

                        EditorUtility.SetDirty(references.menuManager);
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot find Default_MenuManager asset to copy from!");
                    }
                }

                CreateManagerPackage(gameName);

                AssetDatabase.SaveAssets();
                if (GameObject.FindObjectOfType <KickStarter>() == null)
                {
                    bool initScene = EditorUtility.DisplayDialog("Organise scene?", "Process complete.  Would you like to organise the scene objects to begin working?  This can be done at any time within the Scene Manager.", "Yes", "No");
                    if (initScene)
                    {
                        references.sceneManager.InitialiseObjects();
                    }
                }
            }
            catch (System.Exception e)
            {
                ACDebug.LogWarning("Could not create Manager. Does the subdirectory " + managerPath + " exist?");
                Debug.LogException(e, this);
                pageNumber--;
            }
        }
Esempio n. 9
0
        private void OnGUI()
        {
            if (!Application.isPlaying)
            {
                if (AdvGame.GetReferences())
                {
                    menuManager = AdvGame.GetReferences().menuManager;

                    if (menuManager && menuManager.drawInEditor && AdvGame.GetReferences().viewingMenuManager)
                    {
                        if (menuManager.GetSelectedMenu() != null)
                        {
                            AC.Menu menu = menuManager.GetSelectedMenu();

                            if (menu.IsUnityUI())
                            {
                                return;
                            }

                            CheckScreenSize(menu);

                            if ((menu.appearType == AppearType.Manual || menu.appearType == AppearType.OnInputKey) && menu.pauseWhenEnabled && menuManager.pauseTexture)
                            {
                                GUI.DrawTexture(AdvGame.GUIRect(0.5f, 0.5f, 1f, 1f), menuManager.pauseTexture, ScaleMode.ScaleToFit, true, 0f);
                            }

                            if ((menu.positionType == AC_PositionType.FollowCursor || menu.positionType == AC_PositionType.AppearAtCursorAndFreeze || menu.positionType == AC_PositionType.OnHotspot || menu.positionType == AC_PositionType.AboveSpeakingCharacter || menu.positionType == AC_PositionType.AbovePlayer) && AdvGame.GetReferences().cursorManager&& AdvGame.GetReferences().cursorManager.pointerIcon.texture)
                            {
                                CursorIconBase icon = AdvGame.GetReferences().cursorManager.pointerIcon;
                                GUI.DrawTexture(AdvGame.GUIBox(new Vector2(AdvGame.GetMainGameViewSize().x / 2f, AdvGame.GetMainGameViewSize().y / 2f), icon.size), icon.texture, ScaleMode.ScaleToFit, true, 0f);
                            }

                            menu.StartDisplay();

                            foreach (MenuElement element in menu.visibleElements)
                            {
                                SetStyles(element);

                                for (int i = 0; i < element.GetNumSlots(); i++)
                                {
                                    if (menuManager.GetSelectedElement() == element && element.isClickable && i == 0)
                                    {
                                        //	element.PreDisplay (i, true, 0);
                                        element.Display(highlightedStyle, i, 1f, true);
                                    }

                                    else
                                    {
                                        //	element.PreDisplay (i, true, 0);
                                        element.Display(normalStyle, i, 1f, false);
                                    }
                                }

                                if (menu.IsPointerOverSlot(element, 0, Event.current.mousePosition + new Vector2(menu.GetRect().x, menu.GetRect().y)))
                                {
                                    menuManager.SelectElementFromPreview(menu, element);
                                }
                            }

                            menu.EndDisplay();

                            if (menuManager.drawOutlines)
                            {
                                menu.DrawOutline(menuManager.GetSelectedElement());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        private void Finish()
        {
            if (!references)
            {
                GetReferences();
            }

            if (!references)
            {
                return;
            }

            string managerPath = gameName + "/Managers";

            try
            {
                System.IO.Directory.CreateDirectory(Application.dataPath + "/" + managerPath);
            }
            catch
            {
                ACDebug.LogError("Wizard aborted - Could not create directory: " + Application.dataPath + "/" + managerPath + ". Please make sure the Assets direcrory is writeable, and that the intended game name contains no special characters.");
                pageNumber--;
                return;
            }

            try
            {
                ScriptableObject t = CustomAssetUtility.CreateAsset <SceneManager> ("SceneManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SceneManager.asset", gameName + "_SceneManager");
                references.sceneManager = (SceneManager)t;

                t = CustomAssetUtility.CreateAsset <SettingsManager> ("SettingsManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SettingsManager.asset", gameName + "_SettingsManager");
                references.settingsManager = (SettingsManager)t;

                references.settingsManager.saveFileName      = gameName;
                references.settingsManager.cameraPerspective = cameraPerspective;
                references.settingsManager.movementMethod    = movementMethod;
                references.settingsManager.inputMethod       = inputMethod;
                references.settingsManager.interactionMethod = interactionMethod;
                references.settingsManager.hotspotDetection  = hotspotDetection;
                references.settingsManager.movingTurning     = movingTurning;
                if (cameraPerspective == CameraPerspective.TwoPointFiveD)
                {
                    references.settingsManager.forceAspectRatio = true;
                }

                t = CustomAssetUtility.CreateAsset <ActionsManager> ("ActionsManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/ActionsManager.asset", gameName + "_ActionsManager");
                references.actionsManager = (ActionsManager)t;
                AdventureCreator.RefreshActions();
                ActionsManager demoActionsManager = AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Demo/Managers/Demo_ActionsManager.asset", typeof(ActionsManager)) as ActionsManager;
                if (demoActionsManager != null)
                {
                    references.actionsManager.defaultClass     = demoActionsManager.defaultClass;
                    references.actionsManager.defaultClassName = demoActionsManager.defaultClassName;
                }

                t = CustomAssetUtility.CreateAsset <VariablesManager> ("VariablesManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/VariablesManager.asset", gameName + "_VariablesManager");
                references.variablesManager = (VariablesManager)t;

                t = CustomAssetUtility.CreateAsset <InventoryManager> ("InventoryManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/InventoryManager.asset", gameName + "_InventoryManager");
                references.inventoryManager = (InventoryManager)t;

                t = CustomAssetUtility.CreateAsset <SpeechManager> ("SpeechManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SpeechManager.asset", gameName + "_SpeechManager");
                references.speechManager = (SpeechManager)t;

                references.speechManager.ClearLanguages();

                t = CustomAssetUtility.CreateAsset <CursorManager> ("CursorManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/CursorManager.asset", gameName + "_CursorManager");
                references.cursorManager = (CursorManager)t;

                t = CustomAssetUtility.CreateAsset <MenuManager> ("MenuManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/MenuManager.asset", gameName + "_MenuManager");
                references.menuManager = (MenuManager)t;

                CursorManager demoCursorManager = AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Demo/Managers/Demo_CursorManager.asset", typeof(CursorManager)) as CursorManager;
                if (wizardMenu == WizardMenu.Blank)
                {
                    if (demoCursorManager != null)
                    {
                        CursorIcon useIcon = new CursorIcon();
                        useIcon.Copy(demoCursorManager.cursorIcons[0]);
                        references.cursorManager.cursorIcons.Add(useIcon);
                        EditorUtility.SetDirty(references.cursorManager);
                    }
                }
                else
                {
                    if (demoCursorManager != null)
                    {
                        foreach (CursorIcon demoIcon in demoCursorManager.cursorIcons)
                        {
                            CursorIcon newIcon = new CursorIcon();
                            newIcon.Copy(demoIcon);
                            references.cursorManager.cursorIcons.Add(newIcon);
                        }

                        CursorIconBase pointerIcon = new CursorIconBase();
                        pointerIcon.Copy(demoCursorManager.pointerIcon);
                        references.cursorManager.pointerIcon = pointerIcon;
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot find Demo_CursorManager asset to copy from!");
                    }

                    references.cursorManager.allowMainCursor = true;
                    EditorUtility.SetDirty(references.cursorManager);

                    MenuManager demoMenuManager = AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Demo/Managers/Demo_MenuManager.asset", typeof(MenuManager)) as MenuManager;
                    if (demoMenuManager != null)
                    {
                                                #if UNITY_EDITOR
                        references.menuManager.drawOutlines = demoMenuManager.drawOutlines;
                        references.menuManager.drawInEditor = demoMenuManager.drawInEditor;
                                                #endif
                        references.menuManager.pauseTexture = demoMenuManager.pauseTexture;

                        if (wizardMenu != WizardMenu.Blank)
                        {
                            System.IO.Directory.CreateDirectory(Application.dataPath + "/" + gameName + "/UI");
                        }

                        foreach (Menu demoMenu in demoMenuManager.menus)
                        {
                            Menu newMenu = ScriptableObject.CreateInstance <Menu>();
                            newMenu.Copy(demoMenu, true, true);
                            newMenu.Recalculate();

                            if (wizardMenu == WizardMenu.DefaultAC)
                            {
                                newMenu.menuSource = MenuSource.AdventureCreator;
                            }
                            else if (wizardMenu == WizardMenu.DefaultUnityUI)
                            {
                                newMenu.menuSource = MenuSource.UnityUiPrefab;
                            }

                            if (demoMenu.canvas)
                            {
                                string oldCanvasPath = AssetDatabase.GetAssetPath(demoMenu.canvas);
                                string newCanvasPath = "Assets/" + gameName + "/UI/" + demoMenu.canvas.name + ".prefab";
                                if (AssetDatabase.CopyAsset(oldCanvasPath, newCanvasPath))
                                {
                                    AssetDatabase.ImportAsset(newCanvasPath);
                                    newMenu.canvas = (Canvas)AssetDatabase.LoadAssetAtPath(newCanvasPath, typeof(Canvas));
                                }

                                newMenu.rectTransform = null;
                            }

                            newMenu.hideFlags = HideFlags.HideInHierarchy;
                            references.menuManager.menus.Add(newMenu);
                            EditorUtility.SetDirty(references.menuManager);
                            foreach (MenuElement newElement in newMenu.elements)
                            {
                                newElement.hideFlags = HideFlags.HideInHierarchy;
                                AssetDatabase.AddObjectToAsset(newElement, references.menuManager);
                            }
                            AssetDatabase.AddObjectToAsset(newMenu, references.menuManager);
                        }
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot find Demo_MenuManager asset to copy from!");
                    }
                }

                CreateManagerPackage(gameName);

                AssetDatabase.SaveAssets();
                references.sceneManager.InitialiseObjects();
                //pageNumber = 0;
            }
            catch
            {
                ACDebug.LogWarning("Could not create Manager. Does the subdirectory " + Resource.managersDirectory + " exist?");
                pageNumber--;
            }
        }
Esempio n. 11
0
        private ManagerPackage CreateManagerPackage(string folder, SceneManager sceneManager, SettingsManager settingsManager, ActionsManager actionsManager, VariablesManager variablesManager, InventoryManager inventoryManager, SpeechManager speechManager, CursorManager cursorManager, MenuManager menuManager)
        {
            ManagerPackage managerPackage = CustomAssetUtility.CreateAsset <ManagerPackage> ("ManagerPackage", folder);

            AssetDatabase.RenameAsset("Assets/" + folder + "/ManagerPackage.asset", folder + "_ManagerPackage");

            managerPackage.sceneManager     = sceneManager;
            managerPackage.settingsManager  = settingsManager;
            managerPackage.actionsManager   = actionsManager;
            managerPackage.variablesManager = variablesManager;

            managerPackage.inventoryManager = inventoryManager;
            managerPackage.speechManager    = speechManager;
            managerPackage.cursorManager    = cursorManager;
            managerPackage.menuManager      = menuManager;

            managerPackage.AssignManagers();
            EditorUtility.SetDirty(managerPackage);
            AssetDatabase.SaveAssets();

            AdventureCreator.Init();

            return(managerPackage);
        }
Esempio n. 12
0
        private void Finish()
        {
            if (!references)
            {
                GetReferences();
            }

            if (!references)
            {
                return;
            }

            string managerPath = gameName + "/Managers";

            try
            {
                System.IO.Directory.CreateDirectory(Application.dataPath + "/" + managerPath);
            }
            catch (System.Exception e)
            {
                ACDebug.LogError("Wizard aborted - Could not create directory: " + Application.dataPath + "/" + managerPath + ". Please make sure the Assets direcrory is writeable, and that the intended game name contains no special characters.");
                Debug.LogException(e, this);
                pageNumber--;
                return;
            }

            try
            {
                ShowProgress(0f);

                SceneManager newSceneManager = CustomAssetUtility.CreateAsset <SceneManager> ("SceneManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SceneManager.asset", gameName + "_SceneManager");
                references.sceneManager = newSceneManager;

                ShowProgress(0.1f);

                SettingsManager newSettingsManager = CustomAssetUtility.CreateAsset <SettingsManager> ("SettingsManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SettingsManager.asset", gameName + "_SettingsManager");

                newSettingsManager.saveFileName      = gameName;
                newSettingsManager.cameraPerspective = cameraPerspective;
                newSettingsManager.movingTurning     = movingTurning;
                newSettingsManager.movementMethod    = movementMethod;
                newSettingsManager.inputMethod       = inputMethod;
                newSettingsManager.interactionMethod = interactionMethod;
                newSettingsManager.hotspotDetection  = hotspotDetection;
                if (cameraPerspective == CameraPerspective.TwoPointFiveD)
                {
                    newSettingsManager.forceAspectRatio = true;
                }
                references.settingsManager = newSettingsManager;

                ShowProgress(0.2f);

                ActionsManager newActionsManager = CustomAssetUtility.CreateAsset <ActionsManager> ("ActionsManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/ActionsManager.asset", gameName + "_ActionsManager");
                ActionsManager defaultActionsManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_ActionsManager.asset", typeof(ActionsManager)) as ActionsManager;
                if (defaultActionsManager != null)
                {
                    newActionsManager.defaultClass     = defaultActionsManager.defaultClass;
                    newActionsManager.defaultClassName = defaultActionsManager.defaultClassName;
                }
                references.actionsManager = newActionsManager;
                AdventureCreator.RefreshActions();

                ShowProgress(0.3f);

                VariablesManager newVariablesManager = CustomAssetUtility.CreateAsset <VariablesManager> ("VariablesManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/VariablesManager.asset", gameName + "_VariablesManager");
                references.variablesManager = newVariablesManager;

                ShowProgress(0.4f);

                InventoryManager newInventoryManager = CustomAssetUtility.CreateAsset <InventoryManager> ("InventoryManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/InventoryManager.asset", gameName + "_InventoryManager");
                references.inventoryManager = newInventoryManager;

                ShowProgress(0.5f);

                SpeechManager newSpeechManager = CustomAssetUtility.CreateAsset <SpeechManager> ("SpeechManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/SpeechManager.asset", gameName + "_SpeechManager");
                newSpeechManager.ClearLanguages();
                references.speechManager = newSpeechManager;

                ShowProgress(0.6f);

                CursorManager newCursorManager = CustomAssetUtility.CreateAsset <CursorManager> ("CursorManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/CursorManager.asset", gameName + "_CursorManager");
                references.cursorManager = newCursorManager;

                ShowProgress(0.7f);

                MenuManager newMenuManager = CustomAssetUtility.CreateAsset <MenuManager> ("MenuManager", managerPath);
                AssetDatabase.RenameAsset("Assets/" + managerPath + "/MenuManager.asset", gameName + "_MenuManager");
                references.menuManager = (MenuManager)newMenuManager;

                CursorManager defaultCursorManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_CursorManager.asset", typeof(CursorManager)) as CursorManager;
                if (wizardMenu == WizardMenu.Blank)
                {
                    if (defaultCursorManager != null)
                    {
                        CursorIcon useIcon = new CursorIcon();
                        useIcon.Copy(defaultCursorManager.cursorIcons[0], false);
                        newCursorManager.cursorIcons.Add(useIcon);
                        EditorUtility.SetDirty(newCursorManager);
                    }
                }
                else
                {
                    if (defaultCursorManager != null)
                    {
                        foreach (CursorIcon defaultIcon in defaultCursorManager.cursorIcons)
                        {
                            CursorIcon newIcon = new CursorIcon();
                            newIcon.Copy(defaultIcon, false);
                            newCursorManager.cursorIcons.Add(newIcon);
                        }

                        CursorIconBase pointerIcon = new CursorIconBase();
                        pointerIcon.Copy(defaultCursorManager.pointerIcon);
                        newCursorManager.pointerIcon = pointerIcon;

                        newCursorManager.lookCursor_ID = defaultCursorManager.lookCursor_ID;
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot find Default_CursorManager asset to copy from!");
                    }

                    newCursorManager.allowMainCursor = true;
                    EditorUtility.SetDirty(newCursorManager);

                    MenuManager defaultMenuManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_MenuManager.asset", typeof(MenuManager)) as MenuManager;
                    if (defaultMenuManager != null)
                    {
                                                #if UNITY_EDITOR
                        newMenuManager.drawOutlines = defaultMenuManager.drawOutlines;
                        newMenuManager.drawInEditor = defaultMenuManager.drawInEditor;
                                                #endif
                        newMenuManager.pauseTexture = defaultMenuManager.pauseTexture;

                        if (wizardMenu != WizardMenu.Blank)
                        {
                            System.IO.Directory.CreateDirectory(Application.dataPath + "/" + gameName + "/UI");
                        }

                        foreach (Menu defaultMenu in defaultMenuManager.menus)
                        {
                            float progress = (float)defaultMenuManager.menus.IndexOf(defaultMenu) / (float)defaultMenuManager.menus.Count;
                            ShowProgress((progress * 0.3f) + 0.7f);

                            Menu newMenu = ScriptableObject.CreateInstance <Menu>();
                            newMenu.Copy(defaultMenu, true, true);
                            newMenu.Recalculate();

                            if (wizardMenu == WizardMenu.DefaultAC)
                            {
                                newMenu.menuSource = MenuSource.AdventureCreator;
                            }
                            else if (wizardMenu == WizardMenu.DefaultUnityUI)
                            {
                                newMenu.menuSource = MenuSource.UnityUiPrefab;
                            }

                            if (newMenu.pauseWhenEnabled)
                            {
                                bool autoSelectUI = (inputMethod == InputMethod.KeyboardOrController);
                                newMenu.autoSelectFirstVisibleElement = autoSelectUI;
                            }

                            if (defaultMenu.PrefabCanvas)
                            {
                                string oldPath = AssetDatabase.GetAssetPath(defaultMenu.PrefabCanvas.gameObject);
                                string newPath = "Assets/" + gameName + "/UI/" + defaultMenu.PrefabCanvas.name + ".prefab";

                                if (AssetDatabase.CopyAsset(oldPath, newPath))
                                {
                                    AssetDatabase.ImportAsset(newPath);
                                    GameObject canvasObNewPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(newPath, typeof(GameObject));
                                    newMenu.PrefabCanvas = canvasObNewPrefab.GetComponent <Canvas>();
                                }
                                else
                                {
                                    newMenu.PrefabCanvas = null;
                                    ACDebug.LogWarning("Could not copy asset " + oldPath + " to " + newPath, defaultMenu.PrefabCanvas.gameObject);
                                }
                                newMenu.rectTransform = null;
                            }

                            foreach (MenuElement newElement in newMenu.elements)
                            {
                                if (newElement != null)
                                {
                                    AssetDatabase.AddObjectToAsset(newElement, newMenuManager);
                                    newElement.hideFlags = HideFlags.HideInHierarchy;
                                }
                                else
                                {
                                    ACDebug.LogWarning("Null element found in " + newMenu.title + " - the interface may not be set up correctly.");
                                }
                            }

                            if (newMenu != null)
                            {
                                AssetDatabase.AddObjectToAsset(newMenu, newMenuManager);
                                newMenu.hideFlags = HideFlags.HideInHierarchy;

                                newMenuManager.menus.Add(newMenu);
                            }
                            else
                            {
                                ACDebug.LogWarning("Unable to create new Menu from original '" + defaultMenu.title + "'");
                            }
                        }

                        EditorUtility.SetDirty(newMenuManager);

                        if (newSpeechManager != null)
                        {
                            newSpeechManager.previewMenuName = "Subtitles";
                            EditorUtility.SetDirty(newSpeechManager);
                        }
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot find Default_MenuManager asset to copy from!");
                    }
                }

                EditorUtility.ClearProgressBar();
                ManagerPackage newManagerPackage = CreateManagerPackage(gameName, newSceneManager, newSettingsManager, newActionsManager, newVariablesManager, newInventoryManager, newSpeechManager, newCursorManager, newMenuManager);

                AssetDatabase.SaveAssets();

                if (newManagerPackage == null || !newManagerPackage.IsFullyAssigned())
                {
                    EditorUtility.DisplayDialog("Wizard failed", "The New Game Wizard failed to generate a new 'Manager Package' file with all eight Managers assigned. Check your '/Assets/" + gameName + "/Managers' directory - the Managers may have been created, and just need assigning in the ManagerPackage asset Inspector, found in '/Assets/" + gameName + "'.", "OK");
                }
                else if (GameObject.FindObjectOfType <KickStarter>() == null)
                {
                    bool initScene = EditorUtility.DisplayDialog("Organise scene?", "Process complete.  Would you like to organise the scene objects to begin working?  This can be done at any time within the Scene Manager.", "Yes", "No");
                    if (initScene)
                    {
                        newSceneManager.InitialiseObjects();
                    }
                }
            }
            catch (System.Exception e)
            {
                ACDebug.LogWarning("Could not create Manager. Does the subdirectory " + managerPath + " exist?");
                Debug.LogException(e, this);
                pageNumber--;
            }
        }