private void NodesGUI(bool isAsset)
        {
            if (AdvGame.GetReferences () && AdvGame.GetReferences ().actionsManager)
            {
                actionsManager = AdvGame.GetReferences ().actionsManager;
            }
            if (actionsManager == null)
            {
                GUILayout.Space (30f);
                EditorGUILayout.HelpBox ("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable ();
                return;
            }
            if (!isAsset && PrefabUtility.GetPrefabType (windowData.target) == PrefabType.Prefab)
            {
                GUILayout.Space (30f);
                EditorGUILayout.HelpBox ("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info);
                return;
            }
            if (!isAsset && windowData.target != null)
            {
                if (windowData.target.source == ActionListSource.AssetFile)
                {
                    GUILayout.Space (30f);
                    EditorGUILayout.HelpBox ("Cannot view Actions, since this object references an Asset file.", MessageType.Info);
                    return;
                }
            }

            bool loseConnection = false;
            Event e = Event.current;

            if (e.isMouse && actionChanging != null)
            {
                if (e.type == EventType.MouseUp)
                {
                    loseConnection = true;
                }
                else if (e.mousePosition.x < 0f || e.mousePosition.x > position.width || e.mousePosition.y < 0f || e.mousePosition.y > position.height)
                {
                    loseConnection = true;
                    actionChanging = null;
                }
            }

            if (isAsset)
            {
                numActions = windowData.targetAsset.actions.Count;
                if (numActions < 1)
                {
                    numActions = 1;
                    AC.Action newAction = ActionList.GetDefaultAction ();
                    newAction.hideFlags = HideFlags.HideInHierarchy;
                    windowData.targetAsset.actions.Add (newAction);
                    AssetDatabase.AddObjectToAsset (newAction, windowData.targetAsset);
                    AssetDatabase.SaveAssets ();
                }
                numActions = windowData.targetAsset.actions.Count;
            }
            else
            {
                numActions = windowData.target.actions.Count;
                if (numActions < 1)
                {
                    numActions = 1;
                    AC.Action newAction = ActionList.GetDefaultAction ();
                    windowData.target.actions.Add (newAction);
                }
                numActions = windowData.target.actions.Count;
            }

            EditorZoomArea.Begin (zoom, new Rect (0, 0, position.width / zoom, position.height / zoom - 24));
            scrollPosition = GUI.BeginScrollView (new Rect (0, 24, position.width / zoom, position.height / zoom - 48), scrollPosition, new Rect (0, 0, maxScroll.x, maxScroll.y), false, false);

            BeginWindows ();

            canMarquee = true;
            Vector2 newMaxScroll = Vector2.zero;
            for (int i=0; i<numActions; i++)
            {
                FixConnections (i, isAsset);

                Action _action;
                if (isAsset)
                {
                    _action = windowData.targetAsset.actions[i];
                }
                else
                {
                    _action = windowData.target.actions[i];
                }

                if (i == 0)
                {
                    GUI.Label (new Rect (16, -2, 100, 20), "START", nodeSkin.label);

                    if (_action.nodeRect.x == 50 && _action.nodeRect.y == 50)
                    {
                        // Upgrade
                        _action.nodeRect.x = _action.nodeRect.y = 14;
                        MarkAll (isAsset);
                        PerformEmptyCallBack ("Expand selected");
                        UnmarkAll (isAsset);
                    }
                }

                Vector2 originalPosition = new Vector2 (_action.nodeRect.x, _action.nodeRect.y);

                if (IsActionInView (_action))
                {
                    Color tempColor = GUI.color;
                    GUI.color = actionsManager.EnabledActions[actionsManager.GetActionTypeIndex (_action)].color;

                    if (_action.isRunning && Application.isPlaying)
                    {
                        GUI.color = Color.cyan;
                    }
                    else if (_action.isBreakPoint)
                    {
                        GUI.color = new Color (1f, 0.4f, 0.4f);
                    }
                    else if (actionChanging != null && _action.nodeRect.Contains (e.mousePosition))
                    {
                        GUI.color = new Color (1f, 1f, 0.1f);
                    }
                    else if (_action.isMarked)
                    {
                        GUI.color = new Color (0.7f, 1f, 0.6f);
                    }
                    else if (!_action.isEnabled)
                    {
                        GUI.color = new Color (0.7f, 0.1f, 0.1f);
                    }

                    string label = i + ": " + actionsManager.EnabledActions[actionsManager.GetActionTypeIndex (_action)].GetFullTitle ();
                    if (!_action.isDisplayed)
                    {
                        GUI.skin = emptyNodeSkin;
                        _action.nodeRect.height = 21f;
                        string extraLabel = _action.SetLabel ();
                        if (_action is ActionComment)
                        {
                            if (extraLabel.Length > 40)
                            {
                                extraLabel = extraLabel.Substring (0, 40) + "..)";
                            }
                            label = extraLabel;
                        }
                        else
                        {
                            if (extraLabel.Length > 15)
                            {
                                extraLabel = extraLabel.Substring (0, 15) + "..)";
                            }
                            label += extraLabel;
                        }
                        _action.nodeRect = GUI.Window (i, _action.nodeRect, EmptyNodeWindow, label);
                    }
                    else
                    {
                        GUI.skin = nodeSkin;
                        _action.nodeRect = GUILayout.Window (i, _action.nodeRect, NodeWindow, label, GUILayout.Width (300));
                    }

                    GUI.color = tempColor;
                }

                Vector2 finalPosition = new Vector2 (_action.nodeRect.x, _action.nodeRect.y);
                if (finalPosition != originalPosition)
                {
                    if (isAsset)
                    {
                        DragNodes (_action, windowData.targetAsset.actions, finalPosition - originalPosition);
                    }
                    else
                    {
                        DragNodes (_action, windowData.target.actions, finalPosition - originalPosition);
                    }
                }

                GUI.skin = null;
            //				GUI.color = tempColor;

                if (_action.nodeRect.x + _action.nodeRect.width + 20 > newMaxScroll.x)
                {
                    newMaxScroll.x = _action.nodeRect.x + _action.nodeRect.width + 20;
                }
                if (_action.nodeRect.height != 10)
                {
                    if (_action.nodeRect.y + _action.nodeRect.height + 100 > newMaxScroll.y)
                    {
                        newMaxScroll.y = _action.nodeRect.y + _action.nodeRect.height + 100;
                    }
                }

                LimitWindow (_action);
                DrawSockets (_action, isAsset);

                if (isAsset)
                {
                    windowData.targetAsset.actions = ActionListAssetEditor.ResizeList (windowData.targetAsset, numActions);
                }
                else
                {
                    windowData.target.actions = ActionListEditor.ResizeList (windowData.target.actions, numActions);
                }

                if (actionChanging != null && loseConnection && _action.nodeRect.Contains (e.mousePosition))
                {
                    Reconnect (actionChanging, _action, isAsset);
                }

                if (!isMarquee && _action.nodeRect.Contains (e.mousePosition))
                {
                    canMarquee = false;
                }
            }

            if (loseConnection && actionChanging != null)
            {
                EndConnect (actionChanging, e.mousePosition, isAsset);
            }

            if (actionChanging != null)
            {
                bool onSide = false;
                if (actionChanging is ActionCheck || actionChanging is ActionCheckMultiple || actionChanging is ActionParallel)
                {
                    onSide = true;
                }
                AdvGame.DrawNodeCurve (actionChanging.nodeRect, e.mousePosition, Color.black, offsetChanging, onSide, false, actionChanging.isDisplayed);
            }

            if (e.type == EventType.ContextClick && actionChanging == null && !isMarquee)
            {
                menuPosition = e.mousePosition;
                CreateEmptyMenu (isAsset);
            }

            EndWindows ();
            GUI.EndScrollView ();
            EditorZoomArea.End ();

            if (newMaxScroll.y != 0)
            {
                maxScroll = newMaxScroll;
            }
        }
        public static void RefreshActions()
        {
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().actionsManager == null)
            {
                return;
            }
            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            // Collect data to transfer
            List <ActionType> oldActionTypes = new List <ActionType>();

            foreach (ActionType actionType in actionsManager.AllActions)
            {
                oldActionTypes.Add(actionType);
            }

            actionsManager.AllActions.Clear();

            // Load default Actions
            AddActionsFromFolder(actionsManager, "Assets/" + actionsManager.FolderPath, oldActionTypes);

            // Load custom Actions
            if (!string.IsNullOrEmpty(actionsManager.customFolderPath))
            {
                actionsManager.customFolderPaths.Add(actionsManager.customFolderPath);
                actionsManager.customFolderPath = string.Empty;
            }

            for (int i = 0; i < actionsManager.customFolderPaths.Count; i++)
            {
                string customFolderPath = actionsManager.customFolderPaths[i];

                // Discount duplicates
                bool ignoreMe = false;
                for (int j = 0; j < i; j++)
                {
                    if (actionsManager.customFolderPaths[j] == customFolderPath)
                    {
                        ignoreMe = true;
                    }
                }

                if (ignoreMe)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(customFolderPath) && customFolderPath != actionsManager.FolderPath)
                {
                    try
                    {
                        AddActionsFromFolder(actionsManager, "Assets/" + customFolderPath, oldActionTypes);
                    }
                    catch (System.Exception e)
                    {
                        ACDebug.LogWarning("Can't access directory " + "Assets/" + customFolderPath + " - does it exist?\n\nException: " + e);
                    }
                }
            }

            actionsManager.AllActions.Sort(delegate(ActionType i1, ActionType i2) { return(i1.GetFullTitle(true).CompareTo(i2.GetFullTitle(true))); });
        }
        private static void AddActionsFromFolder(ActionsManager actionsManager, string folderPath, List <ActionType> oldActionTypes)
        {
            DirectoryInfo dir = new DirectoryInfo(folderPath);

            FileInfo[] info = dir.GetFiles("*.cs");
            foreach (FileInfo f in info)
            {
                if (f.Name.StartsWith("._"))
                {
                    continue;
                }

                try
                {
                    int    extentionPosition = f.Name.IndexOf(".cs");
                    string className         = f.Name.Substring(0, extentionPosition);

                    StreamReader streamReader = new StreamReader(f.FullName);
                    string       fileContents = streamReader.ReadToEnd();
                    streamReader.Close();

                    fileContents = fileContents.Replace(" ", "");

                    if (fileContents.Contains("class" + className + ":Action") ||
                        fileContents.Contains("class" + className + ":AC.Action"))
                    {
                        MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript> (folderPath + "/" + f.Name);
                        if (script == null)
                        {
                            continue;
                        }

                        Action tempAction = (Action)CreateInstance(script.GetClass());
                        if (tempAction != null && tempAction is Action)
                        {
                            ActionType newActionType = new ActionType(className, tempAction);

                            // Transfer back data
                            foreach (ActionType oldActionType in oldActionTypes)
                            {
                                if (newActionType.IsMatch(oldActionType))
                                {
                                    newActionType.color     = oldActionType.color;
                                    newActionType.isEnabled = oldActionType.isEnabled;
                                    if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                    {
                                        newActionType.color = Color.white;
                                    }
                                    if (newActionType.color.a < 1f)
                                    {
                                        newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                    }
                                }
                            }

                            actionsManager.AllActions.Add(newActionType);
                        }
                    }
                    else
                    {
                        ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                    }
                }
                catch {}
            }
        }
