Example #1
0
        public new void LoadFrom(Stream stream)
        {
            base.LoadFrom(stream);

            BinaryReader reader = new BinaryReader(stream);

            m_Quality             = reader.ReadInt32();
            m_UpdateWhenOffScreen = reader.ReadBoolean();
            if (file.VersionNumber >= AssetCabinet.VERSION_5_4_1)
            {
                m_SkinnedMotionVectors = reader.ReadBoolean();
                stream.Position       += 2;
            }
            else
            {
                stream.Position += 3;
            }
            m_Mesh = new PPtr <Mesh>(stream, file);

            int numBones = reader.ReadInt32();

            m_Bones = new List <PPtr <Transform> >(numBones);
            for (int i = 0; i < numBones; i++)
            {
                m_Bones.Add(new PPtr <Transform>(stream, file));
            }

            int numBSWeights = reader.ReadInt32();

            m_BlendShapeWeights = new List <float>(numBSWeights);
            for (int i = 0; i < numBSWeights; i++)
            {
                m_BlendShapeWeights.Add(reader.ReadSingle());
            }

            m_RootBone       = new PPtr <Transform>(stream, file);
            m_AABB           = new AABB(stream);
            m_DirtyAABB      = reader.ReadBoolean();
            stream.Position += 3;
        }
Example #2
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_GameObject    = new PPtr <GameObject>(stream, file);
            m_ConnectedBody = new PPtr <Rigidbody>(stream, file);
            m_Anchor        = reader.ReadVector3();
            m_Axis          = reader.ReadVector3();
            m_AutoConfigureConnectedAnchor = reader.ReadBoolean();
            stream.Position  += 3;
            m_ConnectedAnchor = reader.ReadVector3();
            m_SwingAxis       = reader.ReadVector3();
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                m_TwistLimitSpring = new SoftJointLimitSpring(stream);
            }
            m_LowTwistLimit  = new SoftJointLimit(stream, file.VersionNumber);
            m_HighTwistLimit = new SoftJointLimit(stream, file.VersionNumber);
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                m_SwingLimitSpring = new SoftJointLimitSpring(stream);
            }
            m_Swing1Limit = new SoftJointLimit(stream, file.VersionNumber);
            m_Swing2Limit = new SoftJointLimit(stream, file.VersionNumber);
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                m_EnableProjection   = reader.ReadBoolean();
                stream.Position     += 3;
                m_ProjectionDistance = reader.ReadSingle();
                m_ProjectionAngle    = reader.ReadSingle();
            }
            m_BreakForce      = reader.ReadSingle();
            m_BreakTorque     = reader.ReadSingle();
            m_EnableCollision = reader.ReadBoolean();
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                m_EnablePreprocessing = reader.ReadBoolean();
            }
        }
Example #3
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            int numComponents = reader.ReadInt32();

            m_Component = new List <KeyValuePair <UnityClassID, PPtr <Component> > >(numComponents);
            if (file.VersionNumber < AssetCabinet.VERSION_5_5_0)
            {
                for (int i = 0; i < numComponents; i++)
                {
                    m_Component.Add
                    (
                        new KeyValuePair <UnityClassID, PPtr <Component> >
                        (
                            (UnityClassID)reader.ReadInt32(),
                            new PPtr <Component>(stream, file)
                        )
                    );
                }
            }
            else
            {
                for (int i = 0; i < numComponents; i++)
                {
                    PPtr <Component> ptr = new PPtr <Component>(stream, file);
                    m_Component.Add
                    (
                        new KeyValuePair <UnityClassID, PPtr <Component> >(ptr.asset.classID(), ptr)
                    );
                }
            }

            m_Layer    = reader.ReadUInt32();
            m_Name     = reader.ReadNameA4U8();
            m_Tag      = reader.ReadUInt16();
            m_isActive = reader.ReadBoolean();
        }
