示例#1
0
        public override void Update(float deltaTime)
        {
            if (deltaTime > MAX_DELTA_TIME)
            {
                deltaTime = MAX_DELTA_TIME;
            }

            Vector3 vectorToPlayer   = item.position - (item.world.avatarManager.player.position + new Vector3(0, Player.HEAD_POSITION * 0.5f, 0));
            float   distanceToPlayer = vectorToPlayer.magnitude;

            if (distanceToPlayer < PLAYER_CATCH_DISTANCE)
            {
                CWObject objectToAdd = this.item;

                if (objectToAdd.definition.type == CWDefinition.DefinitionType.ItemTile)
                {
                    objectToAdd = new DynamicTile(item.world, ((ItemTileDefinition)item.definition).tileDefinition, -1);
                }

                if (item.world.avatarManager.player.inventory.Add(objectToAdd))
                {
                    item.world.itemManager.RemoveItem(item);
                }
            }
            else if (distanceToPlayer < PLAYER_ATTRACT_DISTANCE)
            {
                Vector3 dirToPlayer = vectorToPlayer.normalized;

                item.position -= dirToPlayer * MOVE_SPEED * deltaTime;
            }
        }
    public GameObject CreateGameObjectFromObject(CWObject cwObject)
    {
        GameObject go = null;

        switch (cwObject.definition.type)
        {
        case CWDefinition.DefinitionType.Item:
            go = CreateItemGameObject((Item)cwObject);
            break;

        case CWDefinition.DefinitionType.Tile:
            go = CreateTileGameObject((DynamicTile)cwObject);
            break;

        case CWDefinition.DefinitionType.ItemTile:
            go = CreateItemTileGameObject((ItemTile)cwObject);
            break;

        case CWDefinition.DefinitionType.Avatar:
            go = CreateAvatarGameObject((CubeWorld.Avatars.Avatar)cwObject);
            break;

        default:
            throw new System.Exception("Unknown game object to create");
        }

        return(go);
    }
    public void DestroyObject(CWObject cwobject)
    {
        GameObject go = createdGO[cwobject];

        createdGO.Remove(cwobject);
        RemoveGameObject(go);
    }
    public void CreateObject(CWObject cwobject)
    {
        GameObject go = CreateGameObjectFromObject(cwobject);

        go.transform.position = GraphicsUnity.CubeWorldVector3ToVector3(cwobject.position);
        createdGO[cwobject]   = go;
    }
    public GameObject FindGameObject(CWObject cwObject)
    {
        if (createdGO.ContainsKey(cwObject))
        {
            return(createdGO[cwObject]);
        }

        return(null);
    }
示例#6
0
 public void PlaySound(string soundId, CWObject fromObject)
 {
     if (sounds.ContainsKey(soundId))
     {
         PlayAudioClip(soundId, GraphicsUnity.CubeWorldVector3ToVector3(fromObject.position), 1.0f);
     }
     else
     {
         Debug.Log("Unknown sound: " + soundId);
     }
 }
示例#7
0
        public void Load(System.IO.BinaryReader br)
        {
            entries.Clear();

            int n = br.ReadInt32();

            for (int i = 0; i < n; i++)
            {
                string id       = br.ReadString();
                int    position = br.ReadInt32();
                int    quantity = br.ReadInt32();

                TileDefinition tileDefinition = owner.world.tileManager.GetTileDefinitionById(id);
                CWObject       cwobject       = null;

                if (tileDefinition != null)
                {
                    //It's a tile
                    DynamicTile dynamicTile = new DynamicTile(owner.world, tileDefinition, -1);

                    cwobject = dynamicTile;
                }
                else
                {
                    ItemDefinition itemDefinition = owner.world.itemManager.GetItemDefinitionById(id);

                    if (itemDefinition != null)
                    {
                        //It's an item
                        Item item;

                        if (itemDefinition.type == CubeWorld.World.Objects.CWDefinition.DefinitionType.ItemTile)
                        {
                            item = new ItemTile(owner.world, (ItemTileDefinition)itemDefinition, -1);
                        }
                        else
                        {
                            item = new Item(owner.world, itemDefinition, -1);
                        }

                        cwobject = item;
                    }
                }

                cwobject.Load(br);

                InventoryEntry ie = new InventoryEntry();
                ie.position = position;
                ie.quantity = quantity;
                ie.cwobject = cwobject;

                entries.Add(ie);
            }
        }
示例#8
0
        /**
         * Adds an object to the inventory.
         *
         * @returns true if the object was added, false if there was no space for the object
         */
        public bool Add(CWObject cwobject)
        {
            InventoryEntry existingEntry = FindInventoryEntryFromDefinition(cwobject.definition);

            if (existingEntry != null)
            {
                existingEntry.quantity++;
            }
            else
            {
                existingEntry          = new InventoryEntry();
                existingEntry.quantity = 1;
                existingEntry.cwobject = cwobject;

                entries.Add(existingEntry);
            }

            return(true);
        }
