Exemplo n.º 1
0
        public static Transform CloneTransformTree(Animator parser, Transform frame, Transform parent)
        {
            Transform trans = new Transform(parser.file);
            GameObject gameObj = new GameObject(parser.file);
            gameObj.m_Name = (string)frame.m_GameObject.instance.m_Name.Clone();
            UniqueName(parser, gameObj);
            gameObj.AddLinkedComponent(trans);

            parser.m_Avatar.instance.AddBone(parent, trans);

            trans.m_LocalRotation = frame.m_LocalRotation;
            trans.m_LocalPosition = frame.m_LocalPosition;
            trans.m_LocalScale = frame.m_LocalScale;
            CopyUnknowns(frame, trans);

            trans.InitChildren(frame.Count);
            for (int i = 0; i < frame.Count; i++)
            {
                trans.AddChild(CloneTransformTree(parser, frame[i], trans));
            }

            return trans;
        }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
        public GameObject Clone(AssetCabinet file)
        {
            GameObject gameObj = new GameObject(file);

            for (int i = 0; i < m_Component.Count; i++)
            {
                Component asset = m_Component[i].Value.asset;

                Type t = asset.GetType();
                MethodInfo info = t.GetMethod("Clone", new Type[] { typeof(AssetCabinet) });
                if (info != null)
                {
                    LinkedByGameObject clone = (LinkedByGameObject)info.Invoke(asset, new object[] { file });
                    gameObj.AddLinkedComponent(clone);
                }
                else
                {
                    string msg = "No Clone method for " + asset.classID2;
                    if (!msgFilter.Contains(msg))
                    {
                        msgFilter.Add(msg);
                        Report.ReportLog(msg);
                    }
                }
            }

            gameObj.m_Layer = m_Layer;
            gameObj.m_Name = m_Name;
            gameObj.m_Tag = m_Tag;
            gameObj.m_isActive = m_isActive;
            return gameObj;
        }
Exemplo n.º 4
0
 static void UniqueName(Animator parser, GameObject gameObj)
 {
     string name = gameObj.m_Name;
     int attempt = 1;
     while (FindFrame(gameObj.m_Name, parser.RootTransform) != null)
     {
         gameObj.m_Name = name + ++attempt;
     }
 }
Exemplo n.º 5
0
        public static Transform CreateTransformTree(Animator parser, ImportedFrame frame, Transform parent)
        {
            Transform trans = new Transform(parser.file);
            GameObject gameObj = new GameObject(parser.file);
            gameObj.m_Name = (string)frame.Name.Clone();
            UniqueName(parser, gameObj);
            gameObj.AddLinkedComponent(trans);

            parser.m_Avatar.instance.AddBone(parent, trans);

            Vector3 t, s;
            Quaternion r;
            frame.Matrix.Decompose(out s, out r, out t);
            t.X *= -1;
            Vector3 euler = FbxUtility.QuaternionToEuler(r);
            euler.Y *= -1;
            euler.Z *= -1;
            trans.m_LocalRotation = FbxUtility.EulerToQuaternion(euler);
            trans.m_LocalPosition = t;
            trans.m_LocalScale = s;

            trans.InitChildren(frame.Count);
            for (int i = 0; i < frame.Count; i++)
            {
                trans.AddChild(CreateTransformTree(parser, frame[i], trans));
            }

            return trans;
        }
Exemplo n.º 6
0
        public void MergeFrame(Transform srcFrame, int destParentId)
        {
            Transform srcParent = new Transform(srcFrame.file);
            GameObject srcGameObj = new GameObject(srcFrame.file);
            srcGameObj.AddLinkedComponent(srcParent);
            srcParent.InitChildren(1);
            srcParent.AddChild(srcFrame);

            Transform destParent;
            if (destParentId < 0)
            {
                destParent = new Transform(srcFrame.file);
                GameObject destGameObj = new GameObject(srcFrame.file);
                destGameObj.AddLinkedComponent(destParent);
                destParent.InitChildren(1);
                destParent.AddChild(Parser.RootTransform);
                Parser.m_GameObject.instance.RemoveLinkedComponent(Parser);
            }
            else
            {
                destParent = Frames[destParentId];
            }

            MergeFrame(srcParent, destParent);

            if (destParentId < 0)
            {
                //Parser.RootTransform = srcParent[0];
                srcParent[0].m_GameObject.instance.AddLinkedComponent(Parser);
                srcParent.RemoveChild(0);
                destParent.m_GameObject.instance.RemoveLinkedComponent(destParent);
                srcFrame.file.RemoveSubfile(destParent.m_GameObject.instance);
                srcFrame.file.RemoveSubfile(destParent);
            }

            srcGameObj.RemoveLinkedComponent(srcParent);
            srcFrame.file.RemoveSubfile(srcGameObj);
            srcFrame.file.RemoveSubfile(srcParent);

            if (Parser.file.Bundle != null)
            {
                Parser.file.Bundle.RegisterForUpdate(Parser.m_GameObject.asset);
            }
            InitLists();
            Changed = true;
        }
Exemplo n.º 7
0
 public Animator GetVirtualAnimator(GameObject gameObject)
 {
     foreach (Animator a in VirtualAnimators)
     {
         if (a.m_GameObject.asset == gameObject ||
             a.m_GameObject.asset is NotLoaded && ((NotLoaded)a.m_GameObject.asset).replacement == gameObject)
         {
             return a;
         }
     }
     return null;
 }