示例#1
0
 private Texture2D GetTexture(Material mat, string name)
 {
     try
     {
         UnityTexEnv texEnv = mat.m_SavedProperties.GetTex(name);
         return texEnv.m_Texture.instance;
     }
     catch
     {
         return null;
     }
 }
示例#2
0
 public dynamic LoadComponent(Stream stream, int index, NotLoaded comp)
 {
     stream.Position = comp.offset;
     try
     {
         switch (comp.classID1)
         {
         case UnityClassID.AnimationClip:
             {
                 AnimationClip animationClip = new AnimationClip(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, animationClip, comp);
                 animationClip.LoadFrom(stream);
                 return animationClip;
             }
         case UnityClassID.Animator:
             {
                 Animator animator = new Animator(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, animator, comp);
                 animator.LoadFrom(stream);
                 return animator;
             }
         case UnityClassID.AnimatorController:
             {
                 AnimatorController animatorController = new AnimatorController(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, animatorController, comp);
                 animatorController.LoadFrom(stream);
                 return animatorController;
             }
         case UnityClassID.AssetBundle:
             {
                 AssetBundle assetBundle = new AssetBundle(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, assetBundle, comp);
                 assetBundle.LoadFrom(stream);
                 return assetBundle;
             }
         case UnityClassID.AudioClip:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 AudioClip ac = new AudioClip(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, ac, comp);
                 ac.LoadFrom(stream);
                 return ac;
             }
         case UnityClassID.AudioListener:
             {
                 AudioListener audioListener = new AudioListener(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, audioListener, comp);
                 audioListener.LoadFrom(stream);
                 return audioListener;
             }
         case UnityClassID.AudioSource:
             {
                 AudioSource audioSrc = new AudioSource(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, audioSrc, comp);
                 audioSrc.LoadFrom(stream);
                 return audioSrc;
             }
         case UnityClassID.Avatar:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 Avatar avatar = new Avatar(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, avatar, comp);
                 avatar.LoadFrom(stream);
                 return avatar;
             }
         case UnityClassID.BoxCollider:
             {
                 BoxCollider boxCol = new BoxCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, boxCol, comp);
                 boxCol.LoadFrom(stream);
                 return boxCol;
             }
         case UnityClassID.Camera:
             {
                 Camera camera = new Camera(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, camera, comp);
                 camera.LoadFrom(stream);
                 return camera;
             }
         case UnityClassID.CapsuleCollider:
             {
                 CapsuleCollider capsuleCol = new CapsuleCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, capsuleCol, comp);
                 capsuleCol.LoadFrom(stream);
                 return capsuleCol;
             }
         case UnityClassID.Cubemap:
             {
                 Cubemap cubemap = new Cubemap(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, cubemap, comp);
                 cubemap.LoadFrom(stream);
                 Parser.Textures.Add(cubemap);
                 return cubemap;
             }
         case UnityClassID.EllipsoidParticleEmitter:
             {
                 EllipsoidParticleEmitter ellipsoid = new EllipsoidParticleEmitter(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, ellipsoid, comp);
                 ellipsoid.LoadFrom(stream);
                 return ellipsoid;
             }
         case UnityClassID.FlareLayer:
             {
                 FlareLayer flareLayer = new FlareLayer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, flareLayer, comp);
                 flareLayer.LoadFrom(stream);
                 return flareLayer;
             }
         case UnityClassID.Light:
             {
                 Light light = new Light(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, light, comp);
                 light.LoadFrom(stream);
                 return light;
             }
         case UnityClassID.LinkToGameObject:
             {
                 LinkToGameObject link = new LinkToGameObject(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, link, comp);
                 link.LoadFrom(stream);
                 return link;
             }
         case UnityClassID.LinkToGameObject223:
             {
                 LinkToGameObject223 link = new LinkToGameObject223(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, link, comp);
                 link.LoadFrom(stream);
                 return link;
             }
         case UnityClassID.LinkToGameObject225:
             {
                 LinkToGameObject225 link = new LinkToGameObject225(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, link, comp);
                 link.LoadFrom(stream);
                 return link;
             }
         case UnityClassID.GameObject:
             {
                 GameObject gameObj = new GameObject(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, gameObj, comp);
                 gameObj.LoadFrom(stream);
                 return gameObj;
             }
         case UnityClassID.Material:
             {
                 Material mat = new Material(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, mat, comp);
                 mat.LoadFrom(stream);
                 return mat;
             }
         case UnityClassID.Mesh:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 Mesh mesh = new Mesh(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, mesh, comp);
                 mesh.LoadFrom(stream);
                 return mesh;
             }
         case UnityClassID.MeshCollider:
             {
                 MeshCollider meshCol = new MeshCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, meshCol, comp);
                 meshCol.LoadFrom(stream);
                 return meshCol;
             }
         case UnityClassID.MeshFilter:
             {
                 MeshFilter meshFilter = new MeshFilter(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, meshFilter, comp);
                 meshFilter.LoadFrom(stream);
                 return meshFilter;
             }
         case UnityClassID.MeshRenderer:
             {
                 MeshRenderer meshRenderer = new MeshRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, meshRenderer, comp);
                 meshRenderer.LoadFrom(stream);
                 return meshRenderer;
             }
         default:
             if (comp.classID2 == UnityClassID.MonoBehaviour)
             {
                 if (Types.Count > 0)
                 {
                     MonoBehaviour monoBehaviour = new MonoBehaviour(this, comp.pathID, comp.classID1, comp.classID2);
                     ReplaceSubfile(index, monoBehaviour, comp);
                     monoBehaviour.LoadFrom(stream);
                     return monoBehaviour;
                 }
                 else
                 {
                     string message = comp.classID2 + " unhandled because of absence of Types in Cabinet (*.assets)";
                     if (!reported.Contains(message))
                     {
                         Report.ReportLog(message);
                         reported.Add(message);
                     }
                     return comp;
                 }
             }
             else
             {
                 string message = "Unhandled class: " + comp.classID1 + "/" + comp.classID2;
                 if (!reported.Contains(message))
                 {
                     Report.ReportLog(message);
                     reported.Add(message);
                 }
             }
             break;
         case UnityClassID.MonoScript:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 MonoScript monoScript = new MonoScript(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, monoScript, comp);
                 monoScript.LoadFrom(stream);
                 return monoScript;
             }
         case UnityClassID.MultiLink:
             {
                 MultiLink multi = new MultiLink(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, multi, comp);
                 multi.LoadFrom(stream);
                 return multi;
             }
         case UnityClassID.ParticleAnimator:
             {
                 ParticleAnimator particleAnimator = new ParticleAnimator(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleAnimator, comp);
                 particleAnimator.LoadFrom(stream);
                 return particleAnimator;
             }
         case UnityClassID.ParticleRenderer:
             {
                 ParticleRenderer particleRenderer = new ParticleRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleRenderer, comp);
                 particleRenderer.LoadFrom(stream);
                 return particleRenderer;
             }
         case UnityClassID.ParticleSystem:
             {
                 ParticleSystem particleSystem = new ParticleSystem(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleSystem, comp);
                 particleSystem.LoadFrom(stream);
                 return particleSystem;
             }
         case UnityClassID.ParticleSystemRenderer:
             {
                 ParticleSystemRenderer particleSystemRenderer = new ParticleSystemRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleSystemRenderer, comp);
                 particleSystemRenderer.LoadFrom(stream);
                 return particleSystemRenderer;
             }
         case UnityClassID.Projector:
             {
                 Projector projector = new Projector(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, projector, comp);
                 projector.LoadFrom(stream);
                 return projector;
             }
         case UnityClassID.Rigidbody:
             {
                 RigidBody rigidBody = new RigidBody(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, rigidBody, comp);
                 rigidBody.LoadFrom(stream);
                 return rigidBody;
             }
         case UnityClassID.Shader:
             {
                 Shader shader = new Shader(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, shader, comp);
                 shader.LoadFrom(stream);
                 return shader;
             }
         case UnityClassID.SkinnedMeshRenderer:
             {
                 SkinnedMeshRenderer sMesh = new SkinnedMeshRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, sMesh, comp);
                 sMesh.LoadFrom(stream);
                 return sMesh;
             }
         case UnityClassID.SphereCollider:
             {
                 SphereCollider sphereCol = new SphereCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, sphereCol, comp);
                 sphereCol.LoadFrom(stream);
                 return sphereCol;
             }
         case UnityClassID.Sprite:
             {
                 Sprite sprite = new Sprite(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, sprite, comp);
                 sprite.LoadFrom(stream);
                 return sprite;
             }
         case UnityClassID.SpriteRenderer:
             {
                 SpriteRenderer spriteRenderer = new SpriteRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, spriteRenderer, comp);
                 spriteRenderer.LoadFrom(stream);
                 return spriteRenderer;
             }
         case UnityClassID.TextAsset:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 TextAsset ta = new TextAsset(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, ta, comp);
                 ta.LoadFrom(stream);
                 return ta;
             }
         case UnityClassID.Texture2D:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 Texture2D tex = new Texture2D(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, tex, comp);
                 tex.LoadFrom(stream);
                 Parser.Textures.Add(tex);
                 return tex;
             }
         case UnityClassID.Transform:
             {
                 Transform trans = new Transform(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, trans, comp);
                 trans.LoadFrom(stream);
                 return trans;
             }
         }
     }
     catch
     {
         Report.ReportLog("Failed to load " + comp.classID1 + "/" + comp.classID2 + " PathID=" + comp.pathID);
         foreach (NotLoaded notLoaded in RemovedList)
         {
             if (notLoaded == comp)
             {
                 RemovedList.Remove(notLoaded);
                 Components.RemoveAt(index);
                 notLoaded.replacement = null;
                 Components.Insert(index, notLoaded);
                 break;
             }
         }
     }
     return null;
 }