示例#9
0
    public void PlayEffect(string effectId, CWObject fromObject)
    {
        if (effects.ContainsKey(effectId))
        {
            ((GameObject)GameObject.Instantiate(effects[effectId], GraphicsUnity.CubeWorldVector3ToVector3(fromObject.position), Quaternion.identity)).transform.parent = goContainer.transform;
        }
        else if (effectsComponents.ContainsKey(effectId))
        {
            GameObject go = gameManagerUnity.objectsManagerUnity.FindGameObject(fromObject);

            if (go)
            {
                go.AddComponent(effectsComponents[effectId]);
            }
            else
            {
                Debug.Log("Effect " + effectId + " found but GameObject to add sound to not found");
            }
        }
        else
        {
            Debug.Log("Unknown effect: " + effectId);
        }
    }
    private void UpdateItemOnHand()
    {
        if (currentObjectInHand != playerUnity.objectInHand)
        {
            if (goInHand)
            {
                playerUnity.gameManagerUnity.objectsManagerUnity.RemoveGameObject(goInHand);

                goInHand = null;
            }

            this.currentObjectInHand = playerUnity.objectInHand;

            if (currentObjectInHand != null)
            {
                goInHand = playerUnity.gameManagerUnity.objectsManagerUnity.CreateGameObjectFromObject(currentObjectInHand);

                goInHand.transform.parent        = hand.transform;
                goInHand.transform.localScale    = new Vector3(1, 1, 1);
                goInHand.transform.localPosition = new Vector3(0, 0, 0);
                goInHand.transform.localRotation = Quaternion.identity;

                switch (currentObjectInHand.definition.type)
                {
                case CWDefinition.DefinitionType.Item:
                    positionHand_Current = positionHand_Item;
                    scaleHand_Current    = scaleHand_Item;
                    rotationHand_Current = rotationHand_Item;
                    break;

                case CWDefinition.DefinitionType.Tile:
                    positionHand_Current = positionHand_Tile;
                    scaleHand_Current    = scaleHand_Tile;
                    rotationHand_Current = rotationHand_Tile;
                    break;
                }

                hand.transform.localPosition = positionHand_Current;
                hand.transform.localScale    = scaleHand_Current;
                hand.transform.localRotation = rotationHand_Current;
            }
        }

        if (handUseAnimationTimer <= 0.0f)
        {
            if (playerUnity.player.input.moveDirection.magnitude > 0.0f)
            {
                handMovementTimer += Time.deltaTime;

                float deltaY = Mathf.Sin(handMovementTimer * 10) * 0.02f;
                float deltaX = Mathf.Sin(handMovementTimer * 10) * 0.01f;

                hand.transform.localPosition = positionHand_Current + new Vector3(deltaX, deltaY, 0.0f);
            }
            else
            {
                handMovementTimer            = 0.0f;
                hand.transform.localPosition = positionHand_Current;
            }
        }
        else
        {
            if (currentObjectInHand != null)
            {
                float deltaRotation = Mathf.Sin(handUseAnimationTimer * 2.0f * Mathf.PI) * 30;

                hand.transform.localPosition = positionHand_Current;

                switch (currentObjectInHand.definition.type)
                {
                case CWDefinition.DefinitionType.Tile:
                    hand.transform.localRotation = rotationHand_Current * Quaternion.Euler(deltaRotation, 0, 0);
                    break;

                case CWDefinition.DefinitionType.Item:
                    hand.transform.localRotation = rotationHand_Current * Quaternion.Euler(0, 0, deltaRotation);
                    break;
                }
            }

            handUseAnimationTimer -= Time.deltaTime;

            if (handUseAnimationTimer <= 0.0f)
            {
                hand.transform.localRotation = rotationHand_Current;
                handUseAnimationTimer        = 0.0f;
            }
        }
    }
示例#11
0
 protected override void OnAddedToObject(CWObject cwobject)
 {
     item = (Item)cwobject;
 }
示例#12
0
 protected virtual void OnAddedToObject(CWObject cwobject)
 {
 }
示例#13
0
 public Inventory(CWObject owner)
 {
     this.owner = owner;
 }
示例#14
0
        internal void AddedToObject(CWObject cwobject)
        {
            this.cwobject = cwobject;

            OnAddedToObject(cwobject);
        }
示例#15
0
 protected override void OnAddedToObject(CWObject cwobject)
 {
     this.avatar = (Avatar)cwobject;
 }
示例#16
0
 public void UpdateObject(CWObject cwobject)
 {
 }
示例#17
0
 protected override void OnAddedToObject(CWObject cwobject)
 {
     tile = (DynamicTile)cwobject;
 }
示例#18
0
        internal void RemovedFromObject()
        {
            this.cwobject = null;

            OnRemovedFromObject();
        }