private void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         // Click, so start drawing a new line.
         pathGameObject = null;
     }
     if (Input.GetButton("Fire1"))
     {
         // Mouse is still down and we are dragging, so keep drawing.
         Draw(Input.mousePosition);
     }
 }
    public void Draw(Vector3 position)
    {
        // Create a plane and see where the mouse click intersects it.
        Plane plane = new Plane(Camera.main.transform.forward * -1, position);
        Ray   ray   = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (plane.Raycast(ray, out float distance))
        {
            if (pathGameObject == null)
            {
                // Starting a new line. Instantiate our "Path Object"
                pathGameObject =
                    UnityEngine.Object.Instantiate(LinePrefab).GetComponent <PathGameObject>();
            }
            else
            {
                // TODO: Check distance between points. This just adds all of them, even
                // if you hold the mouse still.
                Vector3 hitpoint = ray.GetPoint(distance);
                pathGameObject.AddPosition(hitpoint);
            }
        }
    }
Beispiel #3
0
    public void FinishRead()
    {
        width  = 0;
        height = 0;
        foreach (Tilemap tmap in this.GetObjects(typeof(Tilemap)))
        {
            if (tmap.Width > width)
            {
                width = tmap.Width;
            }
            if (tmap.Height > height)
            {
                height = tmap.Height;
            }
            tmap.UpdatePos();
        }

        if (!String.IsNullOrEmpty(Music))
        {
            GameObjects.Add(new MusicObject(Music));
            Music = String.Empty;
        }

        if (!(GameObjects.Exists(x => x is AmbientLightObject)))
        {
            GameObjects.Add(new AmbientLightObject(AmbientLight));
            AmbientLight = new Drawing.Color(1f, 1f, 1f);
        }

        List <IGameObject> new_gameobjects = new List <IGameObject>();

        foreach (IGameObject obj in this.GetObjects())
        {
            if (obj is IPathObject)
            {
                IPathObject path_obj = (IPathObject)obj;
                if (path_obj is PathGameObject)
                {
                    // don't touch
                }
                else if (path_obj.Path != null)
                {
                    PathGameObject new_path_gameobject = new PathGameObject();

                    new_path_gameobject.Path = path_obj.Path;
                    path_obj.Path            = null;
                    path_obj.PathRef         = new_path_gameobject.EntityName;

                    new_gameobjects.Add(new_path_gameobject);
                }
            }
        }
        GameObjects.AddRange(new_gameobjects);

        if (GetObjects(typeof(MusicObject)).Count == 0)
        {
            Add(new MusicObject());
        }

        if (GetObjects(typeof(AmbientLightObject)).Count == 0)
        {
            Add(new AmbientLightObject());
        }
    }