コード例 #1
0
        protected override void Init()
        {
            Inventory = GetEntityBehaviour <InventoryBehaviour>();
            Inventory.InventorySize = 20;

            _playerInteractionPannel = Pannel.Show("PlayerInteractionPannel").GetComponent <PlayerInteractionPannel>();
            Entity.HasUpdation       = true;
        }
コード例 #2
0
        protected override void Init()
        {
            var spriteObject = new GameObject("sprite");

            spriteObject.transform.parent = transform;
            _spriteRenderer        = spriteObject.AddComponent <SpriteRenderer>();
            _spriteRenderer.sprite = GameManager.EntitySpriteDatabase.Get("chest");
            spriteObject.AddComponent <Billboard>();

            _inventoryBehaviour = GetComponent <InventoryBehaviour>();
            _inventoryBehaviour.InventorySize   = 20;
            _inventoryBehaviour.inventoryPannel = "ChestPannel";

            Entity.SetCollider(Vector3.up * 0.5f, 0.6f);
            Entity.IsSelectable = true;
        }
コード例 #3
0
        protected override void EntityUpdate()
        {
            _spriteRenderer.transform.localPosition = new Vector3(
                0,
                Mathf.Sin((Time.time + gameObject.GetInstanceID() / 10.0f) * 2) * 0.1f,
                0);

            // 计算速度和拾取
            if (_pickupBy != null)
            {
                var distPos = _pickupBy.Entity.transform.position + Vector3.up * 0.5f;

                // 和玩家重合后捡起物品
                if (Vector3.Distance(distPos, transform.position) < 0.75f)
                {
                    _spriteRenderer.color =
                        new Color(
                            _spriteRenderer.color.r,
                            _spriteRenderer.color.g,
                            _spriteRenderer.color.b,
                            _spriteRenderer.color.a - 5 * Time.deltaTime);

                    // 捡到物品
                    if (_spriteRenderer.color.a <= float.Epsilon)
                    {
                        _pickupBy.AddItem(ref item);
                        if (item.count == 0)
                        {
                            Entity.BeKilled(_pickupBy.Entity);
                            return;
                        }
                        _pickupBy             = null;
                        _spriteRenderer.color = new Color(_spriteRenderer.color.r, _spriteRenderer.color.g, _spriteRenderer.color.b, 1);
                    }
                }
                else
                {
                    // 继续计算速度
                    velocity = Vector3.SmoothDamp(velocity, (distPos - transform.position) * 5, ref accelerate, 0.1f);
                    _spriteRenderer.color = new Color(_spriteRenderer.color.r, _spriteRenderer.color.g, _spriteRenderer.color.b, 1);
                }
            }
            else
            {
                // 超出范围不受物理影响
                if (Vector3.Distance(transform.position, GameManager.Player.transform.position) > 5 && velocity.y <= float.Epsilon)
                {
                    velocity.y = 0;
                }
                else
                {
                    // 物品受重力影响掉落
                    if (velocity.y <= float.Epsilon && Physics.Raycast(transform.position, Vector3.down, 0.5f, 1 << BlockContainer.Layer))
                    {
                        velocity = Vector3.zero;
                    }
                    else
                    {
                        velocity.y -= 10 * Time.deltaTime;
                    }
                }
            }

            // 运动
            transform.position += velocity * Time.deltaTime;
        }
コード例 #4
0
 protected void OnPlayerPickup(PlayerBehaviour player)
 {
     _pickupBy = player.Inventory;
 }