private void NewControl() { if (m_root != null) { if (!EditorUtility.DisplayDialog("Confirm New Control", "Are you sure you would like to create a new control? Current layout will be discarded!", "Ok", "Cancel")) { return; } foreach (Control child in m_root.Children) { RemoveChildControl(child); } m_workarea.RemoveChild(m_root); RemoveHierarchyEntry(m_root); } m_root = new Control(); m_root.SetSize(100.0f, 100.0f); m_root.SetPosition(m_workarea.Size.x / 2.0f - 50.0f, m_workarea.Size.y / 2.0f - 50.0f); m_root.AddDecorator(new BackgroundColor(Color.gray)); m_workarea.AddChild(m_root); SetSelectedControl(m_root); SetInspectorTarget(m_root); CreateHierarchyEntry(m_root, 0); }
public static void ScaleControl(Control control, float width, float height, float x, float y) { if (control == null) { return; } control.SetSize(new Vector2(width, height)); control.SetPosition(new Vector2(x, y)); }
public override void DragAndDrop_HoverEnter(Package p, int x, int y) { if (m_TabDragControl != null) { throw new InvalidOperationException("ERROR! TabStrip::DragAndDrop_HoverEnter"); } m_TabDragControl = new Highlight(this); m_TabDragControl.MouseInputEnabled = false; m_TabDragControl.SetSize(3, Height); }
/// <summary> /// Sets the size. /// </summary> /// <param name="control">The control.</param> /// <param name="size">The size.</param> public static void SetSize(this Control control, Size size) { if (control.InvokeRequired) { control.BeginInvoke(new MethodInvoker(() => control.SetSize(size))); } else { control.Size = size; control.Refresh(); } }
protected override void OnInitialize() { m_generator = new UFormsCodeGenerator(); title = "Control Designer"; m_menu = new DesignerTopMenu(); m_menu.SetSize(100.0f, CONTROL_DISPLAY_HEIGHT, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel); m_menu.MenuOptionSelected += HandleMenuOptionSelected; AddChild(m_menu); m_inspectorFields = new Dictionary <object, PropertyInfo>(); m_hierarchyItems = new Dictionary <Control, HierarchyItem>(); m_inspector = new Control(); m_inspector.SetPosition(position.width - INSPECTOR_WIDTH, CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING); m_inspector.SetWidth(INSPECTOR_WIDTH); m_inspector.SetMargin(0.0f, 0.0f, SIDE_MARGIN, 0.0f); m_inspector.AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); AddChild(m_inspector); m_hierarchy = new Control(); m_hierarchy.SetPosition(0.0f, CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING); m_hierarchy.SetWidth(HIERARCHY_WIDTH); m_hierarchy.SetMargin(SIDE_MARGIN, 0.0f, 0.0f, 0.0f); m_hierarchy.AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); AddChild(m_hierarchy); m_workarea = new Control(); m_workarea.SetPosition(m_viewportOffset); m_workarea.AddDecorator(new ClipContent()); AddChild(m_workarea); m_resizeHandle = new Control(); m_resizeHandle.SetSize(RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE); m_resizeHandle.AddDecorator(new BackgroundColor(Color.blue)); m_resizeHandle.Visibility = Control.VisibilityMode.Hidden; AddChild(m_resizeHandle); SetSelectedControl(null); SetInspectorTarget(null); ShowToolbox(); }
protected override void Update() { if (m_workarea != null) { m_workarea.SetSize(position.width - INSPECTOR_WIDTH - HIERARCHY_WIDTH, position.height - CONTROL_DISPLAY_HEIGHT); } if (m_inspector != null) { m_inspector.SetPosition(position.width - INSPECTOR_WIDTH, CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING); m_inspector.SetHeight(position.height - CONTROL_DISPLAY_HEIGHT - TOP_MENU_SPACING); } if (m_hierarchy != null) { m_hierarchy.SetHeight(position.height - CONTROL_DISPLAY_HEIGHT - TOP_MENU_SPACING); } if (m_resizeHandle != null && m_selectedControl != null) { float x = m_selectedControl.ScreenRect.x + m_selectedControl.Size.x - m_resizeHandle.Size.x / 2.0f + m_viewportOffset.x; float y = m_selectedControl.ScreenRect.y + m_selectedControl.Size.y - m_resizeHandle.Size.y / 2.0f + m_viewportOffset.y; m_resizeHandle.SetPosition(x, y); } // Ugliest hack possible, used to update the position field continiously as it is modifiable in the designer if (m_inspectorFields != null) { if (m_inspectorFields.Count > 0 && m_selectedControl != null) { foreach (KeyValuePair <object, PropertyInfo> kvp in m_inspectorFields) { if (kvp.Value.Name == "Position" || kvp.Value.Name == "Size") { (kvp.Key as Vector2Field).Value = ( Vector2 )kvp.Value.GetValue(m_selectedControl, null); } } } } base.Update(); Repaint(); }
protected override void OnInitialize() { title = "Toolbox"; m_buttonMapping = new Dictionary<Button, CachedControl>(); m_controlsCache = new ToolboxControlCache(); m_root = new Control(); m_root.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); m_root.AddDecorator( new Scrollbars( true, false, true ) ); m_root.SetSize( 100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage ); // Create category foldouts, index them by name so we can assign our controls Dictionary< string, FoldoutList > foldouts = new Dictionary<string, FoldoutList>(); foreach( string category in m_controlsCache.Categories ) { FoldoutList foldout = new FoldoutList( category, 4.0f, true ); foldout.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); m_root.AddChild( foldout ); foldouts.Add( category, foldout ); } foreach( CachedControl c in m_controlsCache.Controls ) { Button button = new Button( c.name ); button.SetSize( 100.0f, CONTROL_DISPLAY_HEIGHT, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel ); button.Clicked += HandleControlButtonClick; m_buttonMapping.Add( button, c ); foldouts[ c.category ].AddItem( button ); } AddChild( m_root ); }
protected override void OnInitialize() { title = "Toolbox"; m_buttonMapping = new Dictionary <Button, CachedControl>(); m_controlsCache = new ToolboxControlCache(); m_root = new Control(); m_root.AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); m_root.AddDecorator(new Scrollbars(true, false, true)); m_root.SetSize(100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage); // Create category foldouts, index them by name so we can assign our controls Dictionary <string, FoldoutList> foldouts = new Dictionary <string, FoldoutList>(); foreach (string category in m_controlsCache.Categories) { FoldoutList foldout = new FoldoutList(category, 4.0f, true); foldout.SetWidth(100.0f, Control.MetricsUnits.Percentage); m_root.AddChild(foldout); foldouts.Add(category, foldout); } foreach (CachedControl c in m_controlsCache.Controls) { Button button = new Button(c.name); button.SetSize(100.0f, CONTROL_DISPLAY_HEIGHT, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel); button.Clicked += HandleControlButtonClick; m_buttonMapping.Add(button, c); foldouts[c.category].AddItem(button); } AddChild(m_root); }
void SetSize() { Control.SetSize(new winFound.Size(width, height)); }
void SetSize() { Control.SetSize(width, height); }
protected override void OnInitialize() { // Create a container control that will stack several foldouts with categorized system information // Control will fill 100% of our viewport, and will create vertical scrollbars if necesary Control sysinfo = new Control(); sysinfo.AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); sysinfo.AddDecorator(new Scrollbars(true, false, true)); sysinfo.SetSize(100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage); // Create a system information foldout list that will categorize our system information into general and feature categories // Don't forget to set width to 100% of the container width FoldoutList system = new FoldoutList("System", LIST_INDENTATION_PIXELS, true); system.SetWidth(100.0f, Control.MetricsUnits.Percentage); // Create a new foldout list to contain general system infromation and populate it with data // Child foldouts will stretch horizontally to fill the container FoldoutList systemGeneral = new FoldoutList("General", LIST_INDENTATION_PIXELS, true); systemGeneral.SetWidth(100.0f, Control.MetricsUnits.Percentage); systemGeneral.AddItem(new LabelField(SystemInfo.deviceName, "Device Name:")); // Trying to access SystemInfo.deviceUniqueIdentifier from OnGUI seems to made Unity bleed internally, so we pre-cache it systemGeneral.AddItem(new LabelField(UDID, "UDID:")); systemGeneral.AddItem(new LabelField(SystemInfo.deviceModel, "Model:")); systemGeneral.AddItem(new LabelField(SystemInfo.deviceType.ToString(), "Type:")); systemGeneral.AddItem(new LabelField(SystemInfo.processorType, "Processor Type:")); systemGeneral.AddItem(new LabelField(SystemInfo.processorCount.ToString(), "Processor Count:")); systemGeneral.AddItem(new LabelField(string.Format("{0} MB", SystemInfo.systemMemorySize), "System Memory:")); systemGeneral.AddItem(new LabelField(SystemInfo.operatingSystem, "Operating System:")); // Second list for system features FoldoutList systemFeatures = new FoldoutList("Features", LIST_INDENTATION_PIXELS, true); systemFeatures.SetWidth(100.0f, Control.MetricsUnits.Percentage); systemFeatures.AddItem(new LabelField(SystemInfo.supportsVibration.ToString(), "Vibration:")); systemFeatures.AddItem(new LabelField(SystemInfo.supportsGyroscope.ToString(), "Gyroscope:")); systemFeatures.AddItem(new LabelField(SystemInfo.supportsAccelerometer.ToString(), "Accelerometer:")); systemFeatures.AddItem(new LabelField(SystemInfo.supportsLocationService.ToString(), "Location Service:")); // Add both category lists to the system list system.AddItem(systemGeneral); system.AddItem(systemFeatures); // Now recreate the previous structure for graphics information with 3 subcategories for general, features and texture support FoldoutList graphics = new FoldoutList("Graphics Device", LIST_INDENTATION_PIXELS, true); graphics.SetWidth(100.0f, Control.MetricsUnits.Percentage); FoldoutList graphicsGeneral = new FoldoutList("General", LIST_INDENTATION_PIXELS, true); graphicsGeneral.SetWidth(100.0f, Control.MetricsUnits.Percentage); graphicsGeneral.AddItem(new LabelField(SystemInfo.graphicsDeviceID.ToString(), "ID:")); graphicsGeneral.AddItem(new LabelField(SystemInfo.graphicsDeviceName, "Name:")); graphicsGeneral.AddItem(new LabelField(SystemInfo.graphicsDeviceVendorID.ToString(), "VendorID:")); graphicsGeneral.AddItem(new LabelField(SystemInfo.graphicsDeviceVendor, "Vendor:")); graphicsGeneral.AddItem(new LabelField(SystemInfo.graphicsDeviceVersion, "Version:")); graphicsGeneral.AddItem(new LabelField(string.Format("{0} MB", SystemInfo.graphicsMemorySize), "Memory:")); graphicsGeneral.AddItem(new LabelField(SystemInfo.graphicsPixelFillrate.ToString(), "Fillrate:")); graphicsGeneral.AddItem(new LabelField(SystemInfo.graphicsShaderLevel.ToString(), "Shader Level:")); FoldoutList graphicsFeatures = new FoldoutList("Features", LIST_INDENTATION_PIXELS, true); graphicsFeatures.SetWidth(100.0f, Control.MetricsUnits.Percentage); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportedRenderTargetCount.ToString(), "Render Target Count:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supports3DTextures.ToString(), "3D Textures:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsComputeShaders.ToString(), "Compute Shaders:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsImageEffects.ToString(), "Image Effects:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsInstancing.ToString(), "Instancing:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsRenderTextures.ToString(), "Render Textures:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsRenderToCubemap.ToString(), "Render To Cubemap:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsShadows.ToString(), "Built-in Shdows:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsSparseTextures.ToString(), "Sparse Textures:")); graphicsFeatures.AddItem(new LabelField(SystemInfo.supportsStencil.ToString(), "Stencil:")); FoldoutList graphicsTextures = new FoldoutList("Texture Support", LIST_INDENTATION_PIXELS, true); graphicsTextures.SetWidth(100.0f, Control.MetricsUnits.Percentage); graphicsTextures.AddItem(new LabelField(SystemInfo.npotSupport.ToString(), "Non Power of Two:")); foreach (RenderTextureFormat format in System.Enum.GetValues(typeof(RenderTextureFormat))) { graphicsTextures.AddItem(new LabelField(SystemInfo.SupportsRenderTextureFormat(format).ToString(), format.ToString())); } graphics.AddItem(graphicsGeneral); graphics.AddItem(graphicsFeatures); graphics.AddItem(graphicsTextures); // Add top level lists to our container element sysinfo.AddChild(system); sysinfo.AddChild(graphics); // Attach parent container AddChild(sysinfo); }
protected override void OnInitialize() { Vector2 winSize = new Vector3(312.0f, 265.0f); maxSize = winSize; minSize = winSize; autoRepaintOnSceneChange = true; m_root = new Control(); m_root.SetSize(100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage); m_root.AddDecorator(new StackContent()); AddChild(m_root); // Input object field m_original = new ObjectField(typeof(GameObject), true, null, "Original"); m_original.SetHeight(26.0f, Control.MetricsUnits.Pixel); m_original.SetWidth(100.0f, Control.MetricsUnits.Percentage); m_original.SetMargin(5.0f, 5.0f, 5.0f, 5.0f); m_root.AddChild(m_original); // Rotation pivot point m_pivot = new Vector3Field(Vector3.zero, "Pivot:"); m_pivot.SetHeight(40.0f, Control.MetricsUnits.Pixel); m_pivot.SetWidth(100.0f, Control.MetricsUnits.Percentage); m_pivot.SetMargin(5.0f, 5.0f, 5.0f, 5.0f); m_root.AddChild(m_pivot); // Transform control m_transform = new TransformControl(); m_transform.SetWidth(100.0f, Control.MetricsUnits.Percentage); m_transform.SetMargin(5.0f, 5.0f, 5.0f, 5.0f); m_root.AddChild(m_transform); // Count field m_count = new IntField(1, "Duplicate Count:"); m_count.SetHeight(26.0f, Control.MetricsUnits.Pixel); m_count.SetWidth(100.0f, Control.MetricsUnits.Percentage); m_count.SetMargin(5.0f, 5.0f, 5.0f, 5.0f); m_root.AddChild(m_count); // Space field m_space = new EnumDropdown(Space.World, "Space:"); m_space.SetHeight(26.0f, Control.MetricsUnits.Pixel); m_space.SetWidth(100.0f, Control.MetricsUnits.Percentage); m_space.SetMargin(5.0f, 5.0f, 5.0f, 5.0f); m_root.AddChild(m_space); // Duplicate button m_duplicate = new Button("Duplicate"); m_duplicate.SetWidth(100.0f, Control.MetricsUnits.Percentage); m_duplicate.SetMargin(5.0f, 5.0f, 5.0f, 5.0f); m_duplicate.Enabled = false; m_root.AddChild(m_duplicate); // Events m_original.ValueChange += m_original_ValueChange; m_count.ValueChange += m_count_ValueChange; m_duplicate.Clicked += m_duplicate_Clicked; SceneView.onSceneGUIDelegate += SceneViewGUI; }
private void NewControl() { if ( m_root != null ) { if ( !EditorUtility.DisplayDialog( "Confirm New Control", "Are you sure you would like to create a new control? Current layout will be discarded!", "Ok", "Cancel" ) ) { return; } foreach( Control child in m_root.Children ) { RemoveChildControl( child ); } m_workarea.RemoveChild( m_root ); RemoveHierarchyEntry( m_root ); } m_root = new Control(); m_root.SetSize( 100.0f, 100.0f ); m_root.SetPosition( m_workarea.Size.x / 2.0f - 50.0f, m_workarea.Size.y / 2.0f - 50.0f ); m_root.AddDecorator( new BackgroundColor( Color.gray ) ); m_workarea.AddChild( m_root ); SetSelectedControl( m_root ); SetInspectorTarget( m_root ); CreateHierarchyEntry( m_root, 0 ); }
protected override void OnInitialize() { // Create a container control that will stack several foldouts with categorized system information // Control will fill 100% of our viewport, and will create vertical scrollbars if necesary Control sysinfo = new Control(); sysinfo.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); sysinfo.AddDecorator( new Scrollbars( true, false, true ) ); sysinfo.SetSize( 100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage ); // Create a system information foldout list that will categorize our system information into general and feature categories // Don't forget to set width to 100% of the container width FoldoutList system = new FoldoutList( "System", LIST_INDENTATION_PIXELS, true ); system.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); // Create a new foldout list to contain general system infromation and populate it with data // Child foldouts will stretch horizontally to fill the container FoldoutList systemGeneral = new FoldoutList( "General", LIST_INDENTATION_PIXELS, true ); systemGeneral.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); systemGeneral.AddItem( new LabelField( SystemInfo.deviceName, "Device Name:" ) ); // Trying to access SystemInfo.deviceUniqueIdentifier from OnGUI seems to made Unity bleed internally, so we pre-cache it systemGeneral.AddItem( new LabelField( UDID, "UDID:" ) ); systemGeneral.AddItem( new LabelField( SystemInfo.deviceModel, "Model:" ) ); systemGeneral.AddItem( new LabelField( SystemInfo.deviceType.ToString(), "Type:" ) ); systemGeneral.AddItem( new LabelField( SystemInfo.processorType, "Processor Type:" ) ); systemGeneral.AddItem( new LabelField( SystemInfo.processorCount.ToString(), "Processor Count:" ) ); systemGeneral.AddItem( new LabelField( string.Format( "{0} MB", SystemInfo.systemMemorySize ), "System Memory:" ) ); systemGeneral.AddItem( new LabelField( SystemInfo.operatingSystem, "Operating System:" ) ); // Second list for system features FoldoutList systemFeatures = new FoldoutList( "Features", LIST_INDENTATION_PIXELS, true ); systemFeatures.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); systemFeatures.AddItem( new LabelField( SystemInfo.supportsVibration.ToString(), "Vibration:" ) ); systemFeatures.AddItem( new LabelField( SystemInfo.supportsGyroscope.ToString(), "Gyroscope:" ) ); systemFeatures.AddItem( new LabelField( SystemInfo.supportsAccelerometer.ToString(), "Accelerometer:" ) ); systemFeatures.AddItem( new LabelField( SystemInfo.supportsLocationService.ToString(), "Location Service:" ) ); // Add both category lists to the system list system.AddItem( systemGeneral ); system.AddItem( systemFeatures ); // Now recreate the previous structure for graphics information with 3 subcategories for general, features and texture support FoldoutList graphics = new FoldoutList( "Graphics Device", LIST_INDENTATION_PIXELS, true ); graphics.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); FoldoutList graphicsGeneral = new FoldoutList( "General", LIST_INDENTATION_PIXELS, true ); graphicsGeneral.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceID.ToString(), "ID:" ) ); graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceName, "Name:" ) ); graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceVendorID.ToString(), "VendorID:" ) ); graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceVendor, "Vendor:" ) ); graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceVersion, "Version:" ) ); graphicsGeneral.AddItem( new LabelField( string.Format( "{0} MB", SystemInfo.graphicsMemorySize ), "Memory:" ) ); graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsPixelFillrate.ToString(), "Fillrate:" ) ); graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsShaderLevel.ToString(), "Shader Level:" ) ); FoldoutList graphicsFeatures = new FoldoutList( "Features", LIST_INDENTATION_PIXELS, true ); graphicsFeatures.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportedRenderTargetCount.ToString(), "Render Target Count:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supports3DTextures.ToString(), "3D Textures:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsComputeShaders.ToString(), "Compute Shaders:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsImageEffects.ToString(), "Image Effects:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsInstancing.ToString(), "Instancing:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsRenderTextures.ToString(), "Render Textures:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsRenderToCubemap.ToString(), "Render To Cubemap:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsShadows.ToString(), "Built-in Shdows:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsSparseTextures.ToString(), "Sparse Textures:" ) ); graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsStencil.ToString(), "Stencil:" ) ); FoldoutList graphicsTextures = new FoldoutList( "Texture Support", LIST_INDENTATION_PIXELS, true ); graphicsTextures.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); graphicsTextures.AddItem( new LabelField( SystemInfo.npotSupport.ToString(), "Non Power of Two:" ) ); foreach ( RenderTextureFormat format in System.Enum.GetValues( typeof( RenderTextureFormat ) ) ) { graphicsTextures.AddItem( new LabelField( SystemInfo.SupportsRenderTextureFormat( format ).ToString(), format.ToString() ) ); } graphics.AddItem( graphicsGeneral ); graphics.AddItem( graphicsFeatures ); graphics.AddItem( graphicsTextures ); // Add top level lists to our container element sysinfo.AddChild( system ); sysinfo.AddChild( graphics ); // Attach parent container AddChild( sysinfo ); }
protected override void OnInitialize() { Vector2 winSize = new Vector3( 312.0f, 265.0f ); maxSize = winSize; minSize = winSize; autoRepaintOnSceneChange = true; m_root = new Control(); m_root.SetSize( 100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage ); m_root.AddDecorator( new StackContent() ); AddChild( m_root ); // Input object field m_original = new ObjectField( typeof( GameObject ), true, null, "Original" ); m_original.SetHeight( 26.0f, Control.MetricsUnits.Pixel ); m_original.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); m_original.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f ); m_root.AddChild( m_original ); // Rotation pivot point m_pivot = new Vector3Field( Vector3.zero, "Pivot:" ); m_pivot.SetHeight( 40.0f, Control.MetricsUnits.Pixel ); m_pivot.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); m_pivot.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f ); m_root.AddChild( m_pivot ); // Transform control m_transform = new TransformControl(); m_transform.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); m_transform.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f ); m_root.AddChild( m_transform ); // Count field m_count = new IntField( 1, "Duplicate Count:" ); m_count.SetHeight( 26.0f, Control.MetricsUnits.Pixel ); m_count.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); m_count.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f ); m_root.AddChild( m_count ); // Space field m_space = new EnumDropdown( Space.World, "Space:" ); m_space.SetHeight( 26.0f, Control.MetricsUnits.Pixel ); m_space.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); m_space.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f ); m_root.AddChild( m_space ); // Duplicate button m_duplicate = new Button( "Duplicate" ); m_duplicate.SetWidth( 100.0f, Control.MetricsUnits.Percentage ); m_duplicate.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f ); m_duplicate.Enabled = false; m_root.AddChild( m_duplicate ); // Events m_original.ValueChange += m_original_ValueChange; m_count.ValueChange += m_count_ValueChange; m_duplicate.Clicked += m_duplicate_Clicked; SceneView.onSceneGUIDelegate += SceneViewGUI; }
private void CreateField(PropertyInfo prop, object control) { string displayName = prop.Name; // Remove special characters string[] classFrags = displayName.Split('.'); if (classFrags.Length != 0) { displayName = classFrags[classFrags.Length - 1]; } string[] specialFrags = displayName.Split('+'); if (specialFrags.Length != 0) { displayName = specialFrags[specialFrags.Length - 1]; } // Add spacing between capitals displayName = Regex.Replace(displayName, "([a-z])([A-Z])", "$1 $2"); Control fieldControl = null; int lines = 0; if (prop.PropertyType == typeof(int)) { fieldControl = m_inspector.AddChild(new IntField(( int )prop.GetValue(control, null), displayName)); lines = 1; } else if (prop.PropertyType == typeof(float)) { fieldControl = m_inspector.AddChild(new FloatField(( float )prop.GetValue(control, null), displayName)); lines = 1; } else if (prop.PropertyType == typeof(Vector2)) { fieldControl = m_inspector.AddChild(new Vector2Field(( Vector2 )prop.GetValue(control, null), displayName)); lines = 2; } else if (prop.PropertyType == typeof(Vector3)) { fieldControl = m_inspector.AddChild(new Vector3Field(( Vector3 )prop.GetValue(control, null), displayName)); lines = 2; } else if (prop.PropertyType == typeof(Vector4)) { fieldControl = m_inspector.AddChild(new Vector4Field(( Vector4 )prop.GetValue(control, null), displayName)); lines = 2; } else if (prop.PropertyType == typeof(string)) { fieldControl = m_inspector.AddChild(new TextField(( string )prop.GetValue(control, null), displayName)); lines = 1; } else if (prop.PropertyType == typeof(Rect)) { fieldControl = m_inspector.AddChild(new RectField(( Rect )prop.GetValue(control, null), displayName)); lines = 3; } else if (prop.PropertyType == typeof(Color)) { fieldControl = m_inspector.AddChild(new ColorField(( Color )prop.GetValue(control, null), displayName)); lines = 1; } else if (prop.PropertyType == typeof(Bounds)) { fieldControl = m_inspector.AddChild(new BoundsField(( Bounds )prop.GetValue(control, null), displayName)); lines = 3; } else if (prop.PropertyType.IsEnum) { fieldControl = m_inspector.AddChild(new EnumDropdown((System.Enum)prop.GetValue(control, null), displayName)); lines = 1; } else if (prop.PropertyType == typeof(bool)) { fieldControl = m_inspector.AddChild(new Toggle(displayName, ( bool )prop.GetValue(control, null), false)); lines = 1; } if (fieldControl != null) { fieldControl.SetSize(100.0f, 18.0f * lines, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel); fieldControl.SetMargin(5.0f, 0.0f, 5.0f, 0.0f); m_inspectorFields.Add(fieldControl, prop); (fieldControl as IEditable).ValueChange += Inspector_ValueChange; } }
protected override void OnInitialize() { m_generator = new UFormsCodeGenerator(); title = "Control Designer"; m_menu = new DesignerTopMenu(); m_menu.SetSize( 100.0f, CONTROL_DISPLAY_HEIGHT, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel ); m_menu.MenuOptionSelected += HandleMenuOptionSelected; AddChild( m_menu ); m_inspectorFields = new Dictionary<object, PropertyInfo>(); m_hierarchyItems = new Dictionary<Control, HierarchyItem>(); m_inspector = new Control(); m_inspector.SetPosition( position.width - INSPECTOR_WIDTH , CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING ); m_inspector.SetWidth( INSPECTOR_WIDTH ); m_inspector.SetMargin( 0.0f, 0.0f, SIDE_MARGIN, 0.0f ); m_inspector.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); AddChild( m_inspector ); m_hierarchy = new Control(); m_hierarchy.SetPosition( 0.0f, CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING ); m_hierarchy.SetWidth( HIERARCHY_WIDTH ); m_hierarchy.SetMargin( SIDE_MARGIN, 0.0f, 0.0f, 0.0f ); m_hierarchy.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); AddChild( m_hierarchy ); m_workarea = new Control(); m_workarea.SetPosition( m_viewportOffset ); m_workarea.AddDecorator( new ClipContent() ); AddChild( m_workarea ); m_resizeHandle = new Control(); m_resizeHandle.SetSize( RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE ); m_resizeHandle.AddDecorator( new BackgroundColor( Color.blue ) ); m_resizeHandle.Visibility = Control.VisibilityMode.Hidden; AddChild( m_resizeHandle ); SetSelectedControl( null ); SetInspectorTarget( null ); ShowToolbox(); }