void Update() { if (m_doGenerate) { m_doGenerate = EditorUtility.DisplayDialog("", "Are you sure build?", "yes", "no"); } if (m_doGenerate) { m_doGenerate = false; List <string> listPath = m_listPath; List <bool> listToggle = m_listToggle; List <string> tmpPaths = new List <string>(); Dictionary <string, string> projectCodes = new Dictionary <string, string>(); for (int i = 0; i < listPath.Count; i++) { if (listToggle[i]) { projectCodes.Add(listPath[i], System.IO.File.ReadAllText(listPath[i])); } } CheckFolder(AssetBundleTempFolder); if (projectCodes.Count > 0) { List <string> classNames = new List <string>(); CSLE.CLS_Environment csleEnv = ToCSLight.CreateEnvironment(); Dictionary <string, IList <CSLE.Token> > csleProject = csleEnv.Project_ParserToken(projectCodes); foreach (var pair in csleProject) { string className = System.IO.Path.GetFileNameWithoutExtension(pair.Key); string tmpPath = AssetBundleTempFolder + className + ".bytes"; using (var fs = System.IO.File.OpenWrite(tmpPath)) { csleEnv.TokenToStream(pair.Value, fs); } tmpPaths.Add(tmpPath); classNames.Add(className); } string cfgPath = AssetBundleTempFolder + "class.asset"; StringHolder classHolder = ScriptableObject.CreateInstance <StringHolder>(); classHolder.content = classNames.ToArray(); tmpPaths.Add(cfgPath); AssetDatabase.CreateAsset(classHolder, cfgPath); } BuildByName(tmpPaths, ScriptAssetBundleName); EditorUtility.DisplayDialog("finish", "success done!", "ok"); } }
// 从资源包初始化脚本环境 public void InitializeFromAssetBundle(AssetBundle scriptsAssetBundle) { m_clsAssetBundle = scriptsAssetBundle; #if UNITY_EDITOR float timeStart = Time.realtimeSinceStartup; uint monoStart = Profiler.GetMonoUsedSize(); #endif // 获取默认的脚本实例 m_clsEnv = ToCSLight.CreateEnvironment(); m_clsContent = m_clsEnv.CreateContent(); // 预注册脚本类 #if UNITY_EDITOR && !EDITOR_FORCE_ASSET_BUNDLE string rootPath = Application.dataPath + "/CSLight/Editor/CSLogic"; string[] files = System.IO.Directory.GetFiles(rootPath, "*.cs", System.IO.SearchOption.AllDirectories); foreach (var file in files) { string className = System.IO.Path.GetFileNameWithoutExtension(file); m_clsEnv.RegType(new CLS_Type_Class(className, file.Replace('\\', '/'))); } #else StringHolder classHolder = m_clsAssetBundle.LoadAsset("class", typeof(StringHolder)) as StringHolder; foreach (string className in classHolder.content) { m_clsEnv.RegType(new CLS_Type_Class(className, className)); } #endif #if UNITY_EDITOR Debug.Log("script init cost time: " + (Time.realtimeSinceStartup - timeStart)); Debug.Log(string.Format("script init cost memory: {0:0.00}MB", (Profiler.GetMonoUsedSize() - monoStart) / (1024f * 1024f))); timeStart = Time.realtimeSinceStartup; #endif }