Esempio n. 1
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        Spatial spatial = GetTree().Root.GetChild(0) as Spatial;

        if (spatial is null)
        {
            throw new NullReferenceException("Failed to find Spatial node");
        }

        List <CSGSphere>  spheres      = new List <CSGSphere>();
        ImmediateGeometry lineRenderer = null;

        foreach (Node node in spatial.GetChildren())
        {
            Type   type = node.GetType();
            string name = node.Name;

            if (type == typeof(CSGSphere) && name.StartsWith("Sphere"))
            {
                spheres.Add(node as CSGSphere);
            }
            else if (type == typeof(CSGBox) && name.Equals("Cube"))
            {
                cube = node as CSGBox;
            }
            else if (type == typeof(ImmediateGeometry) && name.Equals("LineRenderer"))
            {
                lineRenderer = node as ImmediateGeometry;
            }
        }

        if (spheres.Count < 2)
        {
            throw new NullReferenceException("Failed to find at least two Spheres");
        }

        if (cube is null)
        {
            throw new NullReferenceException("Failed to find Cube");
        }

        if (lineRenderer is null)
        {
            throw new NullReferenceException("Failed to find LineRenderer");
        }

        List <Vector3> sphereOrigins = spheres.Select(sphere => sphere.Transform.origin).ToList();

        if (doLoop)
        {
            sphereOrigins.Add(sphereOrigins[0]);
        }

        points = sphereOrigins.ToArray();

        lineRenderer.Set("globalCoords", false);
        lineRenderer.Set("points", points);
    }