Exemple #4
0
        public void OnAwake()
        {
            ClearVariables();

            // Test for key imports
            References references = (References)Resources.Load(Resource.references);

            if (references)
            {
                SceneManager     sceneManager     = AdvGame.GetReferences().sceneManager;
                SettingsManager  settingsManager  = AdvGame.GetReferences().settingsManager;
                ActionsManager   actionsManager   = AdvGame.GetReferences().actionsManager;
                InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;
                SpeechManager    speechManager    = AdvGame.GetReferences().speechManager;
                CursorManager    cursorManager    = AdvGame.GetReferences().cursorManager;
                MenuManager      menuManager      = AdvGame.GetReferences().menuManager;

                if (sceneManager == null)
                {
                    ACDebug.LogError("No Scene Manager found - please set one using the Adventure Creator Kit wizard");
                }

                if (settingsManager == null)
                {
                    ACDebug.LogError("No Settings Manager found - please set one using the Adventure Creator Kit wizard");
                }
                else
                {
                    if (settingsManager.IsInLoadingScene())
                    {
                        ACDebug.Log("Bypassing regular AC startup because the current scene is the 'Loading' scene.");
                        SetPersistentEngine();
                        return;
                    }

                    // Unity 5.3 has a bug whereby a modified Player prefab is placed in the scene when editing, but not visible
                    // This causes the Player to not load properly, so try to detect this remnant and delete it!
                    GameObject existingPlayer = GameObject.FindGameObjectWithTag(Tags.player);
                    if (existingPlayer != null)
                    {
                        if (settingsManager.GetDefaultPlayer() != null && existingPlayer.name == (settingsManager.GetDefaultPlayer().name + "(Clone)"))
                        {
                            DestroyImmediate(GameObject.FindGameObjectWithTag(Tags.player));
                            ACDebug.LogWarning("Player clone found in scene - this may have been hidden by a Unity bug, and has been destroyed.");
                        }
                    }

                    if (!GameObject.FindGameObjectWithTag(Tags.player))
                    {
                        KickStarter.ResetPlayer(settingsManager.GetDefaultPlayer(), settingsManager.GetDefaultPlayerID(), false, Quaternion.identity);
                    }
                    else
                    {
                        KickStarter.playerPrefab = GameObject.FindWithTag(Tags.player).GetComponent <Player>();

                        if (sceneChanger == null || sceneChanger.GetPlayerOnTransition() == null)
                        {
                            // New local player
                            if (KickStarter.playerPrefab != null)
                            {
                                KickStarter.playerPrefab.Initialise();
                            }
                        }

                        AssignLocalPlayer();
                    }
                }

                if (actionsManager == null)
                {
                    ACDebug.LogError("No Actions Manager found - please set one using the main Adventure Creator window");
                }

                if (inventoryManager == null)
                {
                    ACDebug.LogError("No Inventory Manager found - please set one using the main Adventure Creator window");
                }

                if (variablesManager == null)
                {
                    ACDebug.LogError("No Variables Manager found - please set one using the main Adventure Creator window");
                }

                if (speechManager == null)
                {
                    ACDebug.LogError("No Speech Manager found - please set one using the main Adventure Creator window");
                }

                if (cursorManager == null)
                {
                    ACDebug.LogError("No Cursor Manager found - please set one using the main Adventure Creator window");
                }

                if (menuManager == null)
                {
                    ACDebug.LogError("No Menu Manager found - please set one using the main Adventure Creator window");
                }

                if (GameObject.FindWithTag(Tags.player) == null && KickStarter.settingsManager.movementMethod != MovementMethod.None)
                {
                    ACDebug.LogWarning("No Player found - please set one using the Settings Manager, tagging it as Player and placing it in a Resources folder");
                }
            }
            else
            {
                ACDebug.LogError("No References object found. Please set one using the main Adventure Creator window");
            }

            SetPersistentEngine();

            if (persistentEnginePrefab == null)
            {
                ACDebug.LogError("No PersistentEngine prefab found - please place one in the Resources directory, and tag it as PersistentEngine");
            }
            else
            {
                if (persistentEnginePrefab.GetComponent <Options>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no Options component attached.");
                }
                if (persistentEnginePrefab.GetComponent <RuntimeInventory>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no RuntimeInventory component attached.");
                }
                if (persistentEnginePrefab.GetComponent <RuntimeVariables>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no RuntimeVariables component attached.");
                }
                if (persistentEnginePrefab.GetComponent <PlayerMenus>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no PlayerMenus component attached.");
                }
                if (persistentEnginePrefab.GetComponent <StateHandler>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no StateHandler component attached.");
                }
                if (persistentEnginePrefab.GetComponent <SceneChanger>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no SceneChanger component attached.");
                }
                if (persistentEnginePrefab.GetComponent <SaveSystem>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no SaveSystem component attached.");
                }
                if (persistentEnginePrefab.GetComponent <LevelStorage>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no LevelStorage component attached.");
                }
                if (persistentEnginePrefab.GetComponent <RuntimeLanguages>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no RuntimeLanguages component attached.");
                }
                if (persistentEnginePrefab.GetComponent <ActionListAssetManager>() == null)
                {
                    ACDebug.LogError(persistentEnginePrefab.name + " has no ActionListAssetManager component attached.");
                }
            }

            if (this.GetComponent <MenuSystem>() == null)
            {
                ACDebug.LogError(this.name + " has no MenuSystem component attached.");
            }
            if (this.GetComponent <Dialog>() == null)
            {
                ACDebug.LogError(this.name + " has no Dialog component attached.");
            }
            if (this.GetComponent <PlayerInput>() == null)
            {
                ACDebug.LogError(this.name + " has no PlayerInput component attached.");
            }
            if (this.GetComponent <PlayerInteraction>() == null)
            {
                ACDebug.LogError(this.name + " has no PlayerInteraction component attached.");
            }
            if (this.GetComponent <PlayerMovement>() == null)
            {
                ACDebug.LogError(this.name + " has no PlayerMovement component attached.");
            }
            if (this.GetComponent <PlayerCursor>() == null)
            {
                ACDebug.LogError(this.name + " has no PlayerCursor component attached.");
            }
            if (this.GetComponent <PlayerQTE>() == null)
            {
                ACDebug.LogError(this.name + " has no PlayerQTE component attached.");
            }
            if (this.GetComponent <SceneSettings>() == null)
            {
                ACDebug.LogError(this.name + " has no SceneSettings component attached.");
            }
            else
            {
                if (this.GetComponent <SceneSettings>().navigationMethod == AC_NavigationMethod.meshCollider && this.GetComponent <SceneSettings>().navMesh == null)
                {
                    // No NavMesh, are there Characters in the scene?
                    AC.Char[] allChars = GameObject.FindObjectsOfType(typeof(AC.Char)) as AC.Char[];
                    if (allChars.Length > 0)
                    {
                        ACDebug.LogWarning("No NavMesh set. Characters will not be able to PathFind until one is defined - please choose one using the Scene Manager.");
                    }
                }

                if (this.GetComponent <SceneSettings>().defaultPlayerStart == null)
                {
                    if (AdvGame.GetReferences().settingsManager == null || AdvGame.GetReferences().settingsManager.GetDefaultPlayer() != null)
                    {
                        ACDebug.LogWarning("No default PlayerStart set.  The game may not be able to begin if one is not defined - please choose one using the Scene Manager.");
                    }
                }
            }
            if (this.GetComponent <NavigationManager>() == null)
            {
                ACDebug.LogError(this.name + " has no NavigationManager component attached.");
            }
            if (this.GetComponent <ActionListManager>() == null)
            {
                ACDebug.LogError(this.name + " has no ActionListManager component attached.");
            }
            if (this.GetComponent <EventManager>() == null)
            {
                ACDebug.LogError(this.name + " has no EventManager component attached.");
            }
        }
        public static void ModifyAction(ActionListAsset _target, AC.Action _action, string callback)
        {
            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            if (actionsManager == null)
            {
                return;
            }

            int i = -1;

            if (_action != null && _target.actions.IndexOf(_action) > -1)
            {
                i = _target.actions.IndexOf(_action);
            }

            switch (callback)
            {
            case "Enable":
                Undo.RecordObject(_target, "Enable action");
                _target.actions [i].isEnabled = true;
                break;

            case "Disable":
                Undo.RecordObject(_target, "Disable action");
                _target.actions [i].isEnabled = false;
                break;

            case "Cut":
                Undo.RecordObject(_target, "Cut action");
                List <AC.Action> cutList   = new List <AC.Action>();
                AC.Action        cutAction = Object.Instantiate(_action) as AC.Action;
                cutList.Add(cutAction);
                AdvGame.copiedActions = cutList;
                _target.actions.Remove(_action);
                Undo.DestroyObjectImmediate(_action);
                //UnityEngine.Object.DestroyImmediate (_action, true);
                AssetDatabase.SaveAssets();
                break;

            case "Copy":
                List <AC.Action> copyList   = new List <AC.Action>();
                AC.Action        copyAction = Object.Instantiate(_action) as AC.Action;
                copyAction.name = copyAction.name.Replace("(Clone)", "");
                copyList.Add(copyAction);
                AdvGame.copiedActions = copyList;
                break;

            case "Paste after":
                Undo.RecordObject(_target, "Paste actions");
                List <AC.Action> pasteList = AdvGame.copiedActions;
                int j = i + 1;
                foreach (AC.Action action in pasteList)
                {
                    AC.Action pastedAction = Object.Instantiate(action) as AC.Action;
                    pastedAction.name      = pastedAction.name.Replace("(Clone)", "");
                    pastedAction.hideFlags = HideFlags.HideInHierarchy;
                    _target.actions.Insert(j, pastedAction);
                    j++;
                    AssetDatabase.AddObjectToAsset(pastedAction, _target);
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(pastedAction));
                }
                AssetDatabase.SaveAssets();
                break;

            case "Insert after":
                Undo.RecordObject(_target, "Create action");
                ActionListAssetEditor.AddAction(actionsManager.GetDefaultAction(), i + 1, _target);
                break;

            case "Delete":
                Undo.RecordObject(_target, "Delete action");
                _target.actions.Remove(_action);
                Undo.DestroyObjectImmediate(_action);
                //UnityEngine.Object.DestroyImmediate (_action, true);
                AssetDatabase.SaveAssets();
                break;

            case "Move to top":
                Undo.RecordObject(_target, "Move action to top");
                _target.actions.Remove(_action);
                _target.actions.Insert(0, _action);
                break;

            case "Move up":
                Undo.RecordObject(_target, "Move action up");
                _target.actions.Remove(_action);
                _target.actions.Insert(i - 1, _action);
                break;

            case "Move to bottom":
                Undo.RecordObject(_target, "Move action to bottom");
                _target.actions.Remove(_action);
                _target.actions.Insert(_target.actions.Count, _action);
                break;

            case "Move down":
                Undo.RecordObject(_target, "Move action down");
                _target.actions.Remove(_action);
                _target.actions.Insert(i + 1, _action);
                break;
            }
        }
