예제 #1
0
    ///正面を調べる
    private void search()
    {
        BoxCollider2D tMyCollider = gameObject.GetComponent <BoxCollider2D>();
        float         tCenterX    = tMyCollider.bounds.center.x;
        float         tCenterY    = tMyCollider.bounds.center.y;

        switch (mDirection.value)
        {
        case Direction.direction.Up: tCenterY += 0.5f + tMyCollider.size.y / 2; break;

        case Direction.direction.Down: tCenterY -= 0.5f + tMyCollider.size.y / 2; break;

        case Direction.direction.Left: tCenterX -= 0.5f + tMyCollider.size.x / 2; break;

        case Direction.direction.Right: tCenterX += 0.5f + tMyCollider.size.x / 2; break;
        }
        //調べる範囲
        Vector2 tSearchSize = new Vector2(tMyCollider.size.x,
                                          (mDirection.value == Direction.direction.Left || mDirection.value == Direction.direction.Right)
                                          ? tMyCollider.size.y : tMyCollider.size.x);

        //正面にあるcolliderを取得
        Collider2D[] tColliders = Physics2D.OverlapBoxAll(new Vector2(tCenterX, tCenterY), tSearchSize, 0);
        foreach (Collider2D tCollider in tColliders)
        {
            MapSearchedBehaviour tSearched = tCollider.GetComponent <MapSearchedBehaviour>();
            if (tSearched == null)
            {
                continue;
            }
            tSearched.searched(this);
            return;
        }
    }
예제 #2
0
    static public LocalMap create(string aMapName)
    {
        //マップデータロード
        Arg tMapData = new Arg(MyJson.deserializeResourse("Database/map/" + aMapName));
        List <List <int> > tTroutData = tMapData.get <List <List <int> > >("feild");
        Arg tChipData = tMapData.get <Arg>("chip");

        int tWidth  = tTroutData[0].Count;
        int tHeight = tTroutData.Count;

        MapTrout[,] tTrouts = new MapTrout[tWidth, tHeight];

        //マス
        List <MapCharacter> tCharacters = new List <MapCharacter>();
        GameObject          tTiles      = GameObject.Find("mapTiles");

        for (int tX = 0; tX < tWidth; tX++)
        {
            for (int tY = 0; tY < tHeight; tY++)
            {
                string     tChipNum = tTroutData[tY][tX].ToString();
                List <Arg> tChip    = tChipData.get <List <Arg> >(tChipNum);
                MapTrout   tTrout   = MapTroutCreater.create(tChip);
                tTrout.transform.parent = tTiles.transform;
                tTrout.mapPosition      = new Vector2(tX, tY);
                tTrout.name             = "(" + tX.ToString() + "," + tY.ToString() + ")";
                tTrouts[tX, tY]         = tTrout;
            }
        }
        //オブジェクト
        List <MapObject> tObjects  = new List <MapObject>();
        GameObject       tSpeakers = GameObject.Find("mapSpeakers");

        foreach (Arg tObjectData in tMapData.get <List <Arg> >("object"))
        {
            MapObject tObject = MapObjectCreater.create(tObjectData.get <string>("file"), tObjectData.get <string>("name"));
            tObject.mapPosition = new Vector2(tObjectData.get <float>("x"), tObjectData.get <float>("y"));
            if (tObjectData.ContainsKey("z"))
            {
                tObject.zIndex = tObjectData.get <float>("z");
            }
            tObject.transform.parent = tSpeakers.transform;
            tObjects.Add(tObject);
            //searchEvent
            if (tObjectData.ContainsKey("search"))
            {
                MapSearchedBehaviour tSearched = tObject.gameObject.AddComponent <MapSearchedBehaviour>();
                Arg tEvent = tMapData.get <Arg>("argument").get <Arg>(tObjectData.get <string>("search"));
                tSearched.setSearchedEvent(tEvent);
            }
            //子オブジェクト
        }
        LocalMap tMap = new LocalMap(tTrouts, tCharacters, tObjects, new List <MapEventTrigger>());
        //イベント
        List <MapEventTrigger> tTriggers = new List <MapEventTrigger>();
        GameObject             tEvents   = GameObject.Find("mapEvents");

        foreach (Arg tEventData in tMapData.get <List <Arg> >("event"))
        {
            MapEventTrigger tTrigger = MapEventTriggerCreater.create(tEventData);
            tTrigger.mapPosition      = new Vector2(tEventData.get <float>("x"), tEventData.get <float>("y"));
            tTrigger.transform.parent = tEvents.transform;
            tMap.addEventTrigger(tTrigger);
        }
        return(tMap);
    }