示例#1
0
        /// <summary>
        /// Initializes the DNA script engine.
        /// </summary>
        /// <param name="memsize">The heap memory size to use (note: can not be expanded)</param>
        /// <param name="assemblySearchPaths">Array of assembly search paths to use when loading assemblies</param>
        public static void Init(int memsize = DEFAULT_MEM_SIZE, string[] assemblySearchPaths = null)
        {
            if (_isInitialized)
            {
                throw new System.InvalidOperationException("Dna has already been initialized.  Use Dna.Reset() to reset the interpreter");
            }

            if (assemblySearchPaths == null)
            {
                assemblySearchPaths = defaultAssemblySearchPaths;
            }
            #if UNITY_EDITOR
            string[] finalAssemblySearchPaths = new string[assemblySearchPaths.Length];
            string   unityDir   = UnityEditor.EditorApplication.applicationContentsPath;
            string   projectDir = System.IO.Path.GetDirectoryName(UnityEngine.Application.dataPath);
            for (int i = 0; i < assemblySearchPaths.Length; i++)
            {
                finalAssemblySearchPaths[i] = assemblySearchPaths[i]
                                              .Replace("${UNITY_DIR}", unityDir)
                                              .Replace("${PROJECT_DIR}", projectDir);
            }
            #else
            string[] finalAssemblySearchPaths = assemblySearchPaths;
            #endif

            Mem.Init(memsize);
            H.Init();
            Sys.Init();
            JIT.Init();
            JIT_Execute.Init();
            DnaObject.Init();
            MetaData.Init();
            MonoType.Init();
            Generics.Init();
            Serialization.Init();
            Heap.Init();
            Finalizer.Init();
            InternalCall.Init();
            CLIFile.Init(finalAssemblySearchPaths);
            Type.Init();

            _isInitialized = true;
        }