Exemple #6
0
        public static void ModifyAction(ActionListAsset _target, AC.Action _action, string callback)
        {
            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            if (actionsManager == null)
            {
                return;
            }

            int i = -1;

            if (_action != null && _target.actions.IndexOf(_action) > -1)
            {
                i = _target.actions.IndexOf(_action);
            }

            bool doUndo = (callback != "Copy");

            if (doUndo)
            {
                Undo.SetCurrentGroupName(callback);
                Undo.RecordObjects(new UnityEngine.Object [] { _target }, callback);
                Undo.RecordObjects(_target.actions.ToArray(), callback);
            }

            switch (callback)
            {
            case "Enable":
                _target.actions [i].isEnabled = true;
                break;

            case "Disable":
                _target.actions [i].isEnabled = false;
                break;

            case "Cut":
                List <AC.Action> cutList   = new List <AC.Action>();
                AC.Action        cutAction = Object.Instantiate(_action) as AC.Action;
                cutAction.name = cutAction.name.Replace("(Clone)", "");
                cutList.Add(cutAction);
                AdvGame.copiedActions = cutList;
                DeleteAction(_action, _target);
                break;

            case "Copy":
                List <AC.Action> copyList   = new List <AC.Action>();
                AC.Action        copyAction = Object.Instantiate(_action) as AC.Action;
                copyAction.ClearIDs();
                copyAction.name = copyAction.name.Replace("(Clone)", string.Empty);
                copyList.Add(copyAction);
                AdvGame.copiedActions = copyList;
                break;

            case "Paste after":
                List <AC.Action> pasteList = AdvGame.copiedActions;
                int j = i + 1;
                foreach (AC.Action action in pasteList)
                {
                    if (action == null)
                    {
                        ACDebug.LogWarning("Error when pasting Action - cannot find original. Did you change scene before pasting? If you need to transfer Actions between scenes, copy them to an ActionList asset first.");
                        continue;
                    }

                    AC.Action pastedAction = Object.Instantiate(action) as AC.Action;
                    pastedAction.name = pastedAction.name.Replace("(Clone)", string.Empty);
                    AddAction(pastedAction, j, _target);
                    j++;
                }
                break;

            case "Insert after":
                Action newAction = AddAction(ActionsManager.GetDefaultAction(), i + 1, _target);
                newAction.endAction        = _action.endAction;
                newAction.skipAction       = -1;
                newAction.skipActionActual = _action.skipActionActual;
                break;

            case "Delete":
                DeleteAction(_action, _target);
                break;

            case "Move to top":
                _target.actions.Remove(_action);
                _target.actions.Insert(0, _action);
                break;

            case "Move up":
                _target.actions.Remove(_action);
                _target.actions.Insert(i - 1, _action);
                break;

            case "Move to bottom":
                _target.actions.Remove(_action);
                _target.actions.Insert(_target.actions.Count, _action);
                break;

            case "Move down":
                _target.actions.Remove(_action);
                _target.actions.Insert(i + 1, _action);
                break;
            }

            if (doUndo)
            {
                Undo.RecordObjects(new UnityEngine.Object [] { _target }, callback);
                Undo.RecordObjects(_target.actions.ToArray(), callback);
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
                EditorUtility.SetDirty(_target);
            }
        }
