/// <summary>
        /// Updates the <see cref="SubmoduleMap" /> asset.
        /// </summary>
        public static SubmoduleMap UpdateSubmoduleMap()
        {
            EditorUtility.DisplayProgressBar(
                "UpdateSubmoduleMap",
                "Finding submodule map...",
                0
                );

            SubmoduleMap map;

            map = FindOrCreateSubmoduleMap();

            SerializedObject obj;

            obj = new SerializedObject(map);

            EditorUtility.DisplayProgressBar(
                "UpdateSubmoduleMap",
                "Finding submodule types...",
                0
                );

            System.Type[] types;
            types = SubmoduleMapEditorAdaptor.SubmoduleTypes;

            SerializedProperty elements;

            elements           = obj.FindProperty("m_Elements");
            elements.arraySize = types.Length;

            for (int index = 0; index < types.Length; index++)
            {
                EditorUtility.DisplayProgressBar(
                    "UpdateSubmoduleMap",
                    "Updating submodule map...",
                    index / (float)(types.Length - 1)
                    );

                System.Type type;
                type = types[index];

                SerializedProperty element;
                element = elements.GetArrayElementAtIndex(index);
                element.FindPropertyRelative("SubmoduleName").stringValue = SubmoduleMapEditorAdaptor.GetSubmoduleName(type);
                element.FindPropertyRelative("SubmodulePath").stringValue = SubmoduleMapEditorAdaptor.GetSubmodulePath(type);
                element.FindPropertyRelative("SubmoduleType").stringValue = type.FullName;
            }

            obj.ApplyModifiedPropertiesWithoutUndo();

            EditorUtility.ClearProgressBar();

            return(FindSubmoduleMap());
        }
Esempio n. 2
0
        private static void UpdateMeshAnimatorsToAssetGuids(MenuCommand command)
        {
            string submodulePath;

            submodulePath = SubmoduleMapEditorAdaptor.GetSubmodulePath(command.context.GetType());

            if (!string.IsNullOrEmpty(submodulePath))
            {
                UpdateMeshAnimatorsInPrefabsToAssetGuids(submodulePath);
                UpdateMeshAnimatorsInScenesToAssetGuids(submodulePath);
            }
        }
        private void XcodeHelper(string action)
        {
            string xcodeHelperPath;

            xcodeHelperPath = Path.Combine(ProjectPath, Path.Combine(SubmoduleMapEditorAdaptor.GetSubmodulePath(typeof(SagoBuild.SubmoduleInfo)), "tvOS/.Native/xcode_helper"));

            string xcodeProjectPath;

            xcodeProjectPath = Path.GetDirectoryName(PBXProject.GetPBXProjectPath(this.BuildPath));

            Process p = new Process();

            p.StartInfo.Arguments              = string.Format("'{0}' '{1}'", xcodeProjectPath, action);
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            p.StartInfo.FileName               = xcodeHelperPath;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute        = false;
            p.Start();
            p.WaitForExit();
        }
 /// <summary>
 /// Gets the path to the <see cref="DynamicsManager" /> asset for the specified content submodule.
 /// </summary>
 /// <param name="type">
 /// The <see cref="ContentInfo" /> subclass for the content submodule.
 /// </param>
 public static string GetDynamicsManagerPath(System.Type type)
 {
     return(Path.Combine(SubmoduleMapEditorAdaptor.GetSubmodulePath(type), Path.Combine("Settings", "DynamicsManager.asset")));
 }