Example #4
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_GameObject     = new PPtr <GameObject>(stream, file);
            m_Enabled        = reader.ReadByte();
            stream.Position += 3;
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                OutputAudioMixerGroup = new PPtr <Object>(stream, file);
            }
            m_audioClip           = new PPtr <AudioClip>(stream, file);
            m_PlayOnAwake         = reader.ReadBoolean();
            stream.Position      += 3;
            m_Volume              = reader.ReadSingle();
            m_Pitch               = reader.ReadSingle();
            Loop                  = reader.ReadBoolean();
            Mute                  = reader.ReadBoolean();
            Spatialize            = reader.ReadBoolean();
            stream.Position      += 1;
            Priority              = reader.ReadInt32();
            DopplerLevel          = reader.ReadSingle();
            MinDistance           = reader.ReadSingle();
            MaxDistance           = reader.ReadSingle();
            Pan2D                 = reader.ReadSingle();
            rolloffMode           = reader.ReadInt32();
            BypassEffects         = reader.ReadBoolean();
            BypassListenerEffects = reader.ReadBoolean();
            BypassReverbZones     = reader.ReadBoolean();
            stream.Position      += 1;
            rolloffCustomCurve    = new AnimationCurve <float>(reader, reader.ReadSingle, file.VersionNumber);
            panLevelCustomCurve   = new AnimationCurve <float>(reader, reader.ReadSingle, file.VersionNumber);
            spreadCustomCurve     = new AnimationCurve <float>(reader, reader.ReadSingle, file.VersionNumber);
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                reverbZoneMixCustomCurve = new AnimationCurve <float>(reader, reader.ReadSingle, file.VersionNumber);
            }
        }
Example #5
0
        private static void AddExternalAsset(List <Component> assets, PPtr <Shader> dep)
        {
            Component found = assets.Find
                              (
                delegate(Component c)
            {
                if (c is ExternalAsset)
                {
                    ExternalAsset e = (ExternalAsset)c;
                    return(e.FileID == dep.m_FileID && e.PathID == dep.m_PathID);
                }
                return(false);
            }
                              );

            if (found == null)
            {
                ExternalAsset extShader = new ExternalAsset();
                extShader.FileID = dep.m_FileID;
                extShader.PathID = dep.m_PathID;
                assets.Add(extShader);
            }
        }
Example #6
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_GameObject = new PPtr <GameObject>(stream, file);
            m_Enabled    = reader.ReadByte();
            reader.ReadBytes(3);
            m_Type                = reader.ReadInt32();
            m_Color               = reader.ReadColor4();
            m_Intensity           = reader.ReadSingle();
            m_Range               = reader.ReadSingle();
            m_SpotAngle           = reader.ReadSingle();
            m_CookieSize          = reader.ReadSingle();
            m_Shadows             = new ShadowSettings(stream);
            m_Cookie              = new PPtr <Texture2D>(stream, file);
            m_DrawHalo            = reader.ReadBoolean();
            m_ActuallyLightmapped = reader.ReadBoolean();
            reader.ReadBytes(2);
            m_Flare        = new PPtr <Flare>(stream, file);
            m_RenderMode   = reader.ReadInt32();
            m_CullingMask  = new BitField(stream);
            m_Lightmapping = reader.ReadInt32();
        }
Example #7
0
        public AssetInfo(AssetCabinet file, Stream stream)
        {
            this.file = file;
            BinaryReader reader = new BinaryReader(stream);

            preloadIndex = reader.ReadInt32();
            preloadSize  = reader.ReadInt32();
            PPtr <Object> objPtr = new PPtr <Object>(stream);

            if (objPtr.m_FileID == 0 && objPtr.m_PathID != 0)
            {
                Component comp = file.FindComponent(objPtr.m_PathID, false);
                if (comp == null)
                {
                    comp = new NotLoaded(file, objPtr.m_PathID, 0, 0);
                }
                asset = new PPtr <Object>(comp);
            }
            else
            {
                asset = objPtr;
            }
        }
Example #8
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_GameObject     = new PPtr <GameObject>(stream, file);
            m_Enabled        = reader.ReadByte();
            stream.Position += 3;
            m_Animation      = new PPtr <AnimationClip>(stream, file);

            int numAnimations = reader.ReadInt32();

            m_Animations = new List <PPtr <AnimationClip> >(numAnimations);
            for (int i = 0; i < numAnimations; i++)
            {
                m_Animations.Add(new PPtr <AnimationClip>(stream, file));
            }

            m_WrapMode          = reader.ReadInt32();
            m_PlayAutomatically = reader.ReadBoolean();
            m_AnimatePhysics    = reader.ReadBoolean();
            stream.Position    += 2;
            m_CullingType       = reader.ReadInt32();
        }
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            enabled = reader.ReadBoolean();
            reader.ReadBytes(3);
            type   = reader.ReadInt32();
            plane0 = new PPtr <Transform>(stream, file);
            plane1 = new PPtr <Transform>(stream, file);
            plane2 = new PPtr <Transform>(stream, file);
            plane3 = new PPtr <Transform>(stream, file);
            plane4 = new PPtr <Transform>(stream, file);
            plane5 = new PPtr <Transform>(stream, file);
            dampen = reader.ReadSingle();
            bounce = reader.ReadSingle();
            energyLossOnCollision = reader.ReadSingle();
            minKillSpeed          = reader.ReadSingle();
            particleRadius        = reader.ReadSingle();
            collidesWith          = new BitField(stream);
            quality           = reader.ReadInt32();
            voxelSize         = reader.ReadSingle();
            collisionMessages = reader.ReadBoolean();
            reader.ReadBytes(3);
        }
