Created
March 25, 2017 20:51
-
-
Save Domiii/dccfeac8903f69d31b6708b5450d01c7 to your computer and use it in GitHub Desktop.
UnityEditorTests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Linq; | |
| using System.Collections.Generic; | |
| #if UNITY_EDITOR | |
| using UnityEditor; | |
| [InitializeOnLoad] | |
| class Startup { | |
| static Startup () { | |
| Debug.Log ("Up and running"); | |
| Selection.selectionChanged += OnSelectionChanged; | |
| } | |
| static void OnSelectionChanged () { | |
| // if (Selection.objects.Length > 0) { | |
| // Debug.Log ("New selection: " + string.Join (", ", Selection.objects.Select (obj => obj.name).ToArray ())); | |
| // } else { | |
| // Debug.Log ("Selection cleared."); | |
| // } | |
| TutorialManager.Instance.Highlight (Selection.activeTransform); | |
| //var path = AssetDatabase.GetAssetPath (Selection.activeObject); | |
| //var type = AssetDatabase.GetMainAssetTypeAtPath (path); | |
| var script = Selection.activeObject as MonoScript; | |
| if (script) { | |
| Debug.Log (string.Format ("Selected script `{0}` (length: {1})", script.name, script.text.Length)); | |
| } | |
| } | |
| } | |
| class MyAllPostprocessor : AssetPostprocessor { | |
| static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { | |
| foreach (string str in importedAssets) { | |
| Debug.Log ("Added Asset: " + str); | |
| } | |
| foreach (string str in deletedAssets) { | |
| Debug.Log ("Deleted Asset: " + str); | |
| } | |
| for (int i = 0; i < movedAssets.Length; i++) { | |
| Debug.Log ("Moved Asset: " + movedAssets [i] + " from: " + movedFromAssetPaths [i]); | |
| } | |
| } | |
| } | |
| public class UnityEditorTests : MonoBehaviour { | |
| public static TutorialManager Instance { | |
| get; | |
| private set; | |
| } | |
| public float arrowLength = 2; | |
| public TutorialManager () { | |
| Instance = this; | |
| } | |
| public void Highlight (Transform go) { | |
| if (go) { | |
| Highlighter.Highlight ("Inspector", "Add Component"); | |
| Invoke ("StopHighlight", 2); | |
| } else { | |
| StopHighlight (); | |
| } | |
| } | |
| void OnDrawGizmos () { | |
| if (Selection.activeGameObject) { | |
| var dir = Vector3.down; | |
| var delta = dir * arrowLength; | |
| DrawArrow.ForGizmo (Selection.activeTransform.position - delta, delta); | |
| } | |
| } | |
| void StopHighlight () { | |
| Highlighter.Stop (); | |
| } | |
| } | |
| #endif | |
| public static class DrawArrow { | |
| public static void ForGizmo (Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f) { | |
| Gizmos.DrawRay (pos, direction); | |
| Vector3 right = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 + arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Vector3 left = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 - arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Gizmos.DrawRay (pos + direction, right * arrowHeadLength); | |
| Gizmos.DrawRay (pos + direction, left * arrowHeadLength); | |
| } | |
| public static void ForGizmo (Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f) { | |
| Gizmos.color = color; | |
| Gizmos.DrawRay (pos, direction); | |
| Vector3 right = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 + arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Vector3 left = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 - arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Gizmos.DrawRay (pos + direction, right * arrowHeadLength); | |
| Gizmos.DrawRay (pos + direction, left * arrowHeadLength); | |
| } | |
| public static void ForDebug (Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f) { | |
| Debug.DrawRay (pos, direction); | |
| Vector3 right = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 + arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Vector3 left = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 - arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Debug.DrawRay (pos + direction, right * arrowHeadLength); | |
| Debug.DrawRay (pos + direction, left * arrowHeadLength); | |
| } | |
| public static void ForDebug (Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f) { | |
| Debug.DrawRay (pos, direction, color); | |
| Vector3 right = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 + arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Vector3 left = Quaternion.LookRotation (direction) * Quaternion.Euler (0, 180 - arrowHeadAngle, 0) * new Vector3 (0, 0, 1); | |
| Debug.DrawRay (pos + direction, right * arrowHeadLength, color); | |
| Debug.DrawRay (pos + direction, left * arrowHeadLength, color); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment