|
1 | 1 | ;;; unity.el --- Unity integration for Emacs -*- lexical-binding:t -*-
|
2 | 2 |
|
3 |
| -;; Version: 0.1.2 |
| 3 | +;; Version: 0.1.3 |
4 | 4 | ;; Author: Eliza Velasquez
|
5 | 5 | ;; Created: 30 May 2021
|
6 | 6 | ;; Keywords: unity
|
7 | 7 | ;; URL: https://github.com/elizagamedev/unity.el
|
8 | 8 |
|
9 | 9 | ;;; Commentary:
|
10 | 10 |
|
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. |
18 | 16 | ;;
|
19 | 17 | ;; See README.md for more information.
|
| 18 | +;; |
| 19 | +;; [1] https://github.com/elizagamedev/rider2emacs |
20 | 20 |
|
21 | 21 | ;;; Code:
|
22 | 22 |
|
23 | 23 | (defgroup unity nil
|
24 | 24 | "Unity game engine integration."
|
25 | 25 | :group 'external)
|
26 | 26 |
|
| 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 | + |
27 | 77 | (defcustom unity-var-directory
|
28 | 78 | (expand-file-name (convert-standard-filename "var/unity/")
|
29 | 79 | user-emacs-directory)
|
@@ -61,30 +111,14 @@ See https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line."
|
61 | 111 | :type 'string
|
62 | 112 | :group 'unity)
|
63 | 113 |
|
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")) |
88 | 122 |
|
89 | 123 | (defun unity--code-binary-file ()
|
90 | 124 | "Return the file name of the code shim binary."
|
@@ -156,12 +190,15 @@ interactively."
|
156 | 190 | (switch-to-buffer-other-window subprocess-buffer)
|
157 | 191 | (special-mode))))))
|
158 | 192 |
|
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 |
165 | 202 |
|
166 | 203 | (provide 'unity)
|
167 | 204 |
|
|
0 commit comments