Example #10
0
        public void CopyTo(LoadedByTypeDefinition dest)
        {
            UPPtr.AnimatorRoot = null;
            PPtr <GameObject> gameObjPtr = dest.m_GameObject;

            if (gameObjPtr != null)
            {
                GameObject gameObj = (GameObject)gameObjPtr.asset;
                if (gameObj != null)
                {
                    Transform trans = gameObj.FindLinkedComponent(typeof(Transform));
                    while (trans.Parent != null)
                    {
                        trans = trans.Parent;
                    }
                    UPPtr.AnimatorRoot = trans;
                }
                parser.type.CopyToRootClass(dest.parser.type);
            }
            else
            {
                parser.type.CopyTo(dest.parser.type);
            }
        }
Example #11
0
        private void UpdateComponent(Component asset, List <Tuple <List <PPtr <Object> >, List <KeyValuePair <string, AssetInfo> > > > containerGroups)
        {
            List <Component> assets           = new List <Component>();
            List <Component> transforms       = new List <Component>();
            List <Component> containerRelated = new List <Component>();

            GetDependantAssets(asset, assets, transforms, containerRelated);
            if (asset.classID1 == UnityClassID.GameObject)
            {
                GameObject gameObj  = (GameObject)asset;
                Animator   animator = gameObj.FindLinkedComponent(UnityClassID.Animator);
                if (animator == null)
                {
                    foreach (Component trans in transforms)
                    {
                        GetDependantAssets(trans, assets, null, null);
                    }
                    animator              = new Animator(null, 0, UnityClassID.Animator, UnityClassID.Animator);
                    animator.m_Avatar     = new PPtr <Avatar>((Component)null);
                    animator.m_Controller = new PPtr <RuntimeAnimatorController>((Component)null);
                    GetDependantAssets(animator, assets, transforms, containerRelated);
                    assets.Remove(animator);
                }
            }
            foreach (var group in containerGroups)
            {
                var preloadPart      = group.Item1;
                var containerEntries = group.Item2;
                for (int i = 0; i < containerEntries.Count; i++)
                {
                    var assetPair = containerEntries[i];
                    if (assetPair.Value.asset.asset == asset)
                    {
                        preloadPart.Clear();
                        for (int j = 0; j < assets.Count; j++)
                        {
                            if (assets[j] is ExternalAsset)
                            {
                                ExternalAsset extAsset     = (ExternalAsset)assets[j];
                                PPtr <Object> preloadEntry = new PPtr <Object>((Component)null);
                                preloadEntry.m_FileID = extAsset.FileID;
                                preloadEntry.m_PathID = extAsset.PathID;
                                preloadPart.Add(preloadEntry);
                            }
                            else
                            {
                                preloadPart.Add(new PPtr <Object>(assets[j]));
                            }
                        }

                        string groupName = containerEntries[0].Key;
                        string assetName = AssetCabinet.ToString(asset);
                        if (String.Compare(groupName, assetName, true) != 0)
                        {
                            groupName = assetName.ToLower();
                        }
                        if (containerEntries.Count > 1)
                        {
                            for (int j = 0; j < containerEntries.Count; j++)
                            {
                                switch (containerEntries[j].Value.asset.asset.classID1)
                                {
                                case UnityClassID.Mesh:
                                case UnityClassID.AnimationClip:
                                    containerEntries.RemoveAt(j);
                                    j--;
                                    break;
                                }
                            }
                            for (int j = containerRelated.Count - 1; j >= 0; j--)
                            {
                                AnimationClip clip = containerRelated[j] as AnimationClip;
                                if (clip != null)
                                {
                                    AssetInfo info = new AssetInfo(file);
                                    info.asset = new PPtr <Object>(clip);
                                    containerEntries.Insert(1, new KeyValuePair <string, AssetInfo>(groupName, info));
                                }
                            }
                            for (int j = containerRelated.Count - 1; j >= 0; j--)
                            {
                                MeshRenderer meshR = containerRelated[j] as MeshRenderer;
                                if (meshR != null)
                                {
                                    Mesh mesh = Operations.GetMesh(meshR);
                                    if (mesh != null)
                                    {
                                        AssetInfo info = new AssetInfo(file);
                                        info.asset = new PPtr <Object>(mesh);
                                        containerEntries.Insert(1, new KeyValuePair <string, AssetInfo>(groupName, info));
                                    }
                                }
                            }
                            for (int j = 0; j < containerEntries.Count; j++)
                            {
                                containerEntries[j].Value.preloadSize = assets.Count;
                            }
                        }
                        else
                        {
                            containerEntries[0].Value.preloadSize = assets.Count;
                        }
                        for (int j = 0; j < containerEntries.Count; j++)
                        {
                            if (containerEntries[j].Key != groupName)
                            {
                                containerEntries[j] = new KeyValuePair <string, AssetInfo>(groupName, containerEntries[j].Value);
                            }
                        }
                        return;
                    }
                }
            }
        }
