예제 #1
0
 public void CopyTo(Material dest, bool cloneTextures)
 {
     dest.m_Name = m_Name;
     if (dest.file == file)
     {
         dest.m_Shader = m_Shader;
     }
     else if (m_Shader.instance == null)
     {
         if (m_Shader.m_FileID == 0)
         {
             dest.m_Shader = m_Shader;
         }
         else
         {
             string       assetPath = this.file.References[m_Shader.m_FileID - 1].assetPath;
             int          cabPos    = assetPath.LastIndexOf("/") + 1;
             AssetCabinet cab;
             if (!AssetCabinet.LoadedCabinets.TryGetValue(assetPath.Substring(cabPos), out cab))
             {
                 int fileID = dest.file.MergeReference(file, m_Shader.m_FileID);
                 dest.m_Shader          = new PPtr <Shader>((Component)null);
                 dest.m_Shader.m_FileID = fileID;
                 dest.m_Shader.m_PathID = m_Shader.m_PathID;
             }
             else
             {
                 Shader shader = cab.LoadComponent(m_Shader.m_PathID);
                 dest.m_Shader = new PPtr <Shader>(shader.Clone(dest.file));
             }
         }
     }
     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_LightmapFlags     = m_LightmapFlags;
     dest.m_CustomRenderQueue = m_CustomRenderQueue;
     if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
     {
         dest.stringTagMap = new List <KeyValuePair <FastPropertyName, FastPropertyName> >(stringTagMap);
         if (file.VersionNumber >= AssetCabinet.VERSION_5_6_2)
         {
             dest.m_EnableInstancingVariants = m_EnableInstancingVariants;
             dest.m_DoubleSidedGI            = m_DoubleSidedGI;
             dest.disabledShaderPasses       = new List <string>(disabledShaderPasses);
         }
     }
     m_SavedProperties.CopyTo(dest, cloneTextures);
 }
예제 #2
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;
                            }
                        }

                        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;
                }
            }
        }