MicrosoftDocs / mixed-reality

Mixed Reality documentation
Creative Commons Attribution 4.0 International
173 stars 181 forks source link

Scripting examples needed! #737

Open programmatoroSeduto opened 1 year ago

programmatoroSeduto commented 1 year ago

Hello there,

First of all, great documentation! I'd like to provide some hints to improve it.

it would be great if this page also contained scripting examples, since, from what is reported here, I think it is unclear how to deal with setting up such a feature dynamically. It would be wonderful to have some information about how to implement custom constrains as well.

For instance, I created this example, but I spent a lot of time to understad how, since the reference API is not so helpful (some comments are missing in this link I think: API reference )

    // root of the minimap asset
    private GameObject GoAssetRoot = null;
    // minimap gameobject
    private GameObject goMinimap = null;
    // minimap structure component in the minimap
    private MinimapStructure coMinimapStruct = null;
    // tools root for the minimap
    private GameObject goTools = null;

    private void CreatePlaneTool()
    {
        GameObject goPlaneTool = GameObject.CreatePrimitive(PrimitiveType.Cube);
        goPlaneTool.name = "MinimapSliderTool";
        goPlaneTool.transform.SetParent(goTools.transform);
        goPlaneTool.transform.localPosition = new Vector3(0.5f, 0.0f, 0.5f);
        goPlaneTool.transform.localScale = new Vector3(1.2f, 0.1f, 1.2f);
        goPlaneTool.GetComponent<Renderer>().material = ToolMaterial;

        goPlaneTool.AddComponent<NearInteractionGrabbable>();
        goPlaneTool.AddComponent<ObjectManipulator>();

        ConstraintManager coConstraints = goPlaneTool.GetComponent<ConstraintManager>();

        MoveAxisConstraint coConstraintX = goPlaneTool.AddComponent<MoveAxisConstraint>();
        coConstraintX.ConstraintOnMovement = AxisFlags.XAxis;
        coConstraintX.UseLocalSpaceForConstraint = true;

        MoveAxisConstraint coConstraintZ = goPlaneTool.AddComponent<MoveAxisConstraint>();
        coConstraintZ.ConstraintOnMovement = AxisFlags.ZAxis;
        coConstraintZ.UseLocalSpaceForConstraint = true;
    }

Thank you, have a nice day!


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.