I'm working with reorderable lists in Unity right now and I can't seem to figure out how to update the 'max items' field that is visible in the inspector from a script. I'm a little new to Unity so I might be missing something easy but I didn't see any way from the listed methods or properties to update this field. Just looking to set the max items in a reorderable list to the size of a Dictionary that I have populated.
Any help would be appreciated. Thanks.
Edit: Just to be clear, the value I'm trying to change is the bottom one in the screenshot below:
I've tried things along the lines of listName.maxValue = X, listName.maxSize = X, but (at least out of what Visual Studio Code is showing me) there is no method available to change this value. I even tried opening the Reorderable List script (which is from an imported package) and adding my own method for it but it is still throwing an error after trying to use it.
Note that such a class name already exists namely UnityEditorInternal.ReorderableList.
Make sure on top of your file you have
using UnityEngine.UI.Extensions;
instead of
using UnityEditorInternal;
Related
I have a building grid system in Unity that is based on the TileMap system that already exists. I have systems for placing objects by clicking, and randomly generating objects that also get placed. Placing an object paints the tile a different color to indicate that it's placed.
I'm trying to make a system where you can remove placed objects, which means that the tilemap also needs to be updated to reflect the removal. This doesn't work at all, and creates some issues that I have never encountered and I have no idea how to solve.
I have a function that paints the tiles, and it goes like this:
public void TakeArea(Vector3Int start, Vector3Int size)
{
MainTilemap.BoxFill(start, tileName, start.x, start.y, start.x + size.x, start.y + size.y);
}
This all works for placing, but when I try to do it using an OnClick function, I get some errors. The "start" and "size" are passed on correctly, and when printing the values for the area, I get the correct ones. The problem is with the "tileName" variable this time, as it randomly becomes "Null" when I try to print it, even though in the game itself I an see that the assigned value is not "Null", but it references a tile that should be painted.
I have tried so many things for a couple of hours, but I think I finally found a solution. I made some adjustments to that function so that it's exactly the same as it is when an object is generated, as that already works, so I'm first Instantiating the object with this code:
GameObject oreObj = Instantiate(prefab, poss, Quaternion.identity);
Then I will get the object position and size from there the same way I would as if I was placing the object, so it would be like this:
Vector3Int start = gridLayout.WorldToCell(oreBeingRemoved.GetStartPosition()); TakeAreaWithTile(start, oreBeingRemoved.Size, emptyTile);
When I do all this, I get an error that says
"The variable 'grid' of 'BuildingSystem' has not been assigned. You probably need to assign the grid variable of the 'BuildingSystem' script in then inspector."
The problem is that the variable is assigned. The "grid" is always there in the editor, just like that tile that I talked about was, but it says that it isn't for some reason.
Here's a screenshot:
I have tried rewriting the code so many times, I spent about 10 hours here but nothing seems to be working.
As said in the comments the lines you show do not contain the assignment of the variables or what happens to them in between. Nor does it show how your object is instantiated.
One thing that could be your problem: Prefabs can only be serialized with references to themselves or other Prefabs. References to other objects in the scene will get lost.
A fix would be a method that assigns your grid reference in the Awake method of your BuildingSystem class.
I am attempting to use Specflow to automate web tests using Selenium. So far, things are going mostly fine, but I am now running into a problem. One of my steps allow for a user to input a variable, the step looks like this:
Given I click the (VARIABLE) Menu
And the code behind it is fairly simple, just clicking on a link based on the text that is passed:
driver.FindElement(By.XPath("Xpath to get to the variable")).Click();
However, there is a later step that must use this information. That is fine, you can use "ScenarioContext.Current.Add(string, variable)" and I know about that and have been using it. It functions for the needs that I was first informed of.
My problem is that now the business wants to be able to add multiple items at the same time. This presents two problems. Attempting to just call the step a second time throws an exception: "An item with the same key has already been added." and if I put this into a Scenario Outline, which would allow me to call the variable a second time in a second run, I cannot use the first variable in the final step.
Logically, this means that passing in a variable multiple times is the problem (which makes sense, given it's passing in as a string) and so passing the variable in as an array seems the logical way to go. The idea is that when I pass the parameter from one step to another as an array instead of as a string I theoretically won't run into this error and then I will be able to iterate through the items in the array in that later step with a for loop. This seems like something that SpecFlow should be able to do, but I am having issues finding out just how to achieve this. Does anyone have an idea on how to do this? I attempted to merely use:
Scenario.Context.Current.Add(string, variable).ToArray();
However, that does not work, and all of the examples of "ToArray" I can find in the SpecFlow documentation doesn't seem to be actually changing the variables you pass from one step to another into an array, it seems to be used solely inside of individual steps and never passed between steps. Is passing parameters using ScenarioContext.Current.Add(string, variable) as an array possible in SpecFlow?
Thanks in advance.
the simplest solution to your problem is to add an array (or list) to the context in the first step and then to get it out and add to it and then replace it again in future steps:
List<string> list = new List<String>();
list.Add(variable)
ScenarioContext.Current.Add(name, list);
then later
List<String> currentList = (List<String>) ScenarioContext.Current[string];
currentList.Add(variable);
ScenarioContext.Current[name]=list;
However I feel duty bound to point out some issues with your current solution. You should investigate the PageObject pattern and hide your element selection XPath inside your page objects. Imagine the business decides to change the element that information is stored in. Now you have to change every test that does this:
driver.FindElement(By.XPath("Xpath to get to the variable")).Click();
for that variable. Using the page object pattern this is hidden inside the page object and you would only have a single place to change.
I personally would also consider sharing data using context injection as I find this allows strong typing of the data (so no cast is required like in the example above) and it allows you to know what data is stored, its not just a random bag of stuff).
I'm using ObjectListView with checkboxes, I would like to run a function on selected items to delete them. So i tried this Method but it not working:
private List<Matricule> matrs;
private void button1_Click(object sender, EventArgs e)
{
//List<Song> s = this.olvSongs.CheckedObjects.Count;
//MessageBox.Show(this.olvSongs.CheckedItems.Count + " " + this.olvSongs.CheckedObjects.Count);
string s = "";
foreach (var item in olvMatrs.SelectedItems)
{
matrs.Remove((Matricule)item);
}
this.olvSongs.SetObjects(matrs);
}
how can i do this task.
You talk about check boxes. The line
foreach (var item in olvMatrs.SelectedItems)
iterates through the ITEMS that are SELECTED, not CHECKED! Is that really what you want?
To get the CHECKED OBJECTS use
objectListView1.CheckedObjects
If you really want to get the SELECTED OBJECTS, don't use Selected*Items*. Use
objectListView1.SelectedObjects;
instead. Thats what the OLV is all about. You want to work with the objects, not with ListViewItems.
If you decided WHAT you want to remove, don't remove the objects from your List, but directly from your ObjectListView using
objectListView1.RemoveObjects(myObjects);
You should probably (re-)read this. Especially the section "Mental gear shift - This is important. You need to understand this.".
well, i see that you don't show the code where it adds anything to matrs, so we are certainly short of useful source code. Also, we don't know what a Matricule is, but i can take a pretty good guess with what you already shared.
i believe 1 of 3 things must be happening if matrs is not getting any items removed.
1: are you sure your function is tied to the click event of the button? you can set a break point in the function to make sure it is even executing. or you can add a line to show a messagebox MessageBox.Show("Yes", this.Text); inside that button1_Click() method.
2: if the function is being executed (so it is not option #1), then my 2nd consideration is that perhaps the (Matricule)item is not in the matrs List to be able to be deleted. that Remove function returns a boolean value indicating whether the remove actually deleted something or not.
3: are you sure it is not getting deleted and that what is really happening is that it really is being deleted but your new updated List is not being shown to you?
I believe you think it is #2, but might want to eliminated the possibility of the other 2 easier options (#1 and #3) first. if you do deduce it to be #2, so options #1 and #3 are not happening, then here's the thing with deleting objects by referencing those objects: it easily leads to problems like what you are having. it is so easy to have code that actually attempts to delete a new object with the same properties as another object that is in a List. the clean way that i solve this is try to remove items by their index # rather than a reference to the object itself. but you are not even grabbing the object to be deleted from the List itself. you are grabbing that object from olvMatrs, which is another object list. my best guess from the information you shared is that this is why it's not working, that if you look deeper, that you are trying to Remove an object that is not in the list, so nothing is being Removed. it's an easy mistake to make. i only know because i've done it too before i learned to be super careful about this.
I am having a problem overriding the GetHeight method when developing an iPad application with MonoTouch.Dialog. I am implementing IElementSizing but my GetHeight method never gets called.
Has anyone else ran into this problem? Thanks.
I made sure that my root.UnevenRows = true;
I also tried including the dialog project and placing a breakpoint in the GetHeight() for any of the Elements that implement IElementSizing with no luck. In a previous iPhone project this worked fine but on the iPad I am still stuck. Are there any other 'gotchas' that I could be missing?
This is sort of a bug in MonoTouch.Dialog. Basically, when you assign the Root Element it wants to know whether there are uneven rows so it can create and cache the appropriate UITableViewSource object.
However, if you add Sections with Elements that implement IElementSizing to the Root element after the Source object has already been created. Then it will not call your GetHeight override. An example of this is if you fetch data async and callback and add the resulting Sections / Elements to to the RootElement...or essentially anytime you add Sections / Elements after PrepareRoot() is called.
There is a simple workaround for this:
this.Root.UnevenRows = true;
Without looking at your code however, I cannot say if this is the bug you are seeing.
Hello all,
We are creating a dll on the fly for security, we are attempting to have a dll generated and pushed to clients as a challenge response system... with this we are generating 20 variables each with a unique guid and then programatically selecting which one is referenced in the code... however once it compiles this it no longer has the extra dummy variables in it, just the one that it used.
Does anyone know what i can change in the compiler options to make it stop doing this or trick it into no optimizing those out?
I've tried
U = "71d41342-e56e-4643-b12f-24df0b4506ae";
System.Diagnostics.Debug.WriteLine(U);
string V = "";
referencing it in debug writeline but that didnt seem to be enough to get it to keep it. i also added /Od to disablke optimizations but this didnt seem to help either! Any help would be appreciated
You have several options to achieve that:
add those variables to a Dictionary in a consturctor and provide a method to iterate that Dictionary
OR
try putting static reaonly string in front of that declarations