static public InstantGuiInputText CreateInputText() { InstantGuiInputText element = (InstantGuiInputText)InstantGuiElement.Create("InputText", typeof(InstantGuiInputText), GetSelectedElement()); InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
static public void ForceUpdate() { if (!instance) { instance = (InstantGui)GameObject.FindObjectOfType(typeof(InstantGui)); } instance.Update(); }
static public InstantGuiToggle CreateToggle() { InstantGuiToggle element = (InstantGuiToggle)InstantGuiElement.Create("Toggle", typeof(InstantGuiToggle), GetSelectedElement()); InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
static public InstantGuiButton CreateButton() { InstantGuiButton element = (InstantGuiButton)InstantGuiElement.Create("Button", typeof(InstantGuiButton), GetSelectedElement()); InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
public static void CreateRoot() { GameObject rootobj = new GameObject ("InstantGUI"); InstantGui.instance = rootobj.AddComponent<InstantGui>(); InstantGui.instance.element = rootobj.AddComponent<InstantGuiElement>(); InstantGui.instance.element.relative = new InstantGuiElementPos(0,100,0,100); InstantGui.instance.element.offset = new InstantGuiElementPos(0,0,0,0); InstantGui.instance.element.lockPosition = true; }
public void Point(bool isEditor) //special point variant with custom mouseposition for editor. { //getting mouse pos Vector2 mousePos; if (isEditor) { mousePos = Event.current.mousePosition; mousePos.y = InstantGui.Invert(mousePos.y); } else { mousePos = Input.mousePosition; } pointed = false; //resetting isPointed to all elements pointedOnBackground = false; //getting point offset int leftPointOffset = 0; int rightPointOffset = 0; int topPointOffset = 0; int bottomPointOffset = 0; if (style != null) { leftPointOffset = style.pointOffset.left; rightPointOffset = style.pointOffset.right; topPointOffset = style.pointOffset.top; bottomPointOffset = style.pointOffset.bottom; } if (dynamic && (editable || !isEditor) && mousePos.x >= absolute.left - leftPointOffset && mousePos.x <= absolute.right - rightPointOffset && InstantGui.Invert(mousePos.y) >= absolute.top - topPointOffset && InstantGui.Invert(mousePos.y) <= absolute.bottom - bottomPointOffset) { pointedOnBackground = true; if (!InstantGui.pointed || transform.localPosition.z > InstantGui.pointed.transform.localPosition.z) { if (InstantGui.pointed != null) { InstantGui.pointed.pointed = false; //resetting isHover to old hover element previously assigned this frame } pointed = true; //assignin new hover element if (InstantGui.pointed != this) { InstantGui.pointed = this; } } } //recursive for (int i = 0; i < childElements.Count; i++) { childElements[i].Point(isEditor); } }
static public InstantGuiWindow CreateWindow() { InstantGuiWindow element = (InstantGuiWindow)InstantGuiElement.Create("Window", typeof(InstantGuiWindow), GetSelectedElement()); element.closeButton = InstantGuiElement.Create("Window_CloseButton", typeof(InstantGuiElement), element); element.closeButton.useStylePlacement = true; InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
static public void CreateRoot() { GameObject rootobj = new GameObject("InstantGUI"); InstantGui.instance = rootobj.AddComponent <InstantGui>(); InstantGui.instance.element = rootobj.AddComponent <InstantGuiElement>(); InstantGui.instance.element.relative = new InstantGuiElementPos(0, 100, 0, 100); InstantGui.instance.element.offset = new InstantGuiElementPos(0, 0, 0, 0); InstantGui.instance.element.lockPosition = true; }
static public void CreateRoot() { if (InstantGui.instance == null) { InstantGui.instance = (InstantGui)FindObjectOfType(typeof(InstantGui)); } if (InstantGui.instance == null) { InstantGui.CreateRoot(); } }
static public InstantGuiTextArea CreateTextArea() { InstantGuiTextArea element = (InstantGuiTextArea)InstantGuiElement.Create("TextArea", typeof(InstantGuiTextArea), GetSelectedElement()); element.slider = CreateVerticalSlider(); element.slider.useStylePlacement = true; element.slider.transform.parent = element.transform; InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
static public InstantGuiSlider CreateHorizontalSlider() { InstantGuiSlider element = (InstantGuiSlider)InstantGuiElement.Create("HorizontalSlider", typeof(InstantGuiSlider), GetSelectedElement()); element.diamond = InstantGuiElement.Create("HorizontalSlider_Diamond", typeof(InstantGuiElement), element); element.incrementButton = InstantGuiElement.Create("HorizontalSlider_IncrementButton", typeof(InstantGuiElement), element); element.decrementButton = InstantGuiElement.Create("HorizontalSlider_DecrementButton", typeof(InstantGuiElement), element); element.horizontal = true; InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
static public InstantGuiSlider CreateVerticalSlider() { InstantGuiSlider element = (InstantGuiSlider)InstantGuiElement.Create("VerticalSlider", typeof(InstantGuiSlider), GetSelectedElement()); element.diamond = InstantGuiElement.Create("VerticalSlider_Diamond", typeof(InstantGuiElement), element); element.incrementButton = InstantGuiElement.Create("VerticalSlider_IncrementButton", typeof(InstantGuiElement), element); element.decrementButton = InstantGuiElement.Create("VerticalSlider_DecrementButton", typeof(InstantGuiElement), element); element.diamond.editable = false; //element.diamond.useStylePlacement = true; element.incrementButton.useStylePlacement = true; element.decrementButton.useStylePlacement = true; InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
public static InstantGuiElement GetGuiComponentWithName(string name, string tag) { InstantGuiElement retorno = null; InstantGui gui = FindObjectOfType <InstantGui>(); InstantGuiElement[] elements = gui.GetComponentsInChildren <InstantGuiElement>(true); foreach (InstantGuiElement element in elements) { if (element.name.Equals(name) || (tag != null && element.CompareTag(tag))) { retorno = element; break; } } return(retorno); }
static public InstantGuiTabs CreateTabGroup() { InstantGuiTabs element = (InstantGuiTabs)InstantGuiElement.Create("TabGroup", typeof(InstantGuiTabs), GetSelectedElement()); element.tabs = new InstantGuiElement[1]; element.tabs[0] = InstantGuiElement.Create("Tab", typeof(InstantGuiElement), element); element.fields = new InstantGuiElement[1]; element.fields[0] = InstantGuiElement.Create("Tab_Field", "", typeof(InstantGuiElement), element); element.fields[0].relative.Set(0, 100, 0, 100); element.fields[0].offset.Set(0, 0, 0, 0); element.fields[0].lockPosition = true; element.fields[0].dynamic = false; InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
static public InstantGuiPopup CreatePopup() { InstantGuiPopup element = (InstantGuiPopup)InstantGuiElement.Create("Popup", typeof(InstantGuiPopup), GetSelectedElement()); element.list = CreateList(); //element.list.useStylePlacement = true; element.list.transform.parent = element.transform; element.list.relative.Set(0, 100, 100, 100); element.list.offset.Set(0, 0, 0, 200); //element.diamond = InstantGuiElement.Create("Slider_Diamond", InstantGuiElement, element); //element.incrementButton = InstantGuiElement.Create("Slider_IncrementButton", InstantGuiElement, element); //element.decrementButton = InstantGuiElement.Create("Slider_DecrementButton", InstantGuiElement, element); InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
static public InstantGuiList CreateList() { InstantGuiList element = (InstantGuiList)InstantGuiElement.Create("List", typeof(InstantGuiList), GetSelectedElement()); element.slider = CreateVerticalSlider(); element.slider.useStylePlacement = true; element.slider.transform.parent = element.transform; element.elementStyleName = "List_Element"; //element.diamond = InstantGuiElement.Create("Slider_Diamond", InstantGuiElement, element); //element.incrementButton = InstantGuiElement.Create("Slider_IncrementButton", InstantGuiElement, element); //element.decrementButton = InstantGuiElement.Create("Slider_DecrementButton", InstantGuiElement, element); InstantGui.ForceUpdate(); Selection.activeGameObject = element.gameObject; return(element); }
public void Blend(SubStyle sub, InstantGuiElement element, float blend) //done after base style apply { //removing a blended texture if necessary if ((!sub.enabled || sub.texture == null) && element.blendGuiTexture != null) { GameObject.DestroyImmediate(element.blendGuiTexture.gameObject); } //setting texture if (sub.texture != null) { if (!element.blendGuiTexture) { GameObject obj = new GameObject(element.transform.name + "_blendTexture"); obj.transform.parent = element.transform; //obj.hideFlags = HideFlags.HideInHierarchy; element.blendGuiTexture = obj.AddComponent <GUITexture>(); } if (element.blendGuiTexture.texture != sub.texture) { element.blendGuiTexture.texture = sub.texture; } element.blendGuiTexture.transform.localPosition = new Vector3(0, 0, element.transform.localPosition.z + 0.005f); element.blendGuiTexture.pixelInset = InstantGui.Invert(element.absolute.ToRect(InstantGui.scale)); if (borders != null) { element.blendGuiTexture.border = borders; } element.blendGuiTexture.color = new Color(element.blendGuiTexture.color.r, element.blendGuiTexture.color.g, element.blendGuiTexture.color.b, blend * 0.5f); if (element.mainGuiTexture != null) { element.mainGuiTexture.color = new Color(element.mainGuiTexture.color.r, element.mainGuiTexture.color.g, element.mainGuiTexture.color.b, (1 - blend * blend) * 0.5f); } } if (element.guiTexts != null && element.guiTexts.Length > 0) { element.textMaterial.color = element.textMaterial.color * (1 - blend) + sub.textColor * blend; } }
//File operations static Texture GetTexture(string name) { if (InstantGui.instance == null) { InstantGui.ForceUpdate(); } MonoScript script = MonoScript.FromMonoBehaviour(InstantGui.instance); string path = AssetDatabase.GetAssetPath(script); path = path.Replace("Scripts/InstantGui.cs", "Textures/" + name); Texture tex = (Texture)AssetDatabase.LoadAssetAtPath(path, typeof(Texture)); if (tex == null) { return(null); } return(tex); }
static public InstantGuiElement Create(string name, string style, System.Type type, InstantGuiElement parent) { //finding gui parent if (InstantGui.instance == null) { InstantGui.instance = (InstantGui)FindObjectOfType(typeof(InstantGui)); } if (InstantGui.instance == null) { InstantGui.CreateRoot(); parent = InstantGui.instance.element; } GameObject obj = new GameObject(name); //the object component will be assigned to //adding component InstantGuiElement element = (InstantGuiElement)obj.AddComponent(type); //parenting and setting styleset if (parent != null) { element.transform.parent = parent.transform; element.styleSet = parent.styleSet; //do not assign parent to element! It will get it automaticly } //resetting transform if (obj.transform.parent != null) { obj.transform.localPosition = new Vector3(0, 0, obj.transform.parent.localPosition.z + 1); } else { obj.transform.localPosition = new Vector3(0, 0, 0); } obj.transform.localScale = new Vector3(0, 0, 1); //setting style element.styleName = style; if (element.styleSet != null) { for (int i = 0; i < element.styleSet.styles.Length; i++) { if (element.styleSet.styles[i].name == element.styleName) { element.style = element.styleSet.styles[i]; } } } //setting default size if (element.style != null) { element.relative.Set(element.style.relative); element.offset.Set(element.style.offset); element.layerOffset = element.style.layerOffset; } //pureGui.Update(); return(element); }
public RectOffset pointOffset; // = new RectOffset(0,0,0,0); /* * public InstantGuiStyle() * { * main = new SubStyle(); * pointed = result.pointed.Clone(); * active = result.active.Clone(); * result.disabled = result.disabled.Clone(); * result.relative = result.relative.Clone(); * result.offset = result.offset.Clone(); * result.pointOffset = new RectOffset(result.pointOffset.left, result.pointOffset.right, result.pointOffset.top, result.pointOffset.bottom); * result.borders = new RectOffset(result.borders.left, result.borders.right, result.borders.top, result.borders.bottom); * return result; * } */ public void Apply(SubStyle sub, InstantGuiElement element) { //getting number of texts that should be in element int textsLength = 0; if (element.text.Length == 0) { textsLength = 0; } else { switch (textEffect) { case InstantGuiTextEffect.simple: textsLength = 1; break; case InstantGuiTextEffect.shadow: textsLength = 2; break; case InstantGuiTextEffect.stroke: textsLength = 5; break; } } //should a texture ot text be removed? bool removeTexture = false; bool removeTexts = false; if (!sub.enabled) { removeTexture = true; removeTexts = true; } if (!sub.texture) { removeTexture = true; } if (element.guiTexts.Length != textsLength) { removeTexts = true; //if text Length changed. No text included } if (font != element.currentFont) { removeTexts = true; //if font changed } for (int i = 0; i < element.guiTexts.Length; i++) { if (!element.guiTexts[i]) { removeTexts = true; //if any of guitexts array do not exists } } //removing if (removeTexture && element.mainGuiTexture != null) { GameObject.DestroyImmediate(element.mainGuiTexture.gameObject); } if (removeTexts) { for (int i = element.guiTexts.Length - 1; i >= 0; i--) { if (element.guiTexts[i] != null) { GameObject.DestroyImmediate(element.guiTexts[i].gameObject); } } //creating new array element.guiTexts = new GUIText[textsLength]; } if (!sub.enabled || (!sub.texture && element.text.Length == 0)) { return; } //setting texture if (sub.texture != null) { if (element.mainGuiTexture == null) { GameObject obj = new GameObject(element.transform.name + "_mainTexture"); obj.transform.parent = element.transform; obj.hideFlags = HideFlags.HideInHierarchy; element.mainGuiTexture = obj.AddComponent <GUITexture>(); } if (element.mainGuiTexture.texture != sub.texture) { element.mainGuiTexture.texture = sub.texture; } element.mainGuiTexture.transform.localPosition = new Vector3(0, 0, element.transform.localPosition.z); element.mainGuiTexture.pixelInset = InstantGui.Invert(element.absolute.ToRect(InstantGui.scale)); if (borders != null) { element.mainGuiTexture.border = borders; } } //proportional if (proportional && element.mainGuiTexture != null) { Rect newInset = element.mainGuiTexture.pixelInset; if (1.0f * element.mainGuiTexture.pixelInset.width / element.mainGuiTexture.pixelInset.height < proportionalAspect) { newInset.width = element.mainGuiTexture.pixelInset.height * proportionalAspect; newInset.x -= (newInset.width - element.mainGuiTexture.pixelInset.width) * 0.5f; } else { newInset.height = element.mainGuiTexture.pixelInset.width * (1.0f / proportionalAspect); newInset.y -= (newInset.height - element.mainGuiTexture.pixelInset.height) * 0.5f; } element.mainGuiTexture.pixelInset = newInset; } //setting text if (element.text.Length != 0) { //on font change - remove materials if (!font) { font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf"); } if (font != element.currentFont) { //element.textMaterial=null; //if (element.guiTexts.Length > 1) element.textEffectMaterial=null; for (int i = 0; i < element.guiTexts.Length; i++) { if (element.guiTexts[i] != null) { GameObject.DestroyImmediate(element.guiTexts[i].gameObject); } } element.currentFont = font; } //creating texts for (int i = 0; i < element.guiTexts.Length; i++) { if (element.guiTexts[i] == null) { GameObject obj = new GameObject(element.transform.name + "_text" + i.ToString()); obj.transform.parent = element.transform; obj.hideFlags = HideFlags.HideInHierarchy; element.guiTexts[i] = obj.AddComponent <GUIText>(); //setting materials if (i == 0) { element.textMaterial = new Material(font.material); element.guiTexts[i].material = element.textMaterial; } else if (i > 0 && i == element.guiTexts.Length - 1) //on the last one effect text { element.textEffectMaterial = new Material(font.material); for (int j = 1; j < element.guiTexts.Length; j++) { element.guiTexts[j].material = element.textEffectMaterial; } } } } //setting text params for (int i = 0; i < element.guiTexts.Length; i++) { if (i == 0) { element.textMaterial.color = sub.textColor; } else { element.textEffectMaterial.color = textEffectColor; } element.guiTexts[i].transform.localPosition = new Vector3(0, 0, element.transform.localPosition.z + 0.01f - i * 0.001f); //setting text if (element.guiTexts[i].text != element.text && !element.password) { element.guiTexts[i].text = element.text; } else if (element.password) { element.guiTexts[i].text = ""; for (int j = 0; j < element.text.Length; j++) { element.guiTexts[i].text += "*"; } } if (element.guiTexts[i].font != font) { element.guiTexts[i].font = font; } if (element.guiTexts[i].fontSize != fontSize) { element.guiTexts[i].fontSize = fontSize; } Vector2 pixelOffset = element.absolute.GetCenter(); switch (textAligment) { case InstantGuiTextAligment.center: element.guiTexts[i].anchor = TextAnchor.MiddleCenter; break; case InstantGuiTextAligment.text: pixelOffset.y = element.absolute.top; pixelOffset.x = element.absolute.left; element.guiTexts[i].anchor = TextAnchor.UpperLeft; break; case InstantGuiTextAligment.heading: pixelOffset.y = element.absolute.top; element.guiTexts[i].anchor = TextAnchor.UpperCenter; break; case InstantGuiTextAligment.above: pixelOffset.y = element.absolute.top; element.guiTexts[i].anchor = TextAnchor.LowerCenter; break; case InstantGuiTextAligment.label: pixelOffset.x = element.absolute.left; element.guiTexts[i].anchor = TextAnchor.MiddleRight; break; case InstantGuiTextAligment.rightLabel: pixelOffset.x = element.absolute.right; element.guiTexts[i].anchor = TextAnchor.MiddleLeft; break; } pixelOffset += new Vector2(textOffsetX + sub.textOffsetX, textOffsetY + sub.textOffsetY); element.guiTexts[i].pixelOffset = InstantGui.Invert(pixelOffset); } //aligning text effect if (textEffect == InstantGuiTextEffect.shadow) { element.guiTexts[1].pixelOffset = element.guiTexts[0].pixelOffset + new Vector2(textEffectSize * 0.75f, -textEffectSize); } else if (textEffect == InstantGuiTextEffect.stroke) { element.guiTexts[1].pixelOffset = element.guiTexts[0].pixelOffset + new Vector2(textEffectSize, textEffectSize); element.guiTexts[2].pixelOffset = element.guiTexts[0].pixelOffset + new Vector2(-textEffectSize, textEffectSize); element.guiTexts[3].pixelOffset = element.guiTexts[0].pixelOffset + new Vector2(-textEffectSize, -textEffectSize); element.guiTexts[4].pixelOffset = element.guiTexts[0].pixelOffset + new Vector2(textEffectSize, -textEffectSize); } } }
static public void EditFrame(InstantGuiElement element) { Undo.RecordObject(element, "InstantGui Move"); //getting mouse pos Vector2 mousePos = Event.current.mousePosition; mousePos.y = InstantGui.Invert(mousePos.y); //shift-aligning if (Event.current.shift) { if (Mathf.Abs(mousePos.x - dragStart.x) < Mathf.Abs(mousePos.y - dragStart.y)) { mousePos.x = dragStart.x; } else { mousePos.y = dragStart.y; } } //getting mouse button bool mouseDown = false; bool mouseUp = false; if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { mouseDown = true; dragStart = mousePos; } if (Event.current.type == EventType.MouseUp && Event.current.button == 0) { mouseUp = true; } //selecting locked element if (lockedElement != null) { //element = lockedElement; //Selection.activeGameObject = lockedElement.gameObject; } //duplicating element if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "Duplicate") { GameObject newElement = (GameObject)GameObject.Instantiate(element.gameObject); newElement.name = element.gameObject.name; if (element.transform.parent != null) { newElement.transform.parent = element.transform.parent; } newElement.transform.localPosition = element.transform.localPosition; newElement.transform.localRotation = element.transform.localRotation; newElement.transform.localScale = element.transform.localScale; Selection.activeGameObject = newElement; element = newElement.GetComponent <InstantGuiElement>(); } //key events if (Event.current.type == EventType.keyDown) { //Undo.RegisterUndo(element, "Move PureGUI"); //locking element if (Event.current.keyCode == KeyCode.L) { if (!lockedElement) { lockedElement = element; } else { lockedElement = null; } } //hiding frame if (Event.current.keyCode == KeyCode.H) { drawFrames = !drawFrames; } //moving with keys if (Event.current.keyCode == KeyCode.UpArrow) { element.offset.top--; element.offset.bottom--; } if (Event.current.keyCode == KeyCode.DownArrow) { element.offset.top++; element.offset.bottom++; } if (Event.current.keyCode == KeyCode.LeftArrow) { element.offset.left--; element.offset.right--; } if (Event.current.keyCode == KeyCode.RightArrow) { element.offset.left++; element.offset.right++; } } Rect rect = new Rect(0, 0, frameSize, frameSize); Rect textRect = new Rect(0, 0, 40, 20); //getting if any of dimension is fixed bool fixedWidth = false; bool fixedHeight = false; if (element.style != null) { if (element.style.fixedWidth) { fixedWidth = true; } if (element.style.fixedHeight) { fixedHeight = true; } } if (mouseDown) { nonGridOffset.left = element.offset.left; nonGridOffset.right = element.offset.right; nonGridOffset.top = element.offset.top; nonGridOffset.bottom = element.offset.bottom; nonGridRelative.left = element.relative.left; nonGridRelative.right = element.relative.right; nonGridRelative.top = element.relative.top; nonGridRelative.bottom = element.relative.bottom; } if (mouseUp || mouseDown) { dragging = 0; } //storing borders to assign comfortable int left = element.absolute.left; int right = element.absolute.right; int top = element.absolute.top; int bottom = element.absolute.bottom; //relative left rect.width = frameSize * 1.5f; rect.height = frameSize; rect.x = left - element.offset.left - rect.width * 0.5f; rect.y = element.absolute.GetCenter().y - rect.height * 0.5f; textRect.x = rect.x; textRect.y = rect.y + 16; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 1; } if (dragging == 1) { nonGridRelative.left = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).x); if (Event.current.control) { element.relative.left = (Mathf.RoundToInt(nonGridRelative.left * 0.2f)) * 5; } else { element.relative.left = nonGridRelative.left; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } //relative right if (!fixedWidth) { rect.x = right - element.offset.right - rect.width * 0.5f; rect.y = element.absolute.GetCenter().y - rect.height * 0.5f; textRect.x = rect.x; textRect.y = rect.y - 20; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 2; } if (dragging == 2) { nonGridRelative.right = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).x); if (Event.current.control) { element.relative.right = (Mathf.RoundToInt(nonGridRelative.right * 0.2f)) * 5; } else { element.relative.right = nonGridRelative.right; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } } else { element.relative.right = element.relative.left; } //relative top rect.width = frameSize; rect.height = frameSize * 1.5f; rect.x = element.absolute.GetCenter().x - rect.width * 0.5f; rect.y = top - element.offset.top - rect.height * 0.5f; textRect.x = rect.x + 20; textRect.y = rect.y - 2; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 3; } if (dragging == 3) { nonGridRelative.top = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).y); if (Event.current.control) { element.relative.top = (Mathf.RoundToInt(nonGridRelative.top * 0.2f)) * 5; } else { element.relative.top = nonGridRelative.top; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } //relative bottom if (!fixedHeight) { rect.x = element.absolute.GetCenter().x - rect.width * 0.5f; rect.y = bottom - element.offset.bottom - rect.height * 0.5f; textRect.x = rect.x - 30; textRect.y = rect.y - 2; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 4; } if (dragging == 4) { nonGridRelative.bottom = Mathf.RoundToInt(InstantGuiElementPos.ScreenPointToRelative(element.parentpos, Event.current.mousePosition).y); if (Event.current.control) { element.relative.bottom = (Mathf.RoundToInt(nonGridRelative.bottom * 0.2f)) * 5; } else { element.relative.bottom = nonGridRelative.bottom; } element.offset.GetOffset(element.parentpos, element.relative, element.absolute); } } else { element.relative.bottom = element.relative.top; } rect = new Rect(0, 0, frameSize, frameSize); if (!fixedWidth || !fixedHeight) { //left-top rect.x = element.absolute.left - frameSize * 0.5f; rect.y = element.absolute.top - frameSize * 0.5f; textRect.x = rect.x - 25; textRect.y = (top + bottom) * 0.5f + (top - bottom) * 0.25f; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 5; } if (dragging == 5) { element.offset.left = (int)(nonGridOffset.left + (mousePos.x - dragStart.x)); element.offset.top = (int)(nonGridOffset.top + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.left = Mathf.RoundToInt(element.offset.left * 0.1f) * 10; element.offset.top = Mathf.RoundToInt(element.offset.top * 0.1f) * 10; } } //left-bottom rect.x = element.absolute.left - frameSize * 0.5f; rect.y = element.absolute.bottom - frameSize * 0.5f; textRect.x = (left + right) * 0.5f + (right - left) * 0.25f; textRect.y = rect.y + 10; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 6; } if (dragging == 6) { element.offset.left = (int)(nonGridOffset.left + (mousePos.x - dragStart.x)); element.offset.bottom = (int)(nonGridOffset.bottom + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.left = Mathf.RoundToInt(element.offset.left * 0.1f) * 10; element.offset.bottom = Mathf.RoundToInt(element.offset.bottom * 0.1f) * 10; } } //right-top rect.x = element.absolute.right - frameSize * 0.5f; rect.y = element.absolute.top - frameSize * 0.5f; textRect.x = (left + right) * 0.5f + (left - right) * 0.25f; textRect.y = rect.y - 13; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 7; } if (dragging == 7) { element.offset.right = (int)(nonGridOffset.right + (mousePos.x - dragStart.x)); element.offset.top = (int)(nonGridOffset.top + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.right = Mathf.RoundToInt(element.offset.right * 0.1f) * 10; element.offset.top = Mathf.RoundToInt(element.offset.top * 0.1f) * 10; } } //right-bottom rect.x = element.absolute.right - frameSize * 0.5f; rect.y = element.absolute.bottom - frameSize * 0.5f; textRect.x = rect.x + 15; textRect.y = (top + bottom) * 0.5f + (bottom - top) * 0.25f; if (rect.Contains(Event.current.mousePosition) && mouseDown && dragging == 0 && drawFrames && !Event.current.alt && !element.lockPosition) { dragging = 8; } if (dragging == 8) { element.offset.right = (int)(nonGridOffset.right + (mousePos.x - dragStart.x)); element.offset.bottom = (int)(nonGridOffset.bottom + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.right = Mathf.RoundToInt(element.offset.right * 0.1f) * 10; element.offset.bottom = Mathf.RoundToInt(element.offset.bottom * 0.1f) * 10; } } } //aligning if (!InstantGui.instance) { InstantGui.instance = (InstantGui)FindObjectOfType(typeof(InstantGui)); } if (!EditorApplication.isPlaying) { //InstantGui.instance.Update(); //InstantGui.instance.element.Point(mousePos); InstantGui.width = Screen.width; InstantGui.height = Screen.height; InstantGui.instance.element = InstantGui.instance.GetComponent <InstantGuiElement>(); InstantGui.pointed = null; InstantGui.instance.element.GetChildren(); InstantGui.instance.element.Align(); //element.PreventZeroSize(true); InstantGui.instance.element.Point(true); InstantGui.instance.element.Action(); InstantGui.instance.element.ApplyStyle(); } //moving selected element (or setting fixed) rect = element.absolute.ToRect(); if (InstantGui.pointed == element && mouseDown && dragging == 0 && !Event.current.alt && !element.lockPosition && !selectionChanged) { dragging = 9; } if (dragging == 9) { //Undo.RecordObject(element, "InstantGui Move"); int sizeX = element.absolute.right - element.absolute.left; int sizeY = element.absolute.bottom - element.absolute.top; element.offset.left = (int)(nonGridOffset.left + (mousePos.x - dragStart.x)); element.offset.top = (int)(nonGridOffset.top + (dragStart.y - mousePos.y)); if (Event.current.control) { element.offset.left = Mathf.RoundToInt(element.offset.left * 0.1f) * 10; element.offset.top = Mathf.RoundToInt(element.offset.top * 0.1f) * 10; } element.absolute.GetAbsolute(element.parentpos, element.relative, element.offset); element.offset.GetOffset(element.parentpos, element.relative, new InstantGuiElementPos(element.absolute.left, element.absolute.left + sizeX, element.absolute.top, element.absolute.top + sizeY)); } //selecting other objs if (mouseDown && dragging == 0 && InstantGui.pointed != element && InstantGui.pointed != null && !lockedElement && !Event.current.alt) { Selection.activeGameObject = InstantGui.pointed.gameObject; element = InstantGui.pointed; nonGridOffset.left = element.offset.left; nonGridOffset.right = element.offset.right; nonGridOffset.top = element.offset.top; nonGridOffset.bottom = element.offset.bottom; nonGridRelative.left = element.relative.left; nonGridRelative.right = element.relative.right; nonGridRelative.top = element.relative.top; nonGridRelative.bottom = element.relative.bottom; selectionChanged = true; } else if (selectionChanged) { selectionChanged = false; } }
public override void Action() { base.Action(); //moving if (movable) { if (pointed && Input.GetMouseButtonDown(0)) { dragging = true; sizeX = absolute.right - absolute.left; sizeY = absolute.bottom - absolute.top; dragOffset = new Vector2( offset.left - Input.mousePosition.x, offset.top - InstantGui.Invert(Input.mousePosition.y)); //negative, in common } if (Input.GetMouseButtonUp(0)) { dragging = false; } if (dragging) { offset.left = (int)(Input.mousePosition.x + dragOffset.x); offset.top = (int)(InstantGui.Invert(Input.mousePosition.y) + dragOffset.y); absolute.GetAbsolute(parentpos, relative, offset); //limiting window movement if (scape == InstantGuiWindowScape.screen) { absolute.left = Mathf.Max(absolute.left, 0); absolute.top = Mathf.Max(absolute.top, 0); if (absolute.left > UnityEngine.Screen.width - sizeX) { absolute.left = UnityEngine.Screen.width - sizeX; } if (absolute.top > UnityEngine.Screen.height - sizeY) { absolute.top = UnityEngine.Screen.height - sizeY; } } if (scape == InstantGuiWindowScape.parent) { absolute.left = Mathf.Max(absolute.left, parentpos.left); absolute.top = Mathf.Max(absolute.top, parentpos.top); if (absolute.left > parentpos.right - sizeX) { absolute.left = parentpos.right - sizeX; } if (absolute.top > parentpos.bottom - sizeY) { absolute.top = parentpos.bottom - sizeY; } } offset.GetOffset(parentpos, relative, new InstantGuiElementPos(absolute.left, absolute.left + sizeX, absolute.top, absolute.top + sizeY)); } } //closing if (closeButton != null && closeButton.activated) { gameObject.SetActive(false); } //expanding if (expandButton != null) { if (expandButton.activated && expandButton.check) { nonMaximizedRelative = new InstantGuiElementPos(relative); nonMaximizedOffset = new InstantGuiElementPos(offset); if (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off) { relative = new InstantGuiElementPos(0, 0, 0, 0); offset = new InstantGuiElementPos(0, UnityEngine.Screen.width, 0, UnityEngine.Screen.height); } if (scape == InstantGuiWindowScape.parent) { relative = new InstantGuiElementPos(0, 100, 0, 100); offset = new InstantGuiElementPos(0, 0, 0, 0); } } if (expandButton.activated && !expandButton.check) { relative = nonMaximizedRelative; offset = nonMaximizedOffset; } //re-calc offset on resolution change if (expandButton.check && (scape == InstantGuiWindowScape.screen || scape == InstantGuiWindowScape.off)) { offset = new InstantGuiElementPos(0, UnityEngine.Screen.width, 0, UnityEngine.Screen.height); } } }
static public void ForceUpdate (){ if (!instance) instance = (InstantGui)GameObject.FindObjectOfType(typeof(InstantGui)); instance.Update(); }
public override void Action() { base.Action(); //increment/decrement if (incrementButton != null && incrementButton.activated) { value += buttonStep; } if (decrementButton != null && decrementButton.activated) { value -= buttonStep; } value = Mathf.Clamp(value, min, max); //setting diamond if (diamond != null) { //horizontal if (horizontal) { if (diamond.activated) { #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && Event.current != null && Event.current.alt && Event.current.isMouse) { dragStart = (int)Event.current.mousePosition.x; } else { dragStart = (int)InstantGui.Invert(Input.mousePosition.x); } #else dragStart = (int)InstantGui.Invert(Input.mousePosition.x); #endif valueStart = value; } if (diamond.pressed) { int dragDist = 0; #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && Event.current != null && Event.current.alt && Event.current.isMouse) { dragDist = (int)(Event.current.mousePosition.x - dragStart); } else { dragDist = (int)(InstantGui.Invert(Input.mousePosition.x) - dragStart); } #else dragDist = (int)(InstantGui.Invert(Input.mousePosition.x) - dragStart); #endif int totalDist = absolute.right - absolute.left; value = valueStart - (1.0f * dragDist / totalDist) * (max - min + shownValue); } //rounding value to step if (step > 0.001f) { value = Mathf.Round(value / step) * step; } //clamping value = Mathf.Clamp(value, min, max); diamond.relative.left = (int)((value) / (max - min + shownValue) * 100); diamond.relative.right = (int)((value + shownValue) / (max - min + shownValue) * 100); } //vertical else { //diamondSize = diamond.absolute.bottom - diamond.absolute.top; //fieldStart = absolute.top + diamondSize*0.5f; //fieldEnd = absolute.bottom - diamondSize*0.5f; /* * if (pressed || activated) * { * if (!EditorApplication.isPlayingOrWillChangePlaymode && Event.current!=null && Event.current.alt && Event.current.isMouse) * clickPos = Event.current.mousePosition.y - fieldStart; * else clickPos = InstantGui.Invert(Input.mousePosition.y) - fieldStart; * percent = clickPos/(fieldEnd-fieldStart); * value = percent * (max-min) + min; * } */ if (diamond.activated) { #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && Event.current != null && Event.current.alt && Event.current.isMouse) { dragStart = (int)Event.current.mousePosition.y; } else { dragStart = (int)InstantGui.Invert(Input.mousePosition.y); } #else dragStart = (int)InstantGui.Invert(Input.mousePosition.y); #endif valueStart = value; } if (diamond.pressed) { int dragDist = 0; #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && Event.current != null && Event.current.alt && Event.current.isMouse) { dragDist = (int)(Event.current.mousePosition.y - dragStart); } else { dragDist = (int)(InstantGui.Invert(Input.mousePosition.y) - dragStart); } #else dragDist = (int)(InstantGui.Invert(Input.mousePosition.y) - dragStart); #endif int totalDist = absolute.bottom - absolute.top; value = valueStart + (1.0f * dragDist / totalDist) * (max - min + shownValue); } //rounding value to step if (step > 0.001f) { value = Mathf.Round(value / step) * step; } //clamping value = Mathf.Clamp(value, min, max); diamond.relative.top = (int)((value) / (max - min + shownValue) * 100); diamond.relative.bottom = (int)((value + shownValue) / (max - min + shownValue) * 100); //unchangable slider size //percent = value/(max-min); //diamond.relative.top = (value-shownValue*percent)/(max-min)*100; //diamond.relative.bottom = (value+shownValue*(1-percent))/(max-min)*100; } } //oldValue = value; }