Esempio n. 5
0
        static void ConvertToMeshAudioAsset(string path)
        {
            string submodulePath;

            submodulePath = SubmoduleMapEditorAdaptor.GetSubmodulePath(SubmoduleMapEditorAdaptor.GetSubmoduleType(path)) ?? "Assets";

            string animationName = path;

            while (Path.HasExtension(animationName))
            {
                animationName = Path.GetFileNameWithoutExtension(animationName);
            }

            string animationAssetPath;

            animationAssetPath = string.Format("{0}/MeshAnimations/{1}.asset", submodulePath, animationName);

            string animationResourcePath;

            animationResourcePath = string.Format("{0}/_Resources_/MeshAnimations/{1}.asset", submodulePath, animationName);

            MeshAnimationAsset animationAsset;

            animationAsset = (
                AssetDatabase.LoadAssetAtPath(animationResourcePath, typeof(MeshAnimationAsset)) as MeshAnimationAsset ??
                AssetDatabase.LoadAssetAtPath(animationAssetPath, typeof(MeshAnimationAsset)) as MeshAnimationAsset
                );

            if (!animationAsset)
            {
                Debug.Log("missing animation");
                return;
            }

            string animationPath;

            animationPath = AssetDatabase.GetAssetPath(animationAsset);

            TextAsset textAsset;

            textAsset = AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset)) as TextAsset;

            if (!textAsset)
            {
                Debug.Log("missing xml");
                return;
            }

            XmlDocument document = null;

            try {
                document = new XmlDocument();
                document.LoadXml(textAsset.text);
            } catch {
                Debug.Log("invalid xml");
                return;
            }

            MeshAudioAsset audioAsset;

            audioAsset = AssetDatabase.LoadAssetAtPath(animationPath, typeof(MeshAudioAsset)) as MeshAudioAsset;
            if (!audioAsset)
            {
                audioAsset           = ScriptableObject.CreateInstance <MeshAudioAsset>();
                animationAsset.Audio = audioAsset;
                AssetDatabase.AddObjectToAsset(audioAsset, animationAsset);
                AssetDatabase.SaveAssets();
            }
            audioAsset.hideFlags = HideFlags.HideInHierarchy;
            audioAsset.name      = animationAsset.name;
            audioAsset.Clear();

            bool isComplete;

            isComplete = true;

            foreach (XmlNode sound in document.SelectNodes("/range/sound"))
            {
                int index;
                index = System.Convert.ToInt32(sound.Attributes.GetNamedItem("offset").Value);

                string name;
                name = sound.Attributes.GetNamedItem("id").Value;

                AudioClip audioClip;
                audioClip = FindAudioClip(name);

                if (audioClip)
                {
                    audioAsset.AddAudioClip(index, audioClip);
                }
                else
                {
                    Debug.Log("missing audio clip: " + name);
                    isComplete = false;
                }
            }

            if (isComplete && SagoMeshEditor.EditorSettings.Instance.DeleteIntermediateFiles)
            {
                AssetDatabase.DeleteAsset(path);
            }

            AssetDatabase.SaveAssets();
        }
