コード例 #1
0
    private void Update()
    {
        // @request 위치 전달/수신
        Vector3       player1_pos = player1.transform.position;
        StructRequest request     = new StructRequest();

        request.uid                      = Const.UserData.uid;
        request.request_url              = URL.SyncMovement.ToString();
        request.parameter                = new Dictionary <string, string>();
        request.parameter["posX"]        = player1.gameObject.transform.position.x.ToString();
        request.parameter["posY"]        = player1.gameObject.transform.position.y.ToString();
        request.parameter["opponentUid"] = Const.UserData.opponentUid;

        void CallBack(StructRequest response)
        {
            if (!response.parameter.ContainsKey("opponentPosX"))
            {
                return;
            }

            // 받은 player2 위치 적용
            float      x        = float.Parse(response.parameter["opponentPosX"]);
            float      y        = float.Parse(response.parameter["opponentPosY"]);
            Vector3    next_pos = new Vector3(x, y, player2.transform.position.z);
            EDirection dir      = JUtils.GetDir(next_pos, player2.transform.position);

            player2.Move(dir);
            player2.transform.position = next_pos;
        }

        mNEt.SetCallBack(CallBack);
        mNEt.RequestMsg(request);
    }
コード例 #2
0
 public object Value(string xPath, Type type, string file = null)
 {
     if (FindMatchingFile(file) is XmlFileParser.FileDataHolder data)
     {
         if (data.ParsingFailed)
         {
             return(null);
         }
         if (data.ParsedFile == null)
         {
             try
             {
                 var doc = XDocument.Parse(File.ReadAllText(data.Path));
                 data.ParsedFile = doc;
             }
             catch/*(Exception e)*/
             {
                 data.ParsingFailed = true;
             }
         }
         if (data.ParsingFailed)
         {
             return(null);
         }
         try
         {
             if (typeof(IEnumerable).IsAssignableFrom(type) && type != typeof(string))
             {
                 var selection = ((data.ParsedFile) ?? throw new InvalidOperationException())
                                 .XPathSelectElements(xPath, data.NamespaceManager);
                 var genericType      = JUtils.GetGenericTypeFromEnumerable(type);
                 var untypedSelection = selection.Select(x => x.Value);
                 var enumerable       = untypedSelection as string[] ?? untypedSelection.ToArray();
                 if (enumerable.All(x => JUtils.CanConvertToType(x, genericType)))
                 {
                     return(enumerable.Select(x => JUtils.ConvertToType(x, genericType)));
                 }
             }
             else
             {
                 var selection = ((data.ParsedFile) ?? throw new InvalidOperationException())
                                 .XPathSelectElement(xPath, data.NamespaceManager);
                 if (JUtils.CanConvertToType(selection.Value, type))
                 {
                     return(JUtils.ConvertToType(selection.Value, type));
                 }
             }
         }
         catch
         {
             return(null);
         }
     }
     return(null);
 }
コード例 #3
0
    void AvoidOpponent(ref Dictionary <int, float> near_index_list)
    {
        Character  charac     = mCharacterManager.GetPlayer();
        EDirection dir        = JUtils.GetDir(this.transform.position, charac.transform.position);
        int        next_index = 0;

        switch (dir)
        {
        case EDirection.UP:
            next_index = mCurIndex - Const.TileCntX;
            break;

        case EDirection.Down:
            next_index = mCurIndex + Const.TileCntX;
            break;

        case EDirection.Right:
            next_index = mCurIndex - 1;
            break;

        case EDirection.Left:
            next_index = mCurIndex + 1;
            break;
        }

        int[] keys = new int[near_index_list.Count];
        near_index_list.Keys.CopyTo(keys, 0);
        int iCount = keys.Length;

        for (int i = 0; i < iCount; ++i)
        {
            near_index_list[keys[i]] += 1;
        }
        if (near_index_list.ContainsKey(next_index))
        {
            near_index_list[next_index] += -1f;
        }
    }