Remove the border offsets from a rect.
static public int Remove(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.RectOffset self = (UnityEngine.RectOffset)checkSelf(l); UnityEngine.Rect a1; checkValueType(l, 2, out a1); var ret = self.Remove(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int Remove(IntPtr l) { try { UnityEngine.RectOffset self = (UnityEngine.RectOffset)checkSelf(l); UnityEngine.Rect a1; checkValueType(l, 2, out a1); var ret = self.Remove(a1); pushValue(l, ret); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int Remove(IntPtr l) { try{ UnityEngine.RectOffset self = (UnityEngine.RectOffset)checkSelf(l); UnityEngine.Rect a1; checkType(l, 2, out a1); UnityEngine.Rect ret = self.Remove(a1); pushValue(l, ret); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static int Remove(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UnityEngine.RectOffset obj = (UnityEngine.RectOffset)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectOffset)); UnityEngine.Rect arg0 = (UnityEngine.Rect)ToLua.CheckObject(L, 2, typeof(UnityEngine.Rect)); UnityEngine.Rect o = obj.Remove(arg0); ToLua.PushValue(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int QPYX_Remove_YXQP(IntPtr L_YXQP) { try { ToLua.CheckArgsCount(L_YXQP, 2); UnityEngine.RectOffset QPYX_obj_YXQP = (UnityEngine.RectOffset)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.RectOffset)); UnityEngine.Rect QPYX_arg0_YXQP = StackTraits <UnityEngine.Rect> .Check(L_YXQP, 2); UnityEngine.Rect QPYX_o_YXQP = QPYX_obj_YXQP.Remove(QPYX_arg0_YXQP); ToLua.PushValue(L_YXQP, QPYX_o_YXQP); return(1); } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
void PropertyGUI( ILayerProperty property ) { bool focused = focusedWindow == this; RectOffset margin = new RectOffset( 4,4,4,4 ); Rect rect = GUILayoutUtility.GetRect( 0.0f,0.0f,GUILayout.ExpandWidth(true),GUILayout.Height(32.0f + margin.vertical) ); int controlID = GUIUtility.GetControlID( property.gameObject.GetInstanceID(),FocusType.Passive,rect ); bool selected = Selection.gameObjects.Contains(property.gameObject); if( selected ) { Color[] darkColors = new Color[]{ new Color32( 72,72,72,255 ), new Color32( 62,95,150,255 ) }; Color[] lightColors = new Color[]{ new Color32( 142,142,142,255 ), new Color32( 62,124,230,255 ) }; Color[] colors = !EditorGUIUtility.isProSkin ? lightColors : darkColors; Color color = focused ? colors[1] : colors[0]; EditorGUI.DrawRect( rect,color ); } rect = margin.Remove( rect ); Rect activeRect = new Rect( rect ); activeRect.y = rect.y+rect.height*0.5f-16.0f; activeRect.width = 16.0f; activeRect.height = 16.0f; EditorGUI.BeginChangeCheck(); bool active = EditorGUI.Toggle( activeRect,property.active ); if( EditorGUI.EndChangeCheck() ) { property.active = active; } Rect visibleRect = new Rect( rect ); visibleRect.y = rect.y+rect.height*0.5f; visibleRect.width = 16.0f; visibleRect.height = 16.0f; EditorGUI.BeginChangeCheck(); bool enabled = EditorGUI.Toggle( visibleRect,property.enabled,Styles.visiblyToggle ); if( EditorGUI.EndChangeCheck() ) { property.enabled = enabled; } Rect previewRect = new Rect( rect ); previewRect.x += 16.0f; previewRect.width = 32.0f; previewRect.height = 32.0f; property.OnPreviewGUI( previewRect,GUI.skin.box ); if( Event.current.type == EventType.Repaint ) { GUIContent label = new GUIContent( property.name ); GUIContent orderContent = new GUIContent( property.sortingOrder.ToString() ); GUIStyle labelStyle = Styles.hiLabel; GUIStyle orderStyle = Styles.rightLabel; Rect labelRect = new Rect( rect ); labelRect.x += 48.0f; labelRect.width -= 100.0f - 48.0f; float labelHeight = labelStyle.CalcHeight(label,labelRect.width); labelRect.y += (labelRect.height-labelHeight )*0.5f; labelRect.height = labelHeight; Rect orderRect = new Rect( rect ); orderRect.x = rect.xMax - 100.0f; orderRect.width = 100.0f; float orderHeight = orderStyle.CalcHeight(orderContent,orderRect.width); orderRect.y += (orderRect.height-orderHeight )*0.5f; orderRect.height = orderHeight; Color[] colorArray = !EditorGUIUtility.isProSkin ? s_HierarchyColors : s_DarkColors; int colorCode = property.colorCode; Color color = colorArray[colorCode & 3]; Color onColor = colorArray[(colorCode & 3) + 4]; color.a = colorCode < 4 ? (onColor.a = 1f) : (onColor.a = 0.6f); labelStyle.normal.textColor = color; labelStyle.focused.textColor = color; labelStyle.hover.textColor = color; labelStyle.active.textColor = color; labelStyle.onNormal.textColor = onColor; labelStyle.onHover.textColor = onColor; labelStyle.onActive.textColor = onColor; labelStyle.onFocused.textColor = onColor; labelStyle.Draw( labelRect,label,false,false,selected,focused ); orderStyle.Draw( orderRect,orderContent,false,false,selected,focused ); } Event current = Event.current; switch( current.type ) { case EventType.MouseDown: if( current.button == 0 && rect.Contains(Event.current.mousePosition) ) { if (Event.current.clickCount == 2) { if( SceneView.lastActiveSceneView != null ) { SceneView.lastActiveSceneView.FrameSelected(); } } else { GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = 0; } current.Use(); } break; case EventType.MouseUp: if( GUIUtility.hotControl == controlID && rect.Contains(Event.current.mousePosition) ) { if( EditorGUI.actionKey ) { Object[] objects = Selection.objects; if( objects.Contains( property.gameObject ) ) { ArrayUtility.Remove( ref objects,property.gameObject ); } else { ArrayUtility.Add( ref objects,property.gameObject ); } Selection.objects = objects; } else { Selection.activeGameObject = property.gameObject; } GUIUtility.hotControl = 0; current.Use(); } break; } }
public override void OnInspectorGUI() { EditorGUILayout.BeginVertical( EditorStyles.inspectorDefaultMargins ); serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField( serializedObject.FindProperty( "material" ) ); if( EditorGUI.EndChangeCheck() ) { CreateImportSprites(); } serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndVertical(); TileSet tileSet = target as TileSet; if( tileSet.material != null ) { if( tileSet.material.mainTexture != null ) { EditorGUILayout.BeginVertical( EditorStyles.inspectorDefaultMargins ); string texturePath = AssetDatabase.GetAssetPath( tileSet.material.mainTexture ); TextureImporter textureImporter = AssetImporter.GetAtPath( texturePath ) as TextureImporter; if( textureImporter != null && textureImporter.filterMode != FilterMode.Point ) { EditorGUILayout.BeginVertical( (GUIStyle)"HelpBox" ); GUILayout.Box( new GUIContent( "FilterMode is not Point.\nAre you sure you want to change to Point?",EditorTools.helpWarnIcon ),GUIStyle.none ); if( GUILayout.Button ( "Change to Point" ) ) { textureImporter.filterMode = FilterMode.Point; AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); } EditorGUILayout.EndVertical(); } _ImportFoldout = HeaderGUI(_ImportFoldout, "Import from sprites"); if (_ImportFoldout) { EditorGUILayout.BeginVertical(Styles.greyBorder); bool importable = textureImporter != null && textureImporter.spriteImportMode != SpriteImportMode.None; if (importable) { _ImportSize = EditorGUILayout.IntField("Import Size", _ImportSize); _SpritesScrollPos = EditorGUILayout.BeginScrollView(_SpritesScrollPos,false,false,GUI.skin.horizontalScrollbar,GUI.skin.verticalScrollbar,"As TextArea",GUILayout.Height(300.0f)); // TODO:インポート対象の選択 for (int index = 0; index < textureImporter.spritesheet.Length;index++ ) { SpriteMetaData sprite = textureImporter.spritesheet[index]; RectOffset margin = new RectOffset(4, 4, 4, 4); EditorGUILayout.BeginHorizontal(Styles.greyBorder); _ImportSprites[index] = EditorGUILayout.ToggleLeft("", _ImportSprites[index], GUILayout.Width(16)); float spriteWidth = sprite.rect.width + 8; float spriteHeight = sprite.rect.height + 8; Rect rect = GUILayoutUtility.GetRect(spriteWidth, spriteWidth, spriteHeight, spriteHeight, GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false)); rect = margin.Remove(rect); Rect texCoords = new Rect(sprite.rect.x / tileSet.material.mainTexture.width, sprite.rect.y / tileSet.material.mainTexture.height, sprite.rect.width / tileSet.material.mainTexture.width, sprite.rect.height / tileSet.material.mainTexture.height); GUI.DrawTextureWithTexCoords(rect, tileSet.material.mainTexture, texCoords); EditorGUILayout.LabelField(sprite.name); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Check All", EditorStyles.miniButtonLeft, GUILayout.Width(100.0f))) { for (int index = 0; index < textureImporter.spritesheet.Length; index++) { _ImportSprites[index] = true; } } if (GUILayout.Button("Uncheck All", EditorStyles.miniButtonLeft, GUILayout.Width(100.0f))) { for (int index = 0; index < textureImporter.spritesheet.Length; index++) { _ImportSprites[index] = false; } } EditorGUILayout.Space(); bool checking = false; for (int index = 0; index < textureImporter.spritesheet.Length; index++) { if (_ImportSprites[index]) { checking = true; break; } } GUI.enabled = checking; if (GUILayout.Button("Import", EditorStyles.miniButton, GUILayout.Width(100.0f))) { for (int index = 0; index < textureImporter.spritesheet.Length; index++) { if( !_ImportSprites[index] ) { continue; } SpriteMetaData sprite = textureImporter.spritesheet[index]; Undo.RecordObject(tileSet, "Add Tile"); Tile tile = tileSet.AddTile(); tile.position = new Vector2(sprite.rect.x, tileSet.material.mainTexture.height - sprite.rect.yMax); tile.size = _ImportSize; AssetDatabase.AddObjectToAsset(tile, tileSet); Undo.RegisterCreatedObjectUndo(tile, "Add Tile"); EditorUtility.SetDirty(tileSet); _CurrentTileID = tileSet.tiles.Length - 1; } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("If you want to import from sprites, please be carried out after setting the sprite to this tile texture.", MessageType.Warning); } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); } EditorGUILayout.Space(); EditorGUILayout.LabelField( "Tiles",EditorStyles.boldLabel ); _CurrentTileID = Mathf.Clamp( _CurrentTileID,0,tileSet.tiles.Length-1 ); _CurrentTileID = EditorTools.SelectTileField( tileSet,_CurrentTileID ); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); GUI.enabled = _CurrentTileID >= 0; if( GUILayout.Button ("Insert to " + _CurrentTileID,EditorStyles.miniButtonLeft,GUILayout.Width( 100.0f ) ) ) { Undo.RecordObject( tileSet,"Add Tile" ); Tile tile = tileSet.InsertTile( _CurrentTileID ); AssetDatabase.AddObjectToAsset( tile,tileSet ); Undo.RegisterCreatedObjectUndo( tile,"Add Tile" ); EditorUtility.SetDirty( tileSet ); } GUI.enabled = true; if( GUILayout.Button ("Add to last",EditorStyles.miniButtonRight,GUILayout.Width( 100.0f ) ) ) { Undo.RecordObject( tileSet,"Add Tile" ); Tile tile = tileSet.AddTile(); AssetDatabase.AddObjectToAsset( tile,tileSet ); Undo.RegisterCreatedObjectUndo( tile,"Add Tile" ); EditorUtility.SetDirty( tileSet ); _CurrentTileID = tileSet.tiles.Length - 1; } GUI.enabled = (0 <= _CurrentTileID && _CurrentTileID < tileSet.tiles.Length); Color savedColor = GUI.color; GUI.color = Color.red; if( GUILayout.Button ("Delete",EditorStyles.miniButton,GUILayout.Width( 100.0f ) ) ) { Tile currentTile = tileSet.tiles[_CurrentTileID]; Undo.RegisterCompleteObjectUndo( new Object[]{ tileSet,currentTile },"Remove Tile" ); foreach( TileComponent component in currentTile.GetComponents<TileComponent>() ) { currentTile.RemoveComponent( component ); Undo.DestroyObjectImmediate( component ); } tileSet.RemoveTile( currentTile ); Undo.DestroyObjectImmediate( currentTile ); _CurrentTileID = Mathf.Clamp ( _CurrentTileID,0,tileSet.tiles.Length-1 ); EditorUtility.SetDirty( tileSet ); } GUI.color = savedColor; GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); if( 0 <= _CurrentTileID && _CurrentTileID < tileSet.tiles.Length ) { Tile currentTile = tileSet.tiles[_CurrentTileID]; if( currentTile != null ) { if( _CurrentEditor==null ) { _CurrentEditor = Editor.CreateEditor( currentTile ); } else if( _CurrentEditor.target != currentTile ) { DestroyImmediate( _CurrentEditor ); _CurrentEditor = Editor.CreateEditor( currentTile ); } if( _CurrentEditor != null ) { EditorGUILayout.Space (); EditorGUILayout.BeginVertical( _CurrentEditor.UseDefaultMargins() ? EditorStyles.inspectorDefaultMargins : GUIStyle.none ); _CurrentEditor.OnInspectorGUI(); EditorGUILayout.EndVertical(); } } } } else { EditorGUILayout.HelpBox( "Please set Texture2D to the Material.",MessageType.Warning ); } } else { EditorGUILayout.HelpBox( "Please set Material.",MessageType.Warning ); } }
protected void DrawInspectedRect(Rect instructionRect) { Rect rect = GUILayoutUtility.GetRect((float) 0f, (float) 100f); int top = Mathf.CeilToInt(34f); int bottom = Mathf.CeilToInt(16f); int right = 100; RectOffset offset = new RectOffset(50, right, top, bottom); Rect position = offset.Remove(rect); float imageAspect = instructionRect.width / instructionRect.height; Rect outScreenRect = new Rect(); Rect outSourceRect = new Rect(); GUI.CalculateScaledTextureRects(position, ScaleMode.ScaleToFit, imageAspect, ref outScreenRect, ref outSourceRect); position = outScreenRect; position.width = Mathf.Max(80f, position.width); position.height = Mathf.Max(26f, position.height); Rect rect5 = new Rect { height = 16f, width = offset.left * 2, y = position.y - offset.top }; rect5.x = position.x - (rect5.width / 2f); Rect rect7 = new Rect { height = 16f, width = offset.right * 2, y = position.yMax }; Rect rect6 = rect7; rect6.x = position.xMax - (rect6.width / 2f); rect7 = new Rect { x = position.x, y = rect5.yMax + 2f, width = position.width, height = 16f }; Rect rect8 = rect7; Rect rect9 = rect8; rect9.width = rect8.width / 3f; rect9.x = rect8.x + ((rect8.width - rect9.width) / 2f); Rect rect10 = position; rect10.x = position.xMax; rect10.width = 16f; Rect rect11 = rect10; rect11.height = 16f; rect11.width = offset.right; rect11.y += (rect10.height - rect11.height) / 2f; GUI.Label(rect5, string.Format("({0},{1})", instructionRect.x, instructionRect.y), this.styles.centeredLabel); Handles.color = new Color(1f, 1f, 1f, 0.5f); Vector3 vector = new Vector3(rect8.x, rect9.y); Vector3 vector2 = new Vector3(rect8.x, rect9.yMax); Handles.DrawLine(vector, vector2); vector.x = vector2.x = rect8.xMax; Handles.DrawLine(vector, vector2); vector.x = rect8.x; vector.y = vector2.y = Mathf.Lerp(vector.y, vector2.y, 0.5f); vector2.x = rect9.x; Handles.DrawLine(vector, vector2); vector.x = rect9.xMax; vector2.x = rect8.xMax; Handles.DrawLine(vector, vector2); GUI.Label(rect9, instructionRect.width.ToString(), this.styles.centeredLabel); vector = new Vector3(rect10.x, rect10.y); vector2 = new Vector3(rect10.xMax, rect10.y); Handles.DrawLine(vector, vector2); vector.y = vector2.y = rect10.yMax; Handles.DrawLine(vector, vector2); vector.x = vector2.x = Mathf.Lerp(vector.x, vector2.x, 0.5f); vector.y = rect10.y; vector2.y = rect11.y; Handles.DrawLine(vector, vector2); vector.y = rect11.yMax; vector2.y = rect10.yMax; Handles.DrawLine(vector, vector2); GUI.Label(rect11, instructionRect.height.ToString()); GUI.Label(rect6, string.Format("({0},{1})", instructionRect.xMax, instructionRect.yMax), this.styles.centeredLabel); GUI.Box(position, GUIContent.none); }