Beispiel #1
0
 /// <summary>
 /// 根据指定uid移除角色
 /// </summary>
 /// <returns>成功移除返回<c>true</c>, 否则返回<c>false</c></returns>
 /// <param name="uid">角色uid</param>
 public bool removeUnit(string uid)
 {
     if (m_controllers.ContainsKey(uid))
     {
         var unit = m_controllers[uid];
         unit.destroy();
         m_controllers.Remove(uid);
         var eventData = new SFUnitAddRemove();
         eventData.uid         = uid;
         eventData.addOrRemove = false;
         SFBattleData.instance.dispatcher.dispatchEvent(SFEvent.EVENT_UNIT_ADD_REMOVE, eventData);
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 /// <summary>
 /// 根据指定配置信息添加角色到场景
 /// </summary>
 /// <returns>角色controller</returns>
 /// <param name="conf">配置信息</param>
 public SFUnitController addUnit(SFUnitConf conf)
 {
     if (m_controllers.ContainsKey(conf.uid))
     {
         SFUtils.logWarning("已经存在的UID: {0}", conf.uid);
         return(null);
     }
     if (unitPrefab != null)
     {
         var controllerGO = GameObject.Instantiate(unitPrefab, gameObject.transform.parent);
         var controller   = controllerGO.GetComponent <SFUnitController>();
         controller.init(conf);
         m_controllers.Add(conf.uid, controller);
         var eventData = new SFUnitAddRemove();
         eventData.uid         = conf.uid;
         eventData.addOrRemove = true;
         eventData.curLife     = conf.life;
         eventData.maxLife     = conf.maxLife;
         SFBattleData.instance.dispatcher.dispatchEvent(SFEvent.EVENT_UNIT_ADD_REMOVE, eventData);
         return(controller);
     }
     return(null);
 }