Exemple #1
0
    void test01()
    {
        Debug.Log(Screen.width);
        Debug.Log(Screen.height);
        Dictionary <string, Sprite> dictSprites = new Dictionary <string, Sprite>();

        Sprite[] sprites = Resources.LoadAll <Sprite>("Scavengers_SpriteSheet");
        foreach (Sprite sprite in sprites)
        {
            dictSprites.Add(sprite.name, sprite);
        }
        //===================================================================
        RuntimeAnimatorController aniControl   = Resources.Load <RuntimeAnimatorController>("animation/Player_01");
        AnimationClip             aniClip_Idle = Resources.Load <AnimationClip>("animation/playerClip");

        TestAssert.That(aniControl != null, lev.Error, "aniControl is null");
        TestAssert.That(aniClip_Idle != null, lev.Error, "aniClip_Idle is null");

        GameObject go = new GameObject("palyer");

        go.AddComponent <SpriteRenderer>();
        go.GetComponent <SpriteRenderer>().sprite = dictSprites["Player_01"];
        go.AddComponent <Animator>();
        go.GetComponent <Animator>().runtimeAnimatorController = aniControl;
    }
        public override void Execute()
        {
            int rows = gameModel.rows;
            int cols = gameModel.cols;

            TestAssert.That(rows != 0, lev.Error, "GameBoardCteateCommand Execute::gameModel未重置");
            GameObject board = new GameObject("board");

            board.transform.SetParent(contextView.transform);

            Dictionary <string, Sprite> dictSprites = gameConfig.dictSprites;
            List <string> listFloors  = new List <string>();
            List <string> listOutWall = new List <string>();

            foreach (string name in dictSprites.Keys)
            {
                if (name.StartsWith("Floor"))
                {
                    listFloors.Add(name);
                }
                if (name.StartsWith("OutWall"))
                {
                    listOutWall.Add(name);
                }
            }

            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    GameObject go =
                        GameObject.Instantiate(gameModel.spriteModel, new Vector3(x + 0.5f, y + 0.5f, 0), Quaternion.identity) as GameObject;
                    if (x == 0 || y == 0 || x == cols - 1 || y == rows - 1)
                    {
                        int index = Random.Range(0, listOutWall.Count);
                        go.GetComponent <SpriteRenderer>().sprite = dictSprites[listOutWall[index]];
                        go.AddComponent <BoxCollider2D>();
                        go.GetComponent <BoxCollider2D>().size = new Vector2(0.9f, 0.9f);
                        go.tag = GameTags.OutWall.ToString();
                    }
                    else
                    {
                        int index = Random.Range(0, listFloors.Count);
                        go.GetComponent <SpriteRenderer>().sprite = dictSprites[listFloors[index]];
                    }
                    go.AddComponent <BoardView>();
                    go.GetComponent <SpriteRenderer>().sortingLayerName = GameLayers.BackGround.ToString();
                    go.transform.SetParent(board.transform);
                }
            }
        }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("Clink The Mouse");
            TestLoadConfig.log.Trace("跟踪信息");
            TestLoadConfig.log.Debug("测试信息");
            TestLoadConfig.log.Info("提示信息");
            TestLoadConfig.log.Warn("警告信息");
            TestLoadConfig.log.Error("一般错误信息");
            TestLoadConfig.log.Fatal("致命错误信息");

            TestAssert.That(true, lev.Debug, "TestDebugLog GetMouseButtonDown|");
        }
    }
Exemple #4
0
        public void PostConstruct()
        {
            TestLoadConfig.log.Trace("GameConfig PostConstruct");
            Sprite[] sprites = Resources.LoadAll <Sprite>("Scavengers_SpriteSheet");
            TestAssert.That(sprites != null, lev.Error, "GameModel Reset");

            dictSprites = new Dictionary <string, Sprite>();
            foreach (Sprite sprite in sprites)
            {
                dictSprites.Add(sprite.name, sprite);
                TestLoadConfig.log.DebugFormat("name: {0}", sprite.name);
            }

            smoothing = 0.5f;
        }
Exemple #5
0
        public override void Execute()
        {
            Rigidbody2D rig2d = playerView.GetComponent <Rigidbody2D>();

            TestAssert.That(rig2d != null, "PlayerBehaviourCommand Execute::: rig2d is null");

            Vector2      playerPos = playerView.transform.position;
            RaycastHit2D hit       = Physics2D.Linecast(playerPos, playerPos + ray(), LayerMask.NameToLayer("Player"));

            Debug.DrawLine(playerPos, playerPos + ray(), Color.red, 5);

            if (!playerView.IsAction)
            {
                if (hit.transform == null)
                {
                    playerMove(playerPos);
                }
                else
                {
                    playerAction(hit, playerPos);
                }
            }
        }
Exemple #6
0
        public override void Execute()
        {
            int minCountWall = gameModel.minCountWall;
            int maxCountWall = gameModel.maxCountWall;

            TestAssert.That(maxCountWall != 0, lev.Error, "ItemCreateCommand Execute::gameModel未重置");

            GameObject holder = new GameObject("item");

            holder.transform.SetParent(contextView.transform);

            dictSprites = gameConfig.dictSprites;
            List <string> listObstacles = new List <string>();
            List <string> listFoods     = new List <string>();


            foreach (string name in dictSprites.Keys)
            {
                if (name.StartsWith("ObstacleG"))
                {
                    listObstacles.Add(name);
                }
                if (name.StartsWith("Food"))
                {
                    listFoods.Add(name);
                }
            }
            //创建障碍物
            int wallCount = Random.Range(minCountWall, maxCountWall + 1);//障碍物个数

            InstantiateItems <ObstacleView>(wallCount, listObstacles, holder);
            //创建食物2-level*2
            int foodCount = Random.Range(2, gameModel.level * 2 + 1);

            InstantiateItems <FoodView>(foodCount, listFoods, holder);
        }