public override float Run()
 {
     if (acLogType != ACLogType.No && !string.IsNullOrEmpty(convertedText))
     {
         if (acLogType == ACLogType.AsInfo)
         {
             ACDebug.Log(convertedText);
         }
         else if (acLogType == ACLogType.AsWarning)
         {
             ACDebug.LogWarning(convertedText);
         }
         else if (acLogType == ACLogType.AsError)
         {
             ACDebug.LogError(convertedText);
         }
     }
     return(0f);
 }
 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.");
     }
 }
Exemple #3
0
        private void Awake()
        {
            UnityVersionHandler.EnsureSingleScene();

            if (!UnityVersionHandler.ObjectIsInActiveScene(gameObject))
            {
                return;
            }

            activeKickStarter = FindObjectOfType <KickStarter>();

            if (GameObject.FindWithTag(Tags.mainCamera) == null)
            {
                ACDebug.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 &&
                    GameObject.FindWithTag(Tags.mainCamera).GetComponentInParent <MainCamera>() == null)
                {
                    ACDebug.LogError("MainCamera has no MainCamera component.");
                }
            }

            if (activeKickStarter != null)
            {
                KickStarter.mainCamera.OnAwake();
                activeKickStarter.OnAwake();
                KickStarter.playerInput.OnAwake();
                KickStarter.playerQTE.OnAwake();
                KickStarter.sceneSettings.OnAwake();
                KickStarter.dialog.OnAwake();
                KickStarter.navigationManager.OnAwake();
                KickStarter.actionListManager.OnAwake();

                KickStarter.stateHandler.RegisterWithGameEngine();
            }
            else
            {
                ACDebug.LogError("No KickStarter component found in the scene!");
            }
        }
Exemple #4
0
 /**
  * <summary>Stops the FaceFX animation on a character.</summary>
  * <param name = "speaker">The speaking character</param>
  */
 public static void Stop(AC.Char speaker)
 {
                 #if FaceFXIsPresent
     FaceFXControllerScript_Base fcs = speaker.GetComponent <FaceFXControllerScript_Base>();
     if (fcs == null)
     {
         fcs = speaker.GetComponentInChildren <FaceFXControllerScript_Base>();
     }
     if (fcs != null)
     {
         fcs.StopAnim();
     }
     else
     {
         ACDebug.LogError("No FaceFXControllerScript_Base script found on " + speaker.gameObject.name);
     }
                 #else
     ACDebug.LogError("The 'FaceFXIsPresent' preprocessor define must be declared in the Player Settings.");
                 #endif
 }
Exemple #5
0
        /**
         * <summary>Syncs the component with the correct scene.</summary>
         * <param name = "_multiSceneChecker">The MultiSceneChecker component in the scene for which this component is to sync with.</param>
         */
        public void Initialise(MultiSceneChecker _multiSceneChecker)
        {
                        #if UNITY_5_3 || UNITY_5_4 || UNITY_5_3_OR_NEWER
            UnityEngine.SceneManagement.Scene scene = _multiSceneChecker.gameObject.scene;
            gameObject.name = "SubScene " + scene.buildIndex;

            kickStarter = _multiSceneChecker.GetComponent <KickStarter>();

            sceneInfo = new SceneInfo(scene.name, scene.buildIndex);

            localVariables = _multiSceneChecker.GetComponent <LocalVariables>();
            sceneSettings  = _multiSceneChecker.GetComponent <SceneSettings>();

            UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(gameObject, scene);

            kickStarter = UnityVersionHandler.GetOwnSceneInstance <KickStarter> (gameObject);
            if (kickStarter != null)
            {
                kickStarter.gameObject.SetActive(false);
            }

            mainCamera = UnityVersionHandler.GetOwnSceneInstance <MainCamera> (gameObject);
            if (mainCamera != null)
            {
                mainCamera.gameObject.SetActive(false);
            }

            Player ownPlayer = UnityVersionHandler.GetOwnSceneInstance <Player> (gameObject);
            if (ownPlayer != null)
            {
                ownPlayer.gameObject.SetActive(false);
            }

            if (sceneSettings.OverridesCameraPerspective())
            {
                ACDebug.LogError("The added scene (" + scene.name + ", " + scene.buildIndex + ") overrides the default camera perspective - this feature should not be used in conjunction with multiple-open scenes.", gameObject);
            }

            KickStarter.sceneChanger.RegisterSubScene(this);
                        #endif
        }
Exemple #6
0
        public override void PlayTalk()
        {
            if (character.LipSyncGameObject() && character.GetAnimator())
            {
                string clip = character.talkAnimSprite;
                if (character.doDirections)
                {
                    clip += character.GetSpriteDirection();
                }
                character.GetAnimator().speed = 0f;

                                #if UNITY_EDITOR && (UNITY_5 || UNITY_2017_1_OR_NEWER)
                int hash = Animator.StringToHash(clip);
                if (character.GetAnimator().HasState(0, hash))
                {
                    character.GetAnimator().Play(hash, 0, character.GetLipSyncNormalised());
                }
                else
                {
                    ACDebug.LogError("Cannot play clip " + clip + " on " + character.name);
                }
                                #else
                try
                {
                    character.GetAnimator().Play(clip, 0, character.GetLipSyncNormalised());
                }
                catch
                {}
                                #endif

                character.GetAnimator().speed = 1f;
            }
            else if (character.talkAnimSprite != "")
            {
                PlayStandardAnim(character.talkAnimSprite, character.doDirections);
            }
            else
            {
                PlayIdle();
            }
        }
Exemple #7
0
 /*
  * <summary>Plays a FaceFX animation on a character, based on an AudioClip.</summary>
  * <param name = "speaker">The speaking character</param>
  * <param name = "name">The unique identifier of the line in the format Joe13, where 'Joe' is the name of the character, and '13' is the ID number of ths speech line</param>
  * <param name = "audioClip">The speech AudioClip</param>
  */
 public static void Play(AC.Char speaker, string name, AudioClip audioClip)
 {
                 #if FaceFXIsPresent
     FaceFXControllerScript_Base fcs = speaker.GetComponent <FaceFXControllerScript_Base>();
     if (fcs == null)
     {
         fcs = speaker.GetComponentInChildren <FaceFXControllerScript_Base>();
     }
     if (fcs != null)
     {
         speaker.isLipSyncing = true;
         fcs.PlayAnim("Default_" + name, audioClip);
     }
     else
     {
         ACDebug.LogError("No FaceFXControllerScript_Base script found on " + speaker.gameObject.name);
     }
                 #else
     ACDebug.LogError("The 'FaceFXIsPresent' preprocessor define must be declared in the Player Settings.");
                 #endif
 }
