Example #1
0
        public static Animator OpenAnimator([DefaultVar] UnityParser parser, string name)
        {
            foreach (Component subfile in parser.Cabinet.Components)
            {
                if (subfile.classID() == UnityClassID.Animator)
                {
                    if (subfile is Animator)
                    {
                        Animator a = (Animator)subfile;
                        if (a.m_GameObject.instance.m_Name == name)
                        {
                            return(a);
                        }
                        continue;
                    }
                    NotLoaded animatorComp = (NotLoaded)subfile;
                    Stream    stream       = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed;

                    try
                    {
                        stream.Position = animatorComp.offset;
                        PPtr <GameObject> gameObjPtr = Animator.LoadGameObject(stream, parser.Cabinet.VersionNumber);
                        for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                        {
                            Component gameObjSubfile = parser.Cabinet.Components[i];
                            if (gameObjSubfile.pathID == gameObjPtr.m_PathID)
                            {
                                if (gameObjSubfile is GameObject)
                                {
                                    GameObject gameObj = (GameObject)gameObjSubfile;
                                    if (gameObj.m_Name == name)
                                    {
                                        return(parser.Cabinet.LoadComponent(stream, animatorComp));
                                    }
                                    break;
                                }
                                NotLoaded gameObjComp = (NotLoaded)gameObjSubfile;
                                stream.Position = gameObjComp.offset;
                                if (GameObject.LoadName(stream, parser.Cabinet.VersionNumber) == name)
                                {
                                    return(parser.Cabinet.LoadComponent(stream, animatorComp));
                                }
                                break;
                            }
                        }
                    }
                    finally
                    {
                        if (stream != parser.Uncompressed)
                        {
                            stream.Close();
                            stream.Dispose();
                        }
                    }
                }
            }
            return(null);
        }
Example #2
0
        private string GetNameFromGameObject(bool filter, Stream stream)
        {
            long pos = stream.Position;
            PPtr <GameObject> gameObjPtr = Animator.LoadGameObject(stream);

            if (gameObjPtr.m_PathID == 0)
            {
                stream.Position = pos;
                return(null);
            }
            NotLoaded asset = Parser.Cabinet.FindComponent(gameObjPtr.m_PathID);

            if (filter && asset.Name == null)
            {
                stream.Position = asset.offset;
                asset.Name      = GameObject.LoadName(stream);
            }
            return(asset.Name);
        }