Skip to content

Commit da363ba

Browse files
committed
Add minor mode; make VS code emu obsolete; v0.1.3
1 parent 5f04b17 commit da363ba

File tree

2 files changed

+108
-64
lines changed

2 files changed

+108
-64
lines changed

README.md

+33-26
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# unity.el
22

3-
This package provides some Emacs integration with the Unity game engine. Most
4-
notably, it provides the ability to open source files from Unity in Emacs or
5-
Emacsclient while still generating the solution and project files for use with
6-
`lsp-mode`.
3+
This package provides some Emacs integration with the Unity game engine. It
4+
installs hooks/advice for smoother interop with certain Unity quirks. It's
5+
intended to be used along-side
6+
[rider2emacs](https://github.com/elizagamedev/rider2emacs) so that Unity will
7+
open source files in Emacs and generate the appropriate solution/project files
8+
necessary for LSP integration.
79

8-
Additionally, this package can install hooks/advice for smoother interop with
9-
certain Unity quirks. **Note that these (optional) integrations are experimental
10-
and potentially destructive**; see the `unity-setup` section for more
11-
information.
10+
**Note that these integrations are potentially destructive**; see the
11+
`unity-mode` section for more information.
1212

1313
## Installation
1414

@@ -18,17 +18,35 @@ extend your load path. I recommend
1818

1919
```elisp
2020
(straight-use-package
21-
'(unity :type git :host github :repo "elizagamedev/unity.el"
22-
:files ("*.el" "*.c")))
23-
(add-hook 'after-init-hook #'unity-build-code-shim)
24-
(add-hook 'after-init-hook #'unity-setup)
21+
'(unity :type git :host github :repo "elizagamedev/unity.el"))
22+
(add-hook 'after-init-hook #'unity-mode)
2523
```
2624

27-
## Configuration
25+
## Usage
2826

29-
`unity.el` exposes two functions, `unity-build-code-shim` and `unity-setup`.
27+
### `unity-mode`
3028

31-
### `unity-build-code-shim`
29+
When active, this mode installs hooks, advice, etc. necessary for smoother
30+
Emacs/Unity interop. Currently this is limited to advising `rename-file` and
31+
`delete-file` so that `.meta` files are automatically moved and deleted
32+
alongside their associated files.
33+
34+
While it's unlikely that there are any disasterous bugs lurking in the advice
35+
functions, given that these are destructive operations, *please be mindful* if
36+
you are enabling `unity-mode`. Always use revision control.
37+
38+
### `rider2emacs`
39+
40+
unity.el is intended to be used alongside
41+
[rider2emacs](https://github.com/elizagamedev/rider2emacs), which provides Unity
42+
with the ability to open files in Emacs and generate project files for use with
43+
OmniSharp LSP. See its documentation for details.
44+
45+
### `unity-build-code-shim` (Obsolete)
46+
47+
*The functionality described in this section has been superseded with
48+
[rider2emacs](https://github.com/elizagamedev/rider2emacs), but is left here in
49+
its original text for posterity.*
3250

3351
Unity does not generate project or solution files unless the external text
3452
editor is recognized as Visual Studio, Visual Studio Code, or MonoDevelop.
@@ -63,14 +81,3 @@ absolute path. An example of "External Script Editor Args" might look like:
6381
```sh
6482
/usr/local/bin/emacsclient -n +$(Line):$(Column) $(File)
6583
```
66-
67-
### `unity-setup`
68-
69-
This function installs any hooks, advice, etc. necessary for smoother
70-
Emacs/Unity interop. Currently this is limited to advising `rename-file` and
71-
`delete-file` so that `.meta` files are automatically moved and deleted
72-
alongside their associated files.
73-
74-
While it's unlikely that there are any disasterous bugs lurking in the advice
75-
functions, given that these are destructive operations, *please be mindful* if
76-
you are calling `unity-setup`. Always use revision control.

unity.el

+75-38
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,79 @@
11
;;; unity.el --- Unity integration for Emacs -*- lexical-binding:t -*-
22

3-
;; Version: 0.1.2
3+
;; Version: 0.1.3
44
;; Author: Eliza Velasquez
55
;; Created: 30 May 2021
66
;; Keywords: unity
77
;; URL: https://github.com/elizagamedev/unity.el
88

99
;;; Commentary:
1010

11-
;; This package provides some Emacs integration with the Unity game engine.
12-
;; Most notably, it provides the ability to open source files from Unity in
13-
;; Emacs or Emacsclient while still generating the solution and project files
14-
;; for use with `lsp-mode'.
15-
;;
16-
;; Additionally, this package can install hooks/advice for smoother interop with
17-
;; certain Unity quirks.
11+
;; This package provides some Emacs integration with the Unity game engine. It
12+
;; installs hooks/advice for smoother interop with certain Unity quirks. It's
13+
;; intended to be used along-side rider2emacs [1] so that Unity will open source
14+
;; files in Emacs and generate the appropriate solution/project files necessary
15+
;; for LSP integration.
1816
;;
1917
;; See README.md for more information.
18+
;;
19+
;; [1] https://github.com/elizagamedev/rider2emacs
2020

2121
;;; Code:
2222

2323
(defgroup unity nil
2424
"Unity game engine integration."
2525
:group 'external)
2626

27+
(defun unity--project-path-p (path)
28+
"Return t if PATH is in a Unity project."
29+
(let ((case-fold-search t))
30+
(if (string-match-p "/assets/" path) t)))
31+
32+
(defun unity--rename-file-advice (file newname &optional ok-if-already-exists)
33+
"Advice function for `rename-file' for renaming Unity files.
34+
35+
FILE, NEWNAME, and OK-IF-ALREADY-EXISTS are documented by `rename-file'."
36+
(when (and (unity--project-path-p file)
37+
(unity--project-path-p newname))
38+
(let ((meta-file (concat file ".meta")))
39+
(when (file-exists-p meta-file)
40+
(rename-file meta-file (concat newname ".meta")
41+
ok-if-already-exists)))))
42+
43+
(defun unity--delete-file-advice (file &optional trash)
44+
"Advice function for `delete-file' for deleting Unity files.
45+
46+
FILE and TRASH are documented by `rename-file'."
47+
(when (unity--project-path-p file)
48+
(let ((meta-file (concat file ".meta")))
49+
(when (file-exists-p meta-file)
50+
(delete-file meta-file trash)))))
51+
52+
;;;###autoload
53+
(define-minor-mode unity-mode
54+
"Integrate Emacs with the Unity game engine editor."
55+
:init-value nil
56+
:lighter " Unity"
57+
:global t
58+
:group 'unity
59+
(if unity-mode
60+
(progn
61+
(advice-add #'rename-file :after #'unity--rename-file-advice)
62+
(advice-add #'delete-file :after #'unity--delete-file-advice))
63+
(advice-remove #'rename-file #'unity--rename-file-advice)
64+
(advice-remove #'delete-file #'unity--delete-file-advice)))
65+
66+
;;;###autoload
67+
(defun unity-setup ()
68+
"Activate Unity.el integration.
69+
70+
Deprecated; use `unity-mode' instead."
71+
(interactive)
72+
(unity-mode 1))
73+
(make-obsolete #'unity-setup #'unity-mode "0.1.3")
74+
75+
;;; Obsolete Visual Studio Code definitions follow.
76+
2777
(defcustom unity-var-directory
2878
(expand-file-name (convert-standard-filename "var/unity/")
2979
user-emacs-directory)
@@ -61,30 +111,14 @@ See https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line."
61111
:type 'string
62112
:group 'unity)
63113

64-
(defun unity--project-path-p (path)
65-
"Return t if PATH is in a Unity project."
66-
(let ((case-fold-search t))
67-
(if (string-match-p "/assets/" path) t)))
68-
69-
(defun unity--rename-file-advice (file newname &optional ok-if-already-exists)
70-
"Advice function for `rename-file' for renaming Unity files.
71-
72-
FILE, NEWNAME, and OK-IF-ALREADY-EXISTS are documented by `rename-file'."
73-
(when (and (unity--project-path-p file)
74-
(unity--project-path-p newname))
75-
(let ((meta-file (concat file ".meta")))
76-
(when (file-exists-p meta-file)
77-
(rename-file meta-file (concat newname ".meta")
78-
ok-if-already-exists)))))
79-
80-
(defun unity--delete-file-advice (file &optional trash)
81-
"Advice function for `delete-file' for deleting Unity files.
82-
83-
FILE and TRASH are documented by `rename-file'."
84-
(when (unity--project-path-p file)
85-
(let ((meta-file (concat file ".meta")))
86-
(when (file-exists-p meta-file)
87-
(delete-file meta-file trash)))))
114+
(dolist (var '(unity-var-directory
115+
unity-code-shim-source-directory
116+
unity-cc
117+
unity-vcvarsall-file
118+
unity-vcvarsall-arch))
119+
(make-obsolete-variable var
120+
"Prefer rider2emacs instead of Visual Studio Code emulation."
121+
"0.1.3"))
88122

89123
(defun unity--code-binary-file ()
90124
"Return the file name of the code shim binary."
@@ -156,12 +190,15 @@ interactively."
156190
(switch-to-buffer-other-window subprocess-buffer)
157191
(special-mode))))))
158192

159-
;;;###autoload
160-
(defun unity-setup ()
161-
"Activate Unity.el integration."
162-
(interactive)
163-
(advice-add #'rename-file :after #'unity--rename-file-advice)
164-
(advice-add #'delete-file :after #'unity--delete-file-advice))
193+
(dolist (f '(unity--code-binary-file
194+
unity--build-code-shim-unix
195+
unity--build-code-shim-windows
196+
unity-build-code-shim))
197+
(make-obsolete f
198+
"Prefer rider2emacs instead of Visual Studio Code emulation."
199+
"0.1.3"))
200+
201+
;;; Postlude
165202

166203
(provide 'unity)
167204

0 commit comments

Comments
 (0)