示例#3
0
 private Color4 GetColour(Material mat, string name)
 {
     try
     {
         return mat.m_SavedProperties.GetColour(name);
     }
     catch
     {
         return new Color4(Color.White);
     }
 }
示例#4
0
 private float GetFloat(Material mat, string name)
 {
     try
     {
         return mat.m_SavedProperties.GetFloat(name);
     }
     catch
     {
         return 1f;
     }
 }
示例#5
0
 public void CopyTo(Material dest, bool cloneTextures)
 {
     dest.m_Name = m_Name;
     if (dest.file == file || m_Shader.instance == null)
     {
         dest.m_Shader = m_Shader;
     }
     else
     {
         Shader shader = m_Shader.instance.Clone(dest.file);
         dest.m_Shader = new PPtr<Shader>(shader);
     }
     dest.m_ShaderKeywords = new List<string>(m_ShaderKeywords);
     dest.m_CustomRenderQueue = m_CustomRenderQueue;
     m_SavedProperties.CopyTo(dest, cloneTextures);
 }
示例#6
0
        public void CopyTo(Material dest, bool cloneTextures)
        {
            dest.m_SavedProperties.m_TexEnvs = new List<KeyValuePair<FastPropertyName, UnityTexEnv>>(m_TexEnvs.Count);
            foreach (var src in m_TexEnvs)
            {
                UnityTexEnv texEnv = new UnityTexEnv(dest.file);
                src.Value.CopyTo(texEnv, cloneTextures);
                dest.m_SavedProperties.m_TexEnvs.Add(new KeyValuePair<FastPropertyName, UnityTexEnv>(src.Key, texEnv));
            }

            dest.m_SavedProperties.m_Floats = new List<KeyValuePair<FastPropertyName, float>>(m_Floats.Count);
            foreach (var src in m_Floats)
            {
                dest.m_SavedProperties.m_Floats.Add(src);
            }

            dest.m_SavedProperties.m_Colors = new List<KeyValuePair<FastPropertyName, Color4>>(m_Colors.Count);
            foreach (var src in m_Colors)
            {
                dest.m_SavedProperties.m_Colors.Add(src);
            }
        }
