Example #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;
        }
Example #2
0
        /// <summary>
        /// Resets entire DNA environment to it's initial state, clearing all DnaObject references to null.
        /// </summary>
        public static void Reset()
        {
            Type.Clear();
            CLIFile.Clear();
            InternalCall.Clear();
            Finalizer.Clear();
            Heap.Clear();
            Generics.Clear();
            MonoType.Clear();
            MetaData.Clear();
            DnaObject.Clear();
            JIT_Execute.Clear();
            JIT.Clear();
            Sys.Clear();
            H.Clear();
            Mem.Clear();

            _isInitialized = false;
        }