Esempio n. 6
0
        static void ConvertToMeshAnimationAsset(string path)
        {
            System.Type submoduleType;
            submoduleType = SubmoduleMapEditorAdaptor.GetSubmoduleType(path);

            if (submoduleType == null)
            {
                return;
            }

            string submodulePath;

            submodulePath = SubmoduleMapEditorAdaptor.GetSubmodulePath(submoduleType);

            if (string.IsNullOrEmpty(submodulePath))
            {
                return;
            }

            TextAsset asset;

            asset = AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset)) as TextAsset;

            if (asset == null)
            {
                return;
            }

            XmlDocument document;

            document = new XmlDocument();

            try {
                document.LoadXml(asset.text);
            } catch {
                return;
            }

            XmlNode animationsNode;

            animationsNode = document.SelectSingleNode("/plist/dict/key[text() = 'animations']/following-sibling::dict");

            if (animationsNode == null)
            {
                return;
            }

            XmlNode anchorPointNode;

            anchorPointNode = document.SelectSingleNode("/plist/dict/key[text() = 'anchorPoint']/following-sibling::string");

            Vector2 anchorPoint;

            anchorPoint = ConvertToVector2(anchorPointNode);

            XmlNode contentSizeNode;

            contentSizeNode = document.SelectSingleNode("/plist/dict/key[text() = 'contentSize']/following-sibling::string");

            Vector2 contentSize;

            contentSize = ConvertToVector2(contentSizeNode);

            foreach (XmlNode keyNode in animationsNode.SelectNodes("key"))
            {
                XmlNode dictNode;
                dictNode = keyNode.NextSibling;

                XmlNode delayNode;
                delayNode = dictNode.SelectSingleNode("key[text() = 'delay']/following-sibling::real");

                XmlNodeList stringNodes;
                stringNodes = dictNode.SelectNodes("key[text() = 'frames']/following-sibling::array/string");

                float interval;
                interval = System.Convert.ToSingle(delayNode.InnerText);

                float duration;
                duration = interval * stringNodes.Count;

                MeshAsset[] meshes;
                meshes = new MeshAsset[stringNodes.Count];

                for (int index = 0; index < stringNodes.Count; index++)
                {
                    string meshPath;
                    meshPath = null;

                    MeshAsset mesh;
                    mesh = null;

                    if (!mesh)
                    {
                        meshPath = string.Format("{0}/_Resources_/Meshes/{1}.asset", submodulePath, Path.GetFileNameWithoutExtension(stringNodes.Item(index).InnerText));
                        mesh     = AssetDatabase.LoadAssetAtPath(meshPath, typeof(MeshAsset)) as MeshAsset;
                    }

                    if (!mesh && meshes.Length == 1)
                    {
                        meshPath = string.Format("{0}/Resources/Meshes/{1}_0001.asset", submodulePath, Path.GetFileNameWithoutExtension(stringNodes.Item(index).InnerText));
                        mesh     = AssetDatabase.LoadAssetAtPath(meshPath, typeof(MeshAsset)) as MeshAsset;
                    }

                    if (!mesh)
                    {
                        meshPath = string.Format("{0}/Meshes/{1}.asset", submodulePath, Path.GetFileNameWithoutExtension(stringNodes.Item(index).InnerText));
                        mesh     = AssetDatabase.LoadAssetAtPath(meshPath, typeof(MeshAsset)) as MeshAsset;
                    }

                    if (!mesh && meshes.Length == 1)
                    {
                        meshPath = string.Format("{0}/Meshes/{1}_0001.asset", submodulePath, Path.GetFileNameWithoutExtension(stringNodes.Item(index).InnerText));
                        mesh     = AssetDatabase.LoadAssetAtPath(meshPath, typeof(MeshAsset)) as MeshAsset;
                    }

                    if (!mesh)
                    {
                        EditorUtility.ClearProgressBar();
                        throw new System.Exception(string.Format("Cannot load mesh asset: {0}, {1}, {2}",
                                                                 stringNodes.Item(index).InnerText,
                                                                 string.Format("{0}/Meshes/{1}.asset", submodulePath, Path.GetFileNameWithoutExtension(stringNodes.Item(index).InnerText)),
                                                                 string.Format("{0}/Meshes/{1}_0001.asset", submodulePath, Path.GetFileNameWithoutExtension(stringNodes.Item(index).InnerText))
                                                                 ));
                    }

                    meshes[index] = mesh;
                }

                string animationAssetPath;
                animationAssetPath = string.Format("{0}/MeshAnimations/{1}.asset", submodulePath, keyNode.InnerText);

                string animationResourcePath;
                animationResourcePath = string.Format("{0}/_Resources_/MeshAnimations/{1}.asset", submodulePath, keyNode.InnerText);

                MeshAnimationAsset existingAsset;
                existingAsset = (
                    AssetDatabase.LoadAssetAtPath(animationResourcePath, typeof(MeshAnimationAsset)) as MeshAnimationAsset ??
                    AssetDatabase.LoadAssetAtPath(animationAssetPath, typeof(MeshAnimationAsset)) as MeshAnimationAsset
                    );

                MeshAnimationAsset animationAsset;
                animationAsset             = ScriptableObject.CreateInstance <MeshAnimationAsset>();
                animationAsset.name        = keyNode.InnerText;
                animationAsset.AnchorPoint = anchorPoint;
                animationAsset.Audio       = existingAsset ? existingAsset.Audio : null;
                animationAsset.ContentSize = contentSize;
                animationAsset.Duration    = duration;
                animationAsset.Meshes      = meshes;
                animationAsset.RecalculateBounds();
                animationAsset.RecalculateCrop();

                if (existingAsset)
                {
                    EditorUtility.CopySerialized(animationAsset, existingAsset);
                    AssetDatabase.SaveAssets();
                }
                else
                {
                    // create folder
                    if (!Directory.Exists(Path.GetDirectoryName(animationAssetPath)))
                    {
                        AssetDatabase.CreateFolder(
                            Path.GetDirectoryName(Path.GetDirectoryName(animationAssetPath)),
                            Path.GetFileName(Path.GetDirectoryName(animationAssetPath))
                            );
                    }

                    AssetDatabase.CreateAsset(animationAsset, animationAssetPath);
                    AssetDatabase.SaveAssets();
                }
            }

            if (SagoMeshEditor.EditorSettings.Instance.DeleteIntermediateFiles)
            {
                AssetDatabase.DeleteAsset(path);
            }
            AssetDatabase.SaveAssets();
        }
