public static TextAsset Import(string filePath) { TextAsset ta = new TextAsset(null, 0, UnityClassID.TextAsset, UnityClassID.TextAsset); ta.m_Name = Path.GetFileNameWithoutExtension(filePath); using (BinaryReader reader = new BinaryReader(File.OpenRead(filePath), System.Text.Encoding.UTF8)) { ta.m_Script = new string(reader.ReadChars((int)reader.BaseStream.Length)); } ta.m_PathName = string.Empty; return ta; }
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; }
public TextAsset Clone(AssetCabinet file) { Component text = file.Components.Find ( delegate(Component asset) { return asset.classID1 == UnityClassID.TextAsset && (asset is NotLoaded ? ((NotLoaded)asset).Name : ((TextAsset)asset).m_Name) == m_Name; } ); if (text == null) { file.MergeTypeDefinition(this.file, UnityClassID.TextAsset); TextAsset dest = new TextAsset(file); using (MemoryStream mem = new MemoryStream()) { this.WriteTo(mem); mem.Position = 0; dest.LoadFrom(mem); } return dest; } else if (text is NotLoaded) { NotLoaded notLoaded = (NotLoaded)text; text = file.LoadComponent(file.SourceStream, notLoaded); } return (TextAsset)text; }
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; case UnityClassID.AnimationClip: AnimationClip clip = (AnimationClip)loaded; clip.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; } } }
public void ExportTextAsset(Component asset, string path) { TextAsset text = LoadWhenNeeded(asset); text.Export(path); }