示例#7
0
        public static void ReplaceMaterial(Material mat, ImportedMaterial material)
        {
            if (mat == null)
            {
                throw new Exception("Replacing a material currently requires an existing material with the same name");
            }

            for (int i = 0; i < mat.m_SavedProperties.m_Colors.Count; i++)
            {
                var col = mat.m_SavedProperties.m_Colors[i];
                Color4 att;
                switch (col.Key.name)
                {
                case "_Color":
                    att = material.Diffuse;
                    break;
                case "_SColor":
                    att = material.Ambient;
                    break;
                case "_ReflectColor":
                    att = material.Emissive;
                    break;
                case "_SpecColor":
                    att = material.Specular;
                    break;
                case "_RimColor":
                case "_OutlineColor":
                case "_ShadowColor":
                default:
                    continue;
                }
                mat.m_SavedProperties.m_Colors.RemoveAt(i);
                col = new KeyValuePair<FastPropertyName, Color4>(col.Key, att);
                mat.m_SavedProperties.m_Colors.Insert(i, col);
            }

            for (int i = 0; i < mat.m_SavedProperties.m_Floats.Count; i++)
            {
                var flt = mat.m_SavedProperties.m_Floats[i];
                float att;
                switch (flt.Key.name)
                {
                case "_Shininess":
                    att = material.Power;
                    break;
                case "_RimPower":
                case "_Outline":
                default:
                    continue;
                }
                mat.m_SavedProperties.m_Floats.RemoveAt(i);
                flt = new KeyValuePair<FastPropertyName, float>(flt.Key, att);
                mat.m_SavedProperties.m_Floats.Insert(i, flt);
            }

            for (int i = 0; i < material.Textures.Length && i < mat.m_SavedProperties.m_TexEnvs.Count; i++)
            {
                try
                {
                    Texture2D tex = null;
                    if (material.Textures[i] != string.Empty)
                    {
                        tex = mat.file.Parser.GetTexture(material.Textures[i]);
                    }
                    if (mat.m_SavedProperties.m_TexEnvs[i].Value.m_Texture.asset != tex)
                    {
                        mat.m_SavedProperties.m_TexEnvs[i].Value.m_Texture = new PPtr<Texture2D>(tex);
                    }
                }
                catch (Exception e)
                {
                    Report.ReportLog(e.ToString());
                }
            }
        }
