Beispiel #1
0
    private void CreateEvent(object data)
    {
        Map        map      = ((ObjectLayer)target).parent;
        GameObject prefab   = AssetDatabase.LoadAssetAtPath <GameObject>(GenericPrefabPath);
        MapEvent2D mapEvent = Instantiate(prefab).GetComponent <MapEvent2D>();

        mapEvent.name = "Event" + Random.Range(1000000, 9999999);
        GameObjectUtility.SetParentAndAlign(mapEvent.gameObject, map.objectLayer.gameObject);
        mapEvent.SetPosition(lastMouseTiles);
        Selection.activeObject = mapEvent.gameObject;
        Undo.RegisterCreatedObjectUndo(mapEvent, "Create " + mapEvent.name);
    }
Beispiel #2
0
    private Vector2Int GetCurrentMouseTiles()
    {
        Ray   ray   = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
        Plane plane = new Plane(
            MapEvent2D.TileToWorld(Vector2Int.zero),
            MapEvent2D.TileToWorld(new Vector2Int(1, 1)),
            MapEvent2D.TileToWorld(new Vector2Int(0, 1)));
        float t = 0.0f;

        if (!plane.Raycast(ray, out t))
        {
            return(new Vector2Int(-1, -1));
        }
        else
        {
            Vector3 intersect = ray.origin + ray.direction * t;
            return(MapEvent2D.WorldToTile(intersect) + new Vector2Int(-1, -1));
        }
    }
Beispiel #3
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        GridSelection selection = (GridSelection)target;
        Transform     parent    = GridSelection.grid.transform.parent;

        if (parent != null && parent.GetComponent <Map>())
        {
            if (GUILayout.Button("Create MapEvent2D"))
            {
                MapEvent2D mapEvent = Instantiate(AssetDatabase.LoadAssetAtPath <MapEvent2D>(PrefabPath)).GetComponent <MapEvent2D>();
                mapEvent.name = "Event" + Random.Range(1000000, 9999999);
                Map map = parent.GetComponent <Map>();
                GameObjectUtility.SetParentAndAlign(mapEvent.gameObject, map.objectLayer.gameObject);
                Undo.RegisterCreatedObjectUndo(mapEvent, "Create " + mapEvent.name);
                mapEvent.SetLocation(MapEvent2D.GridLocationTileCoords(GridSelection.position));
                Selection.activeObject = mapEvent.gameObject;
            }
        }
    }