Exemple #7
0
        public static void RefreshActions()
        {
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().actionsManager == null)
            {
                return;
            }

            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            // Collect data to transfer
            List <ActionType> oldActionTypes = new List <ActionType>();

            foreach (ActionType actionType in actionsManager.AllActions)
            {
                oldActionTypes.Add(actionType);
            }

            // Load default Actions
            DirectoryInfo dir = new DirectoryInfo("Assets/" + actionsManager.folderPath);

            FileInfo[] info = dir.GetFiles("*.cs");

            actionsManager.AllActions.Clear();
            foreach (FileInfo f in info)
            {
                int    extentionPosition = f.Name.IndexOf(".cs");
                string className         = f.Name.Substring(0, extentionPosition);
                Action tempAction        = (Action)CreateInstance(className);

                ActionType newActionType = new ActionType(className, tempAction);

                // Transfer back data
                foreach (ActionType oldActionType in oldActionTypes)
                {
                    if (newActionType.IsMatch(oldActionType))
                    {
                        newActionType.color = oldActionType.color;
                        if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                        {
                            newActionType.color = Color.white;
                        }
                        if (newActionType.color.a < 1f)
                        {
                            newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                        }
                    }
                }

                actionsManager.AllActions.Add(newActionType);
            }

            // Load custom Actions
            if (actionsManager.customFolderPath != actionsManager.folderPath)
            {
                dir  = new DirectoryInfo("Assets/" + actionsManager.customFolderPath);
                info = dir.GetFiles("*.cs");

                foreach (FileInfo f in info)
                {
                    try
                    {
                        int    extentionPosition = f.Name.IndexOf(".cs");
                        string className         = f.Name.Substring(0, extentionPosition);
                        Action tempAction        = (Action)CreateInstance(className);
                        if (tempAction is Action)
                        {
                            actionsManager.AllActions.Add(new ActionType(className, tempAction));
                        }
                    }
                    catch {}
                }
            }

            actionsManager.AllActions.Sort(delegate(ActionType i1, ActionType i2) { return(i1.GetFullTitle(true).CompareTo(i2.GetFullTitle(true))); });
            actionsManager.SetEnabled();
        }
        public static void RefreshActions()
        {
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().actionsManager == null)
            {
                return;
            }

            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            // Collect data to transfer
            List <ActionType> oldActionTypes = new List <ActionType>();

            foreach (ActionType actionType in actionsManager.AllActions)
            {
                oldActionTypes.Add(actionType);
            }

            actionsManager.AllActions.Clear();

            // Load default Actions
            string        targetDir = "Assets/" + actionsManager.FolderPath;
            DirectoryInfo dir       = new DirectoryInfo(targetDir);

            FileInfo[] info = dir.GetFiles("*.cs");
            foreach (FileInfo f in info)
            {
                try
                {
                    int    extentionPosition = f.Name.IndexOf(".cs");
                    string className         = f.Name.Substring(0, extentionPosition);

                    StreamReader streamReader = new StreamReader(f.FullName);
                    string       fileContents = streamReader.ReadToEnd();
                    streamReader.Close();

                    fileContents = fileContents.Replace(" ", "");

                    if (fileContents.Contains("class" + className + ":Action") ||
                        fileContents.Contains("class" + className + ":AC.Action"))
                    {
                        MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript> (targetDir + "/" + f.Name);
                        if (script == null)
                        {
                            continue;
                        }

                        Action tempAction = (Action)CreateInstance(script.GetClass());
                        if (tempAction != null && tempAction is Action)
                        {
                            ActionType newActionType = new ActionType(className, tempAction);

                            // Transfer back data
                            foreach (ActionType oldActionType in oldActionTypes)
                            {
                                if (newActionType.IsMatch(oldActionType))
                                {
                                    newActionType.color     = oldActionType.color;
                                    newActionType.isEnabled = oldActionType.isEnabled;
                                    if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                    {
                                        newActionType.color = Color.white;
                                    }
                                    if (newActionType.color.a < 1f)
                                    {
                                        newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                    }
                                }
                            }

                            actionsManager.AllActions.Add(newActionType);
                        }
                    }
                    else
                    {
                        ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                    }
                }
                catch {}
            }

            // Load custom Actions
            if (!string.IsNullOrEmpty(actionsManager.customFolderPath) && actionsManager.UsingCustomActionsFolder)
            {
                targetDir = "Assets/" + actionsManager.customFolderPath;
                dir       = new DirectoryInfo(targetDir);

                try
                {
                    info = dir.GetFiles("*.cs");

                    foreach (FileInfo f in info)
                    {
                        try
                        {
                            int    extentionPosition = f.Name.IndexOf(".cs");
                            string className         = f.Name.Substring(0, extentionPosition);

                            StreamReader streamReader = new StreamReader(f.FullName);
                            string       fileContents = streamReader.ReadToEnd();
                            streamReader.Close();

                            fileContents = fileContents.Replace(" ", "");

                            if (fileContents.Contains("class" + className + ":Action") ||
                                fileContents.Contains("class" + className + ":AC.Action"))
                            {
                                MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript> (targetDir + "/" + f.Name);
                                if (script == null)
                                {
                                    continue;
                                }

                                Action tempAction = (Action)CreateInstance(script.GetClass());
                                if (tempAction != null && tempAction is Action)
                                {
                                    ActionType newActionType = new ActionType(className, tempAction);

                                    // Transfer back data
                                    foreach (ActionType oldActionType in oldActionTypes)
                                    {
                                        if (newActionType.IsMatch(oldActionType))
                                        {
                                            newActionType.color     = oldActionType.color;
                                            newActionType.isEnabled = oldActionType.isEnabled;
                                            if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                            {
                                                newActionType.color = Color.white;
                                            }
                                            if (newActionType.color.a < 1f)
                                            {
                                                newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                            }
                                        }
                                    }

                                    actionsManager.AllActions.Add(newActionType);
                                }
                            }
                            else
                            {
                                ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                            }
                        }
                        catch
                        {}
                    }
                }
                catch (System.Exception e)
                {
                    ACDebug.LogWarning("Can't access directory " + "Assets/" + actionsManager.customFolderPath + " - does it exist?\n\nException: " + e);
                }
            }

            actionsManager.AllActions.Sort(delegate(ActionType i1, ActionType i2) { return(i1.GetFullTitle(true).CompareTo(i2.GetFullTitle(true))); });
        }
