Just to illustrate with some code, Unity is not recognizing the correct alpha key codes the way it is supposed to. Sometimes it recognizes the keys appropriately, but not every time. This happens even when I run a few simple lines of code.
for(int index = 0; index < nextStates.Length; index++)
{
if (Input.GetKeyDown(KeyCode.Alpha2 + index))
{
state = nextStates[index];
}
}
The above code, for example, recognizes the 2nd key on my keyboard. But not every single time and it's pretty basic. What am I doing wrong?
Related
I have a list of materials set by hand called LookUpMaterials and an object which I want to compare if it has those materials.
If both materials correlate, add them to a new list "ChangeableMaterials".
I'm comparing using the sharedMaterials so everything is fine at first. But, when adding the .material to this new list, it creates a instance of the material.
Note: Creating the instance using .material is intended since I'm gonna edit this material anyway.
List<Material> ChangeableMaterials = new List<Material>();
Renderer[] renderers = GetComponentsInChildren<Renderer>();
for(int i = 0; i < renderers.Length; i++)
{
for(int j = 0; j < renderers[i].sharedMaterials.Length; j++)
{
if(LookUpMaterials.Contains(renderers[i].sharedMaterials[j]))
{
ChangeableMaterials.Add(renderers[i].materials[j];
}
}
}
In the first comparison (i,j == 0,0), it runs ok and the material is added to the list. All materials turns into Instances. But then when using sharedMaterials also spits out materials (Instances) in place of the original files and the comparison fails.
I've read multiple times that .sharedMaterials should be the file and not the instance, this is not being the case!
Can someone help me? I can't find the mistake here, just plain confused..
Here's 3 lists how Debug.Log() spits the name of the material
LookUpMaterials
011_Pillow
.materials
011_Pillow (Instance)
.sharedMaterials
011_Pillow (Instance) - Shouldnt be only 011_Pillow?
I am updating sort & filter models via api:
this.gridApi.setFilterModel(filterModels);
this.gridApi.setSortModel(sortModels);
The problem with this is I have a server request bound to the change even of both sort & filter so when user changes then the data is updated. This means when I change model on code like restoring a state or resetting the filters it causes multiple requests.
Is there a way to update the filter/sort model without triggering the event?
I see there is a ColumnEventType parameter but couldn't see how it works. Can I specify some variable that I can look for inside my event handlers to get them to ignore calls that are not generated from user?
I am trying to manage URL state so when url query params change my code sets the models in the grids but this ends up causing the page to reload multiple times because the onFilter and onSort events get called when the model is set and there is no way I can conceive to prevent this.
At the time, you are going to have to manage this yourself, ie, just before you call the setModel, somehow flag this in a shared part of your app (maybe a global variable)
Then when you react to these events, check the estate of this, to guess where it came from.
Note that at the moment, we have added source to the column events, but they are not yet for the model events, we are planning to add them though, but we have no ETA
Hope this helps
I had to solve similar issue. I found solution which working for my kind of situation. Maybe this help someone.
for (let j = 0; j < orders.length; j++) {
const sortModelEntry = orders[j];
if (typeof sortModelEntry.property === 'string') {
const column: Column = this.gridColumnApi.getColumn(sortModelEntry.property);
if (column && ! column.getColDef().suppressSorting) {
column.setSort(sortModelEntry.direction.toLowerCase());
column.setSortedAt(j);
}
}
this.gridApi.refreshHeader();
Where orders is array of key-value object where key is name of column and value is sorting directive (asc/desc).
Set filter without refresh was complicated
for (let j = 0; j < filters.length; j++) {
const filterModelEntry = filters[j];
if (typeof filterModelEntry.property === 'string') {
const column: Column = this.gridColumnApi.getColumn(filterModelEntry.property);
if (column && ! column.getColDef().suppressFilter) {
const filter: any = this.gridApi.getFilterApi(filterModelEntry.property);
filter['filter'] = filterModelEntry.command;
filter['defaultFilter'] = filterModelEntry.command;
filter['eTypeSelector'].value = filterModelEntry.command;
filter['filterValue'] = filterModelEntry.value;
filter['filterText'] = filterModelEntry.value;
filter['eFilterTextField'].value = filterModelEntry.value;
column.setFilterActive(true);
}
}
}
Attributes in filter:
property - name of column
command - filter action (contains, equals, ...)
value - value used in filter
For anyone else looking for a solution to this issue in Nov 2020, tapping into onFilterModified() might help. This gets called before onFilterChanged() so setting a value here (eg. hasUserManuallyChangedTheFilters = false, etc.) and checking the same in the filter changed event is a possible workaround. Although, I haven't found anything similar for onSortChanged() event, one that gets called before the sorting is applied to the grid.
I am not sure any clean way to achieve this but I noticed that FilterChangedEvent has "afterFloatingFilter = false" only if filterModel was updated from ui.
my workaround is as below
onFilterChanged = event:FilterChangedEvent) => {
if(event.afterFloatingFilter === undefined) return;
console.log("SaveFilterModel")
}
I have a situation where I want to remove duplicates from a collection (list) and then join them.
I wanted to make an extension for Joiner, but it is impossible as all constructors are private.
Here's a code snippet of what we did:
Collection<String> tokens = newArrayList();
for (int i = 0; i < numOfFoundTitles; i++) {
if (!tokens.contains(titlesInRange.get(i).titleAsTokens)) {
tokens.add(titlesInRange.get(i).getTitleAsTokens());
}
}
return titleTokensJoiner.join(tokens);
Any suggestions?
I thought about Function / Predicate, but they are not suitable there.
Thanks
Eyal
return titleTokensJoiner.join(ImmutableSet.copyOf(tokens));
Short, sweet, and correct. ImmutableSet preserves the order of the original input, but ignores repeated occurrences of an element after the first occurrence.
I am updating our iPhone app to iOs4 and I ran into an issue "Pass-by-argument in function call is undefined" in the code
for (i = 0; i < self.numberOfSegments; i++) {
[self setWidth:round(width[i]) forSegmentAtIndex:i];
}
Which is fair enough, width[i] hasn't been initialized. Updating the code (below) however gives me this new error, "Assigned value is garbage or undefined". Reading up on this I think that segWidth retains its value as garbage - is that correct and if so how do I clear it?
for (i = 0; i < self.numberOfSegments; i++) {
float segWidth = (float)width[i];
[self setWidth:round(segWidth) forSegmentAtIndex:i];
}
------------- EDIT ------------------
Thanks for the replies guys. More information as follows;
A genericised version of the method is shown below as someFunction. I have removed the ugly cast but still see the "Assigned Value is Garbage or undefined" logic error for the line segWidth = width[i];
I agree it appears the value width[i] doesn't have clear initialisation, I am unsure if it's my lack of understanding of basic Obj-c float types or if there is a logic flaw in my assignment syntax?
- (void)someFunction
{
unsigned int n = self.numberOfSegments;
float width[n];
for (i = 0; i < n; i++) {
width[i] = someFloatValue;
}
...
for (i = 0; i < self.numberOfSegments; i++) {
float segWidth = 0.0;
segWidth = width[i];
[self setWidth:round(segWidth) forSegmentAtIndex:i];
}
}
Definition of setWidth is:
- (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment; // set to 0.0 width to autosize. default is 0.0
I'm assuming that you are calling:
- (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment
And that Pass-by-argument in function call is undefined is actually the LLVM static analyzer error when you do Build and Analyze. (Both rather important data points -- passing along exactly what you were doing and exactly what the output was is quite helpful).
And you say that width[i] hasn't been initialized.
Your fix of adding float segWidth = (float)width[i] very much should cause the analyzer to complain with ** Assigned value is garbage or undefined**. You haven't actually set width[i] to anything. I would suggest filing a bug against the static analyzer, though, because that first error message is really quite thoroughly obtuse.
As Joshua also said, that cast is really weird, too. In general, in Objective-C you should very rarely have to use type casting and pretty much never use it on scalar types.
Consider the two loop counts:
for (i = 0; i < n; i++) {
...
}
for (i = 0; i < self.numberOfSegments; i++) {
...
}
The static analyzer doesn't know that n == self.numberOfSegments and, thus, must assume that the second loop could loop longer than the first. Now, you might say, "But I assigned n = self.numberOfSegments above?!"
You did, but that value could have changed between the first call and second call and, thus, the analyzer has correctly identified that you might be using an uninitialized value.
(Really, it should be saying that you might run off the end of the array, because that is the real risk).
I want to write a word addin that does some computations and updates some ui whenever the user types something or moves the current insertion point. From looking at the MSDN docs, I don't see any obvious way such as an TextTyped event on the document or application objects.
Does anyone know if this is possible without polling the document?
Actually there is a way to run some code when a word has been typed, you can use SmartTags, and override the Recognize method, this method will be called whenever a word is type, which means whenever the user typed some text and hit the space, tab, or enter keys.
one problem with this however is that if you change the text using "Range.Text" it will detect it as a word change and call the function so it can cause infinite loops.
Here is some code I used to achieve this:
public class AutoBrandSmartTag : SmartTag
{
Microsoft.Office.Interop.Word.Document cDoc;
Microsoft.Office.Tools.Word.Action act = new Microsoft.Office.Tools.Word.Action("Test Action");
public AutoBrandSmartTag(AutoBrandEngine.AutoBrandEngine _engine, Microsoft.Office.Interop.Word.Document _doc)
: base("AutoBrandTool.com/SmartTag#AutoBrandSmartTag", "AutoBrand SmartTag")
{
this.cDoc = _doc;
this.Actions = new Microsoft.Office.Tools.Word.Action[] { act };
}
protected override void Recognize(string text, Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite site,
Microsoft.Office.Interop.SmartTag.ISmartTagTokenList tokenList)
{
if (tokenList.Count < 1)
return;
int start = 0;
int length = 0;
int index = tokenList.Count > 1 ? tokenList.Count - 1 : 1;
ISmartTagToken token = tokenList.get_Item(index);
start = token.Start;
length = token.Length;
}
}
As you've probably discovered, Word has events, but they're for really coarse actions like a document open or a switch to another document. I'm guessing MS did this intentionally to prevent a crappy macro from slowing down typing.
In short, there's no great way to do what you want. A Word MVP confirms that in this thread.