/// <summary> /// Spawn the entity at the specified location. /// </summary> /// <param name="location">Location to spawn this entity.</param> /// <returns>Returns the GameObject representing this entity.</returns> virtual public GameObject Spawn(Map map, Vector2 location) { GameObject entity = new GameObject(this.name); entity.transform.position = location; SpriteRenderer renderer = entity.AddComponent <SpriteRenderer>(); renderer.sortingLayerName = "Entities"; renderer.sortingOrder = 0;//1; //1 prevents player from picking up items that they are directly on top of EntitySpriteManager entitySpriteManager = entity.AddComponent <EntitySpriteManager>(); entitySpriteManager.entity = this; BoxCollider2D collider = entity.AddComponent <BoxCollider2D>(); collider.size = colliderSize; AudioSource aSource = entity.AddComponent <AudioSource>(); aSource.playOnAwake = false; aSource.clip = deathSound; Rigidbody2D rigidbody = entity.AddComponent <Rigidbody2D>(); rigidbody.gravityScale = 0f; rigidbody.angularDrag = 0f; rigidbody.freezeRotation = true; entityDropGen.SetLevelAndDifficulty(map); //Update entity's loot gen parameters with this map's level & difficulty. return(entity); }
public static void SetGameData(GraphicsDevice graphicsDevice, IServiceProvider serviceProvider, SpriteBatch spriteBatch, ContentManager contentManager) { GraphicsDevice = graphicsDevice; ServiceProvider = serviceProvider; SpriteBatch = spriteBatch; ContentManager = contentManager; EntitySpriteManager = new(ContentManager); try { EntitySpriteManager.PreloadTextures("entities.sps"); } catch (FileNotFoundException e) { Console.LogError($"Could not find entity sprite file at {e.FileName}!"); } try { LevelManager = new("."); } catch (DirectoryNotFoundException e) { Console.LogError($"Could not find map directory {e.Message}!"); } }
public void Init() { entity = Resources.Load <Entity>("GamePlayer"); testObject = new GameObject("testObject", typeof(SpriteRenderer), typeof(EntitySpriteManager)); spriteMgr = testObject.GetComponent <EntitySpriteManager>(); spriteMgr.entity = entity; Assert.IsNotNull(entity); Assert.IsNotNull(testObject.GetComponent <SpriteRenderer>()); }