Ejemplo n.º 1
0
 public override void OnDrop(PointerEventData eventData)
 {
     if (UIDragDropHandler.CurrentData == null)
     {
         if (UIDragDropHandler.Active)
         {
             if (PlayAudio)
             {
                 AudioPool.PlayClip(StringConst.AudioDefaultItemReturn, transform.position, 0, AudioVolume);
             }
             UIDragDropHandler.Return();
         }
         return;
     }
     if (PlayAudio)
     {
         AudioPool.PlayClip(StringConst.AudioDefaultItemClick, transform.position, 0, AudioVolume);
     }
     if (Data != null)
     {
         TrySwap();
     }
     else
     {
         TryDrop();
     }
 }
Ejemplo n.º 2
0
        protected virtual void TrySwap()
        {
            if (InventoryItem.CanStack(UIDragDropHandler.CurrentData))
            {
                UIDragDropHandler.Take();
                return;
            }
            Entity oldItem = Data;

            UIDragDropHandler.CurrentData.Get <InventoryItem>(i => i.Index = Index);
            if (Player.MainInventory.TryAdd(UIDragDropHandler.CurrentData))
            {
                UIDragDropHandler.Take();
                UIDragDropHandler.SetItem(oldItem);
            }
            else
            {
                if (PlayAudio)
                {
                    AudioPool.PlayClip(StringConst.AudioDefaultItemReturn, transform.position, 0, AudioVolume);
                }
                UIDragDropHandler.Return();
                Player.MainInventory.TryAdd(oldItem);
            }
        }
Ejemplo n.º 3
0
 protected void RejectDrag()
 {
     if (PlayAudio)
     {
         AudioPool.PlayClip(StringConst.AudioDefaultItemReturn, transform.position, 0, AudioVolume);
     }
     UIDragDropHandler.Return();
 }
Ejemplo n.º 4
0
 public void ButtonClicked()
 {
     if (_clickAudio != null)
     {
         AudioPool.PlayClip(_clickAudio, transform.position, 0);
     }
     if (OnButtonClicked != null)
     {
         OnButtonClicked(Index);
     }
 }
Ejemplo n.º 5
0
        private IEnumerator CheckForOrphan(int checkId)
        {
            yield return(0.1f);

            if (Active && _currentId == checkId)
            {
                //Debug.Log("timeout activated");
                AudioPool.PlayClip(StringConst.AudioDefaultItemReturn, transform.position, 0, 0.5f);
                Return();
            }
        }
Ejemplo n.º 6
0
 public void TriggerEvent(ActionStateEvent actionEvent)
 {
     for (int i = 0; i < _actionData.Length; i++)
     {
         if (_actionData[i].Event == actionEvent.State || (_actionData[i].Event == ActionStateEvents.CollisionOrImpact && (actionEvent.State == ActionStateEvents.Impact || actionEvent.State == ActionStateEvents.Collision)))
         {
             if (_actionData[i].Sound != null)
             {
                 AudioPool.PlayClip(_actionData[i].Sound, actionEvent.Position, 0.5f);
             }
             if (_actionData[i].Particle.Animation == null)
             {
                 continue;
             }
             switch (_actionData[i].Event)
             {
             case ActionStateEvents.Collision:
             case ActionStateEvents.CollisionOrImpact:
             case ActionStateEvents.Impact:
                 if (actionEvent.Target != null)
                 {
                     var impactRenderer = actionEvent.Target.Get <ImpactRendererComponent>();
                     if (impactRenderer != null)
                     {
                         impactRenderer.PlayAnimation(_actionData[i].Particle.Animation, _actionData[i].Particle.Color);
                         continue;
                     }
                 }
                 break;
             }
             //var spawn = ItemPool.SpawnScenePrefab(_actionPrefabs[i].Prefab, actionEvent.Position, actionEvent.Rotation);
             //CheckObjectForListener(spawn, actionEvent);
             var particle = SpriteParticleSystem.PlayParticle(_actionData[i].Particle, actionEvent.Position, actionEvent.Rotation);
             if (!_actionData[i].Parent)
             {
                 continue;
             }
             TransformComponent tr = null;
             if (actionEvent.Target == null)
             {
                 tr = actionEvent.Origin.Tr;
             }
             else
             {
                 tr = actionEvent.Target.Tr;
             }
             if (tr != null)
             {
                 tr.SetChild(particle.Tr);
             }
         }
     }
 }
 protected override void TryDrop() {
     var newItem = UIDragDropHandler.CurrentData;
     if (World.Get<EquipmentSystem>().TryEquip(_slot, newItem)) {
         UIDragDropHandler.Take();
     }
     else {
         if (PlayAudio) {
             AudioPool.PlayClip(StringConst.AudioDefaultItemReturn, transform.position, 0, AudioVolume);
         }
         UIFloatingText.InventoryMessage(_slot.LastEquipStatus, RectTransform);
         UIDragDropHandler.Return();
     }
 }