Example #12
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_Name = reader.ReadNameA4();

            int numObjects = reader.ReadInt32();

            m_PreloadTable = new List <PPtr <Object> >(numObjects);
            for (int i = 0; i < numObjects; i++)
            {
                PPtr <Object> objPtr = new PPtr <Object>(stream);
                if (objPtr.m_FileID == 0)
                {
                    Component comp = file.FindComponent(objPtr.m_PathID, false);
                    if (comp == null)
                    {
                        comp = new NotLoaded(file, objPtr.m_PathID, 0, 0);
                    }
                    objPtr = new PPtr <Object>(comp);
                }
                m_PreloadTable.Add(objPtr);
            }

            int numContainerEntries = reader.ReadInt32();

            m_Container = new List <KeyValuePair <string, AssetInfo> >(numContainerEntries);
            for (int i = 0; i < numContainerEntries; i++)
            {
                m_Container.Add
                (
                    new KeyValuePair <string, AssetInfo>
                    (
                        reader.ReadNameA4(), new AssetInfo(file, stream)
                    )
                );
            }

            m_MainAsset = new AssetInfo(file, stream);

            int numScriptComps = reader.ReadInt32();

            m_ScriptCompatibility = new AssetBundleScriptInfo[numScriptComps];
            for (int i = 0; i < numScriptComps; i++)
            {
                m_ScriptCompatibility[i] = new AssetBundleScriptInfo(stream);
            }

            int numClassComps = reader.ReadInt32();

            m_ClassCompatibility = new KeyValuePair <int, uint> [numClassComps];
            for (int i = 0; i < numClassComps; i++)
            {
                m_ClassCompatibility[i] = new KeyValuePair <int, uint>
                                          (
                    reader.ReadInt32(), reader.ReadUInt32()
                                          );
            }

            m_RuntimeCompatibility = reader.ReadUInt32();
        }
Example #13
0
 public void LoadFrom(Stream stream)
 {
     m_OriginalClip = new PPtr <AnimationClip>(stream, file);
     m_OverrideClip = new PPtr <AnimationClip>(stream, file);
 }
Example #14
0
 public AnimationClipOverride(AssetCabinet file, AnimationClip original, AnimationClip overrideClip)
 {
     this.file      = file;
     m_OriginalClip = new PPtr <AnimationClip>(original);
     m_OverrideClip = new PPtr <AnimationClip>(overrideClip);
 }
