Некоторые коды, которые могут быть полезны:
Код для тестирования глифов на ПК:
Код: Выделить всё
[ContextMenu("Draw Glyph Manually")]
public void drawGlyphManually()
{
DrawNewGlyph();
foreach (int index in manuallyDrawnGlyphIndexes)
{
AddGlyphPoint(inputPoints[index]);
}
CheckDrawnGlyph();
}
Код: Выделить всё
public void SetCheckingState(bool state)
{
//This function is called both when the pen starts being used and when it stops being used,
//with the state being set to it's respective value in each case
//set the checkingForMagicPoints variable to the declared bool
//so we only add points to the scroll when the pen is being used, and not when it's just being held or something
checkingForMagicPoints = state;
//check the new state of checkingForMagicPoints
if (checkingForMagicPoints)
{
menuScript.logOnDevMenu("Started drawing!");
targetedScroll.DrawNewGlyph();
}
else
{
//when the pen is no longer being used, send the list of hit points to the scroll
//in order to check what glyph was drawn
menuScript.logOnDevMenu("Stopped drawing!");
targetedScroll.CheckDrawnGlyph();
}
}
Код: Выделить всё
public void CheckDrawnGlyph()
{
List glyphPoints = glyphs[glyphObjects[glyphObjects.Count - 1]];
//create a variable to store the glyph pattern
List glyphPattern = new List();
for (int i = 0; i < glyphPoints.Count - 1; i++)
{
//record the change in index from every point to the next, or in other words, the pattern
glyphPattern.Add(inputPoints.IndexOf(glyphPoints[i + 1]) - inputPoints.IndexOf(glyphPoints[i]));
}
//testing glyph
List triangle = new List { 1, -scrollWidth - 1, scrollWidth };
//parse the pattern into a glyph
if(glyphPattern.SequenceEqual(triangle))
{
menuScript.logOnDevMenu("You drew a triangle!");
}
else
{
menuScript.logOnDevMenu("Glyph not recognized");
menuScript.logOnDevMenu("Glyph pattern: " + string.Join(", ", glyphPattern));
}
}