void Start()
    {
        maxSpeed     = INITIAL_SPEED;
        currentSpeed = INITIAL_SPEED;

        jumpAction.performed      += ctx => jump();
        slideAction.performed     += ctx => slide();
        moveLeftAction.performed  += ctx => moveLeft();
        moveRightAction.performed += ctx => moveRight();

        touchContact.started  += ctx => StartTouchPrimary(ctx);
        touchContact.canceled += ctx => EndTouchPrimary(ctx);

        _body              = gameObject.GetComponent <Rigidbody>();
        _collider          = gameObject.GetComponent <BoxCollider>();
        starting_elevation = _body.transform.position.y;

        inventory           = GameObject.Find("Inventory");
        playerInventoryData = inventory.GetComponent <PlayerInventoryData>();
        anim = GameObject.Find("Player Model").GetComponent <Animator>();
        bagWeightText.text = "0";
        audioController    = gameObject.GetComponent <PlayerAudioController>();
        // TODO: set music audio source ignoreListenerPause to true

        moveLeftAction.Enable();
        moveRightAction.Enable();

        touchContact.Enable();
        touchPosition.Enable();
    }
        private void LoadImage(ObservableCollection <PlayerInventoryData> imageDatas, IList <ItemData> itemDatas, string itemIconBaseUrl)
        {
            foreach (var item in itemDatas)
            {
                if (item != null)
                {
                    string iconUrl = string.Format("{0}{1}__{2}.png", itemIconBaseUrl, item.icon, item.iconcolor);

                    SdtdLocalizationManager.Instance.LocalizationDict.TryGetValue(item.name, out string chinese);

                    PlayerInventoryData playerInventoryData = new PlayerInventoryData()
                    {
                        Source = new Uri(iconUrl, UriKind.Absolute),
                        //HexColor = null,
                        ToolTip = string.Format("{0}{1}{2}{3}数量: {4}{5}品质: {6}",
                                                item.name, Environment.NewLine, chinese, Environment.NewLine,
                                                item.count, Environment.NewLine, item.quality == -1 ? "无" : item.quality.ToString()),
                        English      = item.name,
                        Chinese      = chinese,
                        Count        = item.count,
                        QualityColor = item.qualitycolor
                    };

                    if (item.qualitycolor != null)
                    {
                        playerInventoryData.Count = null;
                    }

                    imageDatas.Add(playerInventoryData);
                }
            }
        }
Esempio n. 3
0
        //load player inventory datas
        private void ReadFromXML_PlayerInventoryData()
        {
            PlayerInventoryData PID = null;

            if (string.IsNullOrEmpty(_FileNameByInventoryData))
            {
                Debug.LogError(GetType() + "/ReadFromXML_PlayerInventoryData()/_FileNameByInventoryData doesn't exist");
                return;
            }

            try
            {
                //load xml
                string strTemp = XmlOperation.GetInstance().LoadXML(_FileNameByExtendalData);

                PID = XmlOperation.GetInstance().DeserializeObject(strTemp, typeof(PlayerInventoryData)) as PlayerInventoryData;

                PlayerInventoryDataProxy.GetInstance().HealthPotionNum = PID.HealthPotionNum;
                PlayerInventoryDataProxy.GetInstance().ManaPotionNum   = PID.ManaPotionNum;
                PlayerInventoryDataProxy.GetInstance().PropATKNum      = PID.PropATKNum;
                PlayerInventoryDataProxy.GetInstance().PropDEFNum      = PID.PropDEFNum;
                PlayerInventoryDataProxy.GetInstance().PropDEXNum      = PID.PropDEXNum;
            }
            catch
            {
                Debug.LogError(GetType() + "/ReadFromXML_PlayerInventoryData()/load game save config data failed");
            }
        }
Esempio n. 4
0
    private float invincibilityDuration = 1f;     // Seconds after which player is invincible against collisions

    void Start()
    {
        maxSpeed                   = INITIAL_SPEED;
        currentSpeed               = INITIAL_SPEED;
        jumpAction.performed      += ctx => Jump();
        slideAction.performed     += ctx => Slide();
        moveLeftAction.performed  += ctx => MoveLeft();
        moveRightAction.performed += ctx => MoveRight();

        _body = gameObject.GetComponent <Rigidbody>();
        starting_elevation = _body.position.y;

        inventory           = GameObject.Find("Inventory");
        playerInventoryData = inventory.GetComponent <PlayerInventoryData>();
    }
    private void Awake()
    {
        GameObject player = GameObject.Find("Inventory");

        if (player != null)
        {
            playerInventoryData = player.GetComponent <PlayerInventoryData>();
        }
        else
        {
            Debug.LogError("Cannot find inventory object named \' Inventory \' in the scene. Please change RecipeUI.cs if the inventory object was renamed.");
        }

        if (playerInventoryData == null)
        {
            Debug.LogError("Cannot find \' PlayerInventoryData \' script on the \' Inventory \' object in the scene. Please change RecipeUI.cs if the inventory object was renamed, or reattach/rename \' PlayerInventoryData \'.");
        }
    }
Esempio n. 6
0
    public PlayerInventoryData SaveInventoryData()
    {
        PlayerInventoryData pid = new PlayerInventoryData();

        pid.equippedItems = new List <ItemData>();

        //Forgot I made a function for this until after typing it all.. damn.

        var equippedItems = GetAllEquipped();

        foreach (Item item in equippedItems)
        {
            if (item == null)
            {
                //Still add null items to make sure everything stays in order. Order is critical to the save/load process
                pid.equippedItems.Add(null);
            }
            else
            {
                pid.equippedItems.Add(item.SaveItemData());
            }
        }

        /*
         * pid.equippedItems.Add(equippedWeapon.SaveItemData());
         * pid.equippedItems.Add(equippedArmor.SaveItemData());
         * pid.equippedItems.Add(equippedHelmet.SaveItemData());
         * pid.equippedItems.Add(equippedGloves.SaveItemData());
         * pid.equippedItems.Add(equippedBoots.SaveItemData());
         */

        pid.heldItems = new List <ItemData>();
        foreach (Item i in items)
        {
            pid.heldItems.Add(i.SaveItemData());
        }

        return(pid);
    }
Esempio n. 7
0
    public void LoadInventoryData(PlayerInventoryData pid)
    {
        ItemFactory itemFactory = FindObjectOfType <ItemFactory>();

        foreach (ItemData id in pid.equippedItems)
        {
            if (id != null)
            {
                Item newItem = itemFactory.SpawnItemOfType(id.itemType);
                newItem.LoadItemData(id);
                EquipItem(newItem);
            }
        }

        foreach (ItemData id in pid.heldItems)
        {
            if (id != null)
            {
                Item newItem = itemFactory.SpawnItemOfType(id.itemType);
                newItem.LoadItemData(id);
                addItem(newItem);
            }
        }
    }