static internal void Init() { var window = (HighlightWindow)GetWindow(typeof(HighlightWindow), false, "Highlight Manager"); window.position = new Rect(window.position.xMin + 100f, window.position.yMin + 100f, 200f, 100f); HighlightData.Load(tags); }
public void SetHighlight(GameObject go, bool active, Transform rayOrigin = null, Material material = null, bool force = false, float duration = 0f) { if (go == null) { return; } if (!force && active && this.IsLocked(go)) { return; } if (material == null) { material = rayOrigin ? m_RayHighlightMaterial : m_DefaultHighlightMaterial; } if (active) // Highlight { Dictionary <GameObject, HighlightData> highlights; if (!m_Highlights.TryGetValue(material, out highlights)) { highlights = new Dictionary <GameObject, HighlightData>(); m_Highlights[material] = highlights; } highlights[go] = new HighlightData { startTime = Time.time, duration = duration }; } else // Unhighlight { if (force) { // A force removal removes the GameObject regardless of how it was highlighted (e.g. with a specific hand) foreach (var gameObjects in m_Highlights.Values) { gameObjects.Remove(go); } } else { Dictionary <GameObject, HighlightData> highlights; if (m_Highlights.TryGetValue(material, out highlights)) { highlights.Remove(go); } } var skinnedMeshRenderer = ComponentUtils <SkinnedMeshRenderer> .GetComponent(go); if (skinnedMeshRenderer) { k_BakedMeshes.Remove(skinnedMeshRenderer); } } }
void OnGUI() { HighlightData.Load(tags); EditorGUILayout.BeginVertical(GUI.skin.box); this.scrollPos = EditorGUILayout.BeginScrollView(this.scrollPos, false, false); //add new data EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); tagKey = EditorGUILayout.TextField(tagKey); tagValue = EditorGUILayout.ColorField("", tagValue); if (GUILayout.Button("+", GUILayout.Width(40), GUILayout.Height(20))) { tags.tagNames.Add(tagKey); tags.tagColors.Add(tagValue); HighlightData.Save(tags); HighlightData.Load(tags); HierarchyHighlight.Init(tags); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //display old data for (int i = 0; i < tags.tagNames.Count; i++) { GUI.color = tags.tagColors[i]; EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); GUI.color = Color.white; GUIStyle lField = new GUIStyle(); lField.normal.textColor = Color.white; EditorGUILayout.LabelField(tags.tagNames[i], lField); if (GUILayout.Button("x", GUILayout.Width(40), GUILayout.Height(20))) { tags.tagNames.RemoveAt(i); tags.tagColors.RemoveAt(i); HighlightData.Save(tags); HighlightData.Load(tags); HierarchyHighlight.Init(tags); } EditorGUILayout.EndHorizontal(); if (tags.tagNames[i] == "GameManager" || tags.tagNames[i] == "Game Manager" || tags.tagNames[i] == "Game manager") { EditorGUILayout.HelpBox("THEHRO!\n\nUSING GAME MANAGERS IN 2018 IS A SIN.\nHERE'S HOW YOU CAN STILL REPENT AND ESCAPE THE DEPTHS OF HELL.\n\nSTEP 1: REMOVE THE GAME MANAGER SCRIPT FROM YOUR GAME.\n\nSTEP 3: KILL AND EAT ANOTHER PROGRAMMER WHO USES GAME MANAGERS.\n\nSTEP 2: SAY 'SORRY SHAKTIMAN' WHEN YOU'RE DONE.", MessageType.Warning, true); } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); }
public IEnumerable <GameObject> ContainedItems() { // Hacky fix because Physics.OverlapSphere does stupid things foreach (var obj in HighlightData.GetAll()) { var renderer = obj.GetComponent <Renderer>(); if (renderer == null) { continue; } if (this.Contains(renderer.bounds.center)) { yield return(obj); } } }
/// <summary> /// Called when task calls <see cref="SceneRenderTask.Draw" /> event. /// </summary> /// <param name="collector">The draw calls collector.</param> public virtual void OnDraw(DrawCallsCollector collector) { if (_highlightMaterial == null) { return; } Matrix m1, m2, world; for (var i = 0; i < _highlights.Count; i++) { HighlightData highlight = _highlights[i]; if (highlight.Target is StaticModel staticModel) { if (staticModel.Model == null) { continue; } staticModel.Transform.GetWorld(out m1); staticModel.Entries[highlight.EntryIndex].Transform.GetWorld(out m2); Matrix.Multiply(ref m2, ref m1, out world); BoundingSphere bounds = BoundingSphere.FromBox(staticModel.Box); collector.AddDrawCall(staticModel.Model, highlight.EntryIndex, _highlightMaterial, ref bounds, ref world); } } if (_highlightTriangles.Count > 0) { var mesh = _highlightTrianglesModel.LODs[0].Meshes[0]; if (!Utils.ArraysEqual(_highlightTrianglesSet, _highlightTriangles)) { _highlightIndicesSet = new int[_highlightTriangles.Count]; for (int i = 0; i < _highlightIndicesSet.Length; i++) { _highlightIndicesSet[i] = i; } _highlightTrianglesSet = _highlightTriangles.ToArray(); mesh.UpdateMesh(_highlightTrianglesSet, _highlightIndicesSet); } world = Matrix.Identity; collector.AddDrawCall(mesh, _highlightMaterial, ref world); } }
private static void ClearMarkers(HighlightData highlightData) { foreach (var selectionMarker in highlightData.Markers) { try { Destroy(selectionMarker.gameObject); } catch (MissingReferenceException) { // Значит маркер был уничтожен вместе с персонажем } } highlightData.Markers.Clear(); highlightData.LastSquadModel = null; }
static HierarchyHighlight() { myTags = new Tags(); screenOn = AssetDatabase.LoadAssetAtPath("Assets/Tools/Toolbag/_Hierarchy Highlight/screenOn.png", typeof(Texture2D)) as Texture2D; screenOff = AssetDatabase.LoadAssetAtPath("Assets/Tools/Toolbag/_Hierarchy Highlight/screenOff.png", typeof(Texture2D)) as Texture2D; popupOn = AssetDatabase.LoadAssetAtPath("Assets/Tools/Toolbag/_Hierarchy Highlight/popupOn.png", typeof(Texture2D)) as Texture2D; popupOff = AssetDatabase.LoadAssetAtPath("Assets/Tools/Toolbag/_Hierarchy Highlight/popupOff.png", typeof(Texture2D)) as Texture2D; moduleOn = AssetDatabase.LoadAssetAtPath("Assets/Tools/Toolbag/_Hierarchy Highlight/moduleOn.png", typeof(Texture2D)) as Texture2D; moduleOff = AssetDatabase.LoadAssetAtPath("Assets/Tools/Toolbag/_Hierarchy Highlight/moduleOff.png", typeof(Texture2D)) as Texture2D; EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyItemRedraw; EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyItemRedraw; // EditorApplication HighlightData.Load(myTags); }
public void Highlight(List <string> query) { // Hacky fix because Physics.OverlapSphere does stupid things foreach (var obj in HighlightData.GetAll(query)) { var renderer = obj.GetComponent <Renderer>(); if (renderer == null) { continue; } if (!this.Contains(renderer.bounds.center)) { continue; } var size = renderer.bounds.extents.Average() * 1.5f; var highlight = Instantiate(HighlightPrefab, renderer.bounds.center, Quaternion.identity); highlight.transform.localScale = new Vector3(size, size, size); highlight.name = obj.name + " highlight"; } }
/// <summary> /// Called when task calls <see cref="SceneRenderTask.CollectDrawCalls" /> event. /// </summary> /// <param name="renderContext">The rendering context.</param> public virtual void OnDraw(ref RenderContext renderContext) { if (_highlightMaterial == null || (_highlights.Count == 0 && _highlightTriangles.Count == 0) || renderContext.View.Pass == DrawPass.Depth ) { return; } Profiler.BeginEvent("ViewportDebugDrawData.OnDraw"); Matrix world; for (var i = 0; i < _highlights.Count; i++) { HighlightData highlight = _highlights[i]; if (highlight.Target is StaticModel staticModel) { var model = staticModel.Model; if (model == null) { continue; } staticModel.Transform.GetWorld(out world); var bounds = BoundingSphere.FromBox(staticModel.Box); // Pick a proper LOD int lodIndex = RenderTools.ComputeModelLOD(model, ref bounds.Center, bounds.Radius, ref renderContext); var lods = model.LODs; if (lods == null || lods.Length < lodIndex || lodIndex < 0) { continue; } var lod = lods[lodIndex]; // Draw meshes for (int meshIndex = 0; meshIndex < lod.Meshes.Length; meshIndex++) { if (lod.Meshes[meshIndex].MaterialSlotIndex == highlight.EntryIndex) { lod.Meshes[meshIndex].Draw(ref renderContext, _highlightMaterial, ref world); } } } } if (_highlightTriangles.Count > 0) { var mesh = _highlightTrianglesModel.LODs[0].Meshes[0]; if (!Utils.ArraysEqual(_highlightTrianglesSet, _highlightTriangles)) { _highlightIndicesSet = new int[_highlightTriangles.Count]; for (int i = 0; i < _highlightIndicesSet.Length; i++) { _highlightIndicesSet[i] = i; } _highlightTrianglesSet = _highlightTriangles.ToArray(); mesh.UpdateMesh(_highlightTrianglesSet, _highlightIndicesSet); } world = Matrix.Identity; mesh.Draw(ref renderContext, _highlightMaterial, ref world); } Profiler.EndEvent(); }
public void SetHighlightData(HighlightData data) { _data = data; }