private void HandleChangeAppearance(LuisMRResult result) { // Get the colors mentioned in the prediction var colorEntity = result.PredictionResult.Entities.FirstOrDefaultItem("MR.Color"); if (colorEntity == null) { return; } // Try to convert the entity color to a Unity color Color color; if (!ColorMapper.TryParseCssString(colorEntity.Value.ToLower(), out color)) { Debug.LogWarning($"The value \"{colorEntity.Value}\" does not map to a known color."); return; } // Get renderer var renderer = GetComponent <Renderer>(); if (renderer == null) { return; } // Set the color renderer.material.color = color; }
private void DoChangeAppearance(LuisMRResult result) { // Get the colors mentioned in the prediction var colorEntity = result.PredictionResult.Entities.FirstOrDefaultItem("MR.Color"); if (colorEntity == null) { return; } // Try to convert the entity color to a Unity color Color color; if (!ColorUtility.TryParseHtmlString(colorEntity.Value.ToLower(), out color)) { return; } // Get renderer var renderer = GetComponent <Renderer>(); if (renderer == null) { return; } // Set the color renderer.material.color = color; }
private void DoScale(LuisMRResult result) { // Which direction? var scaleDirection = result.PredictionResult.Entities.FirstOrDefaultItem("MR.ScaleDirection"); if (scaleDirection == null) { return; } var direction = scaleDirection.FirstOrDefaultResolution(); // TODO: Determine which amount float amount = unspecifiedScaleAmount; // Actual scale switch (direction.ToLower()) { case "decrease": //gameObject.transform.localScale.Scale(new Vector3(amount, amount, amount)); gameObject.transform.localScale *= (1.0f - amount); break; case "increase": gameObject.transform.localScale *= (1.0f + amount); break; } }
/// <summary> /// Find all the scene GameObjects that have names matching the Entity value /// </summary> /// <param name="result"></param> public void Resolve(LuisMRResult result) { //Collect any entities that match the entity names we're looking for var predictionEntities = result.PredictionResult.Entities.Where(x => validEntityNames.Contains(x.Key)).SelectMany(y => y.Value); if (predictionEntities.Count() < 1) { return; } //Join the list of scene objects with prediction entities to get matches in the scene IEnumerable <EntityMap> matchedEntities = from entity in predictionEntities let entityName = entity.Value.ToLower() from sceneEntity in GameObject.FindObjectsOfType <EntityMetaData>() where entityName.Equals(sceneEntity.EntityName.ToLower()) || entityName.Equals(sceneEntity.EntityType.ToLower()) select new EntityMap() { Entity = entity, GameObject = sceneEntity.gameObject, Resolver = this }; //Add all our found entities to the result's entity map, which maps LUIS entities with scene entities. foreach (EntityMap entityMap in matchedEntities) { result.Map(entityMap); } }
/// <summary> /// <inheritdoc/> /// </summary> public void Handle(Intent intent, LuisMRResult result) { //Build up a string of information about the result we got from LUIS StringBuilder sb = new StringBuilder(); sb.AppendLine($"Utterance: {result.Context.PredictionText}"); sb.Append($"Intent: {intent.Name}"); foreach (string entityKey in result.PredictionResult.Entities.Keys) { sb.Append($" [{entityKey}]"); } sb.AppendLine(); sb.AppendLine($"Intent Score: {intent.Score.ToString("P")}"); sb.AppendLine("Entities: "); foreach (string entityKey in result.PredictionResult.Entities.Keys) { sb.AppendLine($" Entity: {entityKey}"); foreach (Entity e in result.PredictionResult.Entities[entityKey]) { sb.AppendLine($" Value: {e.Value}"); sb.AppendLine($" Score: {e.Score}"); } } //Then write it to the console Debug.Log(sb.ToString()); }
/// <summary> /// <inheritdoc/> /// </summary> public void Handle(Intent intent, LuisMRResult result) { switch (intent.Name) { case "MR.ChangeAppearance": HandleChangeAppearance(result); break; } }
/// <summary> /// <inheritdoc/> /// </summary> public void Handle(Intent intent, LuisMRResult result) { switch (intent.Name) { case "MR.Transform": HandleTransform(result); break; } }
private void DoRotate(LuisMRResult result) { // Which direction? var roateDirection = result.PredictionResult.Entities.FirstOrDefaultItem("MR.RotateDirection"); bool counterClockwise = (roateDirection?.Value == "counterclockwise"); // TODO: Determine which amount float amount = unspecifiedRotateAmount; // Rotate gameObject.transform.Rotate(gameObject.transform.up, (counterClockwise ? -amount : amount)); }
private void DoTransform(LuisMRResult result) { // Which transform? string transformTypeName = null; var transformType = result.PredictionResult.Entities.FirstOrDefaultItem("MR.TransformType"); if (transformType != null) { transformTypeName = transformType.Value; } // If a transform type wasn't specified, let's see if there's a scale? if (transformTypeName == null) { // Try to get a scale direciton var scaleDirection = result.PredictionResult.Entities.FirstOrDefaultItem("MR.ScaleDirection"); if (scaleDirection != null) { transformTypeName = "scale"; } } // If there's still no transform type name, nothing to do. if (transformTypeName == null) { Debug.LogWarning("Received Transform intent but could not determine transform type."); return; } // Which transform type? switch (transformTypeName) { case "rotate": DoRotate(result); break; case "scale": DoScale(result); break; case "translate": DoTranslate(result); break; } }
public void Handle(Intent intent, LuisMRResult result) { if (!result.PredictionResult.Entities.ContainsKey(entityTypeName)) { return; } foreach (Entity entity in result.PredictionResult.Entities[entityTypeName]) { if (activateValues.ContainsKey(entity.Value)) { foreach (UnityEvent uEvent in activateValues[entity.Value]) { uEvent.Invoke(); } } } }
private void DoTranslate(LuisMRResult result) { }