Exemple #9
0
        protected void DrawSharedElements(ActionList _target)
        {
            if (IsActionListPrefab(_target))
            {
                EditorGUILayout.HelpBox("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info);
                return;
            }

            int numActions = 0;

            if (_target.source != ActionListSource.AssetFile)
            {
                numActions = _target.actions.Count;
                if (numActions < 1)
                {
                    numActions = 1;
                    AddAction(ActionsManager.GetDefaultAction(), -1, _target);
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();

            if (_target.source == ActionListSource.AssetFile)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(_target, "Expand actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = true;
                }
            }
            if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(_target, "Collapse actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = false;
                }
            }

            GUI.enabled = true;

            if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
            {
                if (_target.source == ActionListSource.AssetFile)
                {
                    if (_target.assetFile != null)
                    {
                        ActionListEditorWindow.Init(_target.assetFile);
                    }
                }
                else
                {
                    ActionListEditorWindow.Init(_target);
                }
            }
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
            {
                _target.Interact();
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (_target.source == ActionListSource.AssetFile)
            {
                return;
            }

            ActionListEditor.ResetList(_target);

            actionsManager = AdvGame.GetReferences().actionsManager;
            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                return;
            }

            if (!actionsManager.displayActionsInInspector)
            {
                EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info);
                return;
            }

            for (int i = 0; i < _target.actions.Count; i++)
            {
                if (_target.actions[i] == null)
                {
                    ACDebug.LogWarning("An empty Action was found, and was deleted", _target);
                    _target.actions.RemoveAt(i);
                    numActions--;
                    continue;
                }

                _target.actions[i].AssignParentList(_target);

                EditorGUILayout.BeginVertical("Button");
                EditorGUILayout.BeginHorizontal();
                int typeIndex = actionsManager.GetActionTypeIndex(_target.actions[i]);

                string actionLabel = " (" + i.ToString() + ") " + actionsManager.GetActionTypeLabel(_target.actions[i], true);
                actionLabel = actionLabel.Replace("\r\n", "");
                actionLabel = actionLabel.Replace("\n", "");
                actionLabel = actionLabel.Replace("\r", "");
                if (actionLabel.Length > 40)
                {
                    actionLabel = actionLabel.Substring(0, 40) + "..)";
                }

                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f));
                }

                if (GUILayout.Button("", CustomStyles.IconCog))
                {
                    ActionSideMenu(i);
                }

                _target.actions[i].isAssetFile = false;

                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isBreakPoint)
                {
                    EditorGUILayout.HelpBox("Break point", MessageType.None);
                }

                if (_target.actions[i].isDisplayed)
                {
                    GUI.enabled = _target.actions[i].isEnabled;

                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type is not listed in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");
                            _target.actions[i] = RebuildAction(_target.actions[i], newTypeIndex, _target, -1, _end);
                        }

                        if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0)
                        {
                            _target.actions[i].ShowGUI(_target.parameters);
                        }
                        else
                        {
                            _target.actions[i].ShowGUI(null);
                        }
                    }
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                GUI.enabled = true;

                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new action"))
            {
                Undo.RecordObject(_target, "Create action");
                numActions += 1;
            }

            _target = ActionListEditor.ResizeList(_target, numActions);
        }
Exemple #10
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 ();
        }
Exemple #11
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);

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

                ShowProgress(0.1f);

                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;
                }

                ShowProgress(0.2f);

                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;
                }

                ShowProgress(0.3f);

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

                ShowProgress(0.4f);

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

                ShowProgress(0.5f);

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

                ShowProgress(0.6f);

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

                ShowProgress(0.7f);

                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], false);
                        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, false);
                            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)
                        {
                            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 (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.");
                                }
                            }

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

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

                        EditorUtility.SetDirty(references.menuManager);

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

                EditorUtility.ClearProgressBar();
                ManagerPackage newManagerPackage = CreateManagerPackage(gameName);

                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. Pleae verify that your Assets directory is writable and try again.", "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)
                    {
                        references.sceneManager.InitialiseObjects();
                    }
                }
            }
            catch (System.Exception e)
            {
                ACDebug.LogWarning("Could not create Manager. Does the subdirectory " + managerPath + " exist?");
                Debug.LogException(e, this);
                pageNumber--;
            }
        }
		protected void DrawSharedElements ()
		{
			ActionList _target = (ActionList) target;
				
			if (_target.source == ActionListSource.AssetFile)
			{
				return;
			}
			
			if (AdvGame.GetReferences () == null)
			{
				Debug.LogError ("A References file is required - please use the Adventure Creator window to create one.");
				EditorGUILayout.LabelField ("No References file found!");
			}
			else
			{
				actionsManager = AdvGame.GetReferences ().actionsManager;
				
				if (actionsManager)
				{
					int numActions = _target.actions.Count;
					if (numActions < 1)
					{
						numActions = 1;
						AC.Action newAction = GetDefaultAction ();
						_target.actions.Add (newAction);
					}

					if (_target.useParameters)
					{
						ShowParametersGUI (_target);
					}

					EditorGUILayout.Space ();
					EditorGUILayout.BeginHorizontal ();
					if (GUILayout.Button ("Expand all", EditorStyles.miniButtonLeft))
					{
						Undo.RecordObject (_target, "Expand actions");
						foreach (AC.Action action in _target.actions)
						{
							action.isDisplayed = true;
						}
					}
					if (GUILayout.Button ("Collapse all", EditorStyles.miniButtonMid))
					{
						Undo.RecordObject (_target, "Collapse actions");
						foreach (AC.Action action in _target.actions)
						{
							action.isDisplayed = false;
						}
					}
					if (GUILayout.Button ("Action List Editor", EditorStyles.miniButtonMid))
					{
						ActionListEditorWindow window = (ActionListEditorWindow) EditorWindow.GetWindow (typeof (ActionListEditorWindow));
						window.Repaint ();
					}
					if (!Application.isPlaying)
					{
						GUI.enabled = false;
					}
					if (GUILayout.Button ("Run now", EditorStyles.miniButtonRight))
					{
						_target.Interact ();
					}
					GUI.enabled = true;
					EditorGUILayout.EndHorizontal ();
					EditorGUILayout.Space ();

					ActionListEditor.ResetList (_target);
					
					for (int i=0; i<_target.actions.Count; i++)
					{
						if (_target.actions[i] == null)
						{
							Debug.LogWarning ("An empty Action was found, and was deleted");
							_target.actions.RemoveAt (i);
						}

						EditorGUILayout.BeginVertical ("Button");
						typeNumber = ActionListEditor.GetTypeNumber (_target.actions[i]);
						categoryNumber = ActionListEditor.GetCategoryNumber (typeNumber);
						subCategoryNumber = ActionListEditor.GetSubCategoryNumber (_target.actions[i].title, categoryNumber);
						
						EditorGUILayout.BeginHorizontal ();
						string actionLabel = " " + (i).ToString() + ": " + _target.actions[i].title + _target.actions[i].SetLabel ();
						_target.actions[i].isDisplayed = EditorGUILayout.Foldout (_target.actions[i].isDisplayed, actionLabel);
						if (!_target.actions[i].isEnabled)
						{
							EditorGUILayout.LabelField ("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth (100f));
						}
						Texture2D icon = (Texture2D) AssetDatabase.LoadAssetAtPath ("Assets/AdventureCreator/Graphics/Textures/inspector-use.png", typeof (Texture2D));
						if (GUILayout.Button (icon, GUILayout.Width (20f), GUILayout.Height (15f)))
						{
							ActionSideMenu (i);
						}

						_target.actions[i].isAssetFile = false;
						
						EditorGUILayout.EndHorizontal ();

						if (_target.actions[i].isDisplayed)
						{
							GUI.enabled = _target.actions[i].isEnabled;

							if (!actionsManager.DoesActionExist (_target.actions[i].GetType ().ToString ()))
							{
								EditorGUILayout.HelpBox ("This Action type has been disabled in the Actions Manager", MessageType.Warning);
							}
							else
							{
								EditorGUILayout.BeginHorizontal ();
								EditorGUILayout.LabelField ("Action type:", GUILayout.Width (150));
								categoryNumber = EditorGUILayout.Popup(categoryNumber, actionsManager.GetActionCategories ());
								subCategoryNumber = EditorGUILayout.Popup(subCategoryNumber, actionsManager.GetActionSubCategories (categoryNumber));
								EditorGUILayout.EndVertical ();
								
								typeNumber = actionsManager.GetTypeNumber (categoryNumber, subCategoryNumber);
								
								EditorGUILayout.Space ();

								// Rebuild constructor if Subclass and type string do not match
								if (_target.actions[i].GetType ().ToString () != actionsManager.GetActionName (typeNumber) &&
									_target.actions[i].GetType ().ToString () != ("AC." + actionsManager.GetActionName (typeNumber)))
								{
									ActionEnd _end = new ActionEnd ();
									_end.resultAction = _target.actions[i].endAction;
									_end.skipAction = _target.actions[i].skipAction;
									_end.linkedAsset = _target.actions[i].linkedAsset;
									_end.linkedCutscene = _target.actions[i].linkedCutscene;

									Undo.RecordObject (_target, "Change Action type");

									_target.actions[i] = ActionListEditor.RebuildAction (_target.actions[i], typeNumber, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene);
								}

								if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0)
								{
									_target.actions[i].ShowGUI (_target.parameters);
								}
								else
								{
									_target.actions[i].ShowGUI (null);
								}
							}
						}

						if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple)
						{
							_target.actions[i].SkipActionGUI (_target.actions, _target.actions[i].isDisplayed);
						}

						GUI.enabled = true;
						
						EditorGUILayout.EndVertical();
						EditorGUILayout.Space ();
					}
					
					if (GUILayout.Button("Add new action"))
					{
						Undo.RecordObject (_target, "Create action");
						numActions += 1;
					}
					
					_target.actions = ActionListEditor.ResizeList (_target.actions, numActions);
				}
			}
		}
        protected bool TestManagerPresence()
        {
            References references = (References)Resources.Load(Resource.references);

            if (references)
            {
                SceneManager     sceneManager     = AdvGame.GetReferences().sceneManager;
                SettingsManager  settingsManager  = AdvGame.GetReferences().settingsManager;
                ActionsManager   actionsManager   = AdvGame.GetReferences().actionsManager;
                InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;
                SpeechManager    speechManager    = AdvGame.GetReferences().speechManager;
                CursorManager    cursorManager    = AdvGame.GetReferences().cursorManager;
                MenuManager      menuManager      = AdvGame.GetReferences().menuManager;

                string missingManagers = string.Empty;
                if (sceneManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Scene";
                }
                if (settingsManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Settings";
                }
                if (actionsManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Actions";
                }
                if (variablesManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Variables";
                }
                if (inventoryManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Inventory";
                }
                if (speechManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Speech";
                }
                if (cursorManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Cursor";
                }
                if (menuManager == null)
                {
                    if (!string.IsNullOrEmpty(missingManagers))
                    {
                        missingManagers += ", ";
                    }
                    missingManagers += "Menu";
                }

                if (!string.IsNullOrEmpty(missingManagers))
                {
                    ACDebug.LogError("Unassigned AC Manager(s): " + missingManagers + " - all Managers must be assigned in the AC Game Editor window for AC to initialise");
                    return(false);
                }
            }
            else
            {
                ACDebug.LogError("No References object found. Please set one using the main Adventure Creator window");
                return(false);
            }

            return(true);
        }