Exemple #8
0
        public override void TurnOn(NavigationMesh navMesh)
        {
            if (navMesh == null || KickStarter.settingsManager == null)
            {
                return;
            }

            if (LayerMask.NameToLayer(KickStarter.settingsManager.navMeshLayer) == -1)
            {
                ACDebug.LogError("Can't find layer " + KickStarter.settingsManager.navMeshLayer + " - please define it in Unity's Tags Manager (Edit -> Project settings -> Tags and Layers).");
            }
            else if (!string.IsNullOrEmpty(KickStarter.settingsManager.navMeshLayer))
            {
                navMesh.gameObject.layer = LayerMask.NameToLayer(KickStarter.settingsManager.navMeshLayer);
            }

            if (navMesh.GetComponent <Collider2D>() == null)
            {
                ACDebug.LogWarning("A 2D Collider component must be attached to " + navMesh.gameObject.name + " for pathfinding to work - please attach one.");
            }
        }
Exemple #9
0
        protected void Start()
        {
                        #if !UltimateFPSIsPresent
            ACDebug.LogError("'UltimateFPSIsPresent' must be listed in your Unity Player Setting's 'Scripting define symbols' for AC's UFPS integration to work.", this);
            return;
                        #else
            // Tell the AC Player component that we'l be controlling movement/rotation manually during Cutscenes
            player.FirstPersonCamera = fpCamera.transform;
            player.SetAnimEngine(AnimationEngine.Custom);
            player.motionControl = MotionControl.Manual;

            // Fixes gun sounds from not always playing
            AudioListener.pause = false;

            // Add events to climbing interactable
            if (fpPlayerEventHandler != null)
            {
                fpPlayerEventHandler.Climb.StartCallbacks += OnStartClimb;
                fpPlayerEventHandler.Climb.StopCallbacks  += OnStopClimb;
            }
                        #endif
        }
        private void CreateMusicEngine()
        {
            if (music == null)
            {
                GameObject musicOb = (GameObject)Instantiate(Resources.Load(Resource.musicEngine));
                if (musicOb != null)
                {
                    musicOb.name = AdvGame.GetName(Resource.musicEngine);
                    if (GameObject.Find("_Sound") && GameObject.Find("_Sound").transform.parent == null)
                    {
                        musicOb.transform.parent = GameObject.Find("_Sound").transform;
                    }
                    music = musicOb.GetComponent <Music>();
                }
                else
                {
                    ACDebug.LogError("Cannot find MusicEngine prefab in /AdventureCreator/Resources - did you import AC completely?");
                }

                GatherObjects();
            }
        }
Exemple #11
0
        private float GetAxis(string axisName)
        {
            switch (axisName)
            {
            case "Horizontal":
                return(OuyaSDK.OuyaInput.GetAxis(0, OuyaController.AXIS_LS_X));

            case "Vertical":
                return(OuyaSDK.OuyaInput.GetAxis(0, OuyaController.AXIS_LS_Y));

            case "CursorHorizontal":
                return(OuyaSDK.OuyaInput.GetAxis(0, OuyaController.AXIS_RS_X));

            case "CursorVertical":
                return(OuyaSDK.OuyaInput.GetAxis(0, OuyaController.AXIS_RS_Y));

            default:
                ACDebug.LogError(string.Format("Unknown Axis: {0}", axisName));
                break;
            }
            return(0f);
        }
Exemple #12
0
 private void ShowCustomGUI()
 {
     EditorGUILayout.BeginVertical(CustomStyles.thinBox);
     showCustom = CustomGUILayout.ToggleHeader(showCustom, "Custom Action scripts");
     if (showCustom)
     {
         GUILayout.BeginHorizontal();
         GUILayout.Label("Folder to search:", GUILayout.Width(110f));
         GUILayout.Label(customFolderPath, EditorStyles.textField, GUILayout.MaxWidth(220f));
         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal();
         if (GUILayout.Button("Set directory", EditorStyles.miniButtonLeft))
         {
             string path     = EditorUtility.OpenFolderPanel("Set custom Actions directory", "Assets", "");
             string dataPath = Application.dataPath;
             if (path.Contains(dataPath))
             {
                 if (path == dataPath)
                 {
                     customFolderPath = "";
                 }
                 else
                 {
                     customFolderPath = path.Replace(dataPath + "/", "");
                 }
             }
             else
             {
                 ACDebug.LogError("Cannot set new directory - be sure to select within the Assets directory.");
             }
         }
         if (GUILayout.Button("Clear", EditorStyles.miniButtonRight))
         {
             customFolderPath = "";
         }
         GUILayout.EndHorizontal();
     }
     EditorGUILayout.EndVertical();
 }
Exemple #13
0
        private void PlayLipSync(bool onlyHead)
        {
            string clip  = character.talkAnimSprite;
            int    layer = (onlyHead) ? character.headLayer : 0;

            if (character.doDirections)
            {
                if (layer > 0)
                {
                    clip += headDirection;
                }
                else
                {
                    clip += character.GetSpriteDirection();
                }
            }
            character.GetAnimator().speed = 0f;

                        #if UNITY_EDITOR && (UNITY_5 || UNITY_2017_1_OR_NEWER)
            int hash = Animator.StringToHash(clip);
            if (character.GetAnimator().HasState(layer, hash))
            {
                character.GetAnimator().Play(hash, layer, character.GetLipSyncNormalised());
            }
            else
            {
                ACDebug.LogError("Cannot play clip " + clip + " (layer " + layer + ") on " + character.name);
            }
                        #else
            try
            {
                character.GetAnimator().Play(clip, layer, character.GetLipSyncNormalised());
            }
            catch
            {}
                        #endif

            character.GetAnimator().speed = 1f;
        }
Exemple #14
0
        private T CreateSoundtrackEngine <T> (string resourceName) where T : Soundtrack
        {
            GameObject soundtrackOb = (GameObject)Instantiate(Resources.Load(resourceName));

            if (soundtrackOb != null)
            {
                soundtrackOb.name = AdvGame.GetName(resourceName);
                if (GameObject.Find("_Sound") && GameObject.Find("_Sound").transform.parent == null)
                {
                    soundtrackOb.transform.parent = GameObject.Find("_Sound").transform;
                }

                GatherObjects();

                return(soundtrackOb.GetComponent <T>());
            }
            else
            {
                ACDebug.LogError("Cannot find " + resourceName + " prefab in /AdventureCreator/Resources - did you import AC completely?");
                return(null);
            }
        }
        override public float Run()
        {
            SceneInfo sceneInfo = new SceneInfo(chooseSceneBy, AdvGame.ConvertTokens(sceneName), sceneNumber);

            if (!isRunning)
            {
                waitedOneMoreFrame = false;
                isRunning          = true;

                if (KickStarter.sceneSettings.OverridesCameraPerspective())
                {
                    ACDebug.LogError("The current scene overrides the default camera perspective - this feature should not be used in conjunction with multiple-open scenes.");
                }

                if (sceneAddRemove == SceneAddRemove.Add)
                {
                    if (KickStarter.sceneChanger.AddSubScene(sceneInfo))
                    {
                        return(defaultPauseTime);
                    }
                }
                else if (sceneAddRemove == SceneAddRemove.Remove)
                {
                    KickStarter.sceneChanger.RemoveScene(sceneInfo);
                }
            }
            else
            {
                if (!waitedOneMoreFrame)
                {
                    waitedOneMoreFrame = true;
                    return(defaultPauseTime);
                }

                if (sceneAddRemove == SceneAddRemove.Add)
                {
                    bool found = false;
                    foreach (SubScene subScene in KickStarter.sceneChanger.GetSubScenes())
                    {
                        if (subScene.SceneInfo.Matches(sceneInfo))
                        {
                            found = true;

                            if (runCutsceneOnStart && subScene.SceneSettings != null && subScene.SceneSettings.cutsceneOnStart != null)
                            {
                                subScene.SceneSettings.cutsceneOnStart.Interact();
                            }
                        }
                    }

                    if (!found)
                    {
                        LogWarning("Adding a non-AC scene additively!  A GameEngine prefab must be placed in scene '" + sceneInfo.GetLabel() + "'.");
                    }
                }

                isRunning = false;
            }

            return(0f);
        }
