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);
 }
Example #2
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;
        }
 protected override void OnAddedToObject(CWObject cwobject)
 {
     this.avatar = (Avatar) cwobject;
 }
    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;
			}
		}
    }
Example #5
0
 public Inventory(CWObject owner)
 {
     this.owner = owner;
 }
    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);
    }
	public void DestroyObject(CWObject cwobject)
	{
		GameObject go = createdGO[cwobject];
		createdGO.Remove(cwobject);
		RemoveGameObject(go);
	}
 protected override void OnAddedToObject(CWObject cwobject)
 {
     item = (Item) cwobject;
 }
	public void UpdateObject(CWObject cwobject)
	{
	}
	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;
    }
    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;
	}
 protected override void OnAddedToObject(CWObject cwobject)
 {
     tile = (DynamicTile) cwobject;
 }