Example #15
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_GameObject = new PPtr <GameObject>(stream, file);
            m_Enabled    = reader.ReadBoolean();
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0 && file.VersionNumber < AssetCabinet.VERSION_5_4_1)
            {
                stream.Position += 3;
            }
            m_CastShadows    = reader.ReadByte();
            m_ReceiveShadows = reader.ReadByte();
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                if (file.VersionNumber >= AssetCabinet.VERSION_5_4_1)
                {
                    m_MotionVectors        = reader.ReadByte();
                    m_LightProbeUsage      = reader.ReadByte();
                    m_ReflectionProbeUsage = reader.ReadByte();
                }
                stream.Position += 2;
            }
            m_LightmapIndex        = file.VersionNumber >= AssetCabinet.VERSION_5_0_0 ? reader.ReadInt32() : reader.ReadByte();
            m_LightmapTilingOffset = reader.ReadVector4();
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                m_LightmapTilingOffsetDynamic = reader.ReadVector4();
            }

            int numMaterials = reader.ReadInt32();

            m_Materials = new List <PPtr <Material> >(numMaterials);
            for (int i = 0; i < numMaterials; i++)
            {
                m_Materials.Add(new PPtr <Material>(stream, file));
            }

            if (file.VersionNumber < AssetCabinet.VERSION_5_5_0)
            {
                int numSubsetIndices = reader.ReadInt32();
                m_SubsetIndices = reader.ReadUInt32Array(numSubsetIndices);
            }
            else
            {
                m_StaticBatchInfo = new StaticBatchInfo(stream);
            }

            m_StaticBatchRoot = new PPtr <Transform>(stream, file);
            if (file.VersionNumber < AssetCabinet.VERSION_5_4_1)
            {
                m_LightProbeUsage = reader.ReadByte();
                stream.Position  += 3;
                if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
                {
                    m_ReflectionProbeUsage = reader.ReadInt32();
                }
            }
            m_ProbeAnchor = new PPtr <Transform>(stream, file);
            if (file.VersionNumber >= AssetCabinet.VERSION_5_4_1)
            {
                m_LightProbeVolumeOverride = new PPtr <GameObject>(stream, file);
            }
            m_SortingLayerID = reader.ReadUInt32();
            if (file.VersionNumber >= AssetCabinet.VERSION_5_6_2)
            {
                m_SortingLayer = reader.ReadInt16();
            }
            m_SortingOrder = reader.ReadInt16();
            if (file.VersionNumber < AssetCabinet.VERSION_5_6_2)
            {
                stream.Position += 2;
            }
            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0 && classID1 == UnityClassID.MeshRenderer)
            {
                m_AdditionalVertexStreams = new PPtr <Mesh>(stream, file);
            }
        }
Example #16
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_GameObject = new PPtr <GameObject>(stream, file);
        }
Example #17
0
 public void LoadFrom(Stream stream)
 {
     m_GameObject = new PPtr <GameObject>(stream, file);
     m_Mesh       = new PPtr <Mesh>(stream, file);
 }
Example #18
0
 public override void LoadFrom(Stream stream)
 {
     Value = new PPtr <Object>(stream, file);
 }