示例#8
0
        public Material Clone(AssetCabinet file, bool cloneTextures)
        {
            Component mat = file.Bundle != null ? file.Bundle.FindComponent(m_Name, UnityClassID.Material) : null;
            if (mat == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Material);

                mat = new Material(file);
                if (file.Bundle != null)
                {
                    file.Bundle.AddComponent(m_Name, mat);
                }
                CopyTo((Material)mat, cloneTextures);
            }
            else if (mat is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)mat;
                if (notLoaded.replacement != null)
                {
                    mat = notLoaded.replacement;
                }
                else
                {
                    mat = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return (Material)mat;
        }
示例#9
0
        public void MergeMaterial(Material mat)
        {
            Material oldMat = Operations.FindMaterial(Materials, mat.m_Name);
            if (oldMat != null)
            {
                if (oldMat == mat)
                {
                    return;
                }
                mat.CopyTo(oldMat, false);
                if (Parser.file.Bundle != null)
                {
                    Parser.file.Bundle.RegisterForUpdate(oldMat);
                }
            }
            else
            {
                Material newMat;
                Component m = Parser.file.Bundle != null ? Parser.file.Bundle.FindComponent(mat.m_Name, UnityClassID.Material) : null;
                if (m == null)
                {
                    newMat = mat.Clone(Parser.file, false);
                }
                else
                {
                    if (m is NotLoaded)
                    {
                        NotLoaded notLoaded = (NotLoaded)m;
                        if (notLoaded.replacement != null)
                        {
                            m = (Material)notLoaded.replacement;
                        }
                        else
                        {
                            m = Parser.file.LoadComponent(notLoaded.pathID);
                        }
                    }
                    oldMat = (Material)m;
                    mat.CopyTo(oldMat, false);
                    if (Parser.file.Bundle != null)
                    {
                        Parser.file.Bundle.RegisterForUpdate(oldMat);
                    }
                    newMat = oldMat;
                }
                if (!Materials.Contains(newMat))
                {
                    Materials.Add(newMat);
                }
            }

            Changed = true;
        }
示例#10
0
 private void AddMaterialToEditor(Material mat)
 {
     Materials.Add(mat);
     if (mat.m_Shader.asset is NotLoaded)
     {
         Shader shader = (Shader)((NotLoaded)mat.m_Shader.asset).replacement;
         if (shader == null)
         {
             shader = Parser.file.LoadComponent(Parser.file.SourceStream, (NotLoaded)mat.m_Shader.asset);
         }
         mat.m_Shader = new PPtr<Shader>(shader);
     }
     foreach (var pair in mat.m_SavedProperties.m_TexEnvs)
     {
         if (pair.Value.m_Texture.asset is NotLoaded)
         {
             Texture2D loadedTex = (Texture2D)((NotLoaded)pair.Value.m_Texture.asset).replacement;
             if (loadedTex == null)
             {
                 loadedTex = Parser.file.LoadComponent(Parser.file.SourceStream, (NotLoaded)pair.Value.m_Texture.asset);
             }
             pair.Value.m_Texture = new PPtr<Texture2D>(loadedTex);
         }
         Texture2D tex = pair.Value.m_Texture.instance;
         if (tex != null && !Textures.Contains(tex))
         {
             Textures.Add(tex);
         }
     }
 }