Exemple #14
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);
        }
        private void OnEnable()
        {
            if (AdvGame.GetReferences ())
            {
                if (AdvGame.GetReferences ().actionsManager)
                {
                    actionsManager = AdvGame.GetReferences ().actionsManager;
                    AdventureCreator.RefreshActions ();
                }
                else
                {
                    ACDebug.LogError ("An Actions Manager is required - please use the Game Editor window to create one.");
                }
            }
            else
            {
                ACDebug.LogError ("A References file is required - please use the Game Editor window to create one.");
            }

            if (windowData.targetAsset != null)
            {
                UnmarkAll (true);
            }
            else
            {
                UnmarkAll (false);
            }
        }
Exemple #16
0
        public static void ModifyAction(ActionList _target, AC.Action _action, string callback)
        {
            int i = -1;

            if (_action != null && _target.actions.IndexOf(_action) > -1)
            {
                i = _target.actions.IndexOf(_action);
            }

            bool doUndo = (callback != "Copy");

            if (doUndo)
            {
                Undo.SetCurrentGroupName(callback);
                Undo.RecordObjects(new UnityEngine.Object [] { _target }, callback);
                Undo.RecordObjects(_target.actions.ToArray(), callback);
            }

            switch (callback)
            {
            case "Enable":
                _action.isEnabled = true;
                break;

            case "Disable":
                _action.isEnabled = false;
                break;

            case "Cut":
                List <AC.Action> cutList   = new List <AC.Action>();
                AC.Action        cutAction = Object.Instantiate(_action) as AC.Action;
                cutAction.name = cutAction.name.Replace("(Clone)", "");
                cutList.Add(cutAction);
                AdvGame.copiedActions = cutList;
                DeleteAction(_action, _target);
                break;

            case "Copy":
                List <AC.Action> copyList   = new List <AC.Action>();
                AC.Action        copyAction = Object.Instantiate(_action) as AC.Action;
                copyAction.name = copyAction.name.Replace("(Clone)", "");
                copyAction.ClearIDs();
                copyAction.nodeRect = new Rect(0, 0, 300, 60);
                copyList.Add(copyAction);
                AdvGame.copiedActions = copyList;
                break;

            case "Paste after":
                List <AC.Action> pasteList = AdvGame.copiedActions;
                _target.actions.InsertRange(i + 1, pasteList);
                AdvGame.DuplicateActionsBuffer();
                break;

            case "Insert end":
                AddAction(ActionsManager.GetDefaultAction(), -1, _target);
                break;

            case "Insert after":
                Action insertAfterAction = AddAction(ActionsManager.GetDefaultAction(), i + 1, _target);
                insertAfterAction.endAction        = _action.endAction;
                insertAfterAction.skipAction       = -1;
                insertAfterAction.skipActionActual = _action.skipActionActual;
                break;

            case "Delete":
                Undo.RecordObject(_target, "Delete action");
                DeleteAction(_action, _target);
                break;

            case "Move to top":
                _target.actions[0].nodeRect.x += 30f;
                _target.actions[0].nodeRect.y += 30f;
                _target.actions.Remove(_action);
                _target.actions.Insert(0, _action);
                break;

            case "Move up":
                _target.actions.Remove(_action);
                _target.actions.Insert(i - 1, _action);
                break;

            case "Move to bottom":
                _target.actions.Remove(_action);
                _target.actions.Insert(_target.actions.Count, _action);
                break;

            case "Move down":
                _target.actions.Remove(_action);
                _target.actions.Insert(i + 1, _action);
                break;

            case "Toggle breakpoint":
                _action.isBreakPoint = !_action.isBreakPoint;
                break;
            }

            if (doUndo)
            {
                Undo.RecordObjects(new UnityEngine.Object [] { _target }, callback);
                Undo.RecordObjects(_target.actions.ToArray(), callback);
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
                EditorUtility.SetDirty(_target);
            }
        }
Exemple #17
0
        public override void OnInspectorGUI()
        {
            ActionListAsset _target = (ActionListAsset)target;

            ActionListAssetEditor.ShowPropertiesGUI(_target);
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(_target, "Expand actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = true;
                }
            }
            if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(_target, "Collapse actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = false;
                }
            }
            if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
            {
                ActionListEditorWindow.Init(_target);
            }
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
            {
                if (KickStarter.actionListAssetManager != null)
                {
                    if (!_target.canRunMultipleInstances)
                    {
                        int numRemoved = KickStarter.actionListAssetManager.EndAssetList(_target);
                        if (numRemoved > 0)
                        {
                            ACDebug.Log("Removed 1 instance of ActionList asset '" + _target.name + "' because it is set to only run one at a time.", _target);
                        }
                    }

                    AdvGame.RunActionListAsset(_target);
                }
                else
                {
                    ACDebug.LogWarning("An AC PersistentEngine object must be present in the scene for ActionList assets to run.", _target);
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                return;
            }

            if (!actionsManager.displayActionsInInspector)
            {
                EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info);
                return;
            }

            for (int i = 0; i < _target.actions.Count; i++)
            {
                int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]);

                if (_target.actions[i] == null)
                {
                    RebuildAction(_target.actions[i], typeIndex, _target, i);
                }

                _target.actions[i].isAssetFile = true;

                EditorGUILayout.BeginVertical("Button");

                string actionLabel = " (" + i + ") " + actionsManager.GetActionTypeLabel(_target.actions[i], true);
                actionLabel = actionLabel.Replace("\r\n", "");
                actionLabel = actionLabel.Replace("\n", "");
                actionLabel = actionLabel.Replace("\r", "");
                if (actionLabel.Length > 40)
                {
                    actionLabel = actionLabel.Substring(0, 40) + "..)";
                }

                EditorGUILayout.BeginHorizontal();
                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.Width(100f));
                }

                if (GUILayout.Button("", CustomStyles.IconCog))
                {
                    ActionSideMenu(_target.actions[i]);
                }
                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isDisplayed)
                {
                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type is not listed in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");

                            RebuildAction(_target.actions[i], newTypeIndex, _target, i, _end);
                        }

                        EditorGUILayout.Space();
                        GUI.enabled = _target.actions[i].isEnabled;

                        if (_target.useParameters)
                        {
                            if (Application.isPlaying)
                            {
                                _target.actions[i].AssignValues(_target.parameters);
                            }

                            _target.actions[i].ShowGUI(_target.parameters);
                        }
                        else
                        {
                            if (Application.isPlaying)
                            {
                                _target.actions[i].AssignValues(null);
                            }
                            _target.actions[i].ShowGUI(null);
                        }
                    }
                    GUI.enabled = true;
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new Action"))
            {
                Undo.RecordObject(_target, "Create action");
                AddAction(ActionsManager.GetDefaultAction(), _target.actions.Count, _target);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_target);
            }
        }
        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 newCanvasPath = "Assets/" + gameName + "/UI/" + defaultMenu.canvas.name + ".prefab";

                                GameObject canvasObInScene = (GameObject)PrefabUtility.InstantiatePrefab(defaultMenu.canvas.gameObject);
                                PrefabUtility.DisconnectPrefabInstance(canvasObInScene);
                                GameObject canvasObNewPrefab = PrefabUtility.CreatePrefab(newCanvasPath, canvasObInScene);

                                newMenu.canvas = canvasObNewPrefab.GetComponent <Canvas>();
                                DestroyImmediate(canvasObInScene);

                                newMenu.rectTransform = null;
                            }

                            foreach (MenuElement newElement in newMenu.elements)
                            {
                                AssetDatabase.AddObjectToAsset(newElement, references.menuManager);
                                newElement.hideFlags = HideFlags.HideInHierarchy;
                            }
                            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--;
            }
        }
