/// <summary> /// Attaches a new componentUnit to a GameObject /// </summary> /// <param name="attachingTo">the GameObject you are attaching the componentUnit to</param> /// <param name="unitName">The Unit's name (Not the game object's name). If this is null it will get it from the stat template</param> /// <param name="stats">The stat template</param> /// <param name="owner">This will need to change</param> /// <returns></returns> public static GameObject attachNewComponent(GameObject attachingTo, string unitName, IUnitStatTemplate stats, int owner) { componentUnit cUnit = attachingTo.AddComponent<componentUnit>(); cUnit.init(unitName, stats, owner); return attachingTo; }
/// <summary> /// Creates a new unit's GameObject and attaches appropriate components. /// </summary> /// <param name="unitName">The Unit's name (Not the game object's name). If this is null it will get it from the stat template</param> /// <param name="stats">The stat template</param> /// <param name="owner">This will need to change, it is unused at the current moment.</param> /// <param name="objectName">The GameObject's name</param> /// <param name="spriteName">The sprite's name</param> /// <param name="tTerrain">The typeTerrain of the unit (Typically this should be unpassable... because it's a unit)</param> /// <param name="mapObjectParent">The map object's parent object</param> /// <returns>The newly created GameObject with attached components</returns> public static GameObject createUnit(string unitName, IUnitStatTemplate stats, int owner, string objectName, string spriteName, TypeTerrain tTerrain = null, componentMapObject mapObjectParent = null) { //TODO: Change owner to a pointer to a player or controller data structure. not enitrely sure how I want to handle that yet. GameObject objUnit = new GameObject(objectName); componentUnitMapObject.attachNewComponent(objUnit, spriteName, tTerrain, mapObjectParent); componentUnit.attachNewComponent(objUnit, unitName, stats, owner); return objUnit; }
/// <summary> /// Handles initialization of unit stats from the template /// </summary> /// <param name="stats">The stat template</param> private void setStatsToTemplate(IUnitStatTemplate stats) { if (_unitName == null) { _unitName = stats.getStatName(); } _maxHealth = stats.getStatHealthMax(); _health = stats.getStatHealth(); }
/// <summary> /// Initializes the unit component. /// </summary> /// <param name="unitName">The unit's name, not the objects not. If null, it will be filled with the stat templates name</param> /// <param name="stats">The stat template</param> /// <param name="owner">This will need to changel.</param> public void init(string unitName, IUnitStatTemplate stats, int owner) { //TODO: Change owner to a pointer to a player or controller data structure. not enitrely sure how I want to handle that yet. _unitName = unitName; setStatsToTemplate(stats); }