示例#1
0
        public bool CreateVirtualAnimator(Component gameObject)
        {
            if (gameObject is NotLoaded && ((NotLoaded)gameObject).replacement != null)
            {
                gameObject = ((NotLoaded)gameObject).replacement;
            }
            if (gameObject is NotLoaded ? IsVirtualAnimator((NotLoaded)gameObject) : GetVirtualAnimator((GameObject)gameObject) != null)
            {
                return(false);
            }

            Animator animator = new Animator(Parser.Cabinet, 0, 0, 0);

            animator.m_Avatar     = new PPtr <Avatar>((Component)null);
            animator.m_GameObject = new PPtr <GameObject>(gameObject);
            VirtualAnimators.Add(animator);
            return(true);
        }
示例#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;
                }
            }
        }