public void CleanUp()
 {
     m_data   = null;
     m_prefab = null;
     m_weight = 1f;
     m_neighbors.Clear();
 }
        protected void WriteData(string id)
        {
            Scene activeScene = SceneManager.GetActiveScene();
            int   moduleCount = m_builders.Count;
            string
                sceneName = activeScene.name,
                destFolderPath, destInfosPath, assetName, num;

            string[] scenePathSplit = activeScene.path.Split('/');

            destInfosPath      =
                destFolderPath = string.Join("/", scenePathSplit, 0, scenePathSplit.Length - 1) + "/" + sceneName + ".gen/";
            Directory.CreateDirectory(destFolderPath);

            destInfosPath += id + ".infos/";
            Directory.CreateDirectory(destInfosPath);

            #region Create manifest

            ModuleConstraintsManifest manifest = ScriptableObject.CreateInstance <ModuleConstraintsManifest>();
            ModuleConstraintsBuilder  moduleBuilder;
            ModuleConstraints         module;
            ModuleConstraints[]       modulesConstraints = new ModuleConstraints[moduleCount];
            int
                totalNeighborsLength = 0,
                headerCount          = m_socketCount * moduleCount;

            string tpl = "{0:0}";

            if (moduleCount >= 10)
            {
                tpl = "{0:00}";
            }
            if (moduleCount >= 100)
            {
                tpl = "{0:000}";
            }
            if (moduleCount >= 1000)
            {
                tpl = "{0:0000}";
            }
            if (moduleCount >= 10000)
            {
                tpl = "{0:00000}";
            }

            for (int i = 0; i < moduleCount; i++)
            {
                moduleBuilder = m_builders[i];

                module          = moduleBuilder.FixData(model);
                module.manifest = manifest;

                if (useGUID)
                {
                    assetName = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(moduleBuilder.m_prefab));
                }
                else
                {
                    num       = string.Format(tpl, i);
                    assetName = num + "." + moduleBuilder.m_prefab.name;
                }

                AssetDatabase.CreateAsset(
                    module,
                    destInfosPath + assetName + ".asset");

                modulesConstraints[i] = module;

                totalNeighborsLength += module.neighbors.Length;
            }

            manifest.infos       = modulesConstraints;
            manifest.socketCount = m_socketCount;
            manifest.moduleCount = moduleCount;
            manifest.model       = model;

            #endregion

            #region Create inlined manifest

            ModuleConstraintsManifestInlined manifestInlined = ScriptableObject.CreateInstance <ModuleConstraintsManifestInlined>();
            int3[]  modulesHeaders = new int3[headerCount];
            float[] modulesWeights = new float[moduleCount];
            int[]
            neighbors = new int[totalNeighborsLength],
            ns;
            int
                b, l, e, nCount,
                hIndex = 0,
                nIndex = 0;

            for (int i = 0; i < moduleCount; i++)
            {
                module = modulesConstraints[i];
                ns     = module.neighbors;
                nCount = ns.Length;

                modulesWeights[i] = module.weight;

                for (int j = 0; j < m_socketCount; j++)
                {
                    b = nIndex + module.begin[j];
                    l = module.lengths[j];
                    e = b + l;

                    modulesHeaders[hIndex++] = int3(b, e, l);
                }

                for (int j = 0; j < nCount; j++)
                {
                    neighbors[nIndex++] = ns[j];
                }
            }

            manifestInlined.moduleCount      = moduleCount;
            manifestInlined.modulesWeights   = modulesWeights;
            manifestInlined.modulesLength    = headerCount;
            manifestInlined.modulesHeaders   = modulesHeaders;
            manifestInlined.modulesNeighbors = neighbors;

            #endregion

            AssetDatabase.CreateAsset(manifestInlined, destFolderPath + id + ".manifest-inlined.asset");
            manifest.inlinedManifest = manifestInlined;

            AssetDatabase.CreateAsset(manifest, destFolderPath + id + ".manifest.asset");

            manifest.u = UnityEngine.Random.Range(0, 10000);

            EditorUtility.SetDirty(manifestInlined);
            EditorUtility.SetDirty(manifest);
        }
 public void Init()
 {
     m_data = ScriptableObject.CreateInstance <ModuleConstraints>();
 }