示例#1
0
        private void CreateMemberSprite()
        {
            var actorsTransformParent = GameObject.Find("Actors");
            var members    = MemberDataModel.Instance.GetActorData();
            var memberSize = members.Count;

            foreach (var(battler, index) in members.Select((battler, index) => (battler, index)))
            {
                var        monsterData    = MonsterDicionary.GetMonsterData(battler.monsterId);
                GameObject memberObject   = new GameObject();
                var        spriteRenderer = CreateSprite(memberObject, battler.monsterId);
                var        padding        = 16 / memberSize;
                var        posX           = (padding * index) - (padding * (memberSize - 1) / 2) - (0.5f * memberSize);
                memberObject.transform.position = new Vector3(posX, -1.9f, 0);
                if (monsterData.imageData.actorScale != 0)
                {
                    memberObject.transform.localScale = new Vector3(monsterData.imageData.actorScale,
                                                                    monsterData.imageData.actorScale, 1);
                }

                memberObject.transform.SetParent(actorsTransformParent.transform, false);
                memberObject.AddComponent <BoxCollider2D>();
                var ui = Object.Instantiate(
                    (GameObject)Resources.Load("Prefabs/Battle/MemberInfo"), memberObject.transform.position, Quaternion.identity,
                    GameObject.Find("FrontCanvas/EnemiesInfo").transform
                    );
                var uiStruct = new UiStruct
                {
                    UiParent = ui.transform,
                    HpBar    = ui.transform.Find("HPBar"),
                    HpText   = ui.transform.Find("HPBar/ValueText"),
                    MpBar    = ui.transform.Find("MPBar"),
                    MpText   = ui.transform.Find("MPBar/ValueText")
                };
                uiStruct.HpText.GetComponent <TextMeshProUGUI>().SetText(battler.parameter.hp.ToString());
                uiStruct.MpText.GetComponent <TextMeshProUGUI>().SetText(battler.parameter.mp.ToString());
                float rate = (float)battler.parameter.hp / battler.parameter.maxHp;
                uiStruct.HpBar.GetComponent <Slider>().value = rate;
                rate = (float)battler.parameter.mp / battler.parameter.maxMp;
                uiStruct.MpBar.GetComponent <Slider>().value = rate;
                _sprites.Add(new BattlerSpriteStruct()
                {
                    UniqId                = battler.uniqId,
                    SpriteObject          = memberObject.transform,
                    SpriteRenderer        = spriteRenderer,
                    MaterialPropertyBlock = new MaterialPropertyBlock(),
                    Ui = uiStruct,
                    StatusTransform = ui.transform.Find("Status"),
                    Statuses        = new List <StateStruct>()
                });
            }
        }
示例#2
0
        private void CreateEnemySprite()
        {
            var enemiesTransformParent = GameObject.Find("Enemies");
            var enemies     = EnemyDataModel.Instance.Data;
            var enemiesSize = enemies.Count;

            foreach (var(battler, index) in enemies.Select((battler, index) => (battler, index)))
            {
                //敵のスプライトの作成
                GameObject enemyObject = new GameObject();
                enemyObject.name = "Enemy";
                var spriteRenderer = CreateSprite(enemyObject, battler.monsterId);
                var padding        = 20 / enemiesSize;
                var posX           = (padding * index) - (padding * (enemiesSize - 1) / 2);
                enemyObject.transform.position = new Vector3(posX, 1.5f, 0);
                enemyObject.transform.SetParent(enemiesTransformParent.transform, false);
                enemyObject.AddComponent <BoxCollider2D>();
                //敵のinfoを作成
                var ui = Object.Instantiate(
                    (GameObject)Resources.Load("Prefabs/Battle/EnemyInfo"), enemyObject.transform.position + new Vector3(0, -1f, 0), Quaternion.identity,
                    GameObject.Find("FrontCanvas/EnemiesInfo").transform
                    );
                var uiStruct = new UiStruct
                {
                    UiParent = ui.transform,
                    HpBar    = ui.transform.Find("HPBar"),
                    HpText   = ui.transform.Find("HPBar/ValueText")
                };
                uiStruct.HpText.GetComponent <TextMeshProUGUI>().SetText(battler.parameter.hp.ToString());
                _sprites.Add(new BattlerSpriteStruct()
                {
                    UniqId                = battler.uniqId,
                    SpriteObject          = enemyObject.transform,
                    SpriteRenderer        = spriteRenderer,
                    MaterialPropertyBlock = new MaterialPropertyBlock(),
                    Ui = uiStruct,
                    StatusTransform = ui.transform.Find("Status"),
                    Statuses        = new List <StateStruct>()
                });
            }
        }