示例#11
0
文件: Mqo.cs 项目: hejob/SB3Utility
            private void Export(string dest, Material mat, Texture2D tex)
            {
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(dest));
                if (!dir.Exists)
                {
                    dir.Create();
                }

                usedTextures = new List<Texture2D>(1);
                using (StreamWriter writer = new StreamWriter(dest, false))
                {
                    writer.WriteLine("Metasequoia Document");
                    writer.WriteLine("Format Text Ver 1.0");
                    writer.WriteLine();

                    if (mat != null)
                    {
                        writer.WriteLine("Material 1 {");
                        string s = "\t\"" + mat.m_Name + "\" vcol(1) col(0.800 0.800 0.800 1.000) dif(0.500) amb(0.100) emi(0.500) spc(0.100) power(30.00)";
                        if (tex != null)
                        {
                            string extension = tex.m_TextureFormat == TextureFormat.DXT1 || tex.m_TextureFormat == TextureFormat.DXT5 ? ".dds" : ".tga";
                            s += " tex(\"" + tex.m_Name + extension + "\")";
                            usedTextures.Add(tex);
                        }
                        writer.WriteLine(s);
                        writer.WriteLine("}");
                    }

                    Mesh mesh = Operations.GetMesh(morphObj);
                    Random rand = new Random();
                    int vertListIdx = 0;
                    for (int i = 0; i < mesh.m_Shapes.shapes.Count; i++)
                    {
                        float[] color = new float[3];
                        for (int k = 0; k < color.Length; k++)
                        {
                            color[k] = (float)((rand.NextDouble() / 2) + 0.5);
                        }

                        writer.WriteLine("Object \"" + mesh.m_Shapes.channels[i].name + "\" {");
                        writer.WriteLine("\tvisible 0");
                        writer.WriteLine("\tshading 1");
                        writer.WriteLine("\tcolor " + color[0].ToFloatString() + " " + color[1].ToFloatString() + " " + color[2].ToFloatString());
                        writer.WriteLine("\tcolor_type 1");
                        SB3Utility.Mqo.ExporterCommon.WriteMeshObject(writer, vertLists[vertListIdx++], faceList, mat != null ? 0 : -1, colorLists[i]);
                        writer.WriteLine("}");
                    }

                    writer.WriteLine("Eof");
                }
            }
示例#12
0
文件: Fbx.cs 项目: hejob/SB3Utility
            private void ConvertMaterial(Material mat)
            {
                ImportedMaterial iMat = ImportedHelpers.FindMaterial(mat.m_Name, MaterialList);
                if (iMat != null)
                {
                    return;
                }

                iMat = new ImportedMaterial();
                iMat.Name = mat.m_Name;

                foreach (var col in mat.m_SavedProperties.m_Colors)
                {
                    switch (col.Key.name)
                    {
                    case "_Color":
                        iMat.Diffuse = col.Value;
                        break;
                    case "_SColor":
                        iMat.Ambient = col.Value;
                        break;
                    case "_ReflectColor":
                        iMat.Emissive = col.Value;
                        break;
                    case "_SpecColor":
                        iMat.Specular = col.Value;
                        break;
                    case "_RimColor":
                    case "_OutlineColor":
                    case "_ShadowColor":
                        break;
                    }
                }

                foreach (var flt in mat.m_SavedProperties.m_Floats)
                {
                    switch (flt.Key.name)
                    {
                    case "_Shininess":
                        iMat.Power = flt.Value;
                        break;
                    case "_RimPower":
                    case "_Outline":
                        break;
                    }
                }

                iMat.Textures = new string[4];
                int numTex = mat.m_SavedProperties.m_TexEnvs.Count > 4 ? 4 : mat.m_SavedProperties.m_TexEnvs.Count;
                for (int i = 0; i < numTex; i++)
                {
                    var tex = mat.m_SavedProperties.m_TexEnvs[i];
                    Texture2D tex2D = tex.Value.m_Texture.instance;
                    if (tex2D != null)
                    {
                        iMat.Textures[i] = tex2D.m_Name + "-" + tex2D.m_TextureFormat + (tex2D.m_TextureFormat == TextureFormat.DXT1 || tex2D.m_TextureFormat == TextureFormat.DXT5 ? ".dds" : ".tga");
                        ConvertTexture2D(tex2D, iMat.Textures[i]);
                    }
                }

                MaterialList.Add(iMat);
            }
