Skip to content
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

Merged
merged 13 commits into from
Nov 2, 2017
Merged

Create layout interactive elements #1165

merged 13 commits into from
Nov 2, 2017

Conversation

brean
Copy link

@brean brean commented Oct 15, 2017

New, small Example for Dynamic Buttons, see #1137

Copy link
Contributor

@StephenHodgson StephenHodgson left a 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;
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Author

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?

Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Author

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");
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree.

@brean
Copy link
Author

brean commented Oct 19, 2017

@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)
Copy link
Contributor

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?

Copy link
Author

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);
}
Copy link
Contributor

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?

Copy link
Author

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();
}
Copy link
Contributor

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?

Copy link
Author

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.

@brean
Copy link
Author

brean commented Oct 24, 2017

@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>>
Copy link
Contributor

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()
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: private

@brean
Copy link
Author

brean commented Oct 24, 2017

@StephenHodgson done.

Copy link
Contributor

@SimonDarksideJ SimonDarksideJ left a 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.

@brean
Copy link
Author

brean commented Nov 2, 2017

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?

@SimonDarksideJ
Copy link
Contributor

The issue is a separate one, not related to this PR, so it doesn't need fixing here.

@StephenHodgson StephenHodgson merged commit 7320519 into microsoft:master Nov 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants