|
Post by Legend on Apr 15, 2018 21:15:14 GMT
so overview - basically from what i find is you can still use both functionalities although i have the attacking controller broken right now ill see about fixing that after i get this part working i basically used the same functions as the attacking ones and seems to be working for the most part - i integrated it into the clicktoplaycard controller the issue i see right now is though: var hover = eventData.pointerCurrentRaycast.gameObject; var cardView = (hover != null) ? hover.GetComponentInParent<BattlefieldCardView>() : null;] this will show whats hovering over currently since draggin and dropping will have a hovering cover over top the mouse it seems to be showing that as the hover object mainly (card front image/ card title etc) any suggestions on this ? so far only thing i can think of is disable the raycast targets in all the objects in the current selected card or something? ? thanks! daniel;
|
|
|
Post by Admin on Apr 15, 2018 23:43:49 GMT
You've got the right idea - use a "Canvas Group" component and you can disable the "Interactable" toggle. Alternatively you can do manual ray casts of a specified layer, and put the cards in your hand and the cards on the table in different layer masks.
|
|
|
Post by Legend on Apr 16, 2018 5:38:54 GMT
So I was thinking about doing it either way aand looking it up and stumbled upon a layer - layer 2 - ignore raycasts -
thought that might work but it didnt which was a bummer basically was an extension to set object and childs to a layer
using UnityEngine; using System.Collections; public static class GameObjectExtension { public static void SetLayer(this GameObject parent, int layer, bool includeChildren = true) { parent.layer = layer; if (includeChildren) { foreach (Transform trans in parent.transform.GetComponentsInChildren<Transform>(true)) { trans.gameObject.layer = layer; } } } } it changed the layer but still for some reason didnt take the other object even with the activecardview set to layer 2 - ignore raycast weird
so i tried canvas group - i figured i would do the interactable disabling method but that didnt seem to work - it disabled the check box i put the canvas group on the player handview so if i understand it correctly should work unless i have to set the canvas group on each object (or the prefab)
the raycast hit alternative appears to be fairly popular more so than the other ones though so may just try that out
thanks for the suggestions!
|
|
|
Post by Admin on Apr 16, 2018 14:34:51 GMT
FYI in your GameObjectExtension, the transform component supports enumerators so you can loop through children using something like this: foreach (Transform child in parent.transform) See docs.unity3d.com/ScriptReference/Transform.html for reference. Also, that sample wont continue to grandchildren, and great-grandchildren etc. Use something like this instead so it could be recursive: trans.gameObject.SetLayer(layer, includeChildren)
|
|
|
Post by Admin on Apr 16, 2018 14:37:15 GMT
Also, if the canvas group component wasn't working for you, I would suggest verifying that you put it on the right GameObject - I believe it needs to be placed on the same object that the Canvas component is placed on. If you modify the alpha and the entire card disappears then it is probably a good placement.
|
|
|
Post by Legend on Apr 16, 2018 14:52:09 GMT
so confused - im noticing when it works the card is behind the target so the mouse pointer is hovering over the target instead... im not modifying the location at all so i find that strange. i noticed that the first or second card i have will appear behind the object when i drag it over and the 3rd or 4th will appear in front but in the scene window i can see it is behind the object - so that is strange - i compared the values of the game object and they seem to be identical with the exception to the x axis which makes sense
anyways im going to attempt that gameobject extension method again cause that seems like it should work - im probably misunderstanding something with unity.
|
|
|
Post by Legend on Apr 16, 2018 15:06:14 GMT
Also, if the canvas group component wasn't working for you, I would suggest verifying that you put it on the right GameObject - I believe it needs to be placed on the same object that the Canvas component is placed on. If you modify the alpha and the entire card disappears then it is probably a good placement. Ya -i tried that i saw all the cards disappear - but i think i figured it out now why - i tried interactable but its actually the blocks raycasts checkbox that needs to be set to false then set to true again at the end (in case of cancel or w.e) bam that fixed it - still perplexed why the layer way didnt work but im going to go with this thanks again for the help!
|
|
|
Post by Legend on Apr 17, 2018 5:15:16 GMT
Have any clue why the drag to attack controller script is not being called simultaneously to the clicktoplaycardcontroller script with both drag handlers attached?? - i have the same drag handlers and such - it doenst look like the waitingforinput state on begin drag isnt getting called.
|
|
|
Post by Admin on Apr 17, 2018 13:41:02 GMT
I believe that the events are only posted to the first encountered script that implements the protocol. One solution would be to make a new "InputController" script that implements all of the events like tapping and dragging, and then posts its own notifications or events so that it is not limited to a single observer.
|
|
|
Post by Legend on Apr 17, 2018 14:17:18 GMT
I was thinking to combine them into one giant one is that what you are thinking? and do some if statements to differentiate between a card and a battlefield creature to either play or attack respectively. - that what you are talking about or you talking about creating another script that actually takes the inputs and then will call the appropriate script or something?
|
|
|
Post by Legend on Apr 17, 2018 15:02:01 GMT
think i got it -
1.create a carddraggable script 2.create a creaturedraggable script 3.change the original scripts to observe the notificaitons from those above scripts 4. attach scripts to the objects card to card creature to the hero and creature.
mimicing the clickable script in a way just for drag instead of click
|
|
|
Post by Legend on Apr 17, 2018 15:17:09 GMT
public class CardDraggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
public const string CardBeginDragNotification = "CardDraggable.CardBeginDragNotification"; public const string CardDraggingNotification = "CardDraggable.CardDraggingNotification"; public const string CardEndDragNotification = "CardDraggable.CardEndDragNotification";
public void OnBeginDrag(PointerEventData eventData) { this.PostNotification(CardBeginDragNotification, eventData); }
public void OnDrag(PointerEventData eventData) { this.PostNotification(CardDraggingNotification, eventData); }
public void OnEndDrag(PointerEventData eventData) { this.PostNotification(CardEndDragNotification, eventData); }
}
awww yaaaaa
right right? im not missing something here that will fail miserably right?
|
|
|
Post by Legend on Apr 17, 2018 19:06:03 GMT
yup that worked - didnt really have to do the samething for the creature but hey why nottt - thanks for the tip - i think that's what you were suggesting anyway.
|
|
|
Post by Legend on Apr 17, 2018 20:38:56 GMT
doing the rest of my tasks - i have to try and change hovering so i know when im over something - i have to ways that i know of to do this
1. make it notification and subscribe to notifications when it is not being hovered over 2. make a script to check within an update to see if the mouse is over an object and deal with that
think there is a third way to use the unity gui but dont want to deal with that.
im leaning towards 1. since the notification system is already in place and i dont really like that update function - just doesnt make sense to me - to check things every frame for a card game cause its so input oriented.
|
|
|
Post by Legend on Apr 17, 2018 20:40:46 GMT
btw if you are getting me tired of putting stuff in the forums - feel free to not comment or tell me - i just figured i would try to if needed help people out as i go through this in case it helps others or you even! ( much less likely you cause you seem to be a wizz at this stuff)
|
|