OnDragListener not working properly - drag-and-drop

Hello everybody and thanks in advance.
I have a strange issue with one of my apps. This app is a MasterMind game which uses drag & drop, dragging coloured circles to holes.
This has been worked right with lots of devices, but recently I tried in a Galaxy S7 and Note 4 where the views(holes) have triggered the ACTION_DRAG_ENTERED outside the view.
Take a look at this screenshots to have a clearer idea...
< RIGHT BEHAVIOUR >
< WRONG BEHAVIOUR >
This is my listener...
class MiDragListener implements OnDragListener
{
#Override
public boolean onDrag(View v, DragEvent event)
{
int accion = event.getAction();
switch (accion)
{
case DragEvent.ACTION_DRAG_STARTED:
case DragEvent.ACTION_DRAG_EXITED:
v.setScaleX((float)1.0);
v.setScaleY((float)1.0);
break;
case DragEvent.ACTION_DRAG_ENTERED:
v.setScaleX((float)2.0);
v.setScaleY((float)2.0);
break;
case DragEvent.ACTION_DRAG_ENDED:
v.setScaleX((float)1.0);
v.setScaleY((float)1.0);
break;
case DragEvent.ACTION_DROP:
break;
default:
break;
}
return true;
}
} // end MiDragListener
although my code has not been changed.
Any help will be appreciated, thanks for your time and attention.

Related

Limit on the number of NPCs

Such an idea, for which I don't even have any ideas how to do it right. In general, the thought is:
There are, say, three NPCs on the stage (Conditionally), and there is also one building (Conditionally). Each NPC has its own task, but I do not know how to take an NPC who does not have a task and send one NPC to work in the building, and not several at once. Namely, each NPC has work statuses, and there is also a status 0, meaning that the NPC is not busy, there may be several such "free" ones, and if one is assigned the status of work - go to the building, then everyone who has this status will go, but how can we make sure that only one free NPC is taken and sent there?
I know the question is as incomprehensible and terrible as possible, but maybe someone will understand...
I made, so, to begin with, the code:
File WorkingPlace:
public static bool SignalFreeNPCPoint = false;
public static int WorkingPlaceNPC = 0;
public void ProductBoardNPC()
{
SignalFreeNPCPoint = true;
WorkingPlaceNPC += 1;
}
public void ProductBoard_Stop()
{
WorkingPlaceNPC -= 1;
SignalFreeNPCPoint = true;
}
This "ProductBoardNPC()" and "ProductBoard_Stop()" method's for button in Unity.
File NPCSctipt:
public List<GameObject> ListGM = new List<GameObject>();
public int TaskNumber = 0;
void Update()
{
TaskManager();
LogicNPC();
}
private void TaskManager()
{
switch (TaskNumber)
{
case 0:
//You code
break;
case 1:
ListGM.Remove(gameObject);
break;
case 2:
ListGM.Remove(gameObject);
break;
case 3:
ListGM.Remove(gameObject);
break;
case 4:
ListGM.Remove(gameObject);
break;
}
}
private void LogicNPC()
{
if (WorkingPlace.SignalFreeNPCPoint == true)
{
if (TaskNumber == 0 & WorkingPlace.WorkingPlaceNPC == 1)
{
ListGM.Add(gameObject);
TaskNumber = 4;
}
if (TaskNumber == 4 & WorkingPlace.WorkingPlaceNPC == 0)
{
TaskNumber = 0;
}
WorkingPlace.SignalFreeNPCPoint = false;
}
}
How the code works:
When you click on the button, an NPC with the status 0 is searched, the last NPC with this status is taken and entered into the array, after which it is given a different status to perform "work", after which it is removed from the array to make room for another NPC.
In this case, the array is a buffer and is simply necessary. If you have better ideas than mine, I will be happy to listen)
The implementation is a clean bike made of crutches, but it works flawlessly. Yes, about FPS drawdowns, it doesn't seem to load the system much, if there are drawdowns, then write what to fix.

transform.childCount not working as intended

I am building my first game with unity, a simple break out game.i am intending that when the level has no children it moves to the next level.but it doesn't seem to work.in the code I put this in the update methode.
else if (_currentLevel != null && _currentLevel.transform.childCount == 0)
{
SwitchState(State.LEVELCOMPLETED);
}
break;
which call this code
case State.LEVELCOMPLETED:
Destroy(_currentBall);
Destroy(_currentLevel);
Level++;
PanelLevelCompleted.SetActive(true);
SwitchState(State.LOADLEVEL, 1.0f);
break;
but it doesn't even get into the first condition although in the editor i can see there's no Childrens.
PS:Sorry if it's not clear if any more details are needed I will add them.
I figure out what was wrong exactly, I failed to assigne the Instantiated level to the current level. I didn't add that part of code in the answer which made it very unclear.
In summary instead of
Instantiate(levels[Level]);
I added
_currentLevel = Instantiate(levels[Level]);
and it worked as intended.