Exemple #19
0
        public static void RefreshActions()
        {
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().actionsManager == null)
            {
                return;
            }

            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            // Collect data to transfer
            List <ActionType> oldActionTypes = new List <ActionType>();

            foreach (ActionType actionType in actionsManager.AllActions)
            {
                oldActionTypes.Add(actionType);
            }

            // Load default Actions
            DirectoryInfo dir = new DirectoryInfo("Assets/" + actionsManager.folderPath);

            FileInfo[] info = dir.GetFiles("*.cs");

            actionsManager.AllActions.Clear();
            foreach (FileInfo f in info)
            {
                try
                {
                    int    extentionPosition = f.Name.IndexOf(".cs");
                    string className         = f.Name.Substring(0, extentionPosition);

                    StreamReader streamReader = new StreamReader(f.FullName);
                    string       fileContents = streamReader.ReadToEnd();
                    streamReader.Close();

                    fileContents = fileContents.Replace(" ", "");

                    if (fileContents.Contains("class" + className + ":Action") ||
                        fileContents.Contains("class" + className + ":AC.Action"))
                    {
                        Action tempAction = (Action)CreateInstance(className);
                        if (tempAction is Action)
                        {
                            ActionType newActionType = new ActionType(className, tempAction);

                            // Transfer back data
                            foreach (ActionType oldActionType in oldActionTypes)
                            {
                                if (newActionType.IsMatch(oldActionType))
                                {
                                    newActionType.color = oldActionType.color;
                                    if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                    {
                                        newActionType.color = Color.white;
                                    }
                                    if (newActionType.color.a < 1f)
                                    {
                                        newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                    }
                                }
                            }

                            actionsManager.AllActions.Add(newActionType);
                        }
                    }
                    else
                    {
                        ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                    }
                }
                catch {}
            }

            // Load custom Actions
            if (actionsManager.customFolderPath != actionsManager.folderPath)
            {
                dir  = new DirectoryInfo("Assets/" + actionsManager.customFolderPath);
                info = dir.GetFiles("*.cs");

                foreach (FileInfo f in info)
                {
                    try
                    {
                        int    extentionPosition = f.Name.IndexOf(".cs");
                        string className         = f.Name.Substring(0, extentionPosition);

                        StreamReader streamReader = new StreamReader(f.FullName);
                        string       fileContents = streamReader.ReadToEnd();
                        streamReader.Close();

                        fileContents = fileContents.Replace(" ", "");

                        if (fileContents.Contains("class" + className + ":Action") ||
                            fileContents.Contains("class" + className + ":AC.Action"))
                        {
                            Action tempAction = (Action)CreateInstance(className);
                            if (tempAction is Action)
                            {
                                actionsManager.AllActions.Add(new ActionType(className, tempAction));
                            }
                        }
                        else
                        {
                            ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                        }
                    }
                    catch {}
                }
            }

            actionsManager.AllActions.Sort(delegate(ActionType i1, ActionType i2) { return(i1.GetFullTitle(true).CompareTo(i2.GetFullTitle(true))); });
            actionsManager.SetEnabled();
        }
        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("Congratulations, 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.");
            }
        }
        public static void ModifyAction(ActionListAsset _target, AC.Action _action, string callback)
        {
            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            if (actionsManager == null)
            {
                return;
            }

            int i = -1;

            if (_action != null && _target.actions.IndexOf(_action) > -1)
            {
                i = _target.actions.IndexOf(_action);
            }

            switch (callback)
            {
            case "Enable":
                Undo.RecordObject(_target, "Enable action");
                _target.actions [i].isEnabled = true;
                break;

            case "Disable":
                Undo.RecordObject(_target, "Disable action");
                _target.actions [i].isEnabled = false;
                break;

            case "Cut":
                Undo.RecordObject(_target, "Cut action");
                List <AC.Action> cutList   = new List <AC.Action>();
                AC.Action        cutAction = Object.Instantiate(_action) as AC.Action;
                cutAction.name = cutAction.name.Replace("(Clone)", "");
                cutList.Add(cutAction);
                AdvGame.copiedActions = cutList;
                _target.actions.Remove(_action);
                Undo.DestroyObjectImmediate(_action);
                //UnityEngine.Object.DestroyImmediate (_action, true);
                AssetDatabase.SaveAssets();
                break;

            case "Copy":
                List <AC.Action> copyList   = new List <AC.Action>();
                AC.Action        copyAction = Object.Instantiate(_action) as AC.Action;
                copyAction.ClearIDs();
                copyAction.name = copyAction.name.Replace("(Clone)", "");
                copyList.Add(copyAction);
                AdvGame.copiedActions = copyList;
                break;

            case "Paste after":
                Undo.RecordObject(_target, "Paste actions");
                List <AC.Action> pasteList = AdvGame.copiedActions;
                int j = i + 1;
                foreach (AC.Action action in pasteList)
                {
                    if (action == null)
                    {
                        ACDebug.LogWarning("Error when pasting Action - cannot find original. Did you change scene before pasting? If you need to transfer Actions between scenes, copy them to an ActionList asset first.");
                        continue;
                    }

                    AC.Action pastedAction = Object.Instantiate(action) as AC.Action;
                    pastedAction.name      = pastedAction.name.Replace("(Clone)", "");
                    pastedAction.hideFlags = HideFlags.HideInHierarchy;
                    _target.actions.Insert(j, pastedAction);
                    j++;
                    AssetDatabase.AddObjectToAsset(pastedAction, _target);
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(pastedAction));
                }
                AssetDatabase.SaveAssets();
                break;

            case "Insert after":
                Undo.RecordObject(_target, "Create action");
                Action newAction = ActionListAssetEditor.AddAction(actionsManager.GetDefaultAction(), i + 1, _target);
                newAction.endAction        = _action.endAction;
                newAction.skipAction       = -1;
                newAction.skipActionActual = _action.skipActionActual;
                break;

            case "Delete":
                Undo.RecordObject(_target, "Delete action");
                _target.actions.Remove(_action);
                Undo.DestroyObjectImmediate(_action);
                //UnityEngine.Object.DestroyImmediate (_action, true);
                AssetDatabase.SaveAssets();
                break;

            case "Move to top":
                Undo.RecordObject(_target, "Move action to top");
                _target.actions.Remove(_action);
                _target.actions.Insert(0, _action);
                break;

            case "Move up":
                Undo.RecordObject(_target, "Move action up");
                _target.actions.Remove(_action);
                _target.actions.Insert(i - 1, _action);
                break;

            case "Move to bottom":
                Undo.RecordObject(_target, "Move action to bottom");
                _target.actions.Remove(_action);
                _target.actions.Insert(_target.actions.Count, _action);
                break;

            case "Move down":
                Undo.RecordObject(_target, "Move action down");
                _target.actions.Remove(_action);
                _target.actions.Insert(i + 1, _action);
                break;
            }
        }
 private void OnEnable()
 {
     if (AdvGame.GetReferences ())
     {
         if (AdvGame.GetReferences ().actionsManager)
         {
             actionsManager = AdvGame.GetReferences ().actionsManager;
             AdventureCreator.RefreshActions ();
         }
         else
         {
             Debug.LogError ("An Actions Manager is required - please use the Game Editor window to create one.");
         }
     }
     else
     {
         Debug.LogError ("A References file is required - please use the Game Editor window to create one.");
     }
 }
        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;
                }

                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--;
            }
        }
