示例#1
0
    public void TaskAppear()
    {
        float elapsedTime = Time.deltaTime;

        if (IsTimeOver())
        {
            // 経過時間オーバーなので処理しない
            return;
        }
        // 総合経過時間を加算
        totalTime += elapsedTime;
        //Debug.Log(string.Format("time={0}", totalTime));

        if (IsDataEnd())
        {
            // データ実行終了 or データがない
            return;
        }

        bool isContinue = true;

        while (isContinue)
        {
            if (currentIndex >= maxCount)
            {
                // データが終端まで実行している
                return;
            }
            StgStageJsonEnemyLaunchData launchData = stgStageJsonEnemyLaunchDatas.Get(currentIndex);
            if (launchData.time <= (int)totalTime)
            {
                // 敵の生成
                {
                    GameObject enemy = enemyFactory.Create(StgEnemyConstant.GetStringToType(launchData.enemy_type), launchData.enemyItemDropDatas);

                    //Instantiate(enemy, new Vector3(launchData.x, launchData.y, launchData.z), Quaternion.identity);

                    // ドロップアイテム設定
                    NormalEnemy enemyBase = enemy.GetComponent <NormalEnemy>();
                    enemyBase.SetPosition(new Vector2(launchData.x, launchData.y));
                    StgItemMultiDropper dropper = new StgItemMultiDropper();
                    for (int i = 0; i < launchData.enemyItemDropDatas.GetCount(); ++i)
                    {
                        StgStageJsonEnemyItemDropData dropData = launchData.enemyItemDropDatas.Get(i);
                        dropper.SetParameter(dropData.Offset, dropData.Type);
                    }
                    dropper.Print();
                    enemyBase.SetItemDropper(dropper);
                }
                ++currentIndex;
            }
            else
            {
                // 処理すべきtimeのデータがない
                return;
            }
        }
    }
示例#2
0
    public override GameObject Create(StgEnemyConstant.Type type, StgStageJsonEnemyItemDropDatas itemDropDatas)
    {
        NormalEnemy normalEnemy = null;

        if (type == StgEnemyConstant.Type.kEnemyNormal)
        {
            GameObject enemy = (GameObject)Resources.Load(SceneShare.Instance.GetGameResourcePathData().Get(GameResourcePathDefine.Type.kNormalEnemyPrefab));
            MhCommon.Assert(enemy != null, "StgEnemyFactory::Create() kEnemyNormal null");
            enemy = Object.Instantiate(enemy);

            normalEnemy = enemy.GetComponent <NormalEnemy>();
            StgItemMultiDropper dropper = new StgItemMultiDropper();
            for (int i = 0; i < itemDropDatas.GetCount(); ++i)
            {
                StgStageJsonEnemyItemDropData dropData = itemDropDatas.Get(i);
                dropper.SetParameter(dropData.Offset, dropData.Type);
            }
            dropper.Print();
            normalEnemy.SetItemDropper(dropper);

            /*
             *              NormalEnemy enemyBase = enemy.GetComponent<NormalEnemy>();
             *              StgItemMultiDropper dropper = new StgItemMultiDropper();
             *              for (int i = 0; i < launchData.enemyItemDropDatas.GetCount(); ++i) {
             *                      StgStageJsonEnemyItemDropData dropData = launchData.enemyItemDropDatas.Get(i);
             *                      dropper.SetParameter(dropData.Offset, dropData.Type);
             *              }
             *              dropper.Print();
             *              enemyBase.SetItemDropper(dropper);
             *
             */

            return(enemy);
        }
        else if (type == StgEnemyConstant.Type.kStraightMoveEnemy)
        {
            GameObject enemy = (GameObject)Resources.Load(SceneShare.Instance.GetGameResourcePathData().Get(GameResourcePathDefine.Type.kStraightMoveEnemyPrefab));
            MhCommon.Assert(enemy != null, "StgEnemyFactory::Create() kNormalEnemyPrefab null");
            enemy = Object.Instantiate(enemy);
            return(enemy);
        }
        else
        {
            MhCommon.Assert(false, "StgEnemyFactory::Create() StgEnemyConstant.Type invalid type=" + type);
            return(null);
        }
    }