GvrEventSystem vs EventSystem

Working on a Unity hybrid VR (cardboard) /2D app. The cardboard side of it works fine. I am having trouble with the 2D/VR switching.
When I am in 2D mode, reticle does not move, although screen taps register. So the app seems unaware of the gyro.
I feel like I am missing something fundamental here. I have a GvrEventSystem prefab that has both an EventSystem and GvrPointerInputModule components.
What obvious thing am I over-looking?
ETA:
I have been asked to add relevant code. Here is the code for 2D-VR switching on-the-fly. This code executes w/out error, and the app switches between VR and 2D mode every 3 seconds:
readonly string NONE_STRING = "";
readonly string CARDBOARD_STRING = "cardboard";
void Start()
{
Invoke("GoPhone", 3.0f);
}
void GoPhone()
{
SetVREnabled(false);
Invoke("GoVR", 3.0f);
}
void GoVR()
{
SetVREnabled(true);
Invoke("GoPhone", 3.0f);
}
void SetVREnabled(bool isEnabled)
{
if (isEnabled)
{
StartCoroutine(LoadDevice(CARDBOARD_STRING));
}
else
{
StartCoroutine(LoadDevice(NONE_STRING));
}
}
IEnumerator LoadDevice(string newDevice)
{
if (String.Compare(XRSettings.loadedDeviceName, newDevice, true) != 0)
{
XRSettings.LoadDeviceByName(newDevice);
yield return null;
if (!XRSettings.loadedDeviceName.Equals(NONE_STRING))
XRSettings.enabled = true;
}
}
Although I feel like my problem is a configuration problem, and not a code problem. In the editor, which does not support VR mode, the app behaves in 2D mode as expected.
Also ETA:
JIC
User error! I did not follow the "Magic Window" instructions as detailed at https://developers.google.com/vr/develop/unity/guides/magic-window... let my folly be a warning to future generations!

Unity Touch phase returning incorrect results

In Unity, I am attempting to use Touch.
I am having non-stop issues with it and have decided to just try and get something simple working first.
Whenever i press the screen, i am expecting Touch.phase to return TouchPhase.Began every time. However, it will sometimes return TouchPhase.Stationary when touching the screen for the first time. I have also noticed that it will sometimes not call TouchPhase.Ended or TouchPhase.Canceled when the touch has left the screen. What am i doing wrong?
Here is my very simple code:
void FixedUpdate() {
if(Input.touchCount == 1) {
Touch touch = Input.GetTouch(0);
switch(touch.phase) {
case TouchPhase.Began:
Debug.Log("Began: " + touch.figerId);
break;
case TouchPhase.Stationary:
Debug.Log("Stationary");
break;
case TouchPhase.Moved:
Debug.Log("Moved");
break;
case TouchPhase.Canceled:
Debug.Log("Canceled");
break;
case TouchPhase.Ended:
Debug.Log("Ended");
break;
default:
Debug.Log("Default");
break;
}
}
}
Touch.phase is updated every frame, so you have to check it within the Update() method.
FixedUpdate() is only called every x frames (fixed framerate), that's the reason you are missing some of the touch phases.

Change sequence of states on a three-state ToggleButton

It seems that the out-of-box sequence for a three-state ToggleButton is On, Indeterminate, Off.
I would like to change this to On, Off, Indeterminate; similar to the question presented here .
I've tried modifying my StateChanging event, but I think that will result in an infinite loop.
I briefly implemented a working solution using ToggleStateChanging to change the order of the states, and then using a global variable to avoid an infinite loop. However, I then had a new problem where the ToggleButton had some sort of auto-theme where it was shaded differently for each state and on MouseHover. I didn't want that theme, so I ultimately just changed the buttons to standard buttons, and now I'm using the buttons' Tag property to emulate ToggleState.
My particular solution uses a Telerik RadButton, but this would work for a standard button as well on a WinForm.
private void myButton_Click(object sender, EventArgs e)
{
RadButton myButton = (RadButton)sender;
switch (myButton.Tag.ToString())
{
case "Indeterminant":
myButton.Tag = "On";
break;
case "On":
myButton.Tag = "Off";
break;
case "Off":
myButton.Tag = "Indeterminant";
break;
default:
break;
}
}