Esempio n. 7
0
        static void ConvertToMeshAsset(string path)
        {
            System.Type submoduleType;
            submoduleType = SubmoduleMapEditorAdaptor.GetSubmoduleType(path);

            if (submoduleType == null)
            {
                return;
            }

            string submodulePath;

            submodulePath = SubmoduleMapEditorAdaptor.GetSubmodulePath(submoduleType);

            if (string.IsNullOrEmpty(submodulePath))
            {
                return;
            }

            // load bytes
            byte[] bytes;
            bytes = System.IO.File.ReadAllBytes(path);

            // header length
            int headerLength = 0;

            headerLength += sizeof(System.Single) + sizeof(System.Single);    // anchor point
            headerLength += sizeof(System.Single) + sizeof(System.Single);    // content size
            headerLength += sizeof(System.Boolean) + sizeof(System.Byte) * 3; // is opaque
            headerLength += sizeof(System.UInt32);                            // index count
            headerLength += sizeof(System.UInt32);                            // vertex count

            // if the bytes are null or not long enough, the file isn't a legacy mesh animation
            if (bytes == null || bytes.Length < headerLength)
            {
                EditorUtility.ClearProgressBar();
                return;
            }

            // read bytes
            MemoryStream stream;

            stream = new MemoryStream(bytes);

            BinaryReader reader;

            reader = new BinaryReader(stream);

            // read anchor point
            Vector2 anchorPoint;

            anchorPoint = new Vector2(reader.ReadSingle(), reader.ReadSingle());

            // read content size
            Vector2 contentSize;

            contentSize = new Vector2(reader.ReadSingle(), reader.ReadSingle());

            // read isOpaque
            bool isOpaque;

            isOpaque = !reader.ReadBoolean();
            reader.ReadByte();
            reader.ReadByte();
            reader.ReadByte();

            // read index count
            uint indexCount;

            indexCount = reader.ReadUInt32();

            // read vertex count
            uint vertexCount;

            vertexCount = reader.ReadUInt32();

            // content length
            int contentLength = 0;

            contentLength += sizeof(System.UInt32) * (int)indexCount;      // indicies
            contentLength += sizeof(System.Byte) * (int)vertexCount * 4;   // colors
            contentLength += sizeof(System.Single) * (int)vertexCount * 2; // positions

            // if the expected length doesn't match the actual length, the file isn't a legacy mesh animation
            if (headerLength + contentLength != bytes.Length)
            {
                reader.Close();
                stream.Close();
                EditorUtility.ClearProgressBar();
                return;
            }

            // read indicies
            int[] indicies = new int[indexCount];
            for (int i = 0; i < indexCount; i++)
            {
                indicies[i] = checked ((int)reader.ReadInt32());
            }

            // read vertices
            Color32[] colors;
            colors = new Color32[vertexCount];

            Vector3[] vertices;
            vertices = new Vector3[vertexCount];

            Vector3 offset;

            offset = new Vector3(contentSize.x * -anchorPoint.x, contentSize.y * -anchorPoint.y, 0.0f);

            Vector3 scale;

            scale = Vector3.one;

            for (int i = 0; i < vertexCount; i++)
            {
                Vector3 vertex;
                vertex   = new Vector3(reader.ReadSingle(), reader.ReadSingle(), 0.0f);
                vertex.x = (vertex.x + offset.x) * scale.x;
                vertex.y = (vertex.y + offset.y) * scale.y;
                vertex.z = (vertex.z + offset.z) * scale.z;

                Color32 color;
                color = new Color32(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());

                vertices[i] = vertex;
                colors[i]   = color;
            }

            reader.Close();
            stream.Close();

            // create mesh
            UnityEngine.Mesh mesh;
            mesh           = new UnityEngine.Mesh();
            mesh.name      = Path.GetFileNameWithoutExtension(path);
            mesh.hideFlags = HideFlags.HideInHierarchy;
            mesh.Clear(false);
            mesh.vertices  = vertices;
            mesh.colors32  = colors;
            mesh.triangles = indicies;
            mesh.RecalculateBounds();

            string resourcePath;

            resourcePath = Path.Combine(submodulePath, string.Format("_Resources_/Meshes/{0}.asset", Path.GetFileNameWithoutExtension(path)));

            string assetPath;

            assetPath = Path.Combine(submodulePath, string.Format("Meshes/{0}.asset", Path.GetFileNameWithoutExtension(path)));

            MeshAsset existingAsset;

            existingAsset = (
                AssetDatabase.LoadAssetAtPath(resourcePath, typeof(MeshAsset)) as MeshAsset ??
                AssetDatabase.LoadAssetAtPath(assetPath, typeof(MeshAsset)) as MeshAsset
                );

            string existingPath;

            existingPath = AssetDatabase.GetAssetPath(existingAsset);

            if (existingAsset)
            {
                bool isReadable;
                isReadable = false;

                Mesh existingMesh = null;
                foreach (Object obj in AssetDatabase.LoadAllAssetsAtPath(existingPath))
                {
                    if (existingMesh = obj as Mesh)
                    {
                        break;
                    }
                }

                if (existingMesh)
                {
                    isReadable = existingMesh.isReadable;
                    Object.DestroyImmediate(existingMesh, true);
                    // BUG:
                    // Calling AssetDatabase.SaveAssets() here somehow destroys `mesh`.
                    // Everything seems to work fine without it.
                    // AssetDatabase.SaveAssets();
                }

                existingAsset.name        = Path.GetFileNameWithoutExtension(path);
                existingAsset.hideFlags   = HideFlags.NotEditable;
                existingAsset.AnchorPoint = anchorPoint;
                existingAsset.ContentSize = contentSize;
                existingAsset.IsOpaque    = isOpaque;
                existingAsset.Mesh        = mesh;

                MeshUtil.SetIsReadable(mesh, isReadable);
                AssetDatabase.AddObjectToAsset(mesh, existingPath);
                AssetDatabase.SaveAssets();
            }
            else
            {
                // create folder
                if (!Directory.Exists(Path.GetDirectoryName(assetPath)))
                {
                    AssetDatabase.CreateFolder(
                        Path.GetDirectoryName(Path.GetDirectoryName(assetPath)),
                        Path.GetFileNameWithoutExtension(Path.GetDirectoryName(assetPath))
                        );
                }

                MeshAsset asset;
                asset             = ScriptableObject.CreateInstance(typeof(MeshAsset)) as MeshAsset;
                asset.name        = Path.GetFileNameWithoutExtension(path);
                asset.hideFlags   = HideFlags.NotEditable;
                asset.AnchorPoint = anchorPoint;
                asset.ContentSize = contentSize;
                asset.IsOpaque    = isOpaque;
                asset.Mesh        = mesh;

                MeshUtil.SetIsReadable(mesh, false);
                AssetDatabase.CreateAsset(asset, assetPath);
                AssetDatabase.AddObjectToAsset(mesh, assetPath);
                AssetDatabase.SaveAssets();
            }

            if (SagoMeshEditor.EditorSettings.Instance.DeleteIntermediateFiles)
            {
                AssetDatabase.DeleteAsset(path);
            }
            AssetDatabase.SaveAssets();
        }
