-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create layout interactive elements #1165
Create layout interactive elements #1165
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
just a few comments
return; | ||
} | ||
int interactivePos = SourceSet.SelectedIndices[0]; | ||
string title = SourceSet.Interactives[interactivePos].gameObject.GetComponent<LabelTheme>().Default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anytime you use GetComponent<T>
you should always check if it's null before using it's returned value.
); | ||
interactive.gameObject.transform.localPosition = new Vector3( | ||
((i / rows) - ((columns - 1) / 2f)) * Distance.x, | ||
-(j - (rows - 1) / 2f) * Distance.y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instad of value / 2
we can use value * 0.5f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think value / 2 is better for (human) readability and I don't think the CPU will mind (its not like we are doing this loop for thousands of objects). Or is there a coding convention I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idk, as a human, I've always hated fractions.
as for CPU perf, gotta remember we're also targeting HoloLens, and it's a mobile device and every little bit counts.
@@ -22,7 +22,7 @@ public class InteractiveSet : MonoBehaviour | |||
public SelectionType Type = SelectionType.single; | |||
|
|||
[Tooltip("Interactives that will be managed by this controller")] | |||
public InteractiveToggle[] Interactives; | |||
public List<InteractiveToggle> Interactives; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of changing this to a list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier to remove items in a list, see the "RemoveInteractive"-method in the same file. If the data changes I don't delete all Interactives and their prefabs, only the delta and update all items afterwards (recycling objects).
LabelTheme lblTheme = gameObject.GetComponent<LabelTheme>(); | ||
if (lblTheme == null) | ||
{ | ||
Debug.LogError("No LabelTheme attached to this Interactive"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably add a component requirement, and always get the component if null, and remove the debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree.
@StephenHodgson I implemented your feedback. Please review. |
@@ -102,6 +99,10 @@ public void UpdateData() | |||
// layouting | |||
int j = i % rows; | |||
Collider collider = interactive.gameObject.GetComponent<Collider>(); | |||
if (collider == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add Collider
to the list of required components?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be the Collider in InteractiveToggle. I can attach the InteractiveToggle-script to any GameObject and have the collider in some child of that GameObject, so I don't think having it as required component is a good idea... we can however ignore the collider boundary size for layouting if it is not present. If you don't have a collider attached directly the user can define the distance between the InteractiveToggles by setting the Offsets-values. Alternatively I could iterate over transform.children recursively and calculate the biggest bounding box, but that seems a bit overkill.
if (InterInst != null) | ||
{ | ||
Interactives.Add(InterInst); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw a warning if our prefab doesn't have the InteractiveToggle
telling the dev to add one to their prefab?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
{ | ||
TargetGroup.Titles = Data[label.Default]; | ||
TargetGroup.UpdateData(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a warning if our object doesn't have a LabelTheme
telling our dev to add one to the object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The Dev would most likely implement his own "DataProvider", where he gets some data from an external source and than acts on it accordingly, putting that data into InteractiveSets/InteractiveGroups as he likes. So I also added some documentation that descibes it a bit more.
…eToggle and add some more documentation
@StephenHodgson I am done integrating your feedback, please review this. |
// some test data - imagine this comming from a web-service | ||
// or some input menu | ||
public Dictionary<string, List<string>> Data = | ||
new Dictionary<string, List<string>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep all of this on one line, and updated the comments with summary tags
|
||
public Vector2 Offsets = new Vector2(0.00f, 0.00f); | ||
|
||
void Start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: private
/// remove unused Interactives from scene | ||
/// </summary> | ||
/// <param name="keep">number of Iteractives that will NOT be deleted</param> | ||
void RemoveInteractives(int keep = 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: private
@StephenHodgson done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the changes in this PR, everything is good.
However, it does highlight an error logging issue @StephenHodgson whereby, repeared ERROR logs are generated when speech recog isn't available. Will need fixing in another PR.
I like to see this merged and it has been approved by @StephenHodgson and @DDReaper . Is there anything I can do to speed up the process? Should I take a deeper look at the Error messages @DDReaper mentioned? |
The issue is a separate one, not related to this PR, so it doesn't need fixing here. |
New, small Example for Dynamic Buttons, see #1137