示例#1
0
    public void eventCreateEnemyUnit(string actorId, string act_target, Vector3 currentLocation, Vector3 targetLocation)
    {
        RemoteEventBase eventBase = new RemoteEventBase(null, RemoteEventBase.VALUE_ACTION_NAME_CREATE, actorId, act_target, enemyId, Time.realtimeSinceStartup.ToString(), currentLocation, targetLocation);

        FireBaseUtil.setBattleEventValue(FireBase_battle, eventBase);
    }
示例#2
0
    // Use this for initialization
    private void gameStart()
    {
        Debug.Log("GameController start+");
        _gameProcessing = true;
        controlUIPanelHost.SetActive(true);
        unitControlPanels = controlUIPanelHost.GetComponentsInChildren <UnitControlPanel>();

        createHumanoid();


        FireBase_battle_event = FireBase_battle.Child(RemoteEventBase.KEY_EVENT_ROOT);
        ////firebase.AuthWithPassword("*****@*****.**", "iloveawei", (AuthData auth) =>
        ////{
        ////    Debug.Log("auth success!!" + auth.Uid);
        ////}, (FirebaseError e) =>
        ////{
        ////    Debug.Log("auth failure!!");
        ////});

        FireBase_battle_event.ChildAdded += (object sender, ChangedEventArgs e) =>
        {
            IDataSnapshot dataSnap = e.DataSnapshot;


            Logger.firebase("Child added! " + sender + ", " + e + ", " + dataSnap.Key);

            try
            {
                List <RemoteEventBase> result = FireBaseUtil.getBattleEventValue(dataSnap);
                onRemoteEvents(result);
            } catch (Exception ex) {
                Debug.Log(ex.Message);
            }

            //    ////String x = dataSnap.Child("x").StringValue;
            //    ////String y = dataSnap.Child("y").StringValue;
            //    ////String z = dataSnap.Child("z").StringValue;

            //    //Dictionary<string, object> value = dataSnap.DictionaryValue;
            //    //string x = value["x"].ToString();
            //    //string y = value["y"].ToString();
            //    //string z = value["z"].ToString();

            //    //if (debugFirebase)
            //    //    Debug.Log("Child added! " + dataSnap.Key + ", s " + dataSnap.DictionaryValue + ", x " + x + ", y " + y + ", z " + z);

            //    //Vector3 p = new Vector3(float.Parse(x), float.Parse(y), float.Parse(z));
            //    //foreach (Humanoid h in humanoid)
            //    //{
            //    //    h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //    //};
        };

        //firebase.ChildRemoved += (object sender, ChangedEventArgs e) =>
        //{
        //    IDataSnapshot dataSnap = e.DataSnapshot;
        //    if (debugFirebase)
        //        Debug.Log("Child removed! " + sender + ", " + e + ", " + dataSnap);
        //};

        FireBase_battle_event.ValueUpdated += (object sender, ChangedEventArgs ex) => {
            IDataSnapshot dataSnap = ex.DataSnapshot;
            Logger.firebase("Child ValueUpdated! " + sender + ", " + ex + ", " + dataSnap.Key);

            //    //String x = dataSnap.Child("x").StringValue;
            //    //String y = dataSnap.Child("y").StringValue;
            //    //String z = dataSnap.Child("z").StringValue;

            //    //Debug.Log("Child ValueUpdated! " + dataSnap.Key + ", " + dataSnap.StringValue + ", " + x + ", " + y + ", " + z);

            //    //Vector3 p = new Vector3(x, y, z);
            //    //foreach (Humanoid h in humanoid)
            //    //{
            //    //    h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //    //};

            //    //try
            //    //{
            //    //    Dictionary<string, object> value = dataSnap.DictionaryValue;
            //    //    string x = value["x"].ToString();
            //    //    string y = value["y"].ToString();
            //    //    string z = value["z"].ToString();

            //    //    Debug.Log("Child ValueUpdated! " + dataSnap.Key + ", s " + dataSnap.DictionaryValue + ", x " + x + ", y " + y + ", z " + z);

            //    //    Vector3 p = new Vector3(float.Parse(x), float.Parse(y), float.Parse(z));
            //    //    foreach (Humanoid h in humanoid)
            //    //    {
            //    //        h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //    //    };
            //    //}
            //    //catch (Exception exx) {
            //    //    Debug.Log(exx.ToString());
            //    //}
        };

        FireBase_battle_event.ChildChanged += (object sender, ChangedEventArgs e) => {
            //firebase.Child(enemyId.ToString()).ChildChanged += (object sender, ChangedEventArgs e) => {
            IDataSnapshot dataSnap = e.DataSnapshot;

            Logger.firebase("Child ChildChanged! " + sender + ", " + e + ", " + dataSnap.Key);

            //String x = dataSnap.Child("x").StringValue;
            //String y = dataSnap.Child("y").StringValue;
            //String z = dataSnap.Child("z").StringValue;

            //Debug.Log("Child ChildChanged! " + dataSnap.Key + ", " + x + ", " + y + ", " + z);

            //Vector3 p = new Vector3(float.Parse(x), float.Parse(y), float.Parse(z));
            //foreach (Humanoid h in humanoid)
            //{
            //    h.onRemoteUpdate(Int32.Parse(dataSnap.Key), p);
            //};

/*
 *          try
 *          {
 *              List<JsonBaseUnit> result = JsonBaseUnit.getFirebaseValue(dataSnap);
 *              foreach (Humanoid h in humanoid)
 *              {
 *                  foreach (JsonBaseUnit json in result)
 *                  {
 *                      h.onRemoteUpdate(json);
 *                  }
 *              }
 *          }
 *          catch (Exception ex)
 *          {
 *              Debug.Log(ex.ToString());
 *          }*/
        };

        //firebase.ChildChanged += (object sender, ChangedEventArgs e) => {
        //firebase.Child(playerId.ToString()).Child("attack").ChildChanged += (object sender, ChangedEventArgs e) => {
        //IDataSnapshot dataSnap = e.DataSnapshot;
        //if (debugFirebase)
        //    Debug.Log("attack ChildChanged! " + sender + ", " + e + ", " + dataSnap.Key);

        /*           try
         *         {
         *             List<JsonBaseAttack> result = JsonBaseAttack.getFirebaseValue(dataSnap);
         *             foreach (Humanoid h in humanoid)
         *             {
         *                 foreach (JsonBaseAttack json in result)
         *                 {
         *                     //h.onRemoteUpdate(json.getId(), json.getVector3());
         *                 }
         *             }
         *         }
         *         catch (Exception ex)
         *         {
         *             Debug.Log(ex.ToString());
         *         }*/
        //};

        FireBase_battle.SetValue("GameStart!");

        //Dictionary<string, object> value = new Dictionary<string, object>();
        //Dictionary<string, object> location = new Dictionary<string, object>();

        //location.Add("x", "9");
        //location.Add("y", "9");
        //location.Add("z", "999");
        //value.Add("action", "move");
        //value.Add("action_unit_id", "123");
        //value.Add("current_location", location);

        //firebase.Child("FightLog").Push().SetValue(value);

        //value.Add("target_location", location);
        //firebase.Child("FightLog").Push().SetValue(value);

        Debug.Log("GameController start-");
    }