Esempio n. 8
0
 /// <summary>
 /// Gets the path to the <see cref="GraphicsSettings" /> asset for the specified content submodule.
 /// </summary>
 /// <param name="type">
 /// The <see cref="ContentInfo" /> subclass for the content submodule.
 /// </param>
 public static string GetGraphicsSettingsPath(System.Type type)
 {
     return(Path.Combine(SubmoduleMapEditorAdaptor.GetSubmodulePath(type), Path.Combine("Settings", "GraphicsSettings.asset")));
 }
Esempio n. 9
0
 /// <summary>
 /// Gets the <see cref="ContentInfo.SceneAssetBundleName" /> for the specified content submodule.
 /// </summary>
 /// <param name="type">
 /// The <see cref="ContentInfo" /> subclass for the content submodule.
 /// </param>
 private static string GetSceneAssetBundleName(System.Type type)
 {
     return(string.Format("{0}_scenes", SubmoduleMapEditorAdaptor.GetSubmoduleName(type).ToLower()));
 }
Esempio n. 10
0
        /// <summary>
        /// Applies the <see cref="ContentInfo.SceneAssetBundleName" /> to every
        /// asset that should be included in the scene asset bundle for the
        /// content submodule.
        /// </summary>
        /// <param name="type">
        /// The <see cref="ContentInfo" /> subclass for the content submodule.
        /// </param>
        private static void ApplySceneAssetBundleName(System.Type type)
        {
            ContentInfo contentInfo;

            contentInfo = FindOrCreateContentInfo(type);

            string progressTitle;

            progressTitle = string.Format("ApplyAssetBundleNames");

            string progressInfo1;

            progressInfo1 = string.Format("Finding scenes: {0}", contentInfo.SceneAssetBundleName);

            string progressInfo2;

            progressInfo2 = string.Format("Applying asset bundle name: {0}", contentInfo.SceneAssetBundleName);

            int progressIndex;

            progressIndex = 0;

            float progressTotal;

            progressTotal = 1;

            EditorUtility.DisplayProgressBar(progressTitle, progressInfo1, progressIndex / progressTotal);

            string submodulePath;

            submodulePath = SubmoduleMapEditorAdaptor.GetSubmodulePath(type);

            string[] allScenePaths;
            allScenePaths = (
                AssetDatabase
                .FindAssets("t:SceneAsset", new string[] { submodulePath })
                .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
                .ToArray()
                );

            string[] scenePaths;
            scenePaths = (
                AssetDatabase
                .FindAssets("t:SceneAsset", new string[] { submodulePath })
                .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
                .Where(path => path.Contains("_Scenes_"))
                .Where(path => File.Exists(path))
                .ToArray()
                );

            progressIndex = 0;
            progressTotal = allScenePaths.Length - 1;

            foreach (string scenePath in allScenePaths)
            {
                EditorUtility.DisplayProgressBar(progressTitle, progressInfo2, progressIndex / progressTotal);
                progressIndex++;

                string assetBundleName;
                assetBundleName = scenePaths.Contains(scenePath) ? contentInfo.SceneAssetBundleName : null;

                AssetImporter importer;
                importer = AssetImporter.GetAtPath(scenePath);
                importer.SetAssetBundleNameAndVariant(assetBundleName, null);
                EditorUtility.SetDirty(importer);
                AssetDatabase.WriteImportSettingsIfDirty(scenePath);
            }

            AssetDatabase.RemoveUnusedAssetBundleNames();
            EditorUtility.ClearProgressBar();
        }