Exemple #16
0
        public override Vector3[] GetPointsArray(Vector3 _originPos, Vector3 _targetPos, AC.Char _char = null)
        {
            if (KickStarter.sceneSettings == null || KickStarter.sceneSettings.navMesh == null)
            {
                return(base.GetPointsArray(_originPos, _targetPos, _char));
            }

            PolygonCollider2D[] polys = KickStarter.sceneSettings.navMesh.PolygonCollider2Ds;
            if (polys == null || polys.Length == 0)
            {
                return(base.GetPointsArray(_originPos, _targetPos, _char));
            }

            CalcSearchRadius(KickStarter.sceneSettings.navMesh);

            AddCharHoles(polys, _char, KickStarter.sceneSettings.navMesh);

            List <Vector3> pointsList3D = new List <Vector3> ();

            if (IsLineClear(_originPos, _targetPos))
            {
                pointsList3D.Add(_targetPos);
                return(pointsList3D.ToArray());
            }

            // Iterate through polys, find originPos neareset to _originPos
            int     nearestOriginIndex = -1;
            float   minDist            = 0f;
            Vector2 originPos          = Vector2.zero;
            Vector2 originPos2D        = new Vector2(_originPos.x, _originPos.y);

            for (int i = 0; i < polys.Length; i++)
            {
                Vector2 testOriginPos = GetNearestToMesh(_originPos, polys[i], (polys.Length > 1));
                float   dist          = (originPos2D - testOriginPos).sqrMagnitude;
                if (nearestOriginIndex < 0 || dist < minDist)
                {
                    minDist            = dist;
                    originPos          = testOriginPos;
                    nearestOriginIndex = i;
                }
            }
            if (nearestOriginIndex < 0)
            {
                nearestOriginIndex = 0;
            }
            Vector2 targetPos = GetNearestToMesh(_targetPos, polys[nearestOriginIndex], (polys.Length > 1));

            Vector2[] pointsList = allVertexData[nearestOriginIndex];
            pointsList = AddEndsToList(pointsList, originPos, targetPos);

            bool useCache = (KickStarter.sceneSettings.navMesh.characterEvasion == CharacterEvasion.None) ? true : false;

            float[,] weight = pointsToWeight(pointsList, useCache, nearestOriginIndex);
            int[] precede = buildSpanningTree(0, 1, weight);
            if (precede == null)
            {
                ACDebug.LogWarning("Pathfinding error - cannot build spanning tree from " + originPos + " to " + targetPos);
                pointsList3D.Add(_targetPos);
                return(pointsList3D.ToArray());
            }

            int[] _path = getShortestPath(0, 1, precede);
            foreach (int i in _path)
            {
                if (i < pointsList.Length)
                {
                    Vector3 vertex = new Vector3(pointsList[i].x, pointsList[i].y, _originPos.z);
                    pointsList3D.Insert(0, vertex);
                }
            }

            if (pointsList3D.Count > 1)
            {
                if (pointsList3D[0] == _originPos || (Mathf.Approximately(pointsList3D[0].x, originPos.x) && Mathf.Approximately(pointsList3D[0].y, originPos.y)))
                {
                    pointsList3D.RemoveAt(0);                           // Remove origin point from start
                }
            }
            else if (pointsList3D.Count == 0)
            {
                ACDebug.LogError("Error attempting to pathfind to point " + _targetPos + " corrected = " + targetPos);
                pointsList3D.Add(originPos);
            }

            return(pointsList3D.ToArray());
        }