Example #19
0
        public override void CopyTo(UType dest)
        {
            Component asset = null;

            if (Value.asset != null)
            {
                string name = AssetCabinet.ToString(Value.asset);
                asset = ((UPPtr)dest).file.Bundle.FindComponent(name, Value.asset.classID());
                if (asset == null)
                {
                    switch (Value.asset.classID())
                    {
                    case UnityClassID.GameObject:
                        if (((UPPtr)dest).Value == null)
                        {
                            GameObject gObj = (GameObject)Value.asset;
                            if (gObj != null)
                            {
                                Transform trans = gObj.FindLinkedComponent(typeof(Transform));
                                trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                                if (trans != null)
                                {
                                    asset = trans.m_GameObject.instance;
                                    break;
                                }
                            }
                            Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                            break;
                        }
                        return;

                    case UnityClassID.Light:
                        GameObject gameObj = ((Light)Value.asset).m_GameObject.instance;
                        if (gameObj != null)
                        {
                            Transform trans = gameObj.FindLinkedComponent(typeof(Transform));
                            trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                            if (trans != null)
                            {
                                asset = trans.m_GameObject.instance.FindLinkedComponent(UnityClassID.Light);
                            }
                            else
                            {
                                foreach (Component a in ((UPPtr)dest).file.Components)
                                {
                                    if (a.classID() == UnityClassID.Light)
                                    {
                                        string n = a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a);
                                        if (n == name)
                                        {
                                            asset = a;
                                            Report.ReportLog("Warning! Unsharp search for PPtr<" + Value.asset.classID() + "> " + Name + " to " + name + " found PathID=" + a.pathID);
                                            break;
                                        }
                                    }
                                }
                                if (asset == null)
                                {
                                    Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                                }
                            }
                        }
                        break;

                    case UnityClassID.MonoBehaviour:
                        gameObj = ((MonoBehaviour)Value.asset).m_GameObject.instance;
                        if (gameObj != null)
                        {
                            Transform trans = gameObj.FindLinkedComponent(typeof(Transform));
                            trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                            if (trans != null)
                            {
                                AssetCabinet.TypeDefinition srcDef =
                                    this.file.VersionNumber < AssetCabinet.VERSION_5_5_0
                                                                        ? this.file.Types.Find
                                    (
                                        delegate(AssetCabinet.TypeDefinition def)
                                {
                                    return(def.typeId == (int)((MonoBehaviour)Value.asset).classID1);
                                }
                                    )
                                                                        : this.file.Types[(int)((MonoBehaviour)Value.asset).classID1];
                                bool found       = false;
                                var  m_Component = trans.m_GameObject.instance.m_Component;
                                for (int i = 0; i < m_Component.Count; i++)
                                {
                                    if (m_Component[i].Value.asset != null && m_Component[i].Value.asset.classID() == UnityClassID.MonoBehaviour)
                                    {
                                        AssetCabinet.TypeDefinition destDef =
                                            ((UPPtr)dest).file.VersionNumber < AssetCabinet.VERSION_5_5_0
                                                                                        ? ((UPPtr)dest).file.Types.Find
                                            (
                                                delegate(AssetCabinet.TypeDefinition def)
                                        {
                                            return(def.typeId == (int)((MonoBehaviour)m_Component[i].Value.asset).classID1);
                                        }
                                            )
                                                                                        : ((UPPtr)dest).file.Types[(int)((MonoBehaviour)m_Component[i].Value.asset).classID1];
                                        if (AssetCabinet.CompareTypes(destDef, srcDef))
                                        {
                                            asset = m_Component[i].Value.asset;
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found)
                                {
                                    asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                                    trans.m_GameObject.instance.AddLinkedComponent((LinkedByGameObject)asset);
                                }
                            }
                            else
                            {
                                Report.ReportLog("Error! Reference to " + Value.asset.classID() + " " + name + " lost. Member " + Name);
                            }
                        }
                        else
                        {
                            asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                        }
                        break;

                    case UnityClassID.MonoScript:
                        asset = ((MonoScript)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Sprite:
                        asset = ((Sprite)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Transform:
                        asset = AnimatorRoot != null?Operations.FindFrame(((Transform)Value.asset).GetTransformPath(), AnimatorRoot) : null;

                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Reference to " + UnityClassID.Transform + " " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Material:
                        asset = ((Material)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.MeshRenderer:
                    case UnityClassID.SkinnedMeshRenderer:
                        asset = AnimatorRoot != null?Operations.FindMesh(AnimatorRoot, name) : null;

                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Reference to " + Value.asset.classID() + " " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Texture2D:
                        asset = ((Texture2D)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Cubemap:
                        asset = ((Cubemap)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    default:
                        if (Value.asset is LoadedByTypeDefinition)
                        {
                            LoadedByTypeDefinition loadedByTypeDef = (LoadedByTypeDefinition)Value.asset;
                            PPtr <GameObject>      gameObjPtr      = loadedByTypeDef.m_GameObject;
                            if (gameObjPtr == null)
                            {
                                AssetCabinet file = ((UPPtr)dest).file;
                                foreach (Component a in file.Components)
                                {
                                    if (a.classID() == loadedByTypeDef.classID() &&
                                        (a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a)) == loadedByTypeDef.m_Name)
                                    {
                                        asset = a;

                                        file = null;
                                        break;
                                    }
                                }
                                if (file != null)
                                {
                                    asset = loadedByTypeDef.Clone(file);
                                }
                            }
                            else
                            {
                                Transform srcTrans  = gameObjPtr.instance.FindLinkedComponent(typeof(Transform));
                                Transform destTrans = AnimatorRoot != null?Operations.FindFrame(srcTrans.GetTransformPath(), AnimatorRoot) : null;

                                if (destTrans != null)
                                {
                                    asset = destTrans.m_GameObject.instance.FindLinkedComponent(loadedByTypeDef.classID());
                                }
                                else
                                {
                                    foreach (Component a in ((UPPtr)dest).file.Components)
                                    {
                                        if (a.classID() == Value.asset.classID())
                                        {
                                            string n = a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a);
                                            if (n == name)
                                            {
                                                asset = a;
                                                Report.ReportLog("Warning! Unsharp search for PPtr<" + Value.asset.classID() + "> " + Name + " to " + name + " found PathID=" + a.pathID);
                                                break;
                                            }
                                        }
                                    }
                                    if (asset == null)
                                    {
                                        Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Report.ReportLog("Warning! Reference to " + Value.asset.classID() + " " + name + " unhandled. Member " + Name);
                        }
                        break;
                    }
                }
            }
            ((UPPtr)dest).Value = new PPtr <Object>(asset);
        }
Example #20
0
 public void LoadFrom(Stream stream)
 {
     renderer = new PPtr <MeshRenderer>(stream, file);
 }
Example #21
0
        private static void GetDependantAssets(Component asset, List <Component> assets, List <Component> transforms, List <Component> containerRelated)
        {
            if (asset != null && !assets.Contains(asset))
            {
                assets.Add(asset);
                switch (asset.classID1)
                {
                case UnityClassID.Animator:
                    Animator animator = (Animator)asset;
                    GetDependantAssets(animator.m_Avatar.asset, assets, transforms, containerRelated);
                    GetDependantAssets(animator.m_Controller.asset, assets, transforms, containerRelated);
                    foreach (Component ren in containerRelated)
                    {
                        GetDependantAssets(ren, assets, null, null);
                        if (ren is MeshRenderer)
                        {
                            MeshRenderer meshR   = (MeshRenderer)ren;
                            PPtr <Mesh>  meshPtr = Operations.GetMeshPtr(meshR);
                            if (meshPtr != null)
                            {
                                if (meshPtr.m_FileID != 0)
                                {
                                    Component found = assets.Find
                                                      (
                                        delegate(Component c)
                                    {
                                        if (c is ExternalAsset)
                                        {
                                            ExternalAsset e = (ExternalAsset)c;
                                            return(e.FileID == meshPtr.m_FileID && e.PathID == meshPtr.m_PathID);
                                        }
                                        return(false);
                                    }
                                                      );
                                    if (found == null)
                                    {
                                        ExternalAsset extMesh = new ExternalAsset();
                                        extMesh.FileID = meshPtr.m_FileID;
                                        extMesh.PathID = meshPtr.m_PathID;
                                        assets.Add(extMesh);
                                    }
                                }
                                else if (meshPtr.instance != null && !assets.Contains(meshPtr.instance))
                                {
                                    assets.Add(meshPtr.instance);
                                }
                            }
                            foreach (PPtr <Material> matPtr in meshR.m_Materials)
                            {
                                if (!assets.Contains(matPtr.asset))
                                {
                                    GetDependantAssets(matPtr.asset, assets, null, null);
                                }
                            }
                        }
                    }
                    assets.Sort
                    (
                        delegate(Component c1, Component c2)
                    {
                        if (c1 is ExternalAsset)
                        {
                            ExternalAsset e1 = (ExternalAsset)c1;
                            if (c2 is ExternalAsset)
                            {
                                ExternalAsset e2 = (ExternalAsset)c2;
                                return(e1.FileID != e2.FileID ? e1.FileID.CompareTo(e2.FileID)
                                                                                : e1.PathID.CompareTo(e2.PathID));
                            }
                            return(-1);
                        }
                        else if (c2 is ExternalAsset)
                        {
                            return(1);
                        }
                        return(c1.pathID.CompareTo(c2.pathID));
                    }
                    );
                    break;

                case UnityClassID.Avatar:
                    break;

                case UnityClassID.AnimatorController:
                    AnimatorController aCon = (AnimatorController)asset;
                    for (int i = 0; i < aCon.m_AnimationClips.Count; i++)
                    {
                        assets.Add(aCon.m_AnimationClips[i].asset);
                        containerRelated.Add(aCon.m_AnimationClips[i].asset);
                    }
                    break;

                case UnityClassID.AnimationClip:
                    break;

                case UnityClassID.GameObject:
                    GameObject gameObj = (GameObject)asset;
                    animator = null;
                    foreach (var compPair in gameObj.m_Component)
                    {
                        switch (compPair.Key)
                        {
                        case UnityClassID.Transform:
                            Transform trans = (Transform)compPair.Value.instance;
                            transforms.Add(trans);
                            foreach (Transform child in trans)
                            {
                                GetDependantAssets(child.m_GameObject.asset, assets, transforms, containerRelated);
                            }
                            break;

                        case UnityClassID.Animator:
                            animator = (Animator)compPair.Value.asset;
                            break;

                        case UnityClassID.MeshRenderer:
                        case UnityClassID.MeshFilter:
                        case UnityClassID.SkinnedMeshRenderer:
                            containerRelated.Add(compPair.Value.asset);
                            break;

                        case UnityClassID.MonoBehaviour:
                            GetDependantAssets(compPair.Value.asset, assets, transforms, containerRelated);
                            break;

                        default:
                            if (!assets.Contains(compPair.Value.asset))
                            {
                                assets.Add(compPair.Value.asset);
                            }
                            break;
                        }
                    }
                    if (animator != null)
                    {
                        foreach (Component trans in transforms)
                        {
                            GetDependantAssets(trans, assets, null, null);
                        }
                        GetDependantAssets(animator, assets, transforms, containerRelated);
                    }
                    break;

                case UnityClassID.Light:
                    break;

                default:
                    if (asset.classID2 == UnityClassID.MonoBehaviour)
                    {
                        MonoBehaviour monoB = (MonoBehaviour)asset;
                        if (!assets.Contains(monoB.m_MonoScript.asset))
                        {
                            assets.Add(monoB.m_MonoScript.asset);
                        }
                    }
                    break;

                case UnityClassID.MonoScript:
                    break;

                case UnityClassID.Transform:
                    break;

                case UnityClassID.MeshRenderer:
                case UnityClassID.MeshFilter:
                case UnityClassID.SkinnedMeshRenderer:
                    break;

                case UnityClassID.Material:
                    Material mat = (Material)asset;
                    foreach (var texVal in mat.m_SavedProperties.m_TexEnvs)
                    {
                        GetDependantAssets(texVal.Value.m_Texture.asset, assets, transforms, containerRelated);
                    }
                    if (mat.m_Shader.m_FileID != 0)
                    {
                        AddExternalAsset(assets, mat.m_Shader);
                    }
                    else if (mat.m_Shader.instance != null)
                    {
                        GetDependantAssets(mat.m_Shader.asset, assets, transforms, containerRelated);
                    }
                    break;

                case UnityClassID.Shader:
                    Shader shader = (Shader)asset;
                    foreach (PPtr <Shader> dep in shader.m_Dependencies)
                    {
                        if (dep.m_FileID != 0)
                        {
                            AddExternalAsset(assets, dep);
                        }
                        else if (dep.asset != null)
                        {
                            GetDependantAssets(dep.asset, assets, transforms, containerRelated);
                        }
                    }
                    break;

                case UnityClassID.Sprite:
                    assets.Remove(asset);
                    Sprite sprite = (Sprite)asset;
                    assets.Add(sprite.m_RD.texture.asset);
                    assets.Add(sprite);
                    break;

                case UnityClassID.Texture2D:
                    break;
                }
            }
        }
Example #22
0
 public GenericBinding()
 {
     script = new PPtr <Object>((Component)null);
     typeID = (uint)UnityClassID.Transform;
 }
Example #23
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            m_Name   = reader.ReadNameA4U8();
            m_Shader = new PPtr <Shader>(stream, file);

            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                string   space_separated   = reader.ReadNameA4U8();
                string[] split             = space_separated.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int      numShaderKeywords = split.Length;
                m_ShaderKeywords = new List <string>(numShaderKeywords);
                for (int i = 0; i < numShaderKeywords; i++)
                {
                    m_ShaderKeywords.Add(split[i]);
                }
                m_LightmapFlags = reader.ReadUInt32();

                if (file.VersionNumber >= AssetCabinet.VERSION_5_6_2)
                {
                    m_EnableInstancingVariants = reader.ReadBoolean();
                    m_DoubleSidedGI            = reader.ReadBoolean();
                    stream.Position           += 2;
                }
            }
            else
            {
                int numShaderKeywords = reader.ReadInt32();
                m_ShaderKeywords = new List <string>(numShaderKeywords);
                for (int i = 0; i < numShaderKeywords; i++)
                {
                    m_ShaderKeywords.Add(reader.ReadNameA4U8());
                }
            }

            m_CustomRenderQueue = reader.ReadInt32();

            if (file.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                int numNames = reader.ReadInt32();
                stringTagMap = new List <KeyValuePair <FastPropertyName, FastPropertyName> >(numNames);
                for (int i = 0; i < numNames; i++)
                {
                    stringTagMap.Add
                    (
                        new KeyValuePair <FastPropertyName, FastPropertyName>
                        (
                            new FastPropertyName(stream),
                            new FastPropertyName(stream)
                        )
                    );
                }

                if (file.VersionNumber >= AssetCabinet.VERSION_5_6_2)
                {
                    int numPasses = reader.ReadInt32();
                    disabledShaderPasses = new List <string>(numPasses);
                    for (int i = 0; i < numPasses; i++)
                    {
                        disabledShaderPasses.Add(reader.ReadNameA4U8());
                    }
                }
            }

            m_SavedProperties = new UnityPropertySheet(file, stream);
        }