示例#13
0
        public void PasteAllMarked()
        {
            int components = Parser.Cabinet.Components.Count;

            try
            {
                Parser.Cabinet.BeginLoadingSkippedComponents();
                foreach (object obj in Gui.Scripting.Variables.Values)
                {
                    if (obj is Unity3dEditor && (Unity3dEditor)obj != this)
                    {
                        Unity3dEditor       editor  = (Unity3dEditor)obj;
                        HashSet <Component> remove  = new HashSet <Component>();
                        HashSet <Component> replace = new HashSet <Component>();
                        foreach (Component asset in editor.Marked)
                        {
                            Component loaded;
                            if (asset is NotLoaded)
                            {
                                loaded = editor.Parser.Cabinet.LoadComponent(asset.pathID);
                                remove.Add(asset);
                                replace.Add(loaded);
                            }
                            else
                            {
                                loaded = asset;
                            }
                            switch (asset.classID2)
                            {
                            case UnityClassID.Texture2D:
                                Texture2D tex = (Texture2D)loaded;
                                tex.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.Cubemap:
                                Cubemap cubemap = (Cubemap)loaded;
                                cubemap.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.Material:
                                Material mat = (Material)loaded;
                                mat.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.Mesh:
                                Mesh mesh = (Mesh)loaded;
                                mesh.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.Shader:
                                Shader shader = (Shader)loaded;
                                shader.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.Sprite:
                                Sprite sprite = (Sprite)loaded;
                                sprite.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.Animator:
                                Parser.Cabinet.MergeTypeDefinition(loaded.file, UnityClassID.GameObject);
                                Parser.Cabinet.MergeTypeDefinition(loaded.file, UnityClassID.Transform);
                                Animator anim = (Animator)loaded;
                                anim.m_GameObject.instance.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.GameObject:
                                Parser.Cabinet.MergeTypeDefinition(loaded.file, UnityClassID.GameObject);
                                Parser.Cabinet.MergeTypeDefinition(loaded.file, UnityClassID.Transform);
                                GameObject gameObj = (GameObject)loaded;
                                Component  clone   = gameObj.Clone(Parser.Cabinet);

                                Animator vAnim = new Animator(Parser.Cabinet, 0, 0, 0);
                                vAnim.m_Avatar     = new PPtr <Avatar>((Component)null);
                                vAnim.m_GameObject = new PPtr <GameObject>(clone);
                                if (loaded.file.Bundle.numContainerEntries(gameObj.m_Name, UnityClassID.GameObject) > 1)
                                {
                                    Report.ReportLog("Warning! Animator " + gameObj.m_Name + " has multiple entries in the AssetBundle's Container.");
                                }
                                vAnim.file.Bundle.AddComponent(vAnim.m_GameObject.instance.m_Name, clone);
                                VirtualAnimators.Add(vAnim);
                                if (loaded != asset)
                                {
                                    foreach (Animator a in editor.VirtualAnimators)
                                    {
                                        if (a.m_GameObject.asset == asset)
                                        {
                                            a.m_GameObject = new PPtr <GameObject>(loaded);
                                            break;
                                        }
                                    }
                                }
                                break;

                            case UnityClassID.Avatar:
                                Avatar avatar = (Avatar)loaded;
                                avatar.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.MonoBehaviour:
                                MonoBehaviour monoB = (MonoBehaviour)loaded;
                                monoB.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.TextAsset:
                                TextAsset text = (TextAsset)loaded;
                                text.Clone(Parser.Cabinet);
                                break;

                            case UnityClassID.AnimationClip:
                                AnimationClip clip = (AnimationClip)loaded;
                                clip.Clone(Parser.Cabinet);
                                break;
                            }
                        }

                        do
                        {
                            HashSet <Tuple <Component, Component> > loopSet = new HashSet <Tuple <Component, Component> >(AssetCabinet.IncompleteClones);
                            AssetCabinet.IncompleteClones.Clear();
                            foreach (var pair in loopSet)
                            {
                                Component  src  = pair.Item1;
                                Component  dest = pair.Item2;
                                Type       t    = src.GetType();
                                MethodInfo info = t.GetMethod("CopyTo", new Type[] { t });
                                info.Invoke(src, new object[] { dest });
                            }
                        }while (AssetCabinet.IncompleteClones.Count > 0);

                        foreach (Component asset in remove)
                        {
                            editor.Marked.Remove(asset);
                        }
                        foreach (Component asset in replace)
                        {
                            editor.Marked.Add(asset);
                        }
                    }
                }
            }
            finally
            {
                Parser.Cabinet.EndLoadingSkippedComponents();
                if (components != Parser.Cabinet.Components.Count)
                {
                    Changed = true;
                }
            }
        }