コード例 #1
0
ファイル: PuzzleManager.cs プロジェクト: ukcat5503/Way
    public static void GenerateMap(StageInfo item, int stageNumber, bool isActive = false)
    {
        var old = GameObject.Find("Stage " + stageNumber);

        var stageObj = new GameObject("Stage " + stageNumber);
        var mapObj   = new GameObject("Maps");
        var objObj   = new GameObject("Objects");

        if (old)
        {
            Destroy(old);
            StageObject[stageNumber] = stageObj;
        }
        else
        {
            StageObject.Add(stageObj);
        }

        stageObj.transform.parent = instance.transform;
        mapObj.transform.parent   = stageObj.transform;
        objObj.transform.parent   = stageObj.transform;
        for (int z = 0; z < item.Map.GetLength(0); ++z)
        {
            for (int x = 0; x < item.Map.GetLength(1); ++x)
            {
                Vector3 pos = new Vector3(x, -stageNumber * kMapDepth, (item.Map.GetLength(0) - z) + 0.25f);
                if (item.Map[z, x] == 0)
                {
                    continue;
                }
                var obj = Instantiate(instance.generateBlocks[item.Map[z, x]], pos, instance.generateBlocks[item.Map[z, x]].transform.rotation) as GameObject;
                obj.transform.parent = mapObj.transform;
                obj.name             = "[" + x + "," + z + "] " + obj.name;
                obj.layer            = LayerMask.NameToLayer("DefaultBlock");
            }
        }

        foreach (var objItem in item.Objects)
        {
            var obj = Instantiate(instance.generateObjects[objItem.obj], objItem.GetPos(-stageNumber * kMapDepth, item.Map.GetLength(0)), instance.generateObjects[objItem.obj].transform.rotation);
            obj.transform.parent = objObj.transform;
            obj.name             = "[" + objItem.pos.x + "," + objItem.pos.z + "] " + obj.name;
        }

        foreach (var objItem in item.Coins)
        {
            var obj = Instantiate(instance.coinPrefabs, objItem.GetPos(-stageNumber * kMapDepth, item.Map.GetLength(0)), instance.coinPrefabs.transform.rotation);
            obj.transform.parent = objObj.transform;
            obj.name             = "[" + objItem.pos.x + "," + objItem.pos.z + "] " + obj.name;
            // obj.GetComponent<CoinParticle>().microCoin = objItem.microCoin;
        }

        stageObj.SetActive(isActive);
        ResetMapState();
    }