Example #1
0
 /// <summary>
 /// When the Template Settings is loaded, create a copy and save it.
 /// Set the variable <see cref="m_dialogsSettings"/> to the profile newly created
 /// </summary>
 /// <param name="_loadedAsset">Template Settings Asset</param>
 private static void OnSettingsAssetLoaded(AsyncOperationHandle <TextAsset> _loadedAsset)
 {
     if (_loadedAsset.Result == null)
     {
         Debug.LogError("IS NULL");
         return;
     }
     m_dialogsSettings = JsonUtility.FromJson <DialoguesSettings>(_loadedAsset.Result.ToString());
     SaveProfile();
 }
        /// <summary>
        /// Load the Settings Template stored in <see cref="DialoguesSettings.SettingsFilePath"/>
        /// </summary>
        private void LoadSettingsFiles()
        {
            if (!File.Exists(DialoguesSettings.SettingsFilePath))
            {
                return;
            }
            string _jsonSettings = File.ReadAllText(DialoguesSettings.SettingsFilePath);

            m_dialogsSettings = JsonUtility.FromJson <DialoguesSettings>(_jsonSettings);
        }
Example #3
0
 /// <summary>
 /// Init the Editor Settings of the DialogCondition Node
 /// </summary>
 /// <param name="_nodeStyle">Style of the node</param>
 /// <param name="_connectionPointStyle">Style of the conection points</param>
 /// <param name="_conditionIcon">Icon of the Condition Node</param>
 /// <param name="_pointIcon">Icon of the connection points</param>
 /// <param name="_onRemoveCondition">Event called when the Icon is removed</param>
 public void InitEditorSettings(GUIStyle _nodeStyle, GUIStyle _selectedNodeStyle, GUIStyle _connectionPointStyle, GUIContent _conditionIcon, GUIContent _pointIcon, Action <DialogueCondition> _onRemoveCondition, DialoguesSettings _dialogSettings)
 {
     m_nodeStyle               = _nodeStyle;
     m_selectedNodeStyle       = _selectedNodeStyle;
     m_connectionPointStyle    = _connectionPointStyle;
     m_currentIcon             = _conditionIcon;
     m_pointIcon               = _pointIcon;
     m_onRemoveDialogCondition = _onRemoveCondition;
     m_dialogSettings          = _dialogSettings;
     m_conditionsDescriptor    = m_dialogSettings.LuaConditions.Split('\n').Select(c => c.Split('=')[0].Trim()).ToArray();
     InitConditionsFromString();
 }
        /// <summary>
        /// Load the DialogsSettings Profile according to the PlayMode
        /// In <see cref="PlayModeStateChange.EnteredEditMode"/> load the stored Profile in <see cref="DialoguesSettings.SettingsFilePath"/>
        /// In <see cref="PlayModeStateChange.EnteredPlayMode"/> get the <see cref="DialoguesSettingsManager.DialogsSettings"/> profile
        /// </summary>
        /// <param name="_playmode">PlayModeStateChange</param>
        private void LoadSettingsForPlayMode(PlayModeStateChange _playmode)
        {
            switch (_playmode)
            {
            case PlayModeStateChange.EnteredEditMode:
                if (!Directory.Exists(DialoguesSettings.SettingsPath))
                {
                    Directory.CreateDirectory(DialoguesSettings.SettingsPath);
                }
                if (!File.Exists(DialoguesSettings.SettingsFilePath))
                {
                    m_dialogsSettings = new DialoguesSettings();
                    SaveSettings(false);
                }
                else
                {
                    LoadSettingsFiles();
                }
                m_localisationKeys      = m_dialogsSettings.LocalisationKeys;
                m_audioLocalisationKeys = m_dialogsSettings.AudioLocalisationKeys;
                break;

            case PlayModeStateChange.EnteredPlayMode:
                m_dialogsSettings = DialoguesSettingsManager.DialogsSettings;
                break;

            case PlayModeStateChange.ExitingPlayMode:
                break;

            default:
                break;
            }
            if (m_dialogsSettings == null)
            {
                return;
            }
            m_conditionsPair = new List <ConditionPair>();
            if (m_dialogsSettings.LuaConditions == string.Empty)
            {
                return;
            }
            string[] _conditions = m_dialogsSettings.LuaConditions.Split('\n');
            for (int i = 0; i < _conditions.Length; i++)
            {
                string[] _pair = _conditions[i].Split('=');
                if (_pair[0].Trim() == string.Empty || _pair[1].Trim() == string.Empty)
                {
                    return;
                }
                m_conditionsPair.Add(new ConditionPair(_pair[0].Trim(), _pair[1].Trim()));
            }
        }
