public IEnumerable<AssetReference> LoadAssets(AssetContainer<Func<Texture2D>> textureContainer, AssetContainer<SpriteFont> fontContainer) { var assetTileReference = new AssetReference(typeof(ITile), Color.White, "blank"); var snakeHeadReference = new AssetReference(typeof(SnakePiece), Color.White, "snakeHead"); var snakeBodyReference = new AssetReference(typeof(SnakePiece), Color.Blue, "snakeBody"); try { textureContainer.Add(assetTileReference.Reference, content => new StaticTexture(content.Load<Texture2D>(@"Map/tile")).GetTexture); textureContainer.Add(snakeHeadReference.Reference, content => new StaticTexture(content.Load<Texture2D>(@"Mobs/snakeHead")).GetTexture); textureContainer.Add(snakeBodyReference.Reference, content => new StaticTexture(content.Load<Texture2D>(@"Mobs/snakeBody")).GetTexture); fontContainer.Add("scoreFont", content => content.Load<SpriteFont>(@"Fonts/scoreFont")); } catch (Exception ex) { Debug.Write("Error while loading content " + ex.Message); throw; } return new List<AssetReference> { assetTileReference, snakeHeadReference, snakeBodyReference }; }
public SnakeClone(Action<Vector2> configureLevelSize, ILevelTracker levelTracker, IAssetProvider assetProvider, SpriteBatch batch, ContentManager content) { this.assetProvider = assetProvider; this.levelTracker = levelTracker; this.configureLevelSize = configureLevelSize; AddMessages(new RenderedMessage(() => "snake", new Color(44, 62, 80)), new RenderedMessage(()=>"\n\n{arrow keys}", new Color(241, 196, 15)), new RenderedMessage(() => "\n\n\n\nto navigate", new Color(240, 240, 241)), new RenderedMessage(() => "\n\n\n\n\n\n\n{enter}", new Color(241, 196, 15)), new RenderedMessage(() => "\n\n\n\n\n\n\n\n\nto play", new Color(240, 240, 241)), new RenderedMessage(() => "\n\n\n\n\n\n\n\n\n\n\n\n{escape}", new Color(241, 196, 15)), new RenderedMessage(() => "\n\n\n\n\n\n\n\n\n\n\n\n\n\nto quit", new Color(240, 240, 241))); onContinuePlaying = () => NewLevel(levelTracker.Next); directionStates = new ReadOnlyCollection<AddState>(new List<AddState> { AddState.To(()=>level.Context.ChangeDirection(new ChangeDirectionState(Direction.Up))) .When(() => Keyboard.IsKeyClicked(InputKeys.Up) && (level.Context.Direction != Direction.Down || !level.Context.SnakeHead.HasTail)), AddState.To(()=>level.Context.ChangeDirection(new ChangeDirectionState(Direction.Down))) .When(() => Keyboard.IsKeyClicked(InputKeys.Down) && (level.Context.Direction != Direction.Up || !level.Context.SnakeHead.HasTail)), AddState.To(()=>level.Context.ChangeDirection(new ChangeDirectionState(Direction.Left))) .When(() => Keyboard.IsKeyClicked(InputKeys.Left) && (level.Context.Direction != Direction.Right || !level.Context.SnakeHead.HasTail)), AddState.To(()=>level.Context.ChangeDirection(new ChangeDirectionState(Direction.Right))) .When(() => Keyboard.IsKeyClicked(InputKeys.Right) && (level.Context.Direction != Direction.Left || !level.Context.SnakeHead.HasTail)) }); var textureContainer = new AssetContainer<Func<Texture2D>>(content); var fontContainer = new AssetContainer<SpriteFont>(content); assetProvider.LoadAssets(textureContainer, fontContainer); renderContext = new RenderContext(assetProvider.RenderInfo, batch, textureContainer, fontContainer); NextLevel(); }
private bool GetResSTexture(TextureFile texFile, AssetContainer cont) { TextureFile.StreamingInfo streamInfo = texFile.m_StreamData; if (streamInfo.path != null && streamInfo.path != "" && cont.FileInstance.parentBundle != null) { //some versions apparently don't use archive:/ string searchPath = streamInfo.path; if (searchPath.StartsWith("archive:/")) { searchPath = searchPath.Substring(9); } searchPath = Path.GetFileName(searchPath); AssetBundleFile bundle = cont.FileInstance.parentBundle.file; AssetsFileReader reader = bundle.reader; AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf; for (int i = 0; i < dirInf.Length; i++) { AssetBundleDirectoryInfo06 info = dirInf[i]; if (info.name == searchPath) { reader.Position = bundle.bundleHeader6.GetFileDataOffset() + info.offset + streamInfo.offset; texFile.pictureData = reader.ReadBytes((int)streamInfo.size); texFile.m_StreamData.offset = 0; texFile.m_StreamData.size = 0; texFile.m_StreamData.path = ""; return(true); } } return(false); } else { return(true); } }
/// <summary> /// Loads the standard data of the unitType from the xml /// /// THE STANDARD DATA cannot reference any other types, it would cause infinite cycles /// /// After this loading, you should register this type so it can be referenced, and then call /// <see cref="UnitType.ParseExtensionData(XElement, GamePack)"/> /// </summary> /// <param name="xml">xml element describing the type, according to <see cref="PackageManager.XMLNamespace"/> schema</param> /// <param name="package">Package this unitType belongs to</param> /// <returns>UnitType with filled standard members</returns> public void Load(XElement xml, GamePack package) { Package = package; //The XML should be validated, there should be no errors string assemblyPath = null; XElement assetsElement = null; XElement extensionElem = null; try { ID = XmlHelpers.GetID(xml); Name = XmlHelpers.GetName(xml); IconRectangle = XmlHelpers.GetIconRectangle(xml); assemblyPath = XmlHelpers.GetPath(xml.Element(UnitTypeXml.Inst.AssemblyPath)); assetsElement = xml.Element(UnitTypeXml.Inst.Assets); extensionElem = XmlHelpers.GetExtensionElement(xml); } catch (Exception e) { LoadError($"Unit type loading failed: Invalid XML of the package {package.Name}", e); } try { Assets = AssetContainer.FromXml(assetsElement, package); } catch (Exception e) { LoadError($"Unit type \"{Name}\"[{ID}] loading failed: Asset instantiation failed with exception: {e.Message}", e); } try { Plugin = TypePlugin.LoadTypePlugin <UnitTypePlugin>(assemblyPath, package, Name, ID, extensionElem); } catch (Exception e) { LoadError($"Unit type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e); } }
public void SetSkin(string skin_name) { string modelname = Animation.gameObject.name; if (Array.Exists(Skins, s => string.Compare(s, skin_name, true) == 0) == false) { throw new System.Exception(string.Format("[{0}] skin failed : {1}", modelname, skin_name)); } if (CurrentSkin != null && CurrentSkin.IsInit == true) { CurrentSkin.Free(); } #if UNITY_EDITOR #if SH_ASSETBUNDLE CharacterSkin prefab = null; string prefab_path = string.Format("Assets/Character_Skin/{0}_skin_{1}.prefab", modelname, skin_name); prefab = AssetDatabase.LoadAssetAtPath <CharacterSkin>(prefab_path); if (EditorApplication.isPlaying == false) { EditorUtility.SetDirty(gameObject); } CurrentSkin = new AssetContainer <CharacterSkin>(new AssetData(prefab.gameObject)); #else CurrentSkin = AssetManager.GetCharacterSkinAsset(modelname, skin_name); #endif #endif CurrentSkin.Alloc(); CurrentSkin.Asset.transform.SetParent(Animation.transform, false); CurrentSkin.Asset.gameObject.name = skin_name; CurrentSkin.Asset.Init(RootBone, m_Bones); SetMaterialDefault(); }
public bool IsAssetExistent(Asset asset, AssetContainer container) => container.assets.items.Any(e => (Asset)e == asset);
public async Task <bool> BatchExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection) { for (int i = 0; i < selection.Count; i++) { selection[i] = new AssetContainer(selection[i], TextureHelper.GetByteArrayTexture(workspace, selection[i])); } OpenFolderDialog ofd = new OpenFolderDialog(); ofd.Title = "Select export directory"; string dir = await ofd.ShowAsync(win); if (dir != null && dir != string.Empty) { StringBuilder errorBuilder = new StringBuilder(); foreach (AssetContainer cont in selection) { string errorAssetName = $"{Path.GetFileName(cont.FileInstance.path)}/{cont.PathId}"; AssetTypeValueField texBaseField = cont.TypeInstance.GetBaseField(); TextureFile texFile = TextureFile.ReadTextureFile(texBaseField); //0x0 texture, usually called like Font Texture or smth if (texFile.m_Width == 0 && texFile.m_Height == 0) { continue; } string file = Path.Combine(dir, $"{texFile.m_Name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.png"); //bundle resS if (!GetResSTexture(texFile, cont)) { string resSName = Path.GetFileName(texFile.m_StreamData.path); errorBuilder.AppendLine($"[{errorAssetName}]: resS was detected but {resSName} was not found in bundle"); continue; } byte[] data = TextureHelper.GetRawTextureBytes(texFile, cont.FileInstance); if (data == null) { string resSName = Path.GetFileName(texFile.m_StreamData.path); errorBuilder.AppendLine($"[{errorAssetName}]: resS was detected but {resSName} was not found on disk"); continue; } bool success = TextureImportExport.ExportPng(data, file, texFile.m_Width, texFile.m_Height, (TextureFormat)texFile.m_TextureFormat); if (!success) { string texFormat = ((TextureFormat)texFile.m_TextureFormat).ToString(); errorBuilder.AppendLine($"[{errorAssetName}]: Failed to decode texture format {texFormat}"); continue; } } if (errorBuilder.Length > 0) { string[] firstLines = errorBuilder.ToString().Split('\n').Take(20).ToArray(); string firstLinesStr = string.Join('\n', firstLines); await MessageBoxUtil.ShowDialog(win, "Some errors occurred while exporting", firstLinesStr); } return(true); } return(false); }
static AssetManager() { AssetContainer = new AssetContainer(); }
public override void OnInspectorGUI() { // If needs to Serialize other attributes base.OnInspectorGUI(); // should be equivalent to DrawDefaultInspector(); // Get the instance that is using the editor AssetContainer <T> container = (AssetContainer <T>)target; serializedObject.Update(); // Shows an array of Asset References: //EditorGUILayout.PropertyField(Nodes, true); // Or, equivalently //foreach (SerializedProperty p in Nodes) // EditorGUILayout.PropertyField(p); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); GUILayout.Label("Components: " + container.Nodes.Count, EditorStyles.boldLabel); if (GUILayout.Button("Refresh")) { LoadAssets(true); } if (GUILayout.Button("Clear")) { ClearAssets(); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); // Calls the object's OnGUI //(serializedObject.targetObject as Container).OnGUI(); for (int i = 0; i < container.Nodes.Count; i++) { T node = container.Nodes[i]; // We add a label and a 'remove' button for each scriptable object GUILayout.BeginHorizontal(); if (fold.Count <= i) { fold.Add(new bool()); } string title = container.Nodes[i].GetType().ToString(); fold[i] = EditorGUILayout.Foldout(fold[i], title, true); if (GUILayout.Button("X", GUILayout.MaxWidth(20f))) { RemoveAssetAt(i); i--; continue; } GUILayout.EndHorizontal(); if (fold[i]) { // Create a sub-inspector for each Scriptable Object if (!editor.ContainsKey(node)) { editor.Add(node, Editor.CreateEditor(container.Nodes[i])); } editor[node].OnInspectorGUI(); EditorGUILayout.Space(); } } DrawButtons(container); serializedObject.ApplyModifiedProperties(); // if (GUI.changed) EditorUtility.SetDirty(item); item <- Container instance }
public override void ProvideScene(string path, AssetContainer container, bool add) { SceneManager.LoadScene(path + ".unity", add ? LoadSceneMode.Additive : LoadSceneMode.Single); }
public virtual void Visit(AssetContainer assetContainer) { }
public virtual void Leave(AssetContainer assetContainer) { }
internal abstract AssetInstance ProvideAssetWithGUID <T>(string guid, AssetContainer container, out string path);
public abstract void ProvideScene(string path, AssetContainer container, bool add);
public abstract AssetReference Provide(string path, AssetContainer container, Type typ);
public ContentContainer(ContentManager content) { Textures = new AssetContainer<Texture2D>(content); Fonts = new AssetContainer<SpriteFont>(content); }
public override AssetReference Provide(string path, AssetContainer container, Type typ) { var asset = ProvideAsset(path, container, typ); return(new AssetReference(asset)); }
public static AssetTypeInstance GetByteArrayTexture(AssetsWorkspace workspace, AssetContainer tex) { var textureTemp = workspace.GetTemplateField(tex.Item); var image_data = textureTemp.children.FirstOrDefault(f => f.name == "image data"); if (image_data == null) { return(null); } image_data.valueType = EnumValueTypes.ByteArray; var texTypeInst = new AssetTypeInstance(new[] { textureTemp }, tex.FileReader, tex.Item.Position); return(texTypeInst); }
protected void OnValidate() { AssetContainer <T> container = (AssetContainer <T>)target; container.OnValidate(); }
public static AssetTypeInstance GetByteArrayTexture(AssetWorkspace workspace, AssetContainer tex) { AssetTypeTemplateField textureTemp = workspace.GetTemplateField(tex.FileInstance.file, tex.ClassId, tex.MonoId); AssetTypeTemplateField image_data = textureTemp.children.FirstOrDefault(f => f.name == "image data"); if (image_data == null) { return(null); } image_data.valueType = EnumValueTypes.ByteArray; AssetTypeInstance textureTypeInstance = new AssetTypeInstance(new[] { textureTemp }, tex.FileReader, tex.FilePosition); return(textureTypeInstance); }
private static AssetContainer CreateContainerIfNotExists(ComboGestureCompiler compiler, string folderToCreateAssetIn) { return(compiler.assetContainer == null?AssetContainer.CreateNew(folderToCreateAssetIn) : AssetContainer.FromExisting(compiler.assetContainer)); }
public override void Visit(AssetContainer assetContainer) => contentIO.CopyDirectoryToOutputDirectory(assetContainer.Path);