Ejemplo n.º 8
0
 protected virtual void TryDrop()
 {
     if (Player.MainInventory.TryAdd(UIDragDropHandler.CurrentData))
     {
         UIDragDropHandler.Take();
     }
     else
     {
         if (PlayAudio)
         {
             AudioPool.PlayClip(StringConst.AudioDefaultItemReturn, transform.position, 0, AudioVolume);
         }
         UIDragDropHandler.Return();
     }
 }
Ejemplo n.º 9
0
 protected override void StartDrag()
 {
     base.StartDrag();
     if (PlayAudio)
     {
         AudioPool.PlayClip(StringConst.AudioDefaultItemClick, transform.position, 0, AudioVolume);
     }
     if (Data.Get <InventoryItem>()?.Inventory?.Owner.HasComponent <PlayerComponent>() ?? false)
     {
         UIDragDropHandler.SetItem(Data, StopDrag, StopDrag, Clear);
     }
     else
     {
         UIDragDropHandler.SetItem(Data, TryAddPlayer, StopDrag, Clear);
     }
     DisableSlotDetails();
 }
Ejemplo n.º 10
0
 public void PlayAudio(int signal, Vector3 position)
 {
     if (_dict.Count == 0)
     {
         for (int i = 0; i < Clips.Count; i++)
         {
             if (!_dict.ContainsKey(Clips[i].Id))
             {
                 _dict.Add(Clips[i].Id, Clips[i].Audio);
             }
         }
     }
     if (!_dict.TryGetValue(signal, out var clip))
     {
         return;
     }
     AudioPool.PlayClip(clip, position);
 }
Ejemplo n.º 11
0
 public void TriggerEvent(ActionStateEvent actionEvent)
 {
     for (int i = 0; i < _actionPrefabs.Length; i++)
     {
         if (_actionPrefabs[i].Event == actionEvent.State)
         {
             if (_actionPrefabs[i].Prefab != null)
             {
                 var spawn = ItemPool.SpawnScenePrefab(_actionPrefabs[i].Prefab, actionEvent.Position, actionEvent.Rotation);
                 CheckObjectForListener(spawn, actionEvent);
             }
             if (_actionPrefabs[i].Sound != null)
             {
                 AudioPool.PlayClip(_actionPrefabs[i].Sound, actionEvent.Position, 0.5f);
             }
         }
     }
 }
Ejemplo n.º 12
0
 public void TriggerEvent(ActionState state, Vector3 position, Quaternion rotation, CharacterTemplate target)
 {
     for (int i = 0; i < _actionData.Length; i++)
     {
         if (_actionData[i].Event == state || (_actionData[i].Event == ActionState.CollisionOrImpact && (state == ActionState.Impact || state == ActionState.Collision)))
         {
             if (_actionData[i].Sound != null)
             {
                 AudioPool.PlayClip(_actionData[i].Sound, position, 0.5f);
             }
             if (_actionData[i].Particle.Animation == null)
             {
                 continue;
             }
             switch (_actionData[i].Event)
             {
             case ActionState.Collision:
             case ActionState.CollisionOrImpact:
             case ActionState.Impact:
                 if (target != null)
                 {
                     var impactRenderer = target.Entity.Get <ImpactRendererComponent>();
                     if (impactRenderer != null)
                     {
                         impactRenderer.PlayAnimation(_actionData[i].Particle.Animation, _actionData[i].Particle.Color);
                         continue;
                     }
                 }
                 break;
             }
             //var spawn = ItemPool.SpawnScenePrefab(_actionPrefabs[i].Prefab, actionEvent.Position, actionEvent.Rotation);
             //CheckObjectForListener(spawn, actionEvent);
             var particle = SpriteParticleSystem.PlayParticle(_actionData[i].Particle, position, rotation);
             if (_actionData[i].Parent && target != null && target.Tr != null)
             {
                 target.Tr.SetChild(particle.Tr);
             }
         }
     }
 }
Ejemplo n.º 13
0
        protected virtual void TryDrop()
        {
            var dragInventoryData = UIDragDropHandler.CurrentData.Get <InventoryItem>();

            if (dragInventoryData.Inventory == Player.MainInventory && Player.MainInventory.TryChangeIndex(dragInventoryData.Index, Index, dragInventoryData))
            {
                Player.MainInventory.ContainerChanged();
                UIDragDropHandler.Take();
                return;
            }
            if (Player.MainInventory.Add(UIDragDropHandler.CurrentData, Index))
            {
                UIDragDropHandler.Take();
            }
            else
            {
                if (PlayAudio)
                {
                    AudioPool.PlayClip(StringConst.AudioDefaultItemReturn, transform.position, 0, AudioVolume);
                }
                UIDragDropHandler.Return();
            }
        }