Exemple #24
0
        private void Awake()
        {
            // Test for key imports
            References references = (References)Resources.Load(Resource.references);

            if (references)
            {
                SceneManager     sceneManager     = AdvGame.GetReferences().sceneManager;
                SettingsManager  settingsManager  = AdvGame.GetReferences().settingsManager;
                ActionsManager   actionsManager   = AdvGame.GetReferences().actionsManager;
                InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager;
                VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;
                SpeechManager    speechManager    = AdvGame.GetReferences().speechManager;
                CursorManager    cursorManager    = AdvGame.GetReferences().cursorManager;
                MenuManager      menuManager      = AdvGame.GetReferences().menuManager;

                if (sceneManager == null)
                {
                    Debug.LogError("No Scene Manager found - please set one using the Adventure Creator Kit wizard");
                }

                if (settingsManager == null)
                {
                    Debug.LogError("No Settings Manager found - please set one using the Adventure Creator Kit wizard");
                }
                else
                {
                    if (settingsManager.IsInLoadingScene())
                    {
                        Debug.Log("Bypassing regular AC startup because the current scene is the 'Loading' scene.");
                        return;
                    }
                    if (!GameObject.FindGameObjectWithTag(Tags.player))
                    {
                        KickStarter.ResetPlayer(settingsManager.GetDefaultPlayer(), settingsManager.GetDefaultPlayerID(), false, Quaternion.identity);
                    }
                    else
                    {
                        KickStarter.playerPrefab = GameObject.FindWithTag(Tags.player).GetComponent <Player>();

                        if (sceneChanger != null && sceneChanger.GetPlayerOnTransition() != null && settingsManager.playerSwitching == PlayerSwitching.DoNotAllow)
                        {
                            // Replace "prefab" player with a local one if one exists
                            GameObject[] playerObs = GameObject.FindGameObjectsWithTag(Tags.player);
                            foreach (GameObject playerOb in playerObs)
                            {
                                if (playerOb.GetComponent <Player>() && sceneChanger.GetPlayerOnTransition() != playerOb.GetComponent <Player>())
                                {
                                    KickStarter.sceneChanger.DestroyOldPlayer();
                                    KickStarter.playerPrefab = playerOb.GetComponent <Player>();
                                    break;
                                }
                            }
                        }
                    }
                }

                if (actionsManager == null)
                {
                    Debug.LogError("No Actions Manager found - please set one using the main Adventure Creator window");
                }

                if (inventoryManager == null)
                {
                    Debug.LogError("No Inventory Manager found - please set one using the main Adventure Creator window");
                }

                if (variablesManager == null)
                {
                    Debug.LogError("No Variables Manager found - please set one using the main Adventure Creator window");
                }

                if (speechManager == null)
                {
                    Debug.LogError("No Speech Manager found - please set one using the main Adventure Creator window");
                }

                if (cursorManager == null)
                {
                    Debug.LogError("No Cursor Manager found - please set one using the main Adventure Creator window");
                }

                if (menuManager == null)
                {
                    Debug.LogError("No Menu Manager found - please set one using the main Adventure Creator window");
                }

                if (GameObject.FindWithTag(Tags.player) == null && KickStarter.settingsManager.movementMethod != MovementMethod.None)
                {
                    Debug.LogWarning("No Player found - please set one using the Settings Manager, tagging it as Player and placing it in a Resources folder");
                }
            }
            else
            {
                Debug.LogError("No References object found. Please set one using the main Adventure Creator window");
            }

            if (persistentEnginePrefab == null)
            {
                try
                {
                    persistentEnginePrefab      = (GameObject)Instantiate(Resources.Load(Resource.persistentEngine));
                    persistentEnginePrefab.name = AdvGame.GetName(Resource.persistentEngine);
                }
                catch {}
            }

            if (persistentEnginePrefab == null)
            {
                Debug.LogError("No PersistentEngine prefab found - please place one in the Resources directory, and tag it as PersistentEngine");
            }
            else
            {
                if (persistentEnginePrefab.GetComponent <Options>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no Options component attached.");
                }
                if (persistentEnginePrefab.GetComponent <RuntimeInventory>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no RuntimeInventory component attached.");
                }
                if (persistentEnginePrefab.GetComponent <RuntimeVariables>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no RuntimeVariables component attached.");
                }
                if (persistentEnginePrefab.GetComponent <PlayerMenus>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no PlayerMenus component attached.");
                }
                if (persistentEnginePrefab.GetComponent <StateHandler>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no StateHandler component attached.");
                }
                if (persistentEnginePrefab.GetComponent <SceneChanger>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no SceneChanger component attached.");
                }
                if (persistentEnginePrefab.GetComponent <SaveSystem>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no SaveSystem component attached.");
                }
                if (persistentEnginePrefab.GetComponent <LevelStorage>() == null)
                {
                    Debug.LogError(persistentEnginePrefab.name + " has no LevelStorage component attached.");
                }
            }

            if (GameObject.FindWithTag(Tags.mainCamera) == null)
            {
                Debug.LogError("No MainCamera found - please click 'Organise room objects' in the Scene Manager to create one.");
            }
            else
            {
                if (GameObject.FindWithTag(Tags.mainCamera).GetComponent <MainCamera>() == null)
                {
                    Debug.LogError("MainCamera has no MainCamera component.");
                }
            }

            if (this.GetComponent <MenuSystem>() == null)
            {
                Debug.LogError(this.name + " has no MenuSystem component attached.");
            }
            if (this.GetComponent <Dialog>() == null)
            {
                Debug.LogError(this.name + " has no Dialog component attached.");
            }
            if (this.GetComponent <PlayerInput>() == null)
            {
                Debug.LogError(this.name + " has no PlayerInput component attached.");
            }
            if (this.GetComponent <PlayerInteraction>() == null)
            {
                Debug.LogError(this.name + " has no PlayerInteraction component attached.");
            }
            if (this.GetComponent <PlayerMovement>() == null)
            {
                Debug.LogError(this.name + " has no PlayerMovement component attached.");
            }
            if (this.GetComponent <PlayerCursor>() == null)
            {
                Debug.LogError(this.name + " has no PlayerCursor component attached.");
            }
            if (this.GetComponent <PlayerQTE>() == null)
            {
                Debug.LogError(this.name + " has no PlayerQTE component attached.");
            }
            if (this.GetComponent <SceneSettings>() == null)
            {
                Debug.LogError(this.name + " has no SceneSettings component attached.");
            }
            else
            {
                if (this.GetComponent <SceneSettings>().navigationMethod == AC_NavigationMethod.meshCollider && this.GetComponent <SceneSettings>().navMesh == null)
                {
                    // No NavMesh, are there Characters in the scene?
                    AC.Char[] allChars = GameObject.FindObjectsOfType(typeof(AC.Char)) as AC.Char[];
                    if (allChars.Length > 0)
                    {
                        Debug.LogWarning("No NavMesh set. Characters will not be able to PathFind until one is defined - please choose one using the Scene Manager.");
                    }
                }

                if (this.GetComponent <SceneSettings>().defaultPlayerStart == null)
                {
                    Debug.LogWarning("No default PlayerStart set.  The game may not be able to begin if one is not defined - please choose one using the Scene Manager.");
                }
            }
            if (this.GetComponent <NavigationManager>() == null)
            {
                Debug.LogError(this.name + " has no NavigationManager component attached.");
            }
            if (this.GetComponent <ActionListManager>() == null)
            {
                Debug.LogError(this.name + " has no ActionListManager component attached.");
            }
        }