protected virtual bool ValidateSetting(Object asset, ScriptReferenceType type) { if (asset == null || type == ScriptReferenceType.TextAsset) { return(true); } string path = AssetDatabase.GetAssetPath(asset); LuaSettings luaSettings = LuaSettings.GetOrCreateSettings(); foreach (string root in luaSettings.SrcRoots) { if (path.StartsWith(root)) { return(true); } } if (path.IndexOf("Resources") >= 0) { return(true); } if (EditorUtility.DisplayDialog("Notice", string.Format("The file \"{0}\" is not in the source code folder of lua. Do you want to add a source code folder?", asset.name), "Yes", "Cancel")) { SettingsService.OpenProjectSettings("Project/LuaSettingsProvider"); return(false); } else { return(true); } }
/// <summary> /// Creates a new LuaEnvironment without initializing the state, for use with a derived type. /// </summary> protected LuaEnvironmentNet() { _compiler = new CodeCompiler(); _parser = new PlainParser(); _runtime = LuaRuntimeNet.Create(this); Settings = new LuaSettings().AsReadOnly(); _globals = new LuaValues.LuaTable(); _modules = new ModuleBinder(); }
public LuaSet GetSetting(string name) { if (LuaSettings.ContainsKey(name)) { return(LuaSettings[name]); } else { return(null); } }
//public static bool IsSettingsAvailable() //{ // return File.Exists(LuaSettings.LUA_SETTINGS_PATH); //} public override void OnActivate(string searchContext, VisualElement rootElement) { m_LuaSettings = LuaSettings.GetSerializedSettings(); var rootsProperty = m_LuaSettings.FindProperty("srcRoots"); m_List = new ReorderableList(rootsProperty.serializedObject, rootsProperty, true, true, true, true); m_List.elementHeight = 21; m_List.drawElementCallback = DrawElement; m_List.drawHeaderCallback = DrawHeader; m_List.onAddDropdownCallback = OnAddElement; m_List.onRemoveCallback = OnRemoveElement; m_List.drawElementBackgroundCallback = DrawElementBackground; }
public void AddSetting(string Name, string Folder, string LuaExecutable, string WorkingPath, string CommandLine, EncodingName Encoding) { var set = new LuaSet(Folder, LuaExecutable, WorkingPath, CommandLine, Encoding); if (LuaSettings.ContainsKey(Name)) { LuaSettings[Name] = set; } else { LuaSettings.Add(Name, set); } XElement element = null; foreach (var xl in XMLLuaSettings.Elements(SettingConstants.SettingKeys.Set)) { if (xl.Element(SettingConstants.SettingKeys.SetName).Value.Contains(Name)) { element = xl; break; } } if (element == null) { element = new XElement(SettingConstants.SettingKeys.Set); element.Add(new XElement(SettingConstants.SettingKeys.SetName, Name)); element.Add(new XElement(SettingConstants.SettingKeys.LuaFolder, Folder)); element.Add(new XElement(SettingConstants.SettingKeys.LuaExec, LuaExecutable)); element.Add(new XElement(SettingConstants.SettingKeys.WorkingPath, WorkingPath)); element.Add(new XElement(SettingConstants.SettingKeys.LuaExecArg, CommandLine)); element.Add(new XElement(SettingConstants.SettingKeys.FileEncoding, Encoding)); XMLLuaSettings.Add(element); } else { element.ReplaceNodes( new XElement(SettingConstants.SettingKeys.SetName, Name), new XElement(SettingConstants.SettingKeys.LuaFolder, Folder), new XElement(SettingConstants.SettingKeys.LuaExec, LuaExecutable), new XElement(SettingConstants.SettingKeys.WorkingPath, WorkingPath), new XElement(SettingConstants.SettingKeys.LuaExecArg, CommandLine), new XElement(SettingConstants.SettingKeys.FileEncoding, Encoding) ); } }
protected virtual string GetFilename(Object asset) { if (asset == null) { return(null); } string path = AssetDatabase.GetAssetPath(asset); if (string.IsNullOrEmpty(path)) { return(null); } int start = path.LastIndexOf("/"); int dotIndex = path.IndexOf(".", start); if (dotIndex > -1) { path = path.Substring(0, dotIndex); } LuaSettings luaSettings = LuaSettings.GetOrCreateSettings(); foreach (string root in luaSettings.SrcRoots) { if (path.StartsWith(root)) { path = path.Replace(root + "/", "").Replace("/", "."); return(path); } } int index = path.IndexOf("Resources"); if (index >= 0) { path = path.Substring(index + 10); } path = path.Replace("/", "."); return(path); }
/// <summary> /// Creates a new environment with the given settings. /// </summary> /// <param name="settings">The settings to give the Environment.</param> /// <exception cref="System.ArgumentNullException">If settings is null.</exception> public LuaEnvironmentNet(LuaSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } _globals = new LuaTable(); _runtime = LuaRuntimeNet.Create(this); _compiler = new CodeCompiler(); _parser = new PlainParser(); _modules = new ModuleBinder(); Settings = settings.AsReadOnly(); // initialize the global variables. LuaStaticLibraries.Initialize(this); _initializeTypes(); }
public void RemoveSetting(string name) { XElement element = null; foreach (var xl in XMLLuaSettings.Elements(SettingConstants.SettingKeys.Set)) { if (xl.Element(SettingConstants.SettingKeys.SetName).Value.Contains(name)) { element = xl; break; } } if (element != null) { element.Remove(); } if (LuaSettings.ContainsKey(name)) { LuaSettings.Remove(name); } }
public bool ContainsSetting(string name) { return(LuaSettings.ContainsKey(name)); }
/// <summary> /// Creates a new environment with the given settings. /// </summary> /// <param name="settings">The settings to give the Environment.</param> /// <exception cref="System.ArgumentNullException">If settings is null.</exception> public LuaEnvironmentNet(LuaSettings settings) { if (settings == null) throw new ArgumentNullException("settings"); this._globals = new LuaValues.LuaTable(); this._runtime = LuaRuntimeNet.Create(this); this._compiler = new CodeCompiler(); this._parser = new PlainParser(); this._modules = new ModuleBinder(); this.Settings = settings.AsReadOnly(); // initialize the global variables. LuaStaticLibraries.Initialize(this); InitializeTypes(); }