Example #5
0
 /// <summary>
 /// Init the Editor settings for the dialog and all of them parts
 /// </summary>
 /// <param name="_nodeStyle">Style of the node</param>
 /// <param name="_connectionPointStyle">Style of the Connection Point</param>
 /// <param name="_basicIcon">Icon of the basic Node Type</param>
 /// <param name="_answerIcon">Icon of the Answer Node Type</param>
 /// <param name="_startingSetIcon">Icon of the starting set</param>
 /// <param name="_pointIcon">Connection Point Icon</param>
 public void InitEditorSettings(GUIStyle _nodeStyle, GUIStyle _selectedNodeStyle, GUIStyle _conditionStyle, GUIStyle _selectedConditionStyle, GUIStyle _starterNodeStyle, GUIStyle _starterNodeStyleSelected, GUIStyle _connectionPointStyle, GUIStyle _conditionConnectionPointStyle, GUIStyle _starterConnectionPointStyle, GUIContent _basicIcon, GUIContent _answerIcon, GUIContent _startingSetIcon, GUIContent _pointIcon, GUIContent _conditionIcon)
 {
     m_defaultNodeStyle              = _nodeStyle;
     m_defaultNodeStyleSelected      = _selectedNodeStyle;
     m_conditionNodeStyle            = _conditionStyle;
     m_conditionNodeStyleSelected    = _selectedConditionStyle;
     m_defaultConnectionPointStyle   = _connectionPointStyle;
     m_conditionConnectionPointStyle = _conditionConnectionPointStyle;
     m_starterNodeStyle              = _starterNodeStyle;
     m_starterNodeStyleSelected      = _starterNodeStyleSelected;
     m_startConnectionPointStyle     = _starterConnectionPointStyle;
     m_icon            = _basicIcon;
     m_answerIcon      = _answerIcon;
     m_startingSetIcon = _startingSetIcon;
     m_pointIcon       = _pointIcon;
     m_conditionIcon   = _conditionIcon;
     if (File.Exists(Path.Combine(LineDescriptorPath, m_spreadSheetID.GetHashCode().ToString() + LineDescriptorPostfixWithExtension)))
     {
         m_lineDescriptor = File.ReadAllText(Path.Combine(LineDescriptorPath, m_spreadSheetID.GetHashCode().ToString() + LineDescriptorPostfixWithExtension));
     }
     if (File.Exists(DialoguesSettings.SettingsFilePath))
     {
         m_dialogSettings = JsonUtility.FromJson <DialoguesSettings>(File.ReadAllText(DialoguesSettings.SettingsFilePath));
     }
     if (m_dialogStarter == null)
     {
         m_dialogStarter = new DialogueStarter(Vector2.zero, m_starterNodeStyle, m_starterNodeStyleSelected, m_startConnectionPointStyle, m_startingSetIcon, m_pointIcon);
     }
     else
     {
         m_dialogStarter.InitEditorSettings(m_starterNodeStyle, m_starterNodeStyleSelected, m_startConnectionPointStyle, m_startingSetIcon, m_pointIcon);
     }
     if (m_dialogSets == null)
     {
         m_dialogSets = new List <DialogueSet>();
     }
     if (m_dialogConditions == null)
     {
         m_dialogConditions = new List <DialogueCondition>();
     }
     for (int i = 0; i < m_dialogSets.Count; i++)
     {
         m_dialogSets[i].InitEditorSettings(_nodeStyle, _selectedNodeStyle, _connectionPointStyle, _basicIcon, _answerIcon, m_pointIcon, RemoveSet);
     }
     for (int i = 0; i < m_dialogConditions.Count; i++)
     {
         m_dialogConditions[i].InitEditorSettings(_conditionStyle, _selectedConditionStyle, _conditionConnectionPointStyle, _conditionIcon, _pointIcon, RemoveCondition, m_dialogSettings);
     }
 }
Example #6
0
        /// <summary>
        /// Load the profile named <see cref="_profileName"/> in the persistant data path.
        /// Set the <see cref="m_dialogsSettings"/> as the loaded profile
        /// </summary>
        /// <param name="_profileName"></param>
        /// <returns></returns>
        public static DialoguesSettings LoadProfile(string _profileName = "defaultProfile")
        {
            string _path = Path.Combine(Application.persistentDataPath, _profileName + ".sav");

            if (!File.Exists(_path))
            {
                CreateOrLoadProfile();
                return(null);
            }
            BinaryFormatter _formatter    = new BinaryFormatter();
            FileStream      _stream       = new FileStream(_path, FileMode.Open);
            string          _jsonSettings = _formatter.Deserialize(_stream) as string;

            DialoguesSettings _settings = JsonUtility.FromJson <DialoguesSettings>(_jsonSettings);

            _stream.Close();
            return(_settings);
        }
Example #7
0
        /// <summary>
        /// Create a new profile based on the Settings Template profile
        /// </summary>
        public static void CreateOrLoadProfile()
        {
#if UNITY_EDITOR
            AsyncOperationHandle <TextAsset> _settingsAssetAsyncHandler = Addressables.LoadAssetAsync <TextAsset>(DialoguesSettings.SettingsFileName);
            _settingsAssetAsyncHandler.Completed += OnSettingsAssetLoaded;
#else
            if (PlayerPrefs.HasKey(PROFILE_KEY))
            {
                CurrentProfileName = PlayerPrefs.GetString(PROFILE_KEY);
                m_dialogsSettings  = LoadProfile(CurrentProfileName);
                if (m_dialogsSettings != null)
                {
                    return;
                }
            }
            AsyncOperationHandle <TextAsset> _settingsAssetAsyncHandler = Addressables.LoadAssetAsync <TextAsset>(DialogsSettings.SettingsFileName);
            _settingsAssetAsyncHandler.Completed += OnSettingsAssetLoaded;
#endif
        }