public new RectTransform Clone(AssetCabinet file) { file.MergeTypeDefinition(this.file, UnityClassID.RectTransform); RectTransform clone = new RectTransform(file); clone.m_LocalRotation = m_LocalRotation; clone.m_LocalPosition = m_LocalPosition; clone.m_LocalScale = m_LocalScale; clone.m_AnchorMin = m_AnchorMin; clone.m_AnchorMax = m_AnchorMax; clone.m_AnchoredPosition = m_AnchoredPosition; clone.m_SizeDelta = m_SizeDelta; clone.m_Pivot = m_Pivot; clone.InitChildren(Count); for (int i = 0; i < Count; i++) { GameObject gameObj = this[i].m_GameObject.instance.Clone(file); clone.AddChild(gameObj.FindLinkedComponent(typeof(RectTransform))); } return(clone); }
public void CopyTo(MonoBehaviour dest) { GameObject destGameObj = dest.m_GameObject.instance; if (destGameObj != null) { Transform animFrame = destGameObj.FindLinkedComponent(typeof(Transform)); while (animFrame.Parent != null) { animFrame = animFrame.Parent; } UPPtr.AnimatorRoot = animFrame; } else { if (m_Name.Length > 0) { dest.file.Bundle.AddComponent(m_Name, dest); } UPPtr.AnimatorRoot = null; } Parser.type.CopyToRootClass(dest.Parser.type); if (dest.file.VersionNumber >= AssetCabinet.VERSION_5_5_0) { AssetCabinet.TypeDefinition destDef = dest.file.Types[(int)dest.classID1]; if (destDef.assetRefIndex == 0xFFFF) { for (int i = 0; i < dest.file.AssetRefs.Count; i++) { PPtr <Object> msRef = dest.file.AssetRefs[i]; if (msRef.asset == dest.m_MonoScript.asset) { destDef.assetRefIndex = (ushort)i; break; } } } } else if (dest.file.VersionNumber > AssetCabinet.VERSION_5_0_0 && dest.file.VersionNumber < AssetCabinet.VERSION_5_4_1) { MonoScript ms = dest.m_MonoScript.instance; int index = -1; if (ms != null) { for (int i = 0; i < dest.file.AssetRefs.Count; i++) { PPtr <Object> objPtr = dest.file.AssetRefs[i]; if (objPtr.asset == ms) { index = i; break; } } } dest.classID2 = (UnityClassID)(index << 16) | UnityClassID.MonoBehaviour; } }
public Transform Clone(AssetCabinet file) { Transform trans = new Transform(file); trans.m_LocalRotation = m_LocalRotation; trans.m_LocalPosition = m_LocalPosition; trans.m_LocalScale = m_LocalScale; trans.InitChildren(Count); for (int i = 0; i < Count; i++) { GameObject gameObj = this[i].m_GameObject.instance.Clone(file); trans.AddChild(gameObj.FindLinkedComponent(UnityClassID.Transform)); } return(trans); }
public void CopyTo(MonoBehaviour dest) { GameObject destGameObj = dest.m_GameObject.instance; if (destGameObj != null) { Transform animFrame = destGameObj.FindLinkedComponent(UnityClassID.Transform); while (animFrame.Parent != null) { animFrame = animFrame.Parent; } UPPtr.AnimatorRoot = animFrame; } else { UPPtr.AnimatorRoot = null; } Parser.type.CopyTo(dest.Parser.type); }
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); } }
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; } } } }
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); }