示例#3
0
    public void Initialize(string resourcePath)
    {
        LoadTextAsset textAsset = new LoadTextAsset();

        textAsset.SetResourcePath(resourcePath);
        bool result = textAsset.Load(true);

        if (result)
        {
            // テキストデータ取得
            var data = textAsset.Get();
            // jsonパース
            var json2 = Utf8Json.JsonSerializer.Deserialize <dynamic>(data);
            System.Collections.Generic.Dictionary <string, object> json3 = json2["stage_data"];

            // 読み込んだjsonデータを敵の出撃データとしてリストに保持する
            foreach (KeyValuePair <string, object> stageDatas in json3)
            {
                Dictionary <string, object> stageParameters = (Dictionary <string, object>)stageDatas.Value;
                StgStageJsonEnemyLaunchData launchData      = new StgStageJsonEnemyLaunchData();
                foreach (KeyValuePair <string, object> stageData in stageParameters)
                {
                    var    key = stageData.Key;
                    string val = stageData.Value as string;
                    if (val != null)
                    {
                        // 値がstringへ変換できた
                        switch (key)
                        {
                        case "enemy_type":
                            launchData.enemy_type = val as string;
                            break;

                        case "time":
                            launchData.time = float.Parse(val);
                            break;

                        case "x":
                            launchData.x = float.Parse(val);
                            break;

                        case "y":
                            launchData.y = float.Parse(val);
                            break;

                        case "z":
                            launchData.z = float.Parse(val);
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        StgStageJsonEnemyItemDropDatas itemDropDatas = new StgStageJsonEnemyItemDropDatas();
                        // key,value形式
                        switch (key)
                        {
                        case "item_drop_data":

                            List <object> itemDropList = stageData.Value as List <object>;
                            foreach (object test in itemDropList)
                            {
                                Dictionary <string, object>   items        = test as Dictionary <string, object>;
                                StgStageJsonEnemyItemDropData itemDropData = new StgStageJsonEnemyItemDropData();
                                foreach (KeyValuePair <string, object> item in items)
                                {
                                    string itemValue = item.Value as string;
                                    switch (item.Key)
                                    {
                                    case "type":
                                        itemDropData.Type = StgItemConstant.GetStringToType(itemValue);
                                        break;

                                    case "offset_x":
                                    {
                                        Vector3 offset = itemDropData.Offset;
                                        offset.x            = float.Parse(itemValue);
                                        itemDropData.Offset = offset;
                                    }
                                    break;

                                    case "offset_y":
                                    {
                                        Vector3 offset = itemDropData.Offset;
                                        offset.y            = float.Parse(itemValue);
                                        itemDropData.Offset = offset;
                                    }
                                    break;

                                    case "offset_z":
                                    {
                                        Vector3 offset = itemDropData.Offset;
                                        offset.z            = float.Parse(itemValue);
                                        itemDropData.Offset = offset;
                                    }
                                    break;

                                    default:
                                        break;
                                    }
                                }
                                itemDropDatas.AddData(itemDropData);
                            }
                            launchData.enemyItemDropDatas.Copy(itemDropDatas);
                            break;

                        default:
                            break;
                        }
                    }
                }
                launchDatas.AddData(launchData);
            }
            launchDatas.Print();
        }
        else
        {
            launchDatas.Initialize();
            throw new System.ArgumentException(string.Format("resource={0} json parse failure", resourcePath));
        }
    }
示例#4
0
 /// <summary>
 /// データ追加
 /// </summary>
 public void AddData(StgStageJsonEnemyItemDropData enemyItemDropData)
 {
     dropList.Add(enemyItemDropData);
 }