コード例 #1
0
    public void SendSync()
    {
        // From Server Only
        if (state.isServer == false)
        {
            return;
        }

        SyncUnits          syncData = new SyncUnits();
        List <NetworkUnit> netUnits = new List <NetworkUnit> ();

        // add all existing units to the list
        foreach (Transform gameUnits in state.gameUnits.transform)
        {
            if (gameUnits.name.Split('-') [0].Equals("GU"))
            {
                // get all the units in this GO
                foreach (Transform unit in gameUnits)
                {
                    var   networkUnit = new NetworkUnit();
                    short ownerID     = short.Parse(gameUnits.name.Split('-') [1]);
                    networkUnit.ownerID  = ownerID;
                    networkUnit.id       = unit.name;
                    networkUnit.unitType = unit.gameObject.GetComponent <UnitController> ().type;
                    netUnits.Add(networkUnit);
                }
            }
            else if (gameUnits.name.Split('-') [0].Equals("IO"))
            {
                foreach (Transform unit in gameUnits)
                {
                    if (unit.gameObject.GetComponent <FlagActions> () == null)
                    {
                        var   networkUnit = new NetworkUnit();
                        short ownerID     = short.Parse(gameUnits.name.Split('-') [1]);
                        networkUnit.ownerID  = ownerID;
                        networkUnit.id       = unit.name;
                        networkUnit.unitType = unit.gameObject.GetComponent <Interactable> ().type;
                        netUnits.Add(networkUnit);
                    }
                }
            }
        }

        syncData.units = netUnits.ToArray();
        // send the new unit to connections
        SendMessage(syncData);
    }
コード例 #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public SyncUnits SyncAllUnit()
 {
     SyncUnits collection = new SyncUnits();
     DataTable dtSource = this.poxy.GetAllSchool();
     if (dtSource != null && dtSource.Rows.Count > 0)
     {
         foreach (DataRow row in dtSource.Rows)
         {
             SyncUnit data = new SyncUnit();
             data.UnitCode = Convert.ToString(row["DWDM"]);
             data.UnitName = Convert.ToString(row["DWMC"]);
             data.UnitType = Convert.ToString(row["DWLBM"]);
             collection.Add(data);
         }
     }
     return collection;
 }
コード例 #3
0
 /// <summary>
 /// 获取全部的学校单位。
 /// </summary>
 /// <returns></returns>
 public SyncUnits SyncAllUnit()
 {
     string err = null;
     DataTable dtSource = this.poxy.SyncAllUnit(out err);
     if (!string.IsNullOrEmpty(err))
     {
         throw new Exception("获取学校单位数据时发生异常:" + err);
     }
     SyncUnits units = new SyncUnits();
     if (dtSource != null && dtSource.Rows.Count > 0)
     {
         foreach (DataRow row in dtSource.Rows)
         {
             SyncUnit su = new SyncUnit();
             su.UnitCode = string.Format("{0}", row["UnitCode"]);
             su.UnitName = string.Format("{0}", row["UnitName"]);
             su.UnitType = string.Format("{0}", row["UnitType"]);
             units.Add(su);
         }
     }
     return units;
 }