Esempio n. 11
0
        /// <summary>
        /// Applies the <see cref="ContentInfo.ResourceAssetBundleName" /> to every
        /// asset that should be included in the resource asset bundle for the
        /// specified content submodule.
        /// </summary>
        /// <param name="type">
        /// The <see cref="ContentInfo" /> subclass for the content submodule.
        /// </param>
        private static void ApplyResourceAssetBundleName(System.Type type)
        {
            // To make sure all of the required assets get added to the resource
            // asset bundle, we need to find:
            //
            //   * All assets in any _Resources_ folder
            //   * All dependencies of assets in any _Resources_ folder
            //   * All dependencies of all scenes
            //
            // We can get the info in C#, but it's very, very slow because Unity
            // has to actually load all the assets before it can figure out the
            // dependencies.
            //
            // Instead, we're calling out to a ruby script to do the heavy lifting.
            // It crawls through the all of the asset files in the submodule and
            // figures out which assets need to be in the resource asset bundle.
            //
            // However, the script can't add the asset bundle name to the meta files
            // directly (modifying the meta files causes Unity to reimport the asset,
            // which is really slow for things like sounds).
            //
            // Instead, the script reads the meta files for all of the assets in the
            // submodule and builds two lists and returns them as JSON data:
            //
            //   * Assets that need the asset bundle name added
            //   * Assets that need the asset bundle name removed
            //
            // Then, in C#, we can just loop through the two lists to add or remove
            // the asset bundle name where necessary using the AssetImporter (which
            // doesn't cause Unity to reimport the asset).

            ContentInfo contentInfo;

            contentInfo = FindOrCreateContentInfo(type);

            string progressTitle;

            progressTitle = string.Format("ApplyAssetBundleNames");

            string progressInfo1;

            progressInfo1 = string.Format("Finding assets: {0}", contentInfo.ResourceAssetBundleName);

            string progressInfo2;

            progressInfo2 = string.Format("Applying asset bundle name: {0}", contentInfo.ResourceAssetBundleName);

            int progressIndex;

            progressIndex = 0;

            float progressTotal;

            progressTotal = 1;

            EditorUtility.DisplayProgressBar(progressTitle, progressInfo1, progressIndex / progressTotal);

            string command;

            command = Path.Combine(SubmoduleMapEditorAdaptor.GetAbsoluteSubmodulePath(typeof(SagoApp.SubmoduleInfo)), ".ruby/resource_asset_bundle_info");

            string[] arguments;
            arguments = new string[] {
                string.Format("--project_path {0}", Path.GetDirectoryName(Application.dataPath)),
                string.Format("--submodule_path {0}", SubmoduleMapEditorAdaptor.GetAbsoluteSubmodulePath(type)),
                string.Format("--asset_bundle_name {0}", contentInfo.ResourceAssetBundleName)
            };

            string error;

            error = string.Empty;

            string output;

            output = string.Empty;

            Process process = new Process();

            process.StartInfo.FileName               = command;
            process.StartInfo.Arguments              = string.Join(" ", arguments);
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.ErrorDataReceived += new DataReceivedEventHandler((object sender, DataReceivedEventArgs e) => {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    error += e.Data + "\n";
                }
            });
            process.OutputDataReceived += new DataReceivedEventHandler((object sender, DataReceivedEventArgs e) => {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    output += e.Data + "\n";
                }
            });
            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            process.WaitForExit();

            if (!string.IsNullOrEmpty(error))
            {
                throw new System.InvalidOperationException(error);
            }

            ResourceAssetBundleInfo info;

            info = JsonUtility.FromJson <ResourceAssetBundleInfo>(output);

            progressIndex = 0;
            progressTotal = info.AddToResourceAssetBundle.Length + info.RemoveFromResourceAssetBundle.Length - 1;

            AssetDatabase.StartAssetEditing();
            foreach (string assetPath in info.AddToResourceAssetBundle)
            {
                EditorUtility.DisplayProgressBar(progressTitle, progressInfo2, progressIndex / progressTotal);
                progressIndex++;

                AssetImporter importer;
                importer = AssetImporter.GetAtPath(assetPath);
                importer.SetAssetBundleNameAndVariant(contentInfo.ResourceAssetBundleName, string.Empty);
                EditorUtility.SetDirty(importer);
                AssetDatabase.WriteImportSettingsIfDirty(assetPath);
            }
            foreach (string assetPath in info.RemoveFromResourceAssetBundle)
            {
                EditorUtility.DisplayProgressBar(progressTitle, progressInfo2, progressIndex++ / progressTotal);
                progressIndex++;

                AssetImporter importer;
                importer = AssetImporter.GetAtPath(assetPath);
                importer.SetAssetBundleNameAndVariant(string.Empty, string.Empty);
                EditorUtility.SetDirty(importer);
                AssetDatabase.WriteImportSettingsIfDirty(assetPath);
            }
            AssetDatabase.StopAssetEditing();
            AssetDatabase.RemoveUnusedAssetBundleNames();
            EditorUtility.ClearProgressBar();
        }
Esempio n. 12
0
 /// <summary>
 /// Gets the path to the <see cref="ContentInfo" /> asset for the specified content submodule.
 /// </summary>
 /// <param name="type">
 /// The <see cref="ContentInfo" /> subclass for the content submodule.
 /// </param>
 public static string GetContentInfoPath(System.Type type)
 {
     return(Path.Combine(SubmoduleMapEditorAdaptor.GetSubmodulePath(type), Path.Combine("Resources", Path.Combine(SubmoduleMapEditorAdaptor.GetSubmoduleName(type), "ContentInfo.asset"))));
 }