Exemple #17
0
        // Layers

        private static bool IsLayerDefined(string layerName, bool addIfUndefined = false)
        {
            SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);

                        #if UNITY_5 || UNITY_2017_1_OR_NEWER
            SerializedProperty allLayers = tagManager.FindProperty("layers");
            if (allLayers == null || !allLayers.isArray)
            {
                return(false);
            }
                        #endif

            // Check if layer is present
            bool foundLayer = false;
            for (int i = 0; i <= 31; i++)
            {
                                #if UNITY_5 || UNITY_2017_1_OR_NEWER
                SerializedProperty sp = allLayers.GetArrayElementAtIndex(i);
                                #else
                string             nm = "User Layer " + i;
                SerializedProperty sp = tagManager.FindProperty(nm);
                                #endif

                if (sp != null && layerName.Equals(sp.stringValue))
                {
                    foundLayer = true;
                    break;
                }
            }

            if (!addIfUndefined)
            {
                return(foundLayer);
            }

            if (foundLayer)
            {
                return(true);
            }

            // Create layer
            SerializedProperty slot = null;
            for (int i = 8; i <= 31; i++)
            {
                                #if UNITY_5 || UNITY_2017_1_OR_NEWER
                SerializedProperty sp = allLayers.GetArrayElementAtIndex(i);
                                #else
                string             nm = "User Layer " + i;
                SerializedProperty sp = tagManager.FindProperty(nm);
                                #endif

                if (sp != null && string.IsNullOrEmpty(sp.stringValue))
                {
                    slot = sp;
                    break;
                }
            }

            if (slot != null)
            {
                slot.stringValue = layerName;
            }
            else
            {
                ACDebug.LogError("Could not find an open Layer Slot for: " + layerName);
                return(false);
            }

            tagManager.ApplyModifiedProperties();

            ACDebug.Log("Created layer: '" + layerName + "'");
            return(true);
        }
        protected bool TestOwnComponents()
        {
            bool testResult = true;

            if (GetComponent <MenuSystem> () == null)
            {
                ACDebug.LogError(name + " has no MenuSystem component attached.", this);
                testResult = false;
            }
            if (GetComponent <Dialog> () == null)
            {
                ACDebug.LogError(name + " has no Dialog component attached.", this);
                testResult = false;
            }
            if (GetComponent <PlayerInput> () == null)
            {
                ACDebug.LogError(name + " has no PlayerInput component attached.", this);
                testResult = false;
            }
            if (GetComponent <PlayerInteraction> () == null)
            {
                ACDebug.LogError(name + " has no PlayerInteraction component attached.", this);
                testResult = false;
            }
            if (GetComponent <PlayerMovement> () == null)
            {
                ACDebug.LogError(name + " has no PlayerMovement component attached.", this);
                testResult = false;
            }
            if (GetComponent <PlayerCursor> () == null)
            {
                ACDebug.LogError(name + " has no PlayerCursor component attached.", this);
                testResult = false;
            }
            if (GetComponent <PlayerQTE> () == null)
            {
                ACDebug.LogError(name + " has no PlayerQTE component attached.", this);
                testResult = false;
            }
            if (GetComponent <SceneSettings> () == null)
            {
                ACDebug.LogError(name + " has no SceneSettings component attached.", this);
                testResult = false;
            }
            if (GetComponent <NavigationManager> () == null)
            {
                ACDebug.LogError(name + " has no NavigationManager component attached.", this);
                testResult = false;
            }
            if (GetComponent <ActionListManager> () == null)
            {
                ACDebug.LogError(name + " has no ActionListManager component attached.", this);
                testResult = false;
            }
            if (GetComponent <EventManager> () == null)
            {
                ACDebug.LogError(name + " has no EventManager component attached.", this);
                testResult = false;
            }

            return(testResult);
        }
        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);
        }
        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("Setup 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 #21
0
        public override float ActionCharAnimRun(ActionCharAnim action)
        {
            string clip2DNew = action.clip2D;

            if (action.includeDirection)
            {
                clip2DNew += action.animChar.GetSpriteDirection();
            }

            if (!action.isRunning)
            {
                action.isRunning = true;

                if (action.method == ActionCharAnim.AnimMethodChar.PlayCustom && action.clip2D != "")
                {
                    if (action.animChar.GetAnimator())
                    {
                                                #if UNITY_EDITOR && (UNITY_5 || UNITY_2017_1_OR_NEWER)
                        int hash = Animator.StringToHash(clip2DNew);
                        if (!character.GetAnimator().HasState(action.layerInt, hash))
                        {
                            ACDebug.LogError("Cannot play clip " + clip2DNew + " on " + character.name);
                        }
                                                #endif

                        action.animChar.charState = CharState.Custom;
                        action.animChar.GetAnimator().CrossFade(clip2DNew, action.fadeTime, action.layerInt);

                        if (action.hideHead && action.animChar.talkingAnimation == TalkingAnimation.Standard && action.animChar.separateTalkingLayer)
                        {
                            PlayHeadAnim(hideHeadClip, false);
                        }
                    }
                }

                else if (action.method == ActionCharAnim.AnimMethodChar.ResetToIdle)
                {
                    if (action.idleAfterCustom)
                    {
                        action.layerInt = 0;
                        return(action.defaultPauseTime);
                    }
                    else
                    {
                        action.animChar.ResetBaseClips();
                        action.animChar.charState = CharState.Idle;
                    }
                }

                else if (action.method == ActionCharAnim.AnimMethodChar.SetStandard)
                {
                    if (action.clip2D != "")
                    {
                        if (action.standard == AnimStandard.Idle)
                        {
                            action.animChar.idleAnimSprite = action.clip2D;
                        }
                        else if (action.standard == AnimStandard.Walk)
                        {
                            action.animChar.walkAnimSprite = action.clip2D;
                        }
                        else if (action.standard == AnimStandard.Talk)
                        {
                            action.animChar.talkAnimSprite = action.clip2D;
                        }
                        else if (action.standard == AnimStandard.Run)
                        {
                            action.animChar.runAnimSprite = action.clip2D;
                        }
                    }

                    if (action.changeSpeed)
                    {
                        if (action.standard == AnimStandard.Walk)
                        {
                            action.animChar.walkSpeedScale = action.newSpeed;
                        }
                        else if (action.standard == AnimStandard.Run)
                        {
                            action.animChar.runSpeedScale = action.newSpeed;
                        }
                    }

                    if (action.changeSound)
                    {
                        if (action.standard == AnimStandard.Walk)
                        {
                            if (action.newSound != null)
                            {
                                action.animChar.walkSound = action.newSound;
                            }
                            else
                            {
                                action.animChar.walkSound = null;
                            }
                        }
                        else if (action.standard == AnimStandard.Run)
                        {
                            if (action.newSound != null)
                            {
                                action.animChar.runSound = action.newSound;
                            }
                            else
                            {
                                action.animChar.runSound = null;
                            }
                        }
                    }
                }

                if (action.willWait && action.clip2D != "")
                {
                    if (action.method == ActionCharAnim.AnimMethodChar.PlayCustom)
                    {
                        return(action.defaultPauseTime);
                    }
                }
            }

            else
            {
                if (action.animChar.GetAnimator())
                {
                    // Calc how much longer left to wait
                    float totalLength = action.animChar.GetAnimator().GetCurrentAnimatorStateInfo(action.layerInt).length;
                    float timeLeft    = (1f - action.animChar.GetAnimator().GetCurrentAnimatorStateInfo(action.layerInt).normalizedTime) * totalLength;

                    // Subtract a small amount of time to prevent overshooting
                    timeLeft -= 0.1f;

                    if (timeLeft > 0f)
                    {
                        return(timeLeft);
                    }
                    else
                    {
                        if (action.method == ActionCharAnim.AnimMethodChar.ResetToIdle)
                        {
                            action.animChar.ResetBaseClips();
                            action.animChar.charState = CharState.Idle;
                        }
                        else if (action.idleAfter)
                        {
                            action.animChar.charState = CharState.Idle;
                        }

                        action.isRunning = false;
                        return(0f);
                    }
                }
                else
                {
                    action.isRunning          = false;
                    action.animChar.charState = CharState.Idle;
                    return(0f);
                }
            }

            return(0f);
        }
Exemple #22
0
        private void Export()
        {
                        #if UNITY_WEBPLAYER
            ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again.");
                        #else
            if (variablesManager == null || exportColumns == null || exportColumns.Count == 0)
            {
                return;
            }

            if (variableLocation == VariableLocation.Local && allScenes)
            {
                bool canProceed = EditorUtility.DisplayDialog("Export variables", "AC will now go through your game, and collect all variables to be exported.\n\nIt is recommended to back up your project beforehand.", "OK", "Cancel");
                if (!canProceed)
                {
                    return;
                }

                if (!UnityVersionHandler.SaveSceneIfUserWants())
                {
                    return;
                }
            }

            string suggestedFilename = "";
            if (AdvGame.GetReferences().settingsManager)
            {
                suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - ";
            }
            if (variableLocation == VariableLocation.Local && allScenes)
            {
                suggestedFilename += " All ";
            }
            suggestedFilename += variableLocation.ToString() + " Variables.csv";

            string fileName = EditorUtility.SaveFilePanel("Export variables", "Assets", suggestedFilename, "csv");
            if (fileName.Length == 0)
            {
                return;
            }

            bool            fail   = false;
            List <string[]> output = new List <string[]>();

            List <string> headerList = new List <string>();
            headerList.Add("ID");
            foreach (ExportColumn exportColumn in exportColumns)
            {
                headerList.Add(exportColumn.GetHeader());
            }
            output.Add(headerList.ToArray());

            // Global
            if (variableLocation == VariableLocation.Global)
            {
                List <GVar> exportVars = new List <GVar>();
                foreach (GVar globalVariable in variablesManager.vars)
                {
                    exportVars.Add(new GVar(globalVariable));
                }

                foreach (GVar exportVar in exportVars)
                {
                    List <string> rowList = new List <string>();
                    rowList.Add(exportVar.id.ToString());
                    foreach (ExportColumn exportColumn in exportColumns)
                    {
                        string cellText = exportColumn.GetCellText(exportVar, VariableLocation.Global, replaceForwardSlashes);
                        rowList.Add(cellText);

                        if (cellText.Contains(CSVReader.csvDelimiter))
                        {
                            fail = true;
                            ACDebug.LogError("Cannot export variables since global variable " + exportVar.id.ToString() + " (" + exportVar.label + ") contains the character '" + CSVReader.csvDelimiter + "'.");
                        }
                    }
                    output.Add(rowList.ToArray());
                }
            }

            // Local
            else if (variableLocation == VariableLocation.Local)
            {
                if (allScenes)
                {
                    string   originalScene = UnityVersionHandler.GetCurrentSceneFilepath();
                    string[] sceneFiles    = AdvGame.GetSceneFiles();
                    foreach (string sceneFile in sceneFiles)
                    {
                        UnityVersionHandler.OpenScene(sceneFile);

                        if (FindObjectOfType <LocalVariables>())
                        {
                            LocalVariables localVariables = FindObjectOfType <LocalVariables>();
                            if (localVariables != null)
                            {
                                string sceneName = UnityVersionHandler.GetCurrentSceneName();
                                output = GatherOutput(output, localVariables.localVars, sceneName);
                            }
                        }
                    }

                    if (originalScene == "")
                    {
                        UnityVersionHandler.NewScene();
                    }
                    else
                    {
                        UnityVersionHandler.OpenScene(originalScene);
                    }
                }
                else
                {
                    string sceneName = UnityVersionHandler.GetCurrentSceneName();
                    output = GatherOutput(output, KickStarter.localVariables.localVars, sceneName);
                }
            }

            // Component
            else if (variableLocation == VariableLocation.Component)
            {
                string sceneName = UnityVersionHandler.GetCurrentSceneName();
                if (variables != null)
                {
                    output = GatherOutput(output, variables.vars, sceneName);
                }
            }

            if (!fail)
            {
                int length = output.Count;

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int j = 0; j < length; j++)
                {
                    sb.AppendLine(string.Join(CSVReader.csvDelimiter, output[j]));
                }

                if (Serializer.SaveFile(fileName, sb.ToString()))
                {
                    int numExported = output.Count - 1;
                    if (numExported == 1)
                    {
                        ACDebug.Log("1 " + variableLocation + " variable exported.");
                    }
                    else
                    {
                        ACDebug.Log(numExported.ToString() + " " + variableLocation + " variables exported.");
                    }
                }
            }
                        #endif
        }
        private void CreateScript()
        {
                        #if UNITY_WEBPLAYER
            ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again.");
                        #else
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().speechManager == null)
            {
                ACDebug.LogError("Cannot create script sheet - no Speech Manager is assigned!");
                return;
            }

            SpeechManager speechManager = AdvGame.GetReferences().speechManager;
            languageIndex = Mathf.Max(languageIndex, 0);

            string suggestedFilename = "Adventure Creator";
            if (AdvGame.GetReferences().settingsManager)
            {
                suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName;
            }
            if (limitToCharacter && characterName != "")
            {
                suggestedFilename += " (" + characterName + ")";
            }
            if (limitToTag && tagID >= 0)
            {
                SpeechTag speechTag = speechManager.GetSpeechTag(tagID);
                if (speechTag != null && speechTag.label.Length > 0)
                {
                    suggestedFilename += " (" + speechTag.label + ")";
                }
            }
            suggestedFilename += " - ";
            if (languageIndex > 0)
            {
                suggestedFilename += speechManager.languages[languageIndex] + " ";
            }
            suggestedFilename += "script.html";

            string fileName = EditorUtility.SaveFilePanel("Save script file", "Assets", suggestedFilename, "html");
            if (fileName.Length == 0)
            {
                return;
            }

            string gameName = "Adventure Creator";
            if (AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.saveFileName.Length > 0)
            {
                gameName = AdvGame.GetReferences().settingsManager.saveFileName;
                if (languageIndex > 0)
                {
                    gameName += " (" + speechManager.languages[languageIndex] + ")";
                }
            }

            System.Text.StringBuilder script = new System.Text.StringBuilder();
            script.Append("<html>\n<head>\n");
            script.Append("<meta http-equiv='Content-Type' content='text/html;charset=ISO-8859-1' charset='UTF-8'>\n");
            script.Append("<title>" + gameName + "</title>\n");
            script.Append("<style> body, table, div, p, dl { font: 400 14px/22px Roboto,sans-serif; } footer { text-align: center; padding-top: 20px; font-size: 12px;} footer a { color: blue; text-decoration: none} </style>\n</head>\n");
            script.Append("<body>\n");

            script.Append("<h1>" + gameName + " - script sheet");
            if (limitToCharacter && characterName != "")
            {
                script.Append(" (" + characterName + ")");
            }
            script.Append("</h1>\n");
            script.Append("<h2>Created: " + DateTime.UtcNow.ToString("HH:mm dd MMMM, yyyy") + "</h2>\n");

            // By scene
            foreach (string sceneFile in speechManager.sceneFiles)
            {
                List <SpeechLine> sceneSpeechLines = new List <SpeechLine>();

                int    slashPoint = sceneFile.LastIndexOf("/") + 1;
                string sceneName  = sceneFile.Substring(slashPoint);

                foreach (SpeechLine line in speechManager.lines)
                {
                    if (line.textType == AC_TextType.Speech &&
                        (line.scene == sceneFile || sceneName == (line.scene + ".unity")) &&
                        (!limitToCharacter || characterName == "" || line.owner == characterName || (line.isPlayer && characterName == "Player")) &&
                        (!limitToTag || line.tagID == tagID))
                    {
                        if (!speechManager.autoNameSpeechFiles && limitToMissingAudio)
                        {
                            if (languageIndex == 0 && line.customAudioClip != null)
                            {
                                continue;
                            }
                            if (speechManager.translateAudio && languageIndex > 0 && line.customTranslationAudioClips.Count > (languageIndex - 1) && line.customTranslationAudioClips[languageIndex - 1] != null)
                            {
                                continue;
                            }
                            if (!speechManager.translateAudio && line.customAudioClip != null)
                            {
                                continue;
                            }
                        }

                        sceneSpeechLines.Add(line);
                    }
                }

                if (sceneSpeechLines != null && sceneSpeechLines.Count > 0)
                {
                    sceneSpeechLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.OrderIdentifier.CompareTo(b.OrderIdentifier)); });

                    script.Append("<hr/>\n<h3><b>Scene:</b> " + sceneName + "</h3>\n");
                    foreach (SpeechLine sceneSpeechLine in sceneSpeechLines)
                    {
                        script.Append(sceneSpeechLine.Print(languageIndex, includeDescriptions, removeTokens));
                    }
                }
            }

            // No scene
            List <SpeechLine> assetSpeechLines = new List <SpeechLine>();

            foreach (SpeechLine line in speechManager.lines)
            {
                if (line.scene == "" &&
                    line.textType == AC_TextType.Speech &&
                    (!limitToCharacter || characterName == "" || line.owner == characterName || (line.isPlayer && characterName == "Player")) &&
                    (!limitToTag || line.tagID == tagID))
                {
                    assetSpeechLines.Add(line);
                }
            }

            if (assetSpeechLines != null && assetSpeechLines.Count > 0)
            {
                assetSpeechLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.OrderIdentifier.CompareTo(b.OrderIdentifier)); });

                script.Append("<hr/>\n<h3>Scene-independent lines:</h3>\n");
                foreach (SpeechLine assetSpeechLine in assetSpeechLines)
                {
                    script.Append(assetSpeechLine.Print(languageIndex, includeDescriptions, removeTokens));
                }
            }

            script.Append("<footer>Generated by <a href='http://adventurecreator.org' target=blank>Adventure Creator</a>, by Chris Burton</footer>\n");
            script.Append("</body>\n</html>");

            Serializer.SaveFile(fileName, script.ToString());
                        #endif

            this.Close();
        }
        private float ActionAnimProcess(ActionAnim action, bool isSkipping)
        {
            if (!action.isRunning)
            {
                action.isRunning = true;

                if (action.methodMecanim == AnimMethodMecanim.ChangeParameterValue && action.animator && action.parameterName != "")
                {
                    if (action.mecanimParameterType == MecanimParameterType.Float)
                    {
                        action.animator.SetFloat(action.parameterName, action.parameterValue);
                    }
                    else if (action.mecanimParameterType == MecanimParameterType.Int)
                    {
                        action.animator.SetInteger(action.parameterName, (int)action.parameterValue);
                    }
                    else if (action.mecanimParameterType == MecanimParameterType.Bool)
                    {
                        bool paramValue = (action.parameterValue > 0f) ? true : false;
                        action.animator.SetBool(action.parameterName, paramValue);
                    }
                    else if (action.mecanimParameterType == MecanimParameterType.Trigger)
                    {
                        if (!isSkipping || action.parameterValue != 1f)
                        {
                            action.animator.SetTrigger(action.parameterName);
                        }
                    }

                    return(0f);
                }

                else if (action.methodMecanim == AnimMethodMecanim.PlayCustom && action.animator)
                {
                    if (action.clip2D != "")
                    {
                                                #if UNITY_EDITOR && UNITY_5
                        int hash = Animator.StringToHash(action.clip2D);
                        if (action.animator.HasState(0, hash))
                        {
                            action.animator.CrossFade(hash, action.fadeTime, action.layerInt);
                        }
                        else
                        {
                            ACDebug.LogError("Cannot play clip " + action.clip2D + " on " + action.animator.name);
                        }
                                                #else
                        try
                        {
                            action.animator.CrossFade(action.clip2D, action.fadeTime, action.layerInt);
                        }
                        catch
                        {}
                                                #endif

                        if (action.willWait)
                        {
                            return(action.defaultPauseTime);
                        }
                    }
                }

                else if (action.methodMecanim == AnimMethodMecanim.BlendShape && action.shapeKey > -1)
                {
                    if (action.shapeObject)
                    {
                        action.shapeObject.Change(action.shapeKey, action.shapeValue, action.fadeTime);

                        if (action.willWait)
                        {
                            return(action.fadeTime);
                        }
                    }
                }
            }
            else
            {
                if (action.methodMecanim == AnimMethodMecanim.BlendShape && action.shapeObject)
                {
                    action.isRunning = false;
                    return(0f);
                }
                else if (action.methodMecanim == AnimMethodMecanim.PlayCustom)
                {
                    if (action.animator && action.clip2D != "")
                    {
                        if (action.animator.GetCurrentAnimatorStateInfo(action.layerInt).normalizedTime < 1f)
                        {
                            return(action.defaultPauseTime / 6f);
                        }
                        else
                        {
                            action.isRunning = false;
                            return(0f);
                        }
                    }
                }
            }

            return(0f);
        }
Exemple #25
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 (!string.IsNullOrEmpty(actionsManager.customFolderPath) && 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();
        }
        /**
         * Assigns its various Manager asset files.
         */
        public void AssignManagers()
        {
            if (AdvGame.GetReferences() != null)
            {
                int numAssigned = 0;

                if (sceneManager)
                {
                    AdvGame.GetReferences().sceneManager = sceneManager;
                    numAssigned++;
                }

                if (settingsManager)
                {
                    AdvGame.GetReferences().settingsManager = settingsManager;
                    numAssigned++;
                }

                if (actionsManager)
                {
                    AdvGame.GetReferences().actionsManager = actionsManager;
                    numAssigned++;
                }

                if (variablesManager)
                {
                    AdvGame.GetReferences().variablesManager = variablesManager;
                    numAssigned++;
                }

                if (inventoryManager)
                {
                    AdvGame.GetReferences().inventoryManager = inventoryManager;
                    numAssigned++;
                }

                if (speechManager)
                {
                    AdvGame.GetReferences().speechManager = speechManager;
                    numAssigned++;
                }

                if (cursorManager)
                {
                    AdvGame.GetReferences().cursorManager = cursorManager;
                    numAssigned++;
                }

                if (menuManager)
                {
                    AdvGame.GetReferences().menuManager = menuManager;
                    numAssigned++;
                }

                                #if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    KickStarter.ClearManagerCache();
                }

                if (KickStarter.sceneManager)
                {
                    KickStarter.sceneManager.GetPrefabsInScene();
                }

                UnityVersionHandler.CustomSetDirty(AdvGame.GetReferences(), true);
                AssetDatabase.SaveAssets();
                                #endif

                if (this)
                {
                    if (numAssigned == 0)
                    {
                        ACDebug.Log(this.name + " No Mangers assigned.");
                    }
                    else if (numAssigned == 1)
                    {
                        ACDebug.Log(this.name + " - (" + numAssigned.ToString() + ") Manager assigned.");
                    }
                    else
                    {
                        ACDebug.Log(this.name + " - (" + numAssigned.ToString() + ") Managers assigned.");
                    }
                }
            }
            else
            {
                ACDebug.LogError("Can't assign managers - no References file found in Resources folder.");
            }
        }
Exemple #27
0
        public override void OnInspectorGUI()
        {
            if (AdvGame.GetReferences() == null)
            {
                ACDebug.LogError("A References file is required - please use the Adventure Creator window to create one.");
                EditorGUILayout.LabelField("No References file found!");
            }
            else
            {
                if (AdvGame.GetReferences().inventoryManager)
                {
                    inventoryManager = AdvGame.GetReferences().inventoryManager;
                }
                if (AdvGame.GetReferences().cursorManager)
                {
                    cursorManager = AdvGame.GetReferences().cursorManager;
                }
                if (AdvGame.GetReferences().settingsManager)
                {
                    settingsManager = AdvGame.GetReferences().settingsManager;
                }

                if (Application.isPlaying)
                {
                    if (_target.gameObject.layer != LayerMask.NameToLayer(settingsManager.hotspotLayer))
                    {
                        EditorGUILayout.HelpBox("Current state: OFF", MessageType.Info);
                    }
                }

                if (_target.lineID > -1)
                {
                    EditorGUILayout.LabelField("Speech Manager ID:", _target.lineID.ToString());
                }

                _target.interactionSource = (AC.InteractionSource)CustomGUILayout.EnumPopup("Interaction source:", _target.interactionSource, "", "The source of the commands that are run when an option is chosen");
                _target.hotspotName       = CustomGUILayout.TextField("Label (if not name):", _target.hotspotName, "", "The display name, if not the GameObject's name");
                _target.highlight         = (Highlight)CustomGUILayout.ObjectField <Highlight> ("Object to highlight:", _target.highlight, true, "", "The Highlight component that controls any highlighting effects associated with the Hotspot");

                if (AdvGame.GetReferences().settingsManager != null && AdvGame.GetReferences().settingsManager.hotspotDrawing == ScreenWorld.WorldSpace)
                {
                    _target.iconSortingLayer = CustomGUILayout.TextField("Icon sorting layer:", _target.iconSortingLayer, "", "The 'Sorting Layer' of the icon's SpriteRenderer");
                    _target.iconSortingOrder = CustomGUILayout.IntField("Icon sprite order:", _target.iconSortingOrder, "", "The 'Order in Layer' of the icon's SpriteRenderer");
                }

                EditorGUILayout.BeginHorizontal();
                _target.centrePoint = (Transform)CustomGUILayout.ObjectField <Transform> ("Centre point (override):", _target.centrePoint, true, "", "A Transform that represents the centre of the Hotspot, if it is not physically at the same point as the Hotspot's GameObject itself");

                if (_target.centrePoint == null)
                {
                    if (GUILayout.Button("Create", autoWidth))
                    {
                        string     prefabName = "Hotspot centre: " + _target.gameObject.name;
                        GameObject go         = SceneManager.AddPrefab("Navigation", "HotspotCentre", true, false, false);
                        go.name = prefabName;
                        go.transform.position = _target.transform.position;
                        _target.centrePoint   = go.transform;
                        go.transform.parent   = _target.transform;
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                _target.walkToMarker = (Marker)CustomGUILayout.ObjectField <Marker> ("Walk-to Marker:", _target.walkToMarker, true, "", "The Marker that the player can optionally automatically walk to before an Interaction runs");
                if (_target.walkToMarker == null)
                {
                    if (GUILayout.Button("Create", autoWidth))
                    {
                        string prefabName = "Marker";
                        if (SceneSettings.IsUnity2D())
                        {
                            prefabName += "2D";
                        }
                        Marker newMarker = SceneManager.AddPrefab("Navigation", prefabName, true, false, true).GetComponent <Marker>();
                        newMarker.gameObject.name   += (": " + _target.gameObject.name);
                        newMarker.transform.position = _target.transform.position;
                        _target.walkToMarker         = newMarker;
                    }
                }
                EditorGUILayout.EndHorizontal();

                _target.limitToCamera = (_Camera)CustomGUILayout.ObjectField <_Camera> ("Limit to camera:", _target.limitToCamera, true, "", "If assigned, then the Hotspot will only be interactive when the assigned _Camera is active");

                EditorGUILayout.BeginHorizontal();
                _target.interactiveBoundary = (InteractiveBoundary)CustomGUILayout.ObjectField <InteractiveBoundary> ("Interactive boundary:", _target.interactiveBoundary, true, "", "If assigned, then the Hotspot will only be interactive when the player is within this Trigger Collider's boundary");
                if (_target.interactiveBoundary == null)
                {
                    if (GUILayout.Button("Create", autoWidth))
                    {
                        string prefabName = "InteractiveBoundary";
                        if (SceneSettings.IsUnity2D())
                        {
                            prefabName += "2D";
                        }
                        InteractiveBoundary newInteractiveBoundary = SceneManager.AddPrefab("Logic", prefabName, true, false, true).GetComponent <InteractiveBoundary>();
                        newInteractiveBoundary.gameObject.name   += (": " + _target.gameObject.name);
                        newInteractiveBoundary.transform.position = _target.transform.position;
                        _target.interactiveBoundary = newInteractiveBoundary;

                        UnityVersionHandler.PutInFolder(newInteractiveBoundary.gameObject, "_Hotspots");
                    }
                }
                EditorGUILayout.EndHorizontal();

                _target.drawGizmos = CustomGUILayout.Toggle("Draw yellow cube?", _target.drawGizmos, "", "If True, then a Gizmo may be drawn in the Scene window at the Hotspots's position");

                if (settingsManager != null && (settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction || settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot || settingsManager.interactionMethod == AC_InteractionMethod.CustomScript))
                {
                    _target.oneClick = CustomGUILayout.Toggle("Single 'Use' Interaction?", _target.oneClick, "", "If True, then clicking the Hotspot will run the Hotspot's first interaction in useButtons, regardless of the Settings Manager's Interaction method");

                    if (_target.oneClick && settingsManager.interactionMethod == AC_InteractionMethod.CustomScript)
                    {
                        EditorGUILayout.HelpBox("The above property can be accessed by reading the Hotspot script's IsSingleInteraction() method.", MessageType.Info);
                    }
                }
                if (_target.oneClick || (settingsManager != null && settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive))
                {
                    if (settingsManager != null && settingsManager.interactionMethod == AC_InteractionMethod.CustomScript)
                    {
                    }
                    else
                    {
                        _target.doubleClickingHotspot = (DoubleClickingHotspot)CustomGUILayout.EnumPopup("Double-clicking:", _target.doubleClickingHotspot, "", "The effect that double-clicking on the Hotspot has");
                    }
                }
                if (settingsManager != null && settingsManager.playerFacesHotspots)
                {
                    _target.playerTurnsHead = CustomGUILayout.Toggle("Players turn heads when active?", _target.playerTurnsHead, "", "If True, then the player will turn their head when the Hotspot is selected");
                }

                EditorGUILayout.Space();

                UseInteractionGUI();

                if (settingsManager == null || settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive || settingsManager.interactionMethod == AC_InteractionMethod.CustomScript)
                {
                    EditorGUILayout.Space();
                    LookInteractionGUI();
                }

                EditorGUILayout.Space();
                InvInteractionGUI();

                EditorGUILayout.Space();
                UnhandledInvInteractionGUI();
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }
Exemple #28
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.");
            }
        }
Exemple #29
0
        public void ShowGUI()
        {
            EditorGUILayout.BeginVertical(CustomStyles.thinBox);
            showEditing = CustomGUILayout.ToggleHeader(showEditing, "ActionList editing settings");
            if (showEditing)
            {
                displayActionsInInspector   = CustomGUILayout.ToggleLeft("List Actions in Inspector window?", displayActionsInInspector, "AC.KickStarter.actionsManager.displayActionsInInspector");
                displayActionsInEditor      = (DisplayActionsInEditor)CustomGUILayout.EnumPopup("Actions in Editor are:", displayActionsInEditor, "AC.KickStarter.actionsManager.displayActionsInEditor");
                actionListEditorScrollWheel = (ActionListEditorScrollWheel)CustomGUILayout.EnumPopup("Using scroll-wheel:", actionListEditorScrollWheel, "AC.KickStarter.actionsManager.actionListEditorScrollWheel");

                if (actionListEditorScrollWheel == ActionListEditorScrollWheel.ZoomsWindow)
                {
                    EditorGUILayout.HelpBox("Panning is possible by holding down the middle-mouse button.", MessageType.Info);
                }

                panSpeed      = CustomGUILayout.FloatField((actionListEditorScrollWheel == ActionListEditorScrollWheel.PansWindow) ? "Panning speed:" : "Zoom speed:", panSpeed, "AC.KickStarter.actionsManager.panSpeed");
                invertPanning = CustomGUILayout.ToggleLeft("Invert panning in ActionList Editor?", invertPanning, "AC.KickStarter.actionsManager.invertPanning");
                allowMultipleActionListWindows = CustomGUILayout.ToggleLeft("Allow multiple ActionList Editor windows?", allowMultipleActionListWindows, "AC.KickStarter.actionsManager.allowMultipleActionListWindows");
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(CustomStyles.thinBox);
            showCustom = CustomGUILayout.ToggleHeader(showCustom, "Custom Action scripts");
            if (showCustom)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Folder to search:", GUILayout.Width(110f));
                GUILayout.Label(customFolderPath, EditorStyles.textField);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Set directory", EditorStyles.miniButtonLeft))
                {
                    string path     = EditorUtility.OpenFolderPanel("Set custom Actions directory", "Assets", "");
                    string dataPath = Application.dataPath;
                    if (path.Contains(dataPath))
                    {
                        if (path == dataPath)
                        {
                            customFolderPath = "";
                        }
                        else
                        {
                            customFolderPath = path.Replace(dataPath + "/", "");
                        }
                    }
                    else
                    {
                        ACDebug.LogError("Cannot set new directory - be sure to select within the Assets directory.");
                    }
                }
                if (GUILayout.Button("Clear", EditorStyles.miniButtonRight))
                {
                    customFolderPath = "";
                }
                GUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();

            if (AllActions.Count > 0)
            {
                GUILayout.Space(10);

                Upgrade();

                EditorGUILayout.BeginVertical(CustomStyles.thinBox);
                showCategories = CustomGUILayout.ToggleHeader(showCategories, "Action categories");
                if (showCategories)
                {
                    ActionCategory[] categories = (ActionCategory[])System.Enum.GetValues(typeof(ActionCategory));

                    for (int i = 0; i < categories.Length; i++)
                    {
                        toggles[i] = GUILayout.Toggle(toggles[i], categories[i].ToString(), "Button");
                        if (toggles[i])
                        {
                            int j = -1;
                            foreach (ActionType subclass in AllActions)
                            {
                                if (subclass.category == categories[i])
                                {
                                    j++;
                                    int enabledIndex = -1;
                                    if (EnabledActions.Contains(subclass))
                                    {
                                        enabledIndex = EnabledActions.IndexOf(subclass);
                                    }

                                    if (selectedClass != null && subclass.category == selectedClass.category && subclass.title == selectedClass.title)
                                    {
                                        EditorGUILayout.BeginVertical("Button");
                                        SpeechLine.ShowField("Name:", subclass.GetFullTitle(), false);
                                        SpeechLine.ShowField("Filename:", subclass.fileName + ".cs", false);
                                        SpeechLine.ShowField("Description:", subclass.description, true);
                                        subclass.isEnabled = true;
                                        EditorGUILayout.BeginHorizontal();
                                        if (enabledIndex >= 0)
                                        {
                                            if (!string.IsNullOrEmpty(defaultClassName) && subclass.fileName == defaultClassName)
                                            {
                                                EditorGUILayout.LabelField("DEFAULT", CustomStyles.subHeader, GUILayout.Width(140f));
                                            }
                                            else if (subclass.isEnabled)
                                            {
                                                if (GUILayout.Button("Make default?", GUILayout.Width(140f)))
                                                {
                                                    if (EnabledActions.Contains(subclass))
                                                    {
                                                        defaultClassName = subclass.fileName;
                                                    }
                                                }
                                            }
                                        }
                                        subclass.color = EditorGUILayout.ColorField("Node colour:", subclass.color);

                                        EditorGUILayout.EndHorizontal();
                                        EditorGUILayout.BeginHorizontal();

                                        if (GUILayout.Button("Search local instances"))
                                        {
                                            SearchForInstances(true, subclass);
                                        }
                                        if (GUILayout.Button("Search all instances"))
                                        {
                                            if (UnityVersionHandler.SaveSceneIfUserWants())
                                            {
                                                SearchForInstances(false, subclass);
                                            }
                                        }

                                        EditorGUILayout.EndHorizontal();
                                        EditorGUILayout.EndVertical();
                                    }
                                    else
                                    {
                                        EditorGUILayout.BeginHorizontal();
                                        if (GUILayout.Button(j.ToString() + ": " + subclass.GetFullTitle(), EditorStyles.label, GUILayout.Width(200f)))
                                        {
                                            selectedClass = subclass;
                                        }
                                        if (!string.IsNullOrEmpty(defaultClassName) && subclass.fileName == defaultClassName)
                                        {
                                            EditorGUILayout.LabelField("DEFAULT", CustomStyles.subHeader, GUILayout.Width(60f));
                                        }
                                        EditorGUILayout.EndHorizontal();
                                        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                                    }
                                }
                            }
                            if (j < 0)
                            {
                                EditorGUILayout.HelpBox("There are no Actions of this category type present!", MessageType.Info);
                            }
                        }
                    }
                }
                EditorGUILayout.EndVertical();

                if (defaultClass > EnabledActions.Count - 1)
                {
                    defaultClass = EnabledActions.Count - 1;
                }
            }
            else
            {
                EditorGUILayout.HelpBox("No Action subclass files found.", MessageType.Warning);
            }

            if (GUI.changed)
            {
                SetEnabled();
                Upgrade();
                EditorUtility.SetDirty(this);
            }
        }
        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--;
            }
        }