public override void OnInspectorGUI() { Outline t = target as Outline; t.fullSpriteGlow = EditorGUILayout.Toggle("Full glow mode", t.fullSpriteGlow); EditorGUILayout.Space(); t.color = EditorGUILayout.ColorField("Outline color", t.color); t.lineThickness = EditorGUILayout.Slider("Line thickness", (int)t.lineThickness, 0, 50); t.lineIntensity = EditorGUILayout.Slider("Line Intensity", t.lineIntensity, 0, 1); t.alphaCutoff = EditorGUILayout.Slider("Alpha cutoff", t.alphaCutoff, 0, 1); t.pixelSnap = EditorGUILayout.Toggle("Pixel snap", t.pixelSnap); EditorGUILayout.Space(); t.flipY = EditorGUILayout.Toggle("flipY", t.flipY); t.hideSprite = EditorGUILayout.Toggle("Hide sprite", t.hideSprite); t.allowOutlineOverlap = EditorGUILayout.Toggle("Allow outline overlap", t.allowOutlineOverlap); t.autoColor = EditorGUILayout.Toggle("Auto color outline", t.autoColor); EditorGUILayout.Space(); t.autoOutline = EditorGUILayout.Toggle("Auto outline", t.autoOutline); if (!t.autoOutline) { t.lastLinkedToFirst = EditorGUILayout.Toggle("Link first and last points", t.lastLinkedToFirst); t.outlineBezier = EditorGUILayout.Toggle("Bezier lines", t.outlineBezier); t.outlineStep = EditorGUILayout.Slider("Outline step", t.outlineStep, .005f, 1f); serializedObject.Update(); outlineVerticesList.DoLayoutList(); serializedObject.ApplyModifiedProperties(); } if (GUI.changed) { SceneView.RepaintAll(); if (EditorApplication.isPlaying || EditorApplication.isPaused) { if (!t.autoOutline) { t.CreateLinerendererPoints(); } } } }
void OnSceneGUI() { // get the chosen game object Outline t = target as Outline; if (t == null) { return; } if (!t.autoOutline) { // grab the center of the parent Vector3 center = t.transform.position; int selectedIndex = -1; bool changed = false; if (GUIUtility.hotControl != 0 && GUIUtility.hotControl != selectedID) { selectedID = -1; } //draw each editable vertices for (int i = 0; i < t.outlineVertices.Count; i++) { currentIndex = i; float size = HandleUtility.GetHandleSize(t.outlineVertices[i].position) * 0.04f; Handles.color = Color.green; if (i != t.outlineVertices.Count - 1) { DrawEditorLine(center, i, i + 1); } Vector3 p = t.outlineVertices[i].position; t.outlineVertices[i].position = Handles.FreeMoveHandle(center + t.outlineVertices[i].position, Quaternion.identity, size, Vector3.zero, CustomDotCap) - center; if (p != t.outlineVertices[i].position) { changed = true; } int dID = -2; dotCapIds.TryGetValue(i, out dID); if (selectedID == dID) { selectedIndex = i; } if (t.outlineBezier) { if (DrawTangentEditor(i)) { changed = true; } } } //last line if enabled if (t.lastLinkedToFirst && t.outlineVertices.Count > 2) { DrawEditorLine(center, t.outlineVertices.Count - 1, 0); } //keyboard event to create / delete seleted node if (Event.current.type == EventType.KeyDown) { Debug.Log("selectedIndex: " + selectedIndex); Debug.Log("selectedID: " + selectedID); if (Event.current.keyCode == KeyCode.P) { Vector3 point = (selectedID == -1) ? Vector3.up * .2f : t.outlineVertices[selectedIndex].position; Vector3 t1 = (selectedID == -1) ? Vector3.up * .1f : t.outlineVertices[selectedIndex].t1; Vector3 t2 = (selectedID == -1) ? Vector3.down * .1f : t.outlineVertices[selectedIndex].t2; t.outlineVertices.Insert((selectedID == -1) ? 0 : selectedIndex, new Outline.OutlineVertice(point, t1, t2)); serializedObject.ApplyModifiedProperties(); SceneView.RepaintAll(); } if (Event.current.keyCode == KeyCode.M) { if (selectedIndex != -1) { t.outlineVertices.RemoveAt(selectedIndex); serializedObject.ApplyModifiedProperties(); dotCapIds.Remove(selectedIndex); SceneView.RepaintAll(); } else { Debug.LogWarning("no point selected to remove !"); } } serializedObject.ApplyModifiedProperties(); } if (changed && !t.autoOutline && (EditorApplication.isPlaying || EditorApplication.isPaused)) { t.CreateLinerendererPoints(); } } }