public override void OnInit() { base.OnInit(); this.GetLayoutComponent(out this.exceptionBorder, LayoutTag.Tag6); this.GetLayoutComponent(out this.alwaysShownText, LayoutTag.Tag4); this.GetLayoutComponent(out this.commandQueue); this.commandQueue.SetScreen(this); this.queueContainer = this.GetLayoutContainer(LayoutTag.Tag3); this.GetLayoutComponent(out this.commandLine); this.commandLine.SetCallbacks(null, (text) => { if (text.Trim() != "`" && string.IsNullOrEmpty(text.Trim()) == false) UnityEngine.UI.Windows.Plugins.Analytics.Analytics.SendEvent(this.windowId, "Command", text); this.AddLineCmd(text); }); this.container = this.GetLayoutContainer(LayoutTag.Tag1); this.HideExceptionBorder(); Application.logMessageReceived += this.OnMessage; }
public IWindowEventsAsync Create(WindowBase window, WindowLayoutElement root) { this.root = root; if (this.component == null && this.root == null) { return(null); } if (this.component == null) { this.root.Setup(null, this); return(null); } var instance = this.component.Spawn(); instance.SetParent(root, setTransformAsSource: false); instance.SetTransformAs(); var rect = instance.transform as RectTransform; rect.sizeDelta = (this.component.transform as RectTransform).sizeDelta; rect.anchoredPosition = (this.component.transform as RectTransform).anchoredPosition; this.root.Setup(instance, this); instance.Setup(window); instance.transform.SetSiblingIndex(this.sortingOrder); this.instance = instance; return(instance); }
private void ArrangeByGrid(WindowLayoutElement element, Vector2 grid) { var rect = element.transform as RectTransform; rect.anchoredPosition = this.GridBy(rect.anchoredPosition, grid); rect.sizeDelta = this.GridBy(rect.sizeDelta, grid); }
public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, bool hovered, WindowLayoutElement selectedElement, System.Action<WindowLayoutElement> onSelection, System.Action<WindowLayoutElement, Rect, bool> onElementGUI, List<WindowLayoutElement> highlighted) { var _target = this.target as LayoutWindowType; var layout = _target.layout.layout; var layoutElements = _target.layout.components; if (layout != null) { if (this.layoutEditor == null) this.layoutEditor = Editor.CreateEditor(layout) as WindowLayoutEditor; if (this.layoutEditor != null) { //var emptyStyle = GUIStyle.none; if (Event.current.type != EventType.Layout) { this.layoutEditor.OnPreviewGUI(color, r, background, drawInfo, selectable: selectable, hovered: hovered, selectedElement: selectedElement, onSelection: onSelection, onElementGUI: (element, elementRect, isClicked) => { if (isClicked == true) { var tag = element.tag; var comp = layoutElements.FirstOrDefault((e) => e.tag == tag); if (comp != null) { this.selectedComponent = comp; } } /*var tag = element.tag; var comp = layoutElements.FirstOrDefault((e) => e.tag == tag); if (comp != null) { comp.OnPreviewGUI(elementRect, emptyStyle); }*/ }, highlighted: highlighted); } } } }
public void OnEnable() { //SceneView.onSceneGUIDelegate -= this.OnSceneView; //SceneView.onSceneGUIDelegate += this.OnSceneView; this._target = this.target as WindowLayoutElement; if (this._target == null) return; this.layout = this._target.GetComponentInParent<WindowLayout>(); /*if (this._target != null) { this.lastPivot = (this._target.transform as RectTransform).pivot; }*/ }
public override void OnInit() { base.OnInit(); this.content = this.GetLayoutContainer(LayoutTag.Tag2); this.tabs = this.GetLayoutComponent<Tabs>(); this.tabs.SetContent(this.content); var i = 0; foreach (var component in this.components) { var button = this.tabs.AddItem<ButtonComponent, WindowComponent>(component); button.SetText((++i).ToString() + ". " + component.name); } }
public void OnPreviewGUI(Color color, Rect rect, GUIStyle style, bool drawInfo, bool selectable, bool hovered, WindowLayoutElement selectedElement, System.Action<WindowLayoutElement> onSelection, List<WindowLayoutElement> highlighted) { var _target = this.target as WindowComponent; this.DrawComponent(_target, _target.name, rect, style); /* var components = _target.GetComponentsInChildren<WindowComponent>(true); var xCount = Mathf.CeilToInt(Mathf.Sqrt(components.Length)); if (xCount == 0) xCount = 1; var yCount = components.Length / xCount; var x = 0; var y = 0; foreach (var comp in components) { //if (comp == this) continue; var c = comp; if (comp is LinkerComponent) { c = (comp as LinkerComponent).prefab; } var xOffset = (r.width / xCount) * x; var yOffset = (r.height / yCount) * y; this.DrawComponent(c, c.name, new Rect(r.x + xOffset, r.y + yOffset, r.width / xCount, r.height / yCount), background); ++x; if (xCount == x) { x = 0; ++y; } }*/ }
private void WaitForAttach(int id, WindowLayoutElement currentAttachComponent = null) { this.currentAttachId = id; this.currentAttachComponent = currentAttachComponent; this.waitForAttach = id >= 0; if (this.waitForAttach == false) { WindowLayoutElement.waitForComponentConnectionElementTemp = null; } }
public void WaitForAttach(int id, WindowLayoutElement currentAttachComponent = null, int index = 0, System.Action<int, int, bool> onAttach = null) { this.onAttach = onAttach; this.currentAttachId = id; this.currentAttachIndex = index; this.currentAttachComponent = currentAttachComponent; this.waitForAttach = id >= 0; if (this.waitForAttach == false) { WindowLayoutElement.waitForComponentConnectionElementTemp = null; } }
public void OnPreviewGUI(Color color, Rect rect, GUIStyle style, WindowLayoutElement selectedElement, System.Action<WindowLayoutElement> onSelection, List<WindowLayoutElement> highlighted) { this.OnPreviewGUI(color, rect, style, drawInfo: true, selectable: true, hovered: false, selectedElement: selectedElement, onSelection: onSelection, onElementGUI: null, highlighted: highlighted); }
public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, WindowLayoutElement selectedElement) { this.OnPreviewGUI(color, r, background, drawInfo, selectable, hovered: false, selectedElement: selectedElement, onSelection: null, onElementGUI: null, highlighted: null); }
public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, WindowLayoutElement selectedElement, System.Action<WindowLayoutElement, Rect, bool> onElementGUI) { var oldColor = GUI.color; var c = Color.white; c.a = 0.3f; GUI.color = c; GUI.Box(r, string.Empty, background); GUI.color = oldColor; var _target = this.target as UnityEngine.UI.Windows.WindowLayout; if (_target == null) return; var selectedColor = color; var notSelectedColor = color; notSelectedColor.a = 0.4f; var elements = _target.elements; if (ME.EditorUtilities.IsPrefab(_target.gameObject) == false && _target.gameObject.activeInHierarchy == true) { var pos = _target.transform.localPosition; _target.transform.localPosition = Vector3.zero; foreach (var element in elements) { var rectTransform = (element.transform as RectTransform); var corners = new Vector3[4]; rectTransform.GetWorldCorners(corners); var rect = new Rect(corners[0].x, -corners[1].y, corners[2].x - corners[1].x, corners[2].y - corners[3].y); element.editorRect = rect; //element.autoStretchX = (rectTransform.anchorMin.x != rectTransform.anchorMax.x); //element.autoStretchY = (rectTransform.anchorMin.y != rectTransform.anchorMax.y); } _target.editorScale = _target.transform.localScale.x; _target.root.editorRect = (_target.root.transform as RectTransform).rect; (_target.transform as RectTransform).localPosition = pos; } var scaleFactor = 0f; if (elements.Count > 0) { scaleFactor = this.GetFactor(new Vector2(_target.root.editorRect.width, _target.root.editorRect.height), new Vector2(r.width, r.height)); } var scaleFactorCanvas = _target.editorScale > 0f ? 1f / _target.editorScale : 1f; scaleFactor *= scaleFactorCanvas; var selected = WindowLayoutStyles.styles.boxSelected; var styles = WindowLayoutStyles.styles.boxes; var stylesSelected = WindowLayoutStyles.styles.boxesSelected; var horArrowsStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horArrowsStyle", "ColorPickerHorizThumb", (style) => new GUIStyle(style)); var vertArrowsStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertArrowsStyle", "ColorPickerVertThumb", (style) => new GUIStyle(style)); var horStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horStyle", "box", (style) => new GUIStyle(style)); var vertStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertStyle", "box", (style) => new GUIStyle(style)); foreach (var element in elements) { element.editorDrawDepth = element.GetComponentsInParent<WindowLayoutElement>(true).Length - 1; var rect = element.editorRect; rect.x *= scaleFactor; rect.y *= scaleFactor; rect.x += r.x + r.width * 0.5f; rect.y += r.y + r.height * 0.5f; rect.width *= scaleFactor; rect.height *= scaleFactor; var style = styles[Mathf.Clamp(element.editorDrawDepth, 0, WindowLayoutStyles.MAX_DEPTH - 1)]; if (rect.Contains(Event.current.mousePosition) == true) { style = stylesSelected[Mathf.Clamp(element.editorDrawDepth, 0, WindowLayoutStyles.MAX_DEPTH - 1)]; element.editorHovered = true; this.Repaint(); } else { element.editorHovered = false; this.Repaint(); } if (WindowLayoutElement.waitForComponentConnectionElementTemp == element) { style = selected; } if (selectedElement != null) { GUI.color = (selectedElement == element) ? selectedColor : notSelectedColor; if (selectedElement == element) style = selected; } else { GUI.color = color; } GUI.Label(rect, string.Empty, style); GUI.color = oldColor; var boxColor = EditorGUIUtility.isProSkin ? oldColor : new Color(1f, 1f, 1f, 0.2f); var marginX = 4f; var marginY = 2f; if (element.autoStretchX == true) { var vRect = new Rect(rect); vRect.x += marginX; vRect.y = vRect.y + vRect.height * 0.5f - vertArrowsStyle.fixedHeight * 0.5f; vRect.width -= marginX * 2f; vRect.height = vertArrowsStyle.fixedHeight; GUI.color = oldColor; GUI.Label(vRect, string.Empty, vertArrowsStyle); GUI.color = boxColor; GUI.Label(vRect, string.Empty, vertStyle); } if (element.autoStretchY == true) { var vRect = new Rect(rect); vRect.x = vRect.x + vRect.width * 0.5f - horArrowsStyle.fixedWidth * 0.5f; vRect.y += marginY; vRect.width = horArrowsStyle.fixedWidth; vRect.height -= marginY * 2f; GUI.color = oldColor; GUI.Label(vRect, string.Empty, horArrowsStyle); GUI.color = boxColor; GUI.Label(vRect, string.Empty, horStyle); } if (Event.current.type == EventType.Repaint) element.tempEditorRect = rect; } if (drawInfo == true || onElementGUI != null) { WindowLayoutElement maxDepthElement = null; var _maxDepth = -1; foreach (var element in elements) { if (element.showInComponentsList == false) continue; if (element.editorHovered == false) continue; if (_maxDepth < element.editorDrawDepth) { _maxDepth = element.editorDrawDepth; maxDepthElement = element; } } foreach (var element in elements) { if (element.showInComponentsList == false) continue; if (element.editorHovered == false || maxDepthElement != element) { continue; } if (GUI.Button(element.tempEditorRect, string.Empty, GUIStyle.none) == true) { if (selectable == true) { WindowLayoutElement.waitForComponentConnectionElementTemp = element; WindowLayoutElement.waitForComponentConnectionTemp = true; if (onElementGUI != null) onElementGUI(element, element.tempEditorRect, true); } } else { if (onElementGUI != null) onElementGUI(element, element.tempEditorRect, false); } } } GUI.color = oldColor; }
public override void OnGUI() { if (this.opened == true) { GUI.Box(new Rect(0f, 0f, Screen.width, Screen.height), string.Empty, Layout.styles.dropShadow); const float settingsWidth = 320f; const float listHeight = 200f; const float padding = 5f; const float closeSize = 30f; const float scrollWidth = 16f; var rect = new Rect(0f, -OFFSET, Screen.width, Screen.height - OFFSET); var rectContent = new Rect(rect.x + MARGIN + settingsWidth + padding, rect.y + MARGIN, rect.width - MARGIN * 2f - padding - settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT); var rectList = new Rect(MARGIN, rect.y + MARGIN, settingsWidth, listHeight - padding); var rectSettings = new Rect(MARGIN, rect.y + MARGIN + listHeight, settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT - listHeight); var rectCloseButton = new Rect(rect.x + rect.width - closeSize, rect.y, closeSize, closeSize); GUI.Box(new Rect(rect.x + MARGIN, rect.y + MARGIN, rect.width - MARGIN * 2f, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT), string.Empty, Layout.styles.layoutBack); GUI.Box(rect, string.Empty, Layout.styles.backLock); GUI.Box(rectList, string.Empty, Layout.styles.content); GUI.Box(rectSettings, string.Empty, Layout.styles.content); GUI.Box(rectContent, string.Empty, Layout.styles.contentScreen); GUI.BeginGroup(rectSettings); { if (this.component != null) { const float offsetTop = 50f; var viewRect = new Rect(0f, 0f, rectSettings.width, 0f); var scrollView = new Rect(0f, 0f + offsetTop, rectSettings.width, rectSettings.height - offsetTop); System.Action<WindowComponent> onChange = (WindowComponent component) => { //Debug.Log(component + "!=" + this.component.component); if (component != this.component.component) { this.component.component = component; this.component.componentParametersEditor = null; this.component.componentParameters = this.component.OnComponentChanged(this.screen, component); } }; var c = EditorGUI.ObjectField(new Rect(5f, 5f, viewRect.width - 40f - 5f * 2f, 16f), this.component.component, typeof(WindowComponent), allowSceneObjects: false) as WindowComponent; if (c != this.component.component) { onChange(c); } var nRect = new Rect(viewRect.width - 40f, 5f, 40f - 5f, 16f); GUILayoutExt.DrawComponentChooser(nRect, this.screen.gameObject, this.component.component, (component) => { onChange(component); }); if (this.component.component != null) { nRect.x = 5f; nRect.width = viewRect.width - 5f * 2f; nRect.y += nRect.height + 5f; this.component.sortingOrder = EditorGUI.IntField(nRect, new GUIContent("Sorting Order"), this.component.sortingOrder); var editor = this.component.componentParametersEditor; if (editor == null && this.component.componentParameters != null) { var e = Editor.CreateEditor(this.component.componentParameters) as IParametersEditor; this.component.componentParametersEditor = e; } if (editor != null) { var h = Mathf.Max(scrollView.height, (editor == null) ? 0f : editor.GetHeight()); viewRect = new Rect(scrollView.x, scrollView.y, viewRect.width - scrollWidth, h); var oldSkin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.settingsScrollPosition = GUI.BeginScrollView(scrollView, this.settingsScrollPosition, viewRect, false, true); GUI.skin = oldSkin; { if (editor != null) { EditorGUIUtility.labelWidth = 100f; //++EditorGUI.indentLevel; editor.OnParametersGUI(viewRect); //--EditorGUI.indentLevel; EditorGUIUtility.LookLikeControls(); } } GUI.EndScrollView(); } else { GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height), "Selected component have no parameters", EditorStyles.centeredGreyMiniLabel); } } } else { GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height), "Select an Element", EditorStyles.centeredGreyMiniLabel); } } GUI.EndGroup(); GUI.BeginGroup(rectList); { const float itemHeight = 30f; this.highlighted.Clear(); var viewRect = new Rect(0f, 0f, rectList.width - scrollWidth, 0f); this.allListHeight = 0f; for (int i = 0; i < this.props.Count; ++i) { var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag); if (root.showInComponentsList == false) continue; if (this.screen.layout.components[i].component == null) { this.highlighted.Add(root); } this.allListHeight += itemHeight; } viewRect.height = Mathf.Max(rectList.height, this.allListHeight); var oldSkin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.listScrollPosition = GUI.BeginScrollView(new Rect(0f, 0f, rectList.width, rectList.height), this.listScrollPosition, viewRect, false, true); GUI.skin = oldSkin; { GUI.BeginGroup(viewRect); { var h = 0f; this.hovered = null; for (int i = 0; i < this.props.Count; ++i) { var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag); if (root.showInComponentsList == false) continue; var r = new Rect(0f, h, viewRect.width, itemHeight); h += r.height; var isSelected = (this.element == root); if (isSelected == true) { GUI.Label(r, this.screen.layout.components[i].description, Layout.styles.listButtonSelected); } else { //r.width -= scrollWidth; if (GUI.Button(r, this.screen.layout.components[i].description, Layout.styles.listButton) == true) { this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == root.tag); this.element = root; } var inRect = rectList.Contains(Event.current.mousePosition - this.listScrollPosition + Vector2.up * 40f); if (GUI.enabled == true) EditorGUIUtility.AddCursorRect(r, MouseCursor.Link); if (r.Contains(Event.current.mousePosition) == true && inRect == true) { this.hovered = this.screen.layout.components[i]; } //r.width += scrollWidth; } //r.width -= scrollWidth; GUI.Label(r, this.screen.layout.components[i].tag.ToString(), Layout.styles.listTag); } } GUI.EndGroup(); } GUI.EndScrollView(); } GUI.EndGroup(); var selected = (this.hovered != null) ? this.screen.layout.layout.GetRootByTag(this.hovered.tag) : this.element; this.editor.OnPreviewGUI(Color.white, rectContent, Layout.styles.content, selected: selected, onSelection: (element) => { this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == element.tag); this.element = element; }, highlighted: this.highlighted); if (GUI.Button(rectCloseButton, string.Empty, Layout.styles.closeButton) == true) { FlowSystemEditorWindow.GetWindow<FlowSystemEditorWindow>().SetEnabled(); this.opened = false; } } }
public override void OnFlowWindowScreenMenuGUI(FD.FlowWindow windowSource, GenericMenu menu) { menu.AddItem(new GUIContent("Components Editor..."), on: false, func: (object win) => { var window = win as FD.FlowWindow; var screen = window.GetScreen() as LayoutWindowType; if (screen != null) { FlowSystemEditorWindow.GetWindow<FlowSystemEditorWindow>().SetDisabled(); //this.window = window; this.screen = screen; this.editor = Editor.CreateEditor(window.GetScreen()) as IPreviewEditor; this.component = null; this.hovered = null; this.element = null; this.listScrollPosition = Vector2.zero; var serializedObject = new SerializedObject(this.screen); var layout = serializedObject.FindProperty("layout"); var components = layout.FindPropertyRelative("components"); this.props.Clear(); for (int i = 0; i < components.arraySize; ++i) { var component = components.GetArrayElementAtIndex(i); this.props.Add(component); this.screen.layout.components[i].OnComponentChanged(this.screen, this.screen.layout.components[i].component); } this.settingsScrollPosition = Vector2.zero; this.opened = true; } }, userData: windowSource); }
public void OnPreviewGUI(Color color, Rect rect, GUIStyle style, bool drawInfo, bool selectable, bool hovered, WindowLayoutElement selectedElement, System.Action<WindowLayoutElement> onSelection, List<WindowLayoutElement> highlighted) { const float sliderHeight = 20f; const float padding = 40f; if (this.styles == null) this.styles = new Styles(); var _target = this.target as TransitionInputTemplateParameters; if (_target == null) return; this.changed = false; if (drawInfo == true) { var sliderRect = new Rect(rect.x + padding, rect.y, rect.width - padding * 2f, sliderHeight); rect.y += sliderHeight; rect.height -= sliderHeight; var newValue = GUI.HorizontalSlider(sliderRect, this.sliderPosition, 0f, 1f); if (newValue != this.sliderPosition) this.changed = true; this.sliderPosition = newValue; } else { this.changed = true; this.hovered = hovered; } var _targetVideo = this.target as TransitionVideoInputTemplateParameters; if (_targetVideo != null) { if (this.targetTexture != null) { GUI.DrawTexture(rect, this.targetTexture); } } var _targetAudio = this.target as TransitionAudioInputTemplateParameters; if (_targetAudio != null) { var pars = _target.GetParameters<TransitionBase.ParametersAudioBase>(); var oldEvent = new Event(Event.current); //Event.current.Use(); this.audioCurveIn = new AnimationCurve(); for (float t = 0f; t <= pars.inDuration + 0.01f; t += 0.05f) { var value = pars.GetVolumeValueIn(t); var key = new Keyframe(t, value); this.audioCurveIn.AddKey(key); } this.audioCurveOut = new AnimationCurve(); for (float t = 0f; t <= pars.outDuration + 0.01f; t += 0.05f) { var value = pars.GetVolumeValueOut(t); var key = new Keyframe(t, value); this.audioCurveOut.AddKey(key); } AnimationCurveUtility.SetLinear(ref this.audioCurveIn); AnimationCurveUtility.SetLinear(ref this.audioCurveOut); this.audioCurveIn.postWrapMode = WrapMode.Clamp; this.audioCurveIn.preWrapMode = WrapMode.Clamp; this.audioCurveOut.postWrapMode = WrapMode.Clamp; this.audioCurveOut.preWrapMode = WrapMode.Clamp; { if (Event.current.type == EventType.MouseDown) Event.current.type = EventType.Repaint; EditorGUI.CurveField(new Rect(rect.x, rect.y, rect.width, rect.height * 0.5f), string.Empty, this.audioCurveIn, Color.red, new Rect(0f, 0f, pars.inDuration, 1f)); EditorGUI.CurveField(new Rect(rect.x, rect.y + rect.height * 0.5f, rect.width, rect.height * 0.5f), string.Empty, this.audioCurveOut, Color.cyan, new Rect(0f, 0f, pars.outDuration, 1f)); if (this.sliderPosition > 0f) { GUI.Box(new Rect(rect.x + (this.sliderPosition * rect.width), rect.y, 3f, rect.height * 0.5f), string.Empty); GUI.Box(new Rect(rect.x + (this.sliderPosition * rect.width), rect.y + rect.height * 0.5f, 3f, rect.height * 0.5f), string.Empty); } EditorGUI.DropShadowLabel(new Rect(rect.x, rect.y, rect.width, rect.height * 0.5f), "In"); EditorGUI.DropShadowLabel(new Rect(rect.x, rect.y + rect.height * 0.5f, rect.width, rect.height * 0.5f), "Out"); } Event.current = oldEvent; } }
protected virtual void OnDestroy() { WindowLayoutElement.waitForComponentConnectionElementTemp = null; }
public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, WindowLayoutElement selectedElement) { this.OnPreviewGUI(color, r, background, drawInfo, selectable); }
public void OnPreviewGUI(Color color, Rect r, GUIStyle background, bool drawInfo, bool selectable, bool hovered, WindowLayoutElement selectedElement, System.Action<WindowLayoutElement> onSelection, System.Action<WindowLayoutElement, Rect, bool> onElementGUI, List<WindowLayoutElement> highlighted) { var oldColor = GUI.color; var c = Color.white; c.a = 0.3f; GUI.color = c; GUI.Box(r, string.Empty, background); GUI.color = oldColor; var _target = this.target as UnityEngine.UI.Windows.WindowLayout; if (_target == null) return; var selectedColor = color; var notSelectedColor = color; notSelectedColor.a = 0.4f; var elements = _target.elements; if (ME.EditorUtilities.IsPrefab(_target.gameObject) == false && _target.gameObject.activeInHierarchy == true) { this.CalculateRects(_target); } var scaleFactor = 0f; if (elements.Count > 0) { scaleFactor = this.GetFactor(new Vector2(_target.root.editorRectLocal.width, _target.root.editorRectLocal.height), new Vector2(r.width, r.height)); } if (ME.EditorUtilities.IsPrefab(_target.gameObject) == true) { if (this.processReconnection == false && scaleFactor == 0f) { this.processReconnection = true; // We must re-attach prefab var tempGo = UnityEditor.PrefabUtility.InstantiatePrefab(_target.gameObject) as GameObject; Selection.activeGameObject = tempGo; foreach (var component in tempGo.GetComponents<Component>()) { var editor = Editor.CreateEditor(component) as WindowLayoutEditor; if (editor != null) { editor.CalculateRects(component as UnityEngine.UI.Windows.WindowLayout); EditorUtility.SetDirty(component); } } var i = 0; EditorApplication.update += () => { ++i; if (i == 30) { UnityEditor.PrefabUtility.ReplacePrefab(tempGo, PrefabUtility.GetPrefabParent(tempGo), ReplacePrefabOptions.ConnectToPrefab); GameObject.DestroyImmediate(tempGo); this.processReconnection = false; } }; } } var scaleFactorCanvas = _target.editorScale > 0f ? 1f / _target.editorScale : 1f; scaleFactor *= scaleFactorCanvas; var selected = WindowLayoutStyles.styles.boxSelected; var styles = WindowLayoutStyles.styles.boxes; var stylesSelected = WindowLayoutStyles.styles.boxesSelected; var elementSelectedStyle = WindowLayoutStyles.styles.layoutElementSelected; var elementHighlightStyle = WindowLayoutStyles.styles.layoutElementHighlighted; var horArrowsStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horArrowsStyle", "ColorPickerHorizThumb", (style) => new GUIStyle(style)); var vertArrowsStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertArrowsStyle", "ColorPickerVertThumb", (style) => new GUIStyle(style)); var horStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.horStyle", "box", (style) => new GUIStyle(style)); var vertStyle = ME.Utilities.CacheStyle("WindowLayout.GetEditorStyle.vertStyle", "box", (style) => new GUIStyle(style)); var selectedRect = new Rect(); foreach (var element in elements) { if (element == null) continue; element.editorDrawDepth = element.GetComponentsInParent<WindowLayoutElement>(true).Length - 1; var rect = element.editorRect; rect.x *= scaleFactor; rect.y *= scaleFactor; rect.x += r.x + r.width * 0.5f; rect.y += r.y + r.height * 0.5f; rect.width *= scaleFactor; rect.height *= scaleFactor; var styleDepth = Mathf.Clamp(element.editorDrawDepth, 0, WindowLayoutStyles.MAX_DEPTH - 1); var style = styles[styleDepth]; if (rect.Contains(Event.current.mousePosition) == true) { style = stylesSelected[styleDepth]; element.editorHovered = true; this.Repaint(); } else { element.editorHovered = false; this.Repaint(); } if (/*WindowLayoutElement.waitForComponentConnectionElementTemp == element ||*/ Selection.gameObjects.Contains(element.gameObject) == true) { style = selected; selectedRect = rect; } if (selectedElement != null) { GUI.color = (selectedElement == element) ? selectedColor : notSelectedColor; if (selectedElement == element) { style = selected; selectedRect = rect; } } else { GUI.color = color; } GUI.Label(rect, string.Empty, style); GUI.color = oldColor; var boxColor = EditorGUIUtility.isProSkin ? oldColor : new Color(1f, 1f, 1f, 0.2f); var marginX = 4f; var marginY = 2f; if (element.autoStretchX == true) { var vRect = new Rect(rect); vRect.x += marginX; vRect.y = vRect.y + vRect.height * 0.5f - vertArrowsStyle.fixedHeight * 0.5f; vRect.width -= marginX * 2f; vRect.height = vertArrowsStyle.fixedHeight; GUI.color = oldColor; GUI.Label(vRect, string.Empty, vertArrowsStyle); GUI.color = boxColor; GUI.Label(vRect, string.Empty, vertStyle); } if (element.autoStretchY == true) { var vRect = new Rect(rect); vRect.x = vRect.x + vRect.width * 0.5f - horArrowsStyle.fixedWidth * 0.5f; vRect.y += marginY; vRect.width = horArrowsStyle.fixedWidth; vRect.height -= marginY * 2f; GUI.color = oldColor; GUI.Label(vRect, string.Empty, horArrowsStyle); GUI.color = boxColor; GUI.Label(vRect, string.Empty, horStyle); } if (Event.current.type == EventType.Repaint) element.tempEditorRect = rect; } if (highlighted != null) { foreach (var element in elements) { if (highlighted.Contains(element) == true) { GUI.Box(element.tempEditorRect, string.Empty, elementHighlightStyle); } } } GUI.Box(selectedRect, string.Empty, elementSelectedStyle); if (drawInfo == true || onElementGUI != null || selectable == true) { WindowLayoutElement maxDepthElement = null; var _maxDepth = -1; foreach (var element in elements) { if (element.showInComponentsList == false) continue; if (element.editorHovered == false) continue; if (_maxDepth < element.editorDrawDepth) { _maxDepth = element.editorDrawDepth; maxDepthElement = element; } } foreach (var element in elements) { if (element.showInComponentsList == false) continue; if (element.editorHovered == false || maxDepthElement != element) { continue; } if (GUI.Button(element.tempEditorRect, string.Empty, GUIStyle.none) == true) { if (selectable == true) { //WindowLayoutElement.waitForComponentConnectionElementTemp = element; //WindowLayoutElement.waitForComponentConnectionTemp = true; if (onSelection != null) onSelection(element); if (onElementGUI != null) onElementGUI(element, element.tempEditorRect, true); } } else { if (onElementGUI != null) onElementGUI(element, element.tempEditorRect, false); } } } GUI.color = oldColor; }