Beispiel #1
0
        public override bool Process(LexiconRuntimeResult runtimeResult)
        {
            // There may be multiple primitives, break the phrase up by primitive entity.
            // E.g. "Create a red cube here and a blue sphere here."
            foreach (LexiconEntityMatch primitiveMatch in runtimeResult.GetEntityMatches(Strings.Primitive))
            {
                PrimitiveType primitiveType = primitiveMatch.EntityValue.GetBinding <PrimitiveType>();
                Material      material      = new Material(shader);

                // We expect the color entity (if present) to come before the primitive entity.
                LexiconEntityMatch colorMatch = runtimeResult.GetEntityBefore(Strings.Color, primitiveMatch);
                if (colorMatch != null)
                {
                    material.color = colorMatch.EntityValue.GetBinding <Color>();
                }

                // Create the primitive. Use a container to anchor from the bottom.
                GameObject container = new GameObject(primitiveType.ToString());
                GameObject primitive = GameObject.CreatePrimitive(primitiveType);
                primitive.GetComponent <Renderer>().material = material;
                float yOffset = primitive.GetComponent <Renderer>().bounds.extents.y;
                primitive.transform.parent        = container.transform;
                primitive.transform.localPosition = new Vector3(0.0f, yOffset, 0.0f);
                container.transform.localScale    = new Vector3(0.2f, 0.2f, 0.2f);
                container.AddComponent <LexiconSelectable>();

                // We expect the position (if present) to come after the primitive entity.
                LexiconEntityMatch positionMatch = runtimeResult.GetEntityAfter(Strings.Position, primitiveMatch);
                if (positionMatch != null && positionMatch.FocusPosition != null)
                {
                    // Use the focus position of the position entity if present.
                    container.transform.position = positionMatch.FocusPosition.Position;
                }
                else if (primitiveMatch.FocusPosition != null)
                {
                    // Otherwise use the focus position of the primitive entity.
                    container.transform.position = primitiveMatch.FocusPosition.Position;
                }
                else
                {
                    // As a fall back we can place the object in front of the camera.
                    Camera mainCamera = Camera.main;
                    if (mainCamera != null)
                    {
                        container.transform.position = mainCamera.transform.position + mainCamera.transform.forward * 2.0f;
                    }
                }
            }

            // We've consumed this intent, return true to prevent other handlers from firing.
            return(true);
        }
        public override bool Process(LexiconRuntimeResult runtimeResult)
        {
            // There may be multiple models, break the phrase up by model entity.
            // E.g. "Create a black king here and a white queen here."
            foreach (LexiconEntityMatch modelMatch in runtimeResult.GetEntityMatches(Strings.ChessPiece))
            {
                GameObject modelPrefab = modelMatch.EntityValue.GetBinding <GameObject>();
//                Material material = new Material(shader);

                // We expect the color entity (if present) to come before the model entity.
                LexiconEntityMatch colorMatch = runtimeResult.GetEntityBefore(Strings.Color, modelMatch);
                //   if (colorMatch != null)
                //     {
                //    material.color = colorMatch.EntityValue.GetBinding<Color>();
                //   }

                // Create the model.
                GameObject model = Instantiate(modelPrefab);
                model.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                //   model.GetComponentInChildren<Renderer>().material = material;
                model.AddComponent <LexiconSelectable>();

                // We expect the position (if present) to come after the model entity.
                LexiconEntityMatch positionMatch = runtimeResult.GetEntityAfter(Strings.Position, modelMatch);
                if (positionMatch != null && positionMatch.FocusPosition != null)
                {
                    // Use the focus position of the position entity if present.
                    model.transform.position = positionMatch.FocusPosition.Position;
                }
                else if (modelMatch.FocusPosition != null)
                {
                    // Otherwise use the focus position of the model entity.
                    model.transform.position = modelMatch.FocusPosition.Position;
                }
                else
                {
                    // As a fall back we can place the object in front of the camera.
                    Camera mainCamera = Camera.main;
                    if (mainCamera != null)
                    {
                        model.transform.position = mainCamera.transform.position + mainCamera.transform.forward * 2.0f;
                    }
                }
            }

            // We've consumed this intent, return true to prevent other handlers from firing.
            return(true);
        }
        public override bool Process(LexiconRuntimeResult runtimeResult)
        {
            // There may be multiple size matches, break the phrase up by size entity.
            // E.g. "Make this one bigger and this one smaller."
            foreach (LexiconEntityMatch sizeMatch in runtimeResult.GetEntityMatches(Strings.Size))
            {
                // Default focus on the size entity.
                FocusSelection focusSelection = sizeMatch.FocusSelection;

                // We expect the selection entity (if present) to come before the size entity.
                LexiconEntityMatch selectionMatch = runtimeResult.GetEntityBefore(Strings.Selection, sizeMatch);
                if (selectionMatch != null)
                {
                    focusSelection = selectionMatch.FocusSelection;
                }

                if (focusSelection != null)
                {
                    GameObject selectedObject = focusSelection.SelectedObject;
                    float      scale          = 1.0f;

                    switch (sizeMatch.EntityValue.ValueName)
                    {
                    case Strings.SizeValues.Grande:
                        scale = 2.0f;
                        break;

                    case Strings.SizeValues.Pequeño:
                        scale = 0.5f;
                        break;
                    }

                    // Scale the selected object by the desired amount.
                    selectedObject.transform.localScale = selectedObject.transform.localScale * scale;
                }
            }

            // We've consumed this intent, return true to prevent other handlers from firing.
            return(true);
        }