Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        Instance     = this;
        CombatEntity = Entity.CreateWithParent <CombatEntity>(CombatContext.Instance);
        CombatEntity.AddComponent <SkillPreviewComponent>();
        //CombatEntity.GetComponent<MotionComponent>().Enable = false;

#if EGAMEPLAY_EXCEL
        var          config  = ConfigHelper.Get <SkillConfig>(1001);
        SkillAbility ability = CombatEntity.AttachSkill <SkillAbility>(config);
        CombatEntity.BindSkillInput(ability, KeyCode.Q);

        config  = ConfigHelper.Get <SkillConfig>(1002);
        ability = CombatEntity.AttachSkill <SkillAbility>(config);
        CombatEntity.BindSkillInput(ability, KeyCode.W);

        config  = ConfigHelper.Get <SkillConfig>(1004);
        ability = CombatEntity.AttachSkill <SkillAbility>(config);
        CombatEntity.BindSkillInput(ability, KeyCode.E);
#else
        SkillConfigObject config  = Resources.Load <SkillConfigObject>("SkillConfigs/Skill_1001_黑火球术");
        SkillAbility      ability = CombatEntity.AttachSkill <SkillAbility>(config);
        CombatEntity.BindSkillInput(ability, KeyCode.Q);

        config  = Resources.Load <SkillConfigObject>("SkillConfigs/Skill_1002_炎爆");
        ability = CombatEntity.AttachSkill <SkillAbility>(config);
        CombatEntity.BindSkillInput(ability, KeyCode.W);

        config  = Resources.Load <SkillConfigObject>("SkillConfigs/Skill_1004_血红激光炮");
        ability = CombatEntity.AttachSkill <SkillAbility>(config);
        CombatEntity.BindSkillInput(ability, KeyCode.E);

        config  = Resources.Load <SkillConfigObject>("SkillConfigs/Skill_1005_火弹");
        ability = CombatEntity.AttachSkill <SkillAbility>(config);
        CombatEntity.BindSkillInput(ability, KeyCode.R);
#endif
        for (int i = InventoryPanelTrm.childCount; i > 0; i--)
        {
            GameObject.Destroy(InventoryPanelTrm.GetChild(i - 1).gameObject);
        }
        var allItemConfigs = ConfigHelper.GetAll <EquipmentConfig>();
        foreach (var item in allItemConfigs)
        {
            var itemObj = GameObject.Instantiate(ItemPrefab);
            itemObj.transform.parent = InventoryPanelTrm;
            itemObj.transform.Find("Icon").GetComponent <UnityEngine.UI.Image>().sprite = Resources.Load <Sprite>($"Icons/{item.Value.Name}");
            var text = itemObj.transform.Find("Text").GetComponent <UnityEngine.UI.Text>();
            text.text = $"+{item.Value.Value}";
            if (item.Value.Attribute == "AttackPower")
            {
                text.color = Color.red;
            }
            itemObj.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => {
                if (EquipmentPanelTrm.childCount >= 4)
                {
                    return;
                }
                var equipObj = GameObject.Instantiate(ItemPrefab);
                equipObj.transform.parent = EquipmentPanelTrm;
                equipObj.transform.Find("Icon").GetComponent <UnityEngine.UI.Image>().sprite = Resources.Load <Sprite>($"Icons/{item.Value.Name}");
                var equipText  = equipObj.transform.Find("Text").GetComponent <UnityEngine.UI.Text>();
                equipText.text = $"+{item.Value.Value}";
                if (item.Value.Attribute == "AttackPower")
                {
                    equipText.color = Color.red;
                }
                var itemData      = Entity.CreateWithParent <ItemData>(CombatEntity);
                equipObj.name     = $"{itemData.Id}";
                itemData.ConfigId = item.Value.Id;
                CombatEntity.AddItemData(itemData);
                equipObj.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => {
                    var id = long.Parse(equipObj.name);
                    CombatEntity.RemoveItemData(id);
                    GameObject.Destroy(equipObj);
                });
            });
        }

        AnimTimer.MaxTime = AnimTime;
    }