void Awake() { _uiItem = this.GetSafeComponent<UIRect>(); float w = Screen.width ; float h = Screen.height; float res = h/w; //Debug.LogWarning(res); if (res > 1.55) //16:10 { _uiItem.leftAnchor.Set(0f, 32f); _uiItem.rightAnchor.Set(0f, 284f); _uiItem.bottomAnchor.Set(0.5f, -126f); _uiItem.topAnchor.Set(0.5f, 126f); } //228 if (res > 1.45 && res < 1.55) //3:2 { _uiItem.leftAnchor.Set(0f, 32f); _uiItem.rightAnchor.Set(0f, 260f); _uiItem.bottomAnchor.Set(0.5f, -114f); _uiItem.topAnchor.Set(0.5f, 114f); } //не нужно //if (res < 1.45) //4:3 }
/// <summary> /// Constructs a UIElement with selected and unselected states /// param rect[] takes an array of UIRect dimentions for drawing of all options /// param path[] takes an array of path names to load appropriate assets from Resources /// param selected specifies whether the element is in selected or unselected state /// </param> public UICheckButton(UIRect rect, bool selected, string[] path) { this.mRect = rect; mSelected = selected; mStyle = new GUIStyle(); mStyle.normal.background = Resources.Load(path[0]) as Texture2D; mStyle.active.background = Resources.Load(path[1]) as Texture2D; mStyle.onNormal.background = Resources.Load(path[1]) as Texture2D; }
private void SetToTarget() { var uiCamera = transform.root.GetComponentInChildren<Camera>(); _uiItem = this.GetSafeComponent<UIRect>(); Vector3 offset = new Vector3(0, _yOffset, 0); Vector3 pos = uiCamera.ScreenToWorldPoint(Camera.main.WorldToScreenPoint(_bottomMarker.position + offset)); _uiItem.transform.position = pos; _uiItem.transform.SetLocalZ(0); }
private void Start() { _uiItem = this.GetSafeComponent<UIRect>(); _uiItem.enabled = false; EventMessenger.Subscribe(GameEvent.OnTutorialCompleteShowText, this, () => Invoke("ShowSprite", _clickInterval)); EventMessenger.Subscribe(GameEvent.OnTutorial_ClickByTarget, this, () => Invoke("MoveToButtonStart", 0f)); Invoke("SetStartPos", 2f); }
void Cache () { mCached = true; mRect = GetComponent<UIRect>(); if (mRect == null) { Renderer ren = GetComponent<Renderer>(); if (ren != null) mMat = ren.material; if (mMat == null) mRect = GetComponentInChildren<UIRect>(); } }
void Start () { _uiItem = this.GetSafeComponent<UIRect>(); //float w = Screen.width ; //float h = Screen.height; //float res = h/w; //Debug.LogWarning(res); _uiItem.leftAnchor.target = _uiItem.rightAnchor.target = transform.root.Find("Panel1"); _uiItem.leftAnchor.Set(0f, 0f); _uiItem.rightAnchor.Set(1f, 0f); _uiItem.ResetAnchors(); }
static int SetAnchor(IntPtr L) { int count = LuaDLL.lua_gettop(L); Type[] types0 = { typeof(UIRect), typeof(GameObject) }; Type[] types1 = { typeof(UIRect), typeof(Transform) }; if (count == 2 && LuaScriptMgr.CheckTypes(L, types0, 1)) { UIRect obj = LuaScriptMgr.GetNetObject <UIRect>(L, 1); GameObject arg0 = LuaScriptMgr.GetNetObject <GameObject>(L, 2); obj.SetAnchor(arg0); return(0); } else if (count == 2 && LuaScriptMgr.CheckTypes(L, types1, 1)) { UIRect obj = LuaScriptMgr.GetNetObject <UIRect>(L, 1); Transform arg0 = LuaScriptMgr.GetNetObject <Transform>(L, 2); obj.SetAnchor(arg0); return(0); } else if (count == 6) { UIRect obj = LuaScriptMgr.GetNetObject <UIRect>(L, 1); GameObject arg0 = LuaScriptMgr.GetNetObject <GameObject>(L, 2); int arg1 = (int)LuaScriptMgr.GetNumber(L, 3); int arg2 = (int)LuaScriptMgr.GetNumber(L, 4); int arg3 = (int)LuaScriptMgr.GetNumber(L, 5); int arg4 = (int)LuaScriptMgr.GetNumber(L, 6); obj.SetAnchor(arg0, arg1, arg2, arg3, arg4); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: UIRect.SetAnchor"); } return(0); }
private static bool OpenUtility_Tab() { try { while (isParagonWindowVisible()) { if (UXHelper.GetControl <UXLabel>("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect.Bonuses.bonus2.Stat").xA20_Text_StructStart_Min84Bytes == "Life On Hit") { return(true); } UIRect Tab = A_Tools.T_D3UI.UIElement.getRect(A_Enums.UIElements.ParagonPointSelect_TabUtility); A_Tools.InputSimulator.IS_Mouse.LeftClick((int)Tab.Left, (int)Tab.Top, (int)Tab.Right, (int)Tab.Bottom); Thread.Sleep(50); } return(false); } catch { return(false); } }
static int get_root(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); UIRect obj = (UIRect)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name root"); } else { LuaDLL.luaL_error(L, "attempt to index root on a nil value"); } } LuaScriptMgr.Push(L, obj.root); return(1); }
/// <summary> /// Manually re-evaluate the current anchor type. /// </summary> protected void ReEvaluateAnchorType() { UIRect rect = target as UIRect; if (rect.leftAnchor.target == rect.rightAnchor.target && rect.leftAnchor.target == rect.bottomAnchor.target && rect.leftAnchor.target == rect.topAnchor.target) { if (rect.leftAnchor.target == null) { mAnchorType = AnchorType.None; } else { mAnchorType = AnchorType.Unified; } } else { mAnchorType = AnchorType.Advanced; } }
// 将锚点设置到相对于父节点的中心,并且各边界距离父节点对应边界占的比例固定,但是如果父节点为空,则只能固定大小 protected void setToNearParentCenterScaleSize() { UIRect parentRect = WidgetUtility.findParentRect(gameObject); if (parentRect == null) { Vector3[] sides = getSides(null); for (int i = 0; i < 4; ++i) { mAnchorPoint[i].setRelative(0.0f); if (i == 0 || i == 2) { mAnchorPoint[i].setAbsolute(sides[i].x); } else { mAnchorPoint[i].setAbsolute(sides[i].y); } } } else { GameObject parent = parentRect.gameObject; Vector3[] sides = getSides(parent); Vector3[] parentSides = WidgetUtility.getParentSides(parent); for (int i = 0; i < 4; ++i) { mAnchorPoint[i].setAbsolute(0.0f); if (i == 0 || i == 2) { mAnchorPoint[i].setRelative(sides[i].x / parentSides[2].x); } else { mAnchorPoint[i].setRelative(sides[i].x / parentSides[1].y); } } } }
static int get_worldCorners(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); UIRect obj = (UIRect)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name worldCorners"); } else { LuaDLL.luaL_error(L, "attempt to index worldCorners on a nil value"); } } LuaScriptMgr.PushArray(L, obj.worldCorners); return(1); }
/// <summary> /// Set the anchor's absolute coordinate relative to the specified parent, keeping the relative setting intact. /// </summary> public void SetHorizontal(Transform parent, float localPos) { if (rect == null) { rect = target.GetComponent <UIRect>(); } if (rect) { Vector3[] sides = rect.GetSides(parent); float targetPos = Mathf.Lerp(sides[0].x, sides[2].x, relative); absolute = Mathf.FloorToInt(localPos - targetPos + 0.5f); } else { Vector3 targetPos = target.position; if (parent != null) { targetPos = parent.InverseTransformPoint(targetPos); } absolute = Mathf.FloorToInt(localPos - targetPos.x + 0.5f); } }
static int set_updateAnchors(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); UIRect obj = (UIRect)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name updateAnchors"); } else { LuaDLL.luaL_error(L, "attempt to index updateAnchors on a nil value"); } } obj.updateAnchors = (UIRect.AnchorUpdate)LuaScriptMgr.GetNetObject(L, 3, typeof(UIRect.AnchorUpdate)); return(0); }
static int set_bottomAnchor(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); UIRect obj = (UIRect)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name bottomAnchor"); } else { LuaDLL.luaL_error(L, "attempt to index bottomAnchor on a nil value"); } } obj.bottomAnchor = (UIRect.AnchorPoint)LuaScriptMgr.GetNetObject(L, 3, typeof(UIRect.AnchorPoint)); return(0); }
static int set_alpha(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); UIRect obj = (UIRect)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name alpha"); } else { LuaDLL.luaL_error(L, "attempt to index alpha on a nil value"); } } obj.alpha = (float)LuaScriptMgr.GetNumber(L, 3); return(0); }
private static int ParentPanelChanged(IntPtr L) { int num = LuaDLL.lua_gettop(L); if (num == 2) { GameObject go = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject)); UIPanel panel = (UIPanel)LuaScriptMgr.GetUnityObject(L, 2, typeof(UIPanel)); NGUITools.ParentPanelChanged(go, panel); return(0); } if (num == 3) { GameObject go2 = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject)); UIRect parent = (UIRect)LuaScriptMgr.GetUnityObject(L, 2, typeof(UIRect)); UIPanel panel2 = (UIPanel)LuaScriptMgr.GetUnityObject(L, 3, typeof(UIPanel)); NGUITools.ParentPanelChanged(go2, parent, panel2); return(0); } LuaDLL.luaL_error(L, "invalid arguments to method: NGUITools.ParentPanelChanged"); return(0); }
/// <summary> /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact. /// </summary> protected void UpdateAnchors(bool resetRelative) { serializedObject.ApplyModifiedProperties(); Object[] objs = serializedObject.targetObjects; for (int i = 0; i < objs.Length; ++i) { UIRect rect = objs[i] as UIRect; if (rect) { UpdateHorizontalAnchor(rect, rect.leftAnchor, resetRelative); UpdateHorizontalAnchor(rect, rect.rightAnchor, resetRelative); UpdateVerticalAnchor(rect, rect.bottomAnchor, resetRelative); UpdateVerticalAnchor(rect, rect.topAnchor, resetRelative); NGUITools.SetDirty(rect); } } serializedObject.Update(); }
static int get_isAnchoredVertically(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); UIRect obj = (UIRect)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name isAnchoredVertically"); } else { LuaDLL.luaL_error(L, "attempt to index isAnchoredVertically on a nil value"); } } LuaScriptMgr.Push(L, obj.isAnchoredVertically); return(1); }
/// <summary> /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact. /// </summary> void UpdateAnchors(bool relative, bool chooseClosest, bool createIfMissing) { serializedObject.ApplyModifiedProperties(); Object[] objs = serializedObject.targetObjects; for (int i = 0; i < objs.Length; ++i) { UIRect rect = objs[i] as UIRect; if (rect) { if (createIfMissing || rect.leftAnchor.target) { UpdateHorizontalAnchor(rect, rect.leftAnchor, relative, chooseClosest); } if (createIfMissing || rect.rightAnchor.target) { UpdateHorizontalAnchor(rect, rect.rightAnchor, relative, chooseClosest); } if (createIfMissing || rect.bottomAnchor.target) { UpdateVerticalAnchor(rect, rect.bottomAnchor, relative, chooseClosest); } if (createIfMissing || rect.topAnchor.target) { UpdateVerticalAnchor(rect, rect.topAnchor, relative, chooseClosest); } UnityEditor.EditorUtility.SetDirty(rect); } } serializedObject.Update(); }
public UIRect FindUIRect(Transform com) { UIRect uirect = null; if (UIRectPool.TryGetValue(com.GetInstanceID(), out uirect) && uirect.IsActivite) { return(uirect); } var comps = com.GetComponents <Behaviour>(); int index = Int32.MaxValue; foreach (var comp in comps) { if (!comp.enabled) { continue; } for (int i = 0; i < Finders.Length; ++i) { var find = Finders[i].Find(comp); if (find != null && i < index) { uirect = find; index = i; break; } } } if (uirect != null) { UIRectPool.Add(uirect.InstanceID, uirect); } return(uirect); }
static int get_updateAnchors(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name updateAnchors"); } else { LuaDLL.luaL_error(L, "attempt to index updateAnchors on a nil value"); } } UIRect obj = (UIRect)o; LuaScriptMgr.PushEnum(L, obj.updateAnchors); return(1); }
static int get_cachedTransform(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name cachedTransform"); } else { LuaDLL.luaL_error(L, "attempt to index cachedTransform on a nil value"); } } UIRect obj = (UIRect)o; LuaScriptMgr.Push(L, obj.cachedTransform); return(1); }
private static IEnumerator PlayingUiAlpha(UIRect ui, float @from, float to, float time, float delayTime, Action finishAction) { if (delayTime > 0) { yield return(new WaitForSeconds(delayTime)); } float a = from; float spd = (to - from) / time; while (time > 0) { ui.alpha = Mathf.Clamp(a, 0, 1); yield return(null); time -= Time.smoothDeltaTime; a += (spd * Time.smoothDeltaTime); } ui.alpha = Mathf.Clamp(to, 0, 1); if (finishAction != null) { finishAction(); } }
static int get_finalAlpha(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name finalAlpha"); } else { LuaDLL.luaL_error(L, "attempt to index finalAlpha on a nil value"); } } UIRect obj = (UIRect)o; LuaScriptMgr.Push(L, obj.finalAlpha); return(1); }
static int set_topAnchor(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name topAnchor"); } else { LuaDLL.luaL_error(L, "attempt to index topAnchor on a nil value"); } } UIRect obj = (UIRect)o; obj.topAnchor = LuaScriptMgr.GetNetObject <UIRect.AnchorPoint>(L, 3); return(0); }
} //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) private void OnEnable() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) if (scrollWheelFactor != 0f) { scrollMomentum = scale * scrollWheelFactor; scrollWheelFactor = 0f; } if (contentRect == null && target != null && Application.get_isPlaying()) { UIWidget component = target.GetComponent <UIWidget>(); if (component != null) { contentRect = component; } } mTargetPos = ((!(target != null)) ? Vector3.get_zero() : target.get_position()); }
void Cache() { mCached = true; if (mTrans == null) { mTrans = transform; } mRect = GetComponent <UIRect>(); mSr = GetComponent <SpriteRenderer>(); if (mRect == null && mSr == null) { Renderer ren = GetComponent <Renderer>(); if (ren != null) { mMat = ren.material; } if (mMat == null) { mRect = GetComponentInChildren <UIRect>(); } } }
static int get_rightAnchor(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name rightAnchor"); } else { LuaDLL.luaL_error(L, "attempt to index rightAnchor on a nil value"); } } UIRect obj = (UIRect)o; LuaScriptMgr.PushObject(L, obj.rightAnchor); return(1); }
/// <summary> /// Constructs a UIElement with series of options to choose from; /// Only one option is selected at a time. param index specifies which option is set to true /// param rect[] takes an array of UIRect dimentions for drawing of all options /// param path[,] takes an array of path names to load appropriate assets from Resources /// </param> public UIRadioButton(UIRect[] rect, int index, string[,] path) { if(index > rect.Length) { return; } this.mRect = rect; mStyle = new GUIStyle[rect.Length]; for(int i = 0; i < mStyle.Length; i++) { mStyle[i] = new GUIStyle(); mStyle[i].normal.background = Resources.Load(path[i,0]) as Texture2D; mStyle[i].active.background = Resources.Load(path[i,1]) as Texture2D; mStyle[i].onNormal.background = Resources.Load(path[i,1]) as Texture2D; } mOptionsTapped = new bool[rect.Length]; mOptionsSelected = new bool[rect.Length]; mOptionsSelected[index] = true; }
/// <summary> /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact. /// </summary> void UpdateAnchor(int index) { serializedObject.ApplyModifiedProperties(); //serializedObject.Update(); Object[] objs = serializedObject.targetObjects; for (int i = 0; i < objs.Length; ++i) { UIRect rect = objs[i] as UIRect; if (rect) { if (index == 0) { UpdateHorizontalAnchor(rect, rect.leftAnchor); } if (index == 1) { UpdateHorizontalAnchor(rect, rect.rightAnchor); } if (index == 2) { UpdateVerticalAnchor(rect, rect.bottomAnchor); } if (index == 3) { UpdateVerticalAnchor(rect, rect.topAnchor); } UnityEditor.EditorUtility.SetDirty(rect); } } //serializedObject.ApplyModifiedProperties(); serializedObject.Update(); }
static int SetAnchor(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(UIRect), typeof(GameObject))) { UIRect obj = (UIRect)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UIRect"); GameObject arg0 = (GameObject)LuaScriptMgr.GetLuaObject(L, 2); obj.SetAnchor(arg0); return(0); } else if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(UIRect), typeof(Transform))) { UIRect obj = (UIRect)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UIRect"); Transform arg0 = (Transform)LuaScriptMgr.GetLuaObject(L, 2); obj.SetAnchor(arg0); return(0); } else if (count == 6) { UIRect obj = (UIRect)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UIRect"); GameObject arg0 = (GameObject)LuaScriptMgr.GetUnityObject(L, 2, typeof(GameObject)); int arg1 = (int)LuaScriptMgr.GetNumber(L, 3); int arg2 = (int)LuaScriptMgr.GetNumber(L, 4); int arg3 = (int)LuaScriptMgr.GetNumber(L, 5); int arg4 = (int)LuaScriptMgr.GetNumber(L, 6); obj.SetAnchor(arg0, arg1, arg2, arg3, arg4); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: UIRect.SetAnchor"); } return(0); }
static void Calculation() { if (Selection.activeGameObject == null) { return; } ScaleAnchor anchor = Selection.activeGameObject.GetComponent <ScaleAnchor>(); if (anchor == null) { return; } var obj = Selection.activeGameObject; Vector2 thisPos = obj.transform.localPosition; // 获取父物体的属性 UIRect parentRect = CustomAnchor.findParentRect(obj); Vector2 parentSize = CustomAnchor.getRectSize(parentRect); // 计算 anchor.mHorizontalRelativePos = thisPos.x / parentSize.x * 2; anchor.mVerticalRelativePos = thisPos.y / parentSize.y * 2; // 设置成自定义方式 anchor.mPadding = PADDING_STYLE.PS_CUSTOM_VALUE; }
static int ChangeParent(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 1) { UIRect obj = (UIRect)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UIRect"); obj.ChangeParent(); return(0); } else if (count == 2) { UIRect obj = (UIRect)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UIRect"); UIRect arg0 = (UIRect)LuaScriptMgr.GetUnityObject(L, 2, typeof(UIRect)); obj.ChangeParent(arg0); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: UIRect.ChangeParent"); } return(0); }
public static int ChangeParent(IntPtr l) { int result; try { int num = LuaDLL.pua_gettop(l); if (num == 1) { UIRect uIRect = (UIRect)LuaObject.checkSelf(l); uIRect.ChangeParent(); LuaObject.pushValue(l, true); result = 1; } else if (num == 2) { UIRect uIRect2 = (UIRect)LuaObject.checkSelf(l); UIRect pt; LuaObject.checkType <UIRect>(l, 2, out pt); uIRect2.ChangeParent(pt); LuaObject.pushValue(l, true); result = 1; } else { LuaObject.pushValue(l, false); LuaDLL.pua_pushstring(l, "No matched override function to call"); result = 2; } } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
private void LateUpdate() { #if !UNITY_EDITOR try { #endif // if (ChangeSceneList.Count > 0 && ChangeScenestate == eChangeSceneState.Finished) // { // Action act = ChangeSceneList.Dequeue(); // act(); // } Profiler.BeginSample("UIRect.Update()"); UIRect.Update(); Profiler.EndSample(); #if !UNITY_EDITOR } catch (Exception ex) { Logger.Error(ex.ToString()); } #endif }
void Awake () { mRect = GetComponent<UIRect>(); }
/// <summary> /// Returns whether the specified widget is visible by the panel. /// </summary> public bool IsVisible (UIRect w) { Vector3[] corners = w.worldCorners; return IsVisible(corners[0], corners[1], corners[2], corners[3]); }
private void FindCameraFor(UIRect.AnchorPoint ap) { if (ap.target == null || ap.rect != null) { ap.targetCam = null; } else { ap.targetCam = NGUITools.FindCameraForLayer(ap.target.gameObject.layer); } }
protected virtual void OnDisable() { if (this.mParent) { this.mParent.mChildren.Remove(this); } this.mParent = null; this.mRoot = null; this.mRootSet = false; this.mParentFound = false; }
/// <summary> /// Adjust the widget's position using the specified local delta coordinates. /// </summary> static public void MoveWidget (UIRect w, float x, float y) { MoveRect(w, x, y); }
/// <summary> /// Draw the specified anchor point. /// </summary> static public void DrawAnchorHandle (UIRect.AnchorPoint anchor, Transform myTrans, Vector3[] myCorners, int side, int id) { if (!anchor.target) return; int i0, i1; if (side == 0) { // Left i0 = 0; i1 = 1; } else if (side == 1) { // Top i0 = 1; i1 = 2; } else if (side == 2) { // Right i0 = 3; i1 = 2; } else { // Bottom i0 = 0; i1 = 3; } Vector3 myPos = (myCorners[i0] + myCorners[i1]) * 0.5f; Vector3[] sides = null; if (anchor.rect != null) { sides = anchor.rect.worldCorners; } else if (anchor.target.GetComponent<Camera>() != null) { sides = anchor.target.GetComponent<Camera>().GetWorldCorners(); } Vector3 theirPos; if (sides != null) { Vector3 v0, v1; if (side == 0 || side == 2) { // Left or right v0 = Vector3.Lerp(sides[0], sides[3], anchor.relative); v1 = Vector3.Lerp(sides[1], sides[2], anchor.relative); } else { // Top or bottom v0 = Vector3.Lerp(sides[0], sides[1], anchor.relative); v1 = Vector3.Lerp(sides[3], sides[2], anchor.relative); } theirPos = HandleUtility.ProjectPointLine(myPos, v0, v1); } else { theirPos = anchor.target.position; } NGUIHandles.DrawShadowedLine(myCorners, myPos, theirPos, Color.yellow); if (Event.current.GetTypeForControl(id) == EventType.Repaint) { Vector2 screenPoint = HandleUtility.WorldToGUIPoint(theirPos); Rect rect = new Rect(screenPoint.x - 7f, screenPoint.y - 7f, 14f, 14f); if (mYellowDot == null) mYellowDot = "sv_label_4"; Vector3 v0 = HandleUtility.WorldToGUIPoint(myPos); Vector3 v1 = HandleUtility.WorldToGUIPoint(theirPos); Handles.BeginGUI(); mYellowDot.Draw(rect, GUIContent.none, id); Vector3 diff = v1 - v0; bool isHorizontal = Mathf.Abs(diff.x) > Mathf.Abs(diff.y); float mag = diff.magnitude; if ((isHorizontal && mag > 60f) || (!isHorizontal && mag > 30f)) { Vector3 pos = (myPos + theirPos) * 0.5f; string text = anchor.absolute.ToString(); GUI.color = Color.yellow; if (side == 0) { if (theirPos.x < myPos.x) NGUIHandles.DrawCenteredLabel(pos, text); } else if (side == 1) { if (theirPos.y > myPos.y) NGUIHandles.DrawCenteredLabel(pos, text); } else if (side == 2) { if (theirPos.x > myPos.x) NGUIHandles.DrawCenteredLabel(pos, text); } else if (side == 3) { if (theirPos.y < myPos.y) NGUIHandles.DrawCenteredLabel(pos, text); } GUI.color = Color.white; } Handles.EndGUI(); } }
void Awake () { mRect = GetComponent<UIRect>(); orignFrom = from; orignTo = to; }
void Awake() { // This will allow to set the view in the inspector if we want to ViewRoot = ViewRoot ?? GetComponent<UIRect>(); // Set the alpha to cero so the item is created // invisible. When the show method is called // the view will be made visible using a transition. #if UNITY_EDITOR if (UnityEditor.EditorApplication.isPlaying) UpdateAlpha(0); #else ViewRoot.alpha = 0f; #endif AwakeUnityMsg(); }
public virtual void ParentHasChanged() { this.mParentFound = false; UIRect y = NGUITools.FindInParents<UIRect>(this.cachedTransform.parent); if (this.mParent != y) { if (this.mParent) { this.mParent.mChildren.Remove(this); } this.mParent = y; if (this.mParent) { this.mParent.mChildren.Add(this); } this.mRootSet = false; } }
/// <summary> /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact. /// </summary> static void UpdateVerticalAnchor (UIRect r, UIRect.AnchorPoint anchor, bool relative, bool chooseClosest) { // Update the target if (anchor.target == null) return; // Update the rect anchor.rect = anchor.target.GetComponent<UIRect>(); // Continue only if we have a parent to work with Transform parent = r.cachedTransform.parent; if (parent == null) return; bool inverted = (anchor == r.topAnchor); int i0 = inverted ? 1 : 0; int i1 = inverted ? 2 : 3; // Calculate the bottom side Vector3[] myCorners = r.worldCorners; Vector3 localPos = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f)); if (anchor.rect == null) { // Anchored to a simple transform Vector3 remotePos = parent.InverseTransformPoint(anchor.target.position); anchor.absolute = Mathf.FloorToInt(localPos.y - remotePos.y + 0.5f); anchor.relative = inverted ? 1f : 0f; } else { // Anchored to a rectangle -- must anchor to the same side Vector3[] targetCorners = anchor.rect.worldCorners; if (relative) { Vector3 remotePos = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[i0], targetCorners[i1], 0.5f)); float offset = localPos.y - remotePos.y; targetCorners = anchor.rect.localCorners; float remoteSize = targetCorners[1].y - targetCorners[0].y; anchor.absolute = 0; anchor.relative = offset / remoteSize; if (inverted) anchor.relative += 1f; } else { // We want to choose the side with the shortest offset Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[3], 0.5f)); Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[1], targetCorners[2], 0.5f)); float val0 = localPos.y - side0.y; float val2 = localPos.y - side1.y; float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y; if (chooseClosest) anchor.SetToNearest(val0, val1, val2); else if (inverted) anchor.Set(1f, val2); else anchor.Set(0f, val0); } } }
protected Vector3 GetLocalPos(UIRect.AnchorPoint ac, Transform trans) { if (this.anchorCamera == null || ac.targetCam == null) { return this.cachedTransform.localPosition; } Rect rect = ac.targetCam.rect; Vector3 vector = ac.targetCam.WorldToViewportPoint(ac.target.position); Vector3 vector2 = new Vector3(vector.x * rect.width + rect.x, vector.y * rect.height + rect.y, vector.z); vector2 = this.mCam.ViewportToWorldPoint(vector2); if (trans != null) { vector2 = trans.InverseTransformPoint(vector2); } vector2.x = Mathf.Floor(vector2.x + 0.5f); vector2.y = Mathf.Floor(vector2.y + 0.5f); return vector2; }
/// <summary> /// Initializes a new instance for label /// <param name='rect'> specifies label size /// <param name='path'> specifies path for assets to load from Resources public UILabel(UIRect rect, string path) { this.mRect = rect; mStyle = new GUIStyle(); mStyle.normal.background = Resources.Load(path) as Texture2D; }
/// <summary> /// Auto-upgrade the legacy data. /// </summary> void OnEnable () { if (scrollWheelFactor != 0f) { scrollMomentum = scale * scrollWheelFactor; scrollWheelFactor = 0f; } if (contentRect == null && target != null && Application.isPlaying) { UIWidget w = target.GetComponent<UIWidget>(); if (w != null) contentRect = w; } }
/// <summary> /// Clear the parent rectangle reference. /// </summary> protected virtual void OnDisable () { #if UNITY_EDITOR mEnabled = false; #endif if (mParent) mParent.mChildren.Remove(this); mParent = null; mRoot = null; mRootSet = false; mParentFound = false; }
/// <summary> /// Clear the parent rectangle reference. /// </summary> protected virtual void OnDisable () { if (mParent) mParent.mChildren.Remove(this); mParent = null; mRoot = null; mRootSet = false; mParentFound = false; }
private void OnEnable() { if (this.scrollWheelFactor != 0f) { this.scrollMomentum = this.scale * this.scrollWheelFactor; this.scrollWheelFactor = 0f; } if (this.contentRect == null && this.target != null && Application.isPlaying) { UIWidget component = this.target.GetComponent<UIWidget>(); if (component != null) { this.contentRect = component; } } }
/// <summary> /// Adjust the rectangle's position using the specified local delta coordinates. /// </summary> static public void MoveRect (UIRect rect, float x, float y) { int ix = Mathf.FloorToInt(x + 0.5f); int iy = Mathf.FloorToInt(y + 0.5f); Transform t = rect.cachedTransform; t.localPosition += new Vector3(ix, iy); int anchorCount = 0; if (rect.leftAnchor.target) { ++anchorCount; rect.leftAnchor.absolute += ix; } if (rect.rightAnchor.target) { ++anchorCount; rect.rightAnchor.absolute += ix; } if (rect.bottomAnchor.target) { ++anchorCount; rect.bottomAnchor.absolute += iy; } if (rect.topAnchor.target) { ++anchorCount; rect.topAnchor.absolute += iy; } #if UNITY_EDITOR NGUITools.SetDirty(rect); #endif // If all sides were anchored, we're done if (anchorCount != 0) rect.UpdateAnchors(); }
public static void MoveWidget(UIRect w, float x, float y) { NGUIMath.MoveRect(w, x, y); }
/// <summary> /// Call this function when the rectangle's parent has changed. /// </summary> public virtual void ParentHasChanged () { mParentFound = false; UIRect pt = NGUITools.FindInParents<UIRect>(cachedTransform.parent); if (mParent != pt) { if (mParent) mParent.mChildren.Remove(this); mParent = pt; if (mParent) mParent.mChildren.Add(this); mRootSet = false; } }
private void Awake() { this.mRect = base.GetComponent<UIRect>(); }
private void Cache() { this.mCached = true; this.mRect = base.GetComponent<UIRect>(); this.mSr = base.GetComponent<SpriteRenderer>(); if (this.mRect == null && this.mSr == null) { Renderer component = base.GetComponent<Renderer>(); if (component != null) { this.mMat = component.material; } if (this.mMat == null) { this.mRect = base.GetComponentInChildren<UIRect>(); } } }
/// <summary> /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact. /// </summary> static void UpdateVerticalAnchor(UIRect r, UIRect.AnchorPoint anchor) { // Update the target if (anchor.target == null) { return; } // Update the rect anchor.rect = anchor.target.GetComponent <UIRect>(); // Continue only if we have a parent to work with Transform parent = r.cachedTransform.parent; if (parent == null) { return; } bool inverted = (anchor == r.topAnchor); int i0 = inverted ? 1 : 0; int i1 = inverted ? 2 : 3; // Calculate the bottom side Vector3[] myCorners = r.worldCorners; Vector3 localPos = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f)); if (anchor.rect != null) { // Anchored to a rectangle -- must anchor to the same side Vector3[] targetCorners = anchor.rect.worldCorners; // We want to choose the side with the shortest offset Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[3], 0.5f)); Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[1], targetCorners[2], 0.5f)); float val0 = localPos.y - side0.y; float val2 = localPos.y - side1.y; float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y; anchor.SetToNearest(val0, val1, val2); } else if (anchor.target.camera != null) { Vector3[] sides = anchor.target.camera.GetSides(parent); Vector3 side0 = sides[3]; Vector3 side1 = sides[1]; float val0 = localPos.y - side0.y; float val2 = localPos.y - side1.y; float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y; anchor.SetToNearest(val0, val1, val2); } else { // Anchored to a simple transform Vector3 remotePos = anchor.target.position; if (anchor.targetCam != null) { remotePos = anchor.targetCam.WorldToViewportPoint(remotePos); } if (r.anchorCamera != null) { remotePos = r.anchorCamera.ViewportToWorldPoint(remotePos); } remotePos = parent.InverseTransformPoint(remotePos); anchor.absolute = Mathf.FloorToInt(localPos.y - remotePos.y + 0.5f); anchor.relative = inverted ? 1f : 0f; } }
/// <summary> /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact. /// </summary> static public void UpdateVerticalAnchor (UIRect r, UIRect.AnchorPoint anchor, bool resetRelative) { // Update the target if (anchor.target == null) return; // Update the rect anchor.rect = anchor.target.GetComponent<UIRect>(); // Continue only if we have a parent to work with Transform parent = r.cachedTransform.parent; if (parent == null) return; bool inverted = (anchor == r.topAnchor); int i0 = inverted ? 1 : 0; int i1 = inverted ? 2 : 3; // Calculate the bottom side Vector3[] myCorners = r.worldCorners; Vector3 localPos = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f)); if (anchor.rect != null) { // Anchored to a rectangle -- must anchor to the same side Vector3[] targetCorners = anchor.rect.worldCorners; // We want to choose the side with the shortest offset Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[3], 0.5f)); Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[1], targetCorners[2], 0.5f)); float val0 = localPos.y - side0.y; float val2 = localPos.y - side1.y; if (resetRelative) { float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y; anchor.SetToNearest(val0, val1, val2); } else { float val = localPos.y - Vector3.Lerp(side0, side1, anchor.relative).y; anchor.Set(anchor.relative, val); } } else if (anchor.target.camera != null) { Vector3[] sides = anchor.target.camera.GetSides(parent); Vector3 side0 = sides[3]; Vector3 side1 = sides[1]; float val0 = localPos.y - side0.y; float val2 = localPos.y - side1.y; if (resetRelative) { float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y; anchor.SetToNearest(val0, val1, val2); } else { float val = localPos.y - Vector3.Lerp(side0, side1, anchor.relative).y; anchor.Set(anchor.relative, val); } } else { // Anchored to a simple transform Vector3 remotePos = anchor.target.position; if (anchor.targetCam != null) remotePos = anchor.targetCam.WorldToViewportPoint(remotePos); if (r.anchorCamera != null) remotePos = r.anchorCamera.ViewportToWorldPoint(remotePos); remotePos = parent.InverseTransformPoint(remotePos); anchor.absolute = Mathf.FloorToInt(localPos.y - remotePos.y + 0.5f); anchor.relative = inverted ? 1f : 0f; } }
private void CopyAnchor(UIRect.AnchorPoint source, UIRect.AnchorPoint dest) { dest.target = source.target; dest.relative = source.relative; dest.absolute = source.absolute; }