void OnEnable() { if( mainCamera == null ) { mainCamera = Camera.main; if( mainCamera == null ) { Debug.LogError( "dfFollowObject component is unable to determine which camera is the MainCamera", gameObject ); this.enabled = false; return; } } myControl = GetComponent<dfControl>(); if( myControl == null ) { Debug.LogError( "No dfControl component on this GameObject: " + gameObject.name, gameObject ); this.enabled = false; } if( myControl == null || attach == null ) { Debug.LogWarning( "Configuration incomplete: " + this.name ); this.enabled = false; return; } controlTransform = myControl.transform; followTransform = attach.transform; // Obtain a reference to the dfGUIManager rendering the control manager = myControl.GetManager(); dfFollowObjectSorter.Register( this ); }
void OnEnable () { bm = FindObjectOfType<BehaviorManager>(); tween = GetComponent<dfTweenFloat>(); rm = GetComponent<dfRadialMenu>(); myControl = GetComponent<dfControl>(); oColor = myControl.Color; mainCamera = Camera.main; manager = FindObjectOfType<dfGUIManager>(); }
internal static void Edit( dfGUIManager view, dfDesignGuide guide ) { var window = dfDesignGuideEditor.GetWindow<dfDesignGuideEditor>(); window.title = "Edit Guide"; window.minSize = window.maxSize = new Vector2( 250, 75 ); window.guide = guide; window.view = view; window.ShowUtility(); }
void Start() { info = GetComponent<dfLabel>(); if( info == null ) { this.enabled = false; throw new InvalidProgramException( "No Label component found" ); } view = info.GetManager(); }
void Update() { if( view == null ) { view = info.GetManager(); } frameCount += 1; var elapsed = Time.realtimeSinceStartup - lastUpdate; if( elapsed < interval ) return; lastUpdate = Time.realtimeSinceStartup; float fps = 1f / ( elapsed / (float)frameCount ); #if UNITY_EDITOR var screenSize = view.GetScreenSize(); var screenSizeFormat = string.Format( "{0}x{1}", (int)screenSize.x, (int)screenSize.y ); #else var screenSize = new Vector2( Screen.width, Screen.height ); var screenSizeFormat = string.Format( "{0}x{1}", (int)screenSize.x, (int)screenSize.y ); #endif var statusFormat = @"Screen : {0}, DrawCalls: {1}, Triangles: {2}, Mem: {3:F0}MB, FPS: {4:F0}"; var totalMemory = Profiler.supported ? Profiler.GetMonoUsedSize() / 1048576f : GC.GetTotalMemory( false ) / 1048576f; var status = string.Format( statusFormat, screenSizeFormat, view.TotalDrawCalls, view.TotalTriangles, totalMemory, fps ); info.Text = status.Trim(); frameCount = 0; }
// Use this for initialization void Start() { _health = MaxHealth; isOne = this.gameObject.name.Contains("1"); if (isOne) { BattleGUI.Robot1Health = Health; } else { BattleGUI.Robot2Health = Health; } if (GUI == null) { GUI = GameObject.Find("Battle GUI").GetComponent <dfGUIManager>(); } label = (GameObject)Resources.Load("Floating Label", typeof(GameObject)); }
// Use this for initialization void Start() { turret = gameObject.transform.FindChild("Turret"); if (HumanControlled) { target = GameObject.Find("Target"); Utility.DebugLog = false; } else { int targetLayer = LayerMask.NameToLayer("Target"); HitLayers = 1 << targetLayer; } if (RunBestOnly) { GUI = GameObject.Find("UI Root").GetComponent <dfGUIManager>(); label = (GameObject)Resources.Load("Floating Label", typeof(GameObject)); } }
void OnEnable() { if (mainCamera == null) { mainCamera = Camera.main; if (mainCamera == null) { Debug.LogError("dfFollowObject component is unable to determine which camera is the MainCamera", gameObject); this.enabled = false; return; } } myControl = GetComponent <dfControl>(); if (myControl == null) { Debug.LogError("No dfControl component on this GameObject: " + gameObject.name, gameObject); this.enabled = false; } if (myControl == null || attach == null) { Debug.LogWarning("Configuration incomplete: " + this.name); this.enabled = false; return; } if (myControl.Parent != null) { Debug.LogWarning("For best results, " + myControl + " should be parented directly to the UI Root", this); } controlTransform = myControl.transform; followTransform = attach.transform; // Obtain a reference to the dfGUIManager rendering the control manager = myControl.GetManager(); dfFollowObjectSorter.Register(this); }
public void UpdateTip(GameObject obj, string text, Vector3 vPosition, Color color, float alpha, float fscale) { GameTooltipManager.TooltipContainer tipContainer = this.GetTipContainer(obj); if (tipContainer == null) { return; } if (!tipContainer.tooltip.IsVisible) { tipContainer.tooltip.Show(); } dfGUIManager manager = tipContainer.tooltip.GetManager(); Vector2 screenSize = manager.GetScreenSize(); Camera renderCamera = manager.RenderCamera; Camera camera = Camera.main; Vector3 screenPoint = Camera.main.WorldToScreenPoint(vPosition); screenPoint.x = screenSize.x * (screenPoint.x / camera.pixelWidth); screenPoint.y = screenSize.y * (screenPoint.y / camera.pixelHeight); screenPoint = manager.ScreenToGui(screenPoint); float single = screenPoint.x; float width = tipContainer.tooltip.Width / 2f; Vector3 vector3 = tipContainer.tooltip.transform.localScale; screenPoint.x = single - width * vector3.x; float single1 = screenPoint.y; float height = tipContainer.tooltip.Height; Vector3 vector31 = tipContainer.tooltip.transform.localScale; screenPoint.y = single1 - height * vector31.y; tipContainer.tooltip.RelativePosition = screenPoint; tipContainer.tooltip_label.Text = text; tipContainer.tooltip_label.Color = color; tipContainer.tooltip.Opacity = alpha; tipContainer.lastSeen = Time.frameCount; tipContainer.target = obj; tipContainer.tooltip.transform.localScale = new Vector3(fscale, fscale, fscale); }
public static void DFManagerStartHook(Action <dfGUIManager> orig, dfGUIManager manager) { orig(manager); GameUIRoot root = manager.GetComponent <GameUIRoot>(); if (root != null && GameUIRoot.Instance != null && root == GameUIRoot.Instance && UIRootPrefab != null && root.name == UIRootPrefab.name && root.GetComponent <UIRootProcessedFlag>() == null) { BraveOptionsMenuItem menu = root.transform.Find("OptionsMenuPanelDave").Find("CentralOptionsPanel").Find("GameplayOptionsScrollablePanel").Find("CursorSelectorPanel").GetComponent <BraveOptionsMenuItem>(); BraveOptionsMenuItem prefabMenu = root.transform.Find("OptionsMenuPanelDave").Find("CentralOptionsPanel").Find("GameplayOptionsScrollablePanel").Find("CursorSelectorPanel").GetComponent <BraveOptionsMenuItem>(); List <string> strings = new List <string>(); foreach (string str in prefabMenu.labelOptions) { strings.Add(str); } menu.labelOptions = strings.ToArray(); List <Texture2D> textures = new List <Texture2D>(); foreach (Texture2D texture in UIRootPrefab.GetComponentInChildren <GameCursorController>().cursors) { textures.Add(texture); } root.GetComponentInChildren <GameCursorController>().cursors = textures.ToArray(); root.gameObject.AddComponent <UIRootProcessedFlag>(); } }
private static void setValue( dfGUIManager control, string propertyName, object value ) { var property = control.GetType().GetProperty( propertyName ); if( property == null ) throw new ArgumentException( "Property '" + propertyName + "' does not exist on " + control.GetType().Name ); property.SetValue( control, value, null ); }
protected internal static void SelectTextureAtlas( string label, dfGUIManager view, string propertyName, bool readOnly, bool colorizeIfMissing, int labelWidth ) { var savedColor = GUI.color; var showDialog = false; try { var atlas = getValue( view, propertyName ) as dfAtlas; GUI.enabled = !readOnly; if( atlas == null && colorizeIfMissing ) GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red; dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate( GameObject item ) { var newAtlas = ( item == null ) ? null : item.GetComponent<dfAtlas>(); dfEditorUtil.MarkUndo( view, "Change Atlas" ); setValue( view, propertyName, newAtlas ); }; var value = (dfAtlas)getValue( view, propertyName ); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField( label, "", GUILayout.Width( labelWidth ) ); var displayText = value == null ? "[none]" : value.name; GUILayout.Label( displayText, "TextField" ); var evt = Event.current; if( evt != null ) { Rect textRect = GUILayoutUtility.GetLastRect(); if( evt.type == EventType.mouseDown && evt.clickCount == 2 ) { if( textRect.Contains( evt.mousePosition ) ) { if( GUI.enabled && value != null ) { Selection.activeObject = value; EditorGUIUtility.PingObject( value ); } } } else if( evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform ) { if( textRect.Contains( evt.mousePosition ) ) { var draggedObject = DragAndDrop.objectReferences.First() as GameObject; var draggedFont = draggedObject != null ? draggedObject.GetComponent<dfAtlas>() : null; DragAndDrop.visualMode = ( draggedFont != null ) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None; if( evt.type == EventType.DragPerform ) { selectionCallback( draggedObject ); } evt.Use(); } } } if( GUI.enabled && GUILayout.Button( new GUIContent( " ", "Edit Atlas" ), "IN ObjectField", GUILayout.Width( 14 ) ) ) { showDialog = true; } } EditorGUILayout.EndHorizontal(); GUILayout.Space( 2 ); if( showDialog ) { dfEditorUtil.DelayedInvoke( (System.Action)( () => { var dialog = dfPrefabSelectionDialog.Show( "Select Texture Atlas", typeof( dfAtlas ), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null ); dialog.previewSize = 200; } ) ); } } finally { GUI.enabled = true; GUI.color = savedColor; } }
protected internal static void SelectTextureAtlas( string label, dfGUIManager view, string propertyName, bool readOnly, bool colorizeIfMissing ) { SelectTextureAtlas( label, view, propertyName, readOnly, colorizeIfMissing, 95 ); }
public override void OnInspectorGUI() { var view = target as dfGUIManager; if( lastSelected != view ) { lastSelected = view; lastWidth = view.FixedWidth; lastHeight = view.FixedHeight; lastScale = view.UIScale; } if( view.enabled ) { var screenSize = view.GetScreenSize(); var screenSizeFormat = string.Format( "{0}x{1}", (int)screenSize.x, (int)screenSize.y ); var totalControls = view.GetComponentsInChildren<dfControl>() .Length; var statusFormat = @" Screen size: {4} Total draw calls: {0} Total triangles: {1} Controls rendered: {2} Total controls: {3} "; var status = string.Format( statusFormat.Trim(), view.TotalDrawCalls, view.TotalTriangles, view.NumControlsRendered, totalControls, screenSizeFormat ); EditorGUILayout.HelpBox( status, MessageType.Info ); } dfEditorUtil.LabelWidth = 130f; using( dfEditorUtil.BeginGroup( "Rendering and Behavior" ) ) { if( view.RenderCamera == null ) GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red; var camera = EditorGUILayout.ObjectField( "Render Camera", view.RenderCamera, typeof( Camera ), true ) as Camera; if( camera != view.RenderCamera ) { dfEditorUtil.MarkUndo( view, "Assign Render Camera" ); view.RenderCamera = camera; } if( camera == null ) return; var renderQueue = EditorGUILayout.IntField( "Render Queue", view.RenderQueueBase ); if( renderQueue != view.RenderQueueBase ) { dfEditorUtil.MarkUndo( view, "Change RenderQueue Base Value" ); view.RenderQueueBase = renderQueue; } var activeViews = FindObjectsOfType( typeof( dfGUIManager ) ) as dfGUIManager[]; var duplicateCheck = activeViews.Count( v => v.RenderQueueBase == renderQueue ); if( duplicateCheck > 1 ) { EditorGUILayout.HelpBox( "There is more than one UI Root in this scene with the same Render Queue value", MessageType.Warning ); } var renderModes = new string[] { "Orthographic", "Perspective" }; var currentMode = camera.orthographic ? 0 : 1; var selectedMode = EditorGUILayout.Popup( "Render Mode", currentMode, renderModes ); if( currentMode != selectedMode ) { dfEditorUtil.MarkUndo( view, "Change Render Mode" ); if( selectedMode == 0 ) { camera.orthographic = true; camera.nearClipPlane = -2; camera.farClipPlane = 2; camera.transform.position = view.transform.position; view.transform.localScale = Vector3.one; } else { camera.orthographic = false; camera.nearClipPlane = 0.01f; camera.hideFlags = (HideFlags)0x00; // http://stackoverflow.com/q/2866350/154165 var fov = camera.fieldOfView * Mathf.Deg2Rad; var corners = view.GetCorners(); var width = Vector3.Distance( corners[ 3 ], corners[ 0 ] ); var distance = width / ( 2f * Mathf.Tan( fov / 2f ) ); var back = view.transform.TransformDirection( Vector3.back ) * distance; camera.transform.position = view.transform.position + back; camera.farClipPlane = distance * 2f; } } var pixelPerfect = EditorGUILayout.Toggle( "Pixel Perfect", view.PixelPerfectMode ); if( pixelPerfect != view.PixelPerfectMode ) { dfEditorUtil.MarkUndo( view, "Change Pixel Perfect Mode" ); view.PixelPerfectMode = pixelPerfect; view.Render(); } var eatMouseEvents = EditorGUILayout.Toggle( "Consume Mouse", view.ConsumeMouseEvents ); if( eatMouseEvents != view.ConsumeMouseEvents ) { dfEditorUtil.MarkUndo( view, "Change 'Consume Mouse Events' property" ); view.ConsumeMouseEvents = eatMouseEvents; } if( view.ConsumeMouseEvents ) { EditorGUILayout.HelpBox( "Using the 'Consume Mouse' feature is likely to result in reduced performance on mobile platforms", MessageType.Info ); } } using( dfEditorUtil.BeginGroup( "Defaults and Materials" ) ) { SelectTextureAtlas( "Default Atlas", view, "DefaultAtlas", false, true, 125 ); SelectFontDefinition( "Default Font", view.DefaultAtlas, view, "DefaultFont", true, 125 ); var merge = EditorGUILayout.Toggle( "Merge Materials", view.MergeMaterials ); if( merge != view.MergeMaterials ) { dfEditorUtil.MarkUndo( view, "Change Material Merge Property" ); view.MergeMaterials = merge; view.Render(); } var generateNormals = EditorGUILayout.Toggle( "Generate Normals", view.GenerateNormals ); if( generateNormals != view.GenerateNormals ) { dfRenderData.FlushObjectPool(); dfEditorUtil.MarkUndo( view, "Changed Generate Normals property" ); view.GenerateNormals = generateNormals; view.Render(); } } using( dfEditorUtil.BeginGroup( "Target Resolution" ) ) { #region Force user to apply changes to scale lastScale = EditorGUILayout.FloatField( "UI Scale", lastScale ); GUI.enabled = !Mathf.Approximately( lastScale, view.UIScale ); EditorGUILayout.BeginHorizontal(); { GUILayout.Space( dfEditorUtil.LabelWidth + 5 ); if( GUILayout.Button( "Apply" ) ) { dfEditorUtil.MarkUndo( view, "Change UI Scale" ); view.UIScale = lastScale; view.Render(); } } EditorGUILayout.EndHorizontal(); GUI.enabled = true; var useLegacyMode = EditorGUILayout.Toggle( "Use Legacy Mode", view.UIScaleLegacyMode ); if( useLegacyMode != view.UIScaleLegacyMode ) { dfEditorUtil.MarkUndo( view, "Change UI Scale Mode" ); view.UIScaleLegacyMode = useLegacyMode; view.Render(); } #endregion if( Application.isPlaying ) { var offset = EditInt2( "Offset", "X", "Y", view.UIOffset ); if( offset != view.UIOffset ) { dfEditorUtil.MarkUndo( view, "Change UI Offset" ); view.UIOffset = offset; view.Render(); } } #region Force user to apply changes to width or height lastWidth = EditorGUILayout.IntField( "Screen Width", lastWidth ); lastHeight = EditorGUILayout.IntField( "Screen Height", lastHeight ); GUI.enabled = lastWidth != view.FixedWidth || lastHeight != view.FixedHeight; EditorGUILayout.BeginHorizontal(); { GUILayout.Space( dfEditorUtil.LabelWidth + 5 ); if( GUILayout.Button( "Apply" ) ) { dfEditorUtil.MarkUndo( view, "Change Resolution" ); view.FixedWidth = lastWidth; view.FixedHeight = lastHeight; view.Render(); } } EditorGUILayout.EndHorizontal(); GUI.enabled = true; #endregion #if !UNITY_ANDROID EditorGUILayout.BeginHorizontal(); { GUILayout.Space( dfEditorUtil.LabelWidth + 5 ); if( GUILayout.Button( "Use Build Settings" ) ) { dfEditorUtil.MarkUndo( view, "Change Resolution" ); var newWidth = PlayerSettings.defaultScreenWidth; var newHeight = PlayerSettings.defaultScreenHeight; #if UNITY_WEBPLAYER newWidth = PlayerSettings.defaultWebScreenWidth; newHeight = PlayerSettings.defaultWebScreenHeight; #endif view.FixedWidth = newWidth; view.FixedHeight = newHeight; view.RenderCamera.aspect = view.FixedWidth / view.FixedHeight; view.Render(); lastWidth = view.FixedWidth; lastHeight = view.FixedHeight; } } EditorGUILayout.EndHorizontal(); #endif } using( dfEditorUtil.BeginGroup( "Design-Time Properties", 150 ) ) { var showMeshConfig = EditorPrefs.GetBool( "dfGUIManager.ShowMesh", false ); var showMesh = EditorGUILayout.Toggle( "Show Wireframe", showMeshConfig ); if( showMesh != showMeshConfig ) { EditorPrefs.SetBool( "dfGUIManager.ShowMesh", showMesh ); var meshRenderer = view.GetComponent<MeshRenderer>(); if( meshRenderer != null ) { EditorUtility.SetSelectedWireframeHidden( meshRenderer, !showMesh ); } SceneView.RepaintAll(); } var showRulersConfig = EditorPrefs.GetBool( "dfGUIManager.ShowRulers", true ); var showRulers = EditorGUILayout.Toggle( "Show Rulers", showRulersConfig ); if( showRulers != showRulersConfig ) { EditorPrefs.SetBool( "dfGUIManager.ShowRulers", showRulers ); SceneView.RepaintAll(); } var showGuidesConfig = EditorPrefs.GetBool( "dfGUIManager.ShowGuides", true ); var showGuides = EditorGUILayout.Toggle( "Show Guides", showGuidesConfig ); if( showGuides != showGuidesConfig ) { EditorPrefs.SetBool( "dfGUIManager.ShowGuides", showGuides ); SceneView.RepaintAll(); } var showHintsConfig = EditorPrefs.GetBool( "DaikonForge.ShowHints", true ); var showHints = EditorGUILayout.Toggle( "Show Hints", showHintsConfig ); if( showHints != showHintsConfig ) { EditorPrefs.SetBool( "DaikonForge.ShowHints", showHints ); SceneView.RepaintAll(); } var showExtentsConfig = UnityEditor.EditorPrefs.GetBool( "dfGUIManager.ShowControlExtents", true ); var showExtents = EditorGUILayout.Toggle( "Show Size Markers", showExtentsConfig ); if( showExtentsConfig != showExtents ) { EditorPrefs.SetBool( "dfGUIManager.ShowControlExtents", showExtents ); SceneView.RepaintAll(); } #region Disable "Snap to Grid" for testing new "Snap to Guide" functionality EditorPrefs.SetBool( "dfGUIManager.SnapToGrid", false ); //var snapToGridConfig = EditorPrefs.GetBool( "dfGUIManager.SnapToGrid", false ); //var snapToGrid = EditorGUILayout.Toggle( "Snap To Grid", snapToGridConfig ); //if( snapToGrid != snapToGridConfig ) //{ // EditorPrefs.SetBool( "dfGUIManager.SnapToGrid", snapToGrid ); // SceneView.RepaintAll(); //} #endregion var showGridConfig = EditorPrefs.GetBool( "dfGUIManager.ShowGrid", false ); var showGrid = EditorGUILayout.Toggle( "Show Grid", showGridConfig ); if( showGrid != showGridConfig ) { EditorPrefs.SetBool( "dfGUIManager.ShowGrid", showGrid ); SceneView.RepaintAll(); } var gridSizeConfig = EditorPrefs.GetInt( "dfGUIManager.GridSize", 25 ); var gridSize = Mathf.Max( EditorGUILayout.IntField( "Grid Size", gridSizeConfig ), 5 ); if( gridSize != gridSizeConfig ) { EditorPrefs.SetInt( "dfGUIManager.GridSize", gridSize ); SceneView.RepaintAll(); } var showSafeAreaConfig = EditorPrefs.GetBool( "ShowSafeArea", false ); var showSafeArea = EditorGUILayout.Toggle( "Show Safe Area", showSafeAreaConfig ); if( showSafeArea != showSafeAreaConfig ) { EditorPrefs.SetBool( "ShowSafeArea", showSafeArea ); SceneView.RepaintAll(); } if( showSafeArea ) { var marginConfig = EditorPrefs.GetFloat( "SafeAreaMargin", 10f ); var safeAreaMargin = EditorGUILayout.Slider( "Safe %", marginConfig, 0f, 50f ); if( marginConfig != safeAreaMargin ) { EditorPrefs.SetFloat( "SafeAreaMargin", safeAreaMargin ); SceneView.RepaintAll(); } } } //dfEditorUtil.DrawHorzLine(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); { if( GUILayout.Button( "Help" ) ) { var url = "http://www.daikonforge.com/dfgui/tutorials/"; Application.OpenURL( url ); Debug.Log( "Opened tutorial page at " + url ); } if( GUILayout.Button( "Force Refresh" ) ) { dfGUIManager.RefreshAll( true ); Debug.Log( "User interface manually refreshed" ); } } EditorGUILayout.EndHorizontal(); showDrawCallInfo( view ); }
protected internal static void SelectFontDefinition( string label, dfAtlas atlas, dfGUIManager view, string propertyName, bool colorizeIfMissing, int labelWidth ) { var savedColor = GUI.color; var showDialog = false; try { GUI.enabled = ( atlas != null ); var value = (dfFontBase)getValue( view, propertyName ); if( value == null && colorizeIfMissing ) GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red; dfPrefabSelectionDialog.FilterCallback filterCallback = delegate( GameObject item ) { if( atlas == null ) return false; var font = item.GetComponent<dfFontBase>(); if( font == null ) return false; if( font is dfFont ) { var bitmappedFont = (dfFont)font; if( bitmappedFont.Atlas == null || !dfAtlas.Equals( bitmappedFont.Atlas, atlas ) ) return false; } return true; }; dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate( GameObject item ) { var font = ( item == null ) ? null : item.GetComponent<dfFontBase>(); dfEditorUtil.MarkUndo( view, "Change Font" ); setValue( view, propertyName, font ); }; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField( label, "", GUILayout.Width( labelWidth ) ); var displayText = value == null ? "[none]" : value.name; GUILayout.Label( displayText, "TextField" ); var evt = Event.current; if( evt != null ) { Rect textRect = GUILayoutUtility.GetLastRect(); if( evt.type == EventType.mouseDown && evt.clickCount == 2 ) { if( textRect.Contains( evt.mousePosition ) ) { if( GUI.enabled && value != null ) { Selection.activeObject = value; EditorGUIUtility.PingObject( value ); } } } else if( evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform ) { if( textRect.Contains( evt.mousePosition ) ) { var draggedObject = DragAndDrop.objectReferences.First() as GameObject; var draggedFont = ( draggedObject != null ) ? draggedObject.GetComponent<dfFontBase>() : null; DragAndDrop.visualMode = ( draggedFont != null ) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None; if( evt.type == EventType.DragPerform ) { selectionCallback( draggedObject ); } evt.Use(); } } } if( GUI.enabled && GUILayout.Button( new GUIContent( " ", "Edit Font" ), "IN ObjectField", GUILayout.Width( 14 ) ) ) { showDialog = true; } } EditorGUILayout.EndHorizontal(); if( value is dfDynamicFont || ( value is dfFont && !dfAtlas.Equals( atlas, ( (dfFont)value ).Atlas ) ) ) { GUI.color = Color.white; EditorGUILayout.HelpBox( "The specified font uses a different Material, which could result in an additional draw call each time it is used.", MessageType.Warning ); } GUILayout.Space( 2 ); if( showDialog ) { dfEditorUtil.DelayedInvoke( (System.Action)( () => { dfPrefabSelectionDialog.Show( "Select Font", typeof( dfFontBase ), selectionCallback, dfFontDefinitionInspector.DrawFontPreview, filterCallback ); } ) ); } } finally { GUI.enabled = true; GUI.color = savedColor; } }
protected internal static void SelectFontDefinition( string label, dfAtlas atlas, dfGUIManager view, string propertyName, bool colorizeIfMissing ) { SelectFontDefinition( label, atlas, view, propertyName, colorizeIfMissing, 95 ); }
void HumanController() { var direction = target.transform.position - transform.position; var properDistance = direction.magnitude; var distance = properDistance / SensorRange; direction.Normalize(); direction.y = 0; float angle = Utility.AngleSigned(direction, transform.forward, transform.up); if (Input.GetButtonDown("Fire1")) { Utility.Log("Firing!"); dfGUIManager UI = GameObject.Find("UI Root").GetComponent <dfGUIManager>(); GameObject label = (GameObject)Resources.Load("Floating Label", typeof(GameObject)); print("Pos: " + label.transform.position); dfTweenVector3 tween = label.GetComponent <dfTweenVector3>(); //Destroy(tween); tween.StartValue = UI.WorldPointToGUI(gameObject.transform.position) + new Vector2(0, -50);; //print("Pos: " + label.transform.position); //dfFollowObject follow = label.GetComponent<dfFollowObject>(); //follow.attach = gameObject; //follow.mainCamera = Camera.main; dfLabel glabel = UI.AddPrefab(label) as dfLabel; glabel.RelativePosition = UI.WorldPointToGUI(gameObject.transform.position) + new Vector2(0, -50); glabel.Text = "Lars!"; Attack(properDistance, angle); } if (Input.GetButtonDown("Fire2")) { Utility.Log("Rifling!"); if (angle < 5f && angle > -5f) { Utility.Log("Enemy within [-5, 5] degrees of front"); } RifleAttack(); } if (Input.GetButton("Jump")) { var turretTurnAngle = 1 * TurretTurnSpeed * Time.deltaTime; turret.Rotate(new Vector3(0, turretTurnAngle, 0)); } if (Input.GetKeyDown(KeyCode.M)) { MortarAttack(0.9f); } rifleTimer += Time.deltaTime; mortarTimer += Time.deltaTime; var moveDist = Input.GetAxis("Vertical") * Speed * Time.deltaTime; var turnAngle = Input.GetAxis("Horizontal") * TurnSpeed * Time.deltaTime; // * gas; transform.Rotate(new Vector3(0, turnAngle, 0)); transform.Translate(Vector3.forward * moveDist); attackTimer += Time.deltaTime; }
private void showDrawCallInfo( dfGUIManager view ) { dfEditorUtil.DrawSeparator(); using( dfEditorUtil.BeginGroup( "Draw Calls" ) ) { showDrawCalls = EditorGUILayout.Toggle( "Show Draw Calls", showDrawCalls ); } if( !EditorApplication.isCompiling && showDrawCalls ) { dfEditorUtil.DrawHorzLine(); var controls = view.ControlsRendered; var indices = view.DrawCallStartIndices; var drawCallCount = view.TotalDrawCalls; var list = dfList<string>.Obtain(); var last = 0; var lastControl = ""; try { for( int i = 0; i < drawCallCount; i++ ) { using( dfEditorUtil.BeginGroup( string.Format( "Draw call {0} of {1}", i + 1, drawCallCount ) ) ) { var buffer = view.GetDrawCallBuffer( i ); list.Clear(); var baseSelectionIndex = last; while( last < controls.Count && indices[ last ] == i ) { lastControl = getObjectPath( controls[ last++ ] ); list.Add( ( list.Count + 1 ) + ". " + lastControl ); } EditorGUILayout.ObjectField( "Material", buffer.Material, typeof( Material ), false ); EditorGUILayout.ObjectField( "Texture", buffer.Material.mainTexture, typeof( Texture2D ), false ); EditorGUILayout.IntField( "Triangles", buffer.Triangles.Count / 3 ); if( list.Count == 0 ) { var message = "Control '{0}' creates multiple draw calls"; message = string.Format( message, getObjectPath( controls[ last ] ) ); EditorGUILayout.HelpBox( message, MessageType.Info ); } else { EditorGUILayout.IntField( "Controls", list.Count ); list.Insert( 0, "Select a control" ); int selectedIndex = EditorGUILayout.Popup( "Select Control", 0, list.ToArray() ); if( selectedIndex > 0 ) { dfEditorUtil.DelayedInvoke( () => { Selection.activeObject = controls[ baseSelectionIndex + selectedIndex - 1 ]; } ); } } dfEditorUtil.DrawHorzLine(); } } } catch { } list.Release(); } }
public void Start() { this.control = GetComponent<dfControl>(); this.manager = control.GetManager(); }
private void closeWindow( EditorWindow window ) { if( guide != null ) { var maxValue = ( guide.orientation == dfControlOrientation.Vertical ) ? view.FixedWidth : view.FixedHeight; if( guide.position <= 0 || guide.position >= maxValue ) { EditorUtility.SetDirty( view ); view.guides.Remove( guide ); } view = null; guide = null; this.Close(); } }
public override void OnInspectorGUI() { var view = target as dfGUIManager; if( lastSelected != view ) { lastSelected = view; lastWidth = view.FixedWidth; lastHeight = view.FixedHeight; lastScale = view.UIScale; } if( view.enabled ) { var screenSize = view.GetScreenSize(); var screenSizeFormat = string.Format( "{0}x{1}", (int)screenSize.x, (int)screenSize.y ); var totalControls = view.GetComponentsInChildren<dfControl>() .Length; var statusFormat = @" Screen size: {4} Total draw calls: {0} Total triangles: {1} Controls rendered: {2} Total controls: {3} "; var status = string.Format( statusFormat.Trim(), view.TotalDrawCalls, view.TotalTriangles, view.ControlsRendered, totalControls, screenSizeFormat ); EditorGUILayout.HelpBox( status, MessageType.Info ); } EditorGUIUtility.LookLikeControls( 130f ); EditorGUI.indentLevel += 1; GUILayout.Label( "Rendering", "HeaderLabel" ); { if( view.RenderCamera == null ) GUI.color = Color.red; var camera = EditorGUILayout.ObjectField( "Render Camera", view.RenderCamera, typeof( Camera ), true ) as Camera; if( camera != view.RenderCamera ) { dfEditorUtil.MarkUndo( view, "Assign Render Camera" ); view.RenderCamera = camera; } if( camera == null ) return; var renderModes = new string[] { "Orthographic", "Perspective" }; var currentMode = camera.isOrthoGraphic ? 0 : 1; var selectedMode = EditorGUILayout.Popup( "Render Mode", currentMode, renderModes ); if( currentMode != selectedMode ) { dfEditorUtil.MarkUndo( view, "Change Render Mode" ); if( selectedMode == 0 ) { camera.isOrthoGraphic = true; camera.nearClipPlane = -2; camera.farClipPlane = 2; camera.transform.position = view.transform.position; view.transform.localScale = Vector3.one; } else { camera.isOrthoGraphic = false; camera.nearClipPlane = 0.01f; camera.hideFlags = (HideFlags)0x00; // http://stackoverflow.com/q/2866350/154165 var fov = camera.fieldOfView * Mathf.Deg2Rad; var corners = view.GetCorners(); var width = Vector3.Distance( corners[ 3 ], corners[ 0 ] ); var distance = width / ( 2f * Mathf.Tan( fov / 2f ) ); var back = view.transform.TransformDirection( Vector3.back ) * distance; camera.transform.position = view.transform.position + back; camera.farClipPlane = distance * 2f; } } var pixelPerfect = EditorGUILayout.Toggle( "Pixel Perfect", view.PixelPerfectMode ); if( pixelPerfect != view.PixelPerfectMode ) { dfEditorUtil.MarkUndo( view, "Change Pixel Perfect Mode" ); view.PixelPerfectMode = pixelPerfect; view.Render(); } } GUILayout.Label( "Defaults and Materials", "HeaderLabel"); { SelectTextureAtlas( "Default Atlas", view, "DefaultAtlas", false, true, 125 ); SelectFontDefinition( "Default Font", view.DefaultAtlas, view, "DefaultFont", true, 125 ); var merge = EditorGUILayout.Toggle( "Merge Materials", view.MergeMaterials ); if( merge != view.MergeMaterials ) { dfEditorUtil.MarkUndo( view, "Change Material Merge Property" ); view.MergeMaterials = merge; view.Render(); } var generateNormals = EditorGUILayout.Toggle( "Generate Normals", view.GenerateNormals ); if( generateNormals != view.GenerateNormals ) { dfRenderData.FlushObjectPool(); dfEditorUtil.MarkUndo( view, "Changed Generate Normals property" ); view.GenerateNormals = generateNormals; view.Render(); } } GUILayout.Label( "Resolution", "HeaderLabel" ); { #region Force user to apply changes to scale lastScale = EditorGUILayout.FloatField( "UI Scale", lastScale ); GUI.enabled = !Mathf.Approximately( lastScale, view.UIScale ); EditorGUILayout.BeginHorizontal(); { GUILayout.Space( dfEditorUtil.LabelWidth + 5 ); if( GUILayout.Button( "Apply" ) ) { dfEditorUtil.MarkUndo( view, "Change UI Scale" ); view.UIScale = lastScale; view.Render(); } } EditorGUILayout.EndHorizontal(); GUI.enabled = true; #endregion #region Force user to apply changes to width or height lastWidth = EditorGUILayout.IntField( "Screen Width", lastWidth ); lastHeight = EditorGUILayout.IntField( "Screen Height", lastHeight ); GUI.enabled = lastWidth != view.FixedWidth || lastHeight != view.FixedHeight; EditorGUILayout.BeginHorizontal(); { GUILayout.Space( dfEditorUtil.LabelWidth + 5 ); if( GUILayout.Button( "Apply" ) ) { dfEditorUtil.MarkUndo( view, "Change Resolution" ); view.FixedWidth = lastWidth; view.FixedHeight = lastHeight; view.Render(); } } EditorGUILayout.EndHorizontal(); GUI.enabled = true; #endregion #if !UNITY_ANDROID EditorGUILayout.BeginHorizontal(); { GUILayout.Space( dfEditorUtil.LabelWidth + 5 ); if( GUILayout.Button( "Use Build Settings" ) ) { dfEditorUtil.MarkUndo( view, "Change Resolution" ); #if WEB_PLAYER view.FixedWidth = PlayerSettings.defaultWebScreenWidth; view.FixedHeight = PlayerSettings.defaultWebScreenHeight; #else view.FixedWidth = PlayerSettings.defaultScreenWidth; view.FixedHeight = PlayerSettings.defaultScreenHeight; #endif view.RenderCamera.aspect = view.FixedWidth / view.FixedHeight; view.Render(); lastWidth = view.FixedWidth; lastHeight = view.FixedHeight; } } EditorGUILayout.EndHorizontal(); #endif } GUILayout.Label( "Designer", "HeaderLabel" ); { var showMeshConfig = EditorPrefs.GetBool( "dfGUIManager.ShowMesh", false ); var showMesh = EditorGUILayout.Toggle( "Show Wireframe", showMeshConfig ); if( showMesh != showMeshConfig ) { EditorPrefs.SetBool( "dfGUIManager.ShowMesh", showMesh ); var meshRenderer = view.GetComponent<MeshRenderer>(); if( meshRenderer != null ) { EditorUtility.SetSelectedWireframeHidden( meshRenderer, !showMesh ); } SceneView.RepaintAll(); } var showRulersConfig = EditorPrefs.GetBool( "dfGUIManager.ShowRulers", true ); var showRulers = EditorGUILayout.Toggle( "Show Rulers", showRulersConfig ); if( showRulers != showRulersConfig ) { EditorPrefs.SetBool( "dfGUIManager.ShowRulers", showRulers ); SceneView.RepaintAll(); } var snapToGridConfig = EditorPrefs.GetBool( "dfGUIManager.SnapToGrid", false ); var snapToGrid = EditorGUILayout.Toggle( "Snap To Grid", snapToGridConfig ); if( snapToGrid != snapToGridConfig ) { EditorPrefs.SetBool( "dfGUIManager.SnapToGrid", snapToGrid ); SceneView.RepaintAll(); } var showGridConfig = EditorPrefs.GetBool( "dfGUIManager.ShowGrid", false ); var showGrid = EditorGUILayout.Toggle( "Show Grid", showGridConfig ); if( showGrid != showGridConfig ) { EditorPrefs.SetBool( "dfGUIManager.ShowGrid", showGrid ); SceneView.RepaintAll(); } var gridSizeConfig = EditorPrefs.GetInt( "dfGUIManager.GridSize", 25 ); var gridSize = Mathf.Max( EditorGUILayout.IntField( "Grid Size", gridSizeConfig ), 5 ); if( gridSize != gridSizeConfig ) { EditorPrefs.SetInt( "dfGUIManager.GridSize", gridSize ); SceneView.RepaintAll(); } var showSafeAreaConfig = EditorPrefs.GetBool( "ShowSafeArea", false ); var showSafeArea = EditorGUILayout.Toggle( "Show Safe Area", showSafeAreaConfig ); if( showSafeArea != showSafeAreaConfig ) { EditorPrefs.SetBool( "ShowSafeArea", showSafeArea ); SceneView.RepaintAll(); } if( showSafeArea ) { var marginConfig = EditorPrefs.GetFloat( "SafeAreaMargin", 10f ); var safeAreaMargin = EditorGUILayout.Slider( "Safe %", marginConfig, 0f, 50f ); if( marginConfig != safeAreaMargin ) { EditorPrefs.SetFloat( "SafeAreaMargin", safeAreaMargin ); SceneView.RepaintAll(); } } } //dfEditorUtil.DrawHorzLine(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); { if( GUILayout.Button( "Help" ) ) { var url = "http://www.daikonforge.com/dfgui/tutorials/"; Application.OpenURL( url ); Debug.Log( "Opened tutorial page at " + url ); } if( GUILayout.Button( "Force Refresh" ) ) { dfGUIManager.RefreshAll( true ); Debug.Log( "User interface manually refreshed" ); } } EditorGUILayout.EndHorizontal(); if( Application.isPlaying ) { for( int i = 0; i < view.TotalDrawCalls; i++ ) { dfEditorUtil.DrawSeparator(); var drawcall = view.GetDrawCallBuffer( i ); if( drawcall.Material == null ) { continue; } GUILayout.Label( "Draw call: " + ( i + 1 ), "HeaderLabel" ); EditorGUILayout.ObjectField( "Material", drawcall.Material, typeof( Material ), false ); EditorGUILayout.IntField( "Triangles: ", drawcall.Triangles.Count / 3 ); } dfEditorUtil.DrawSeparator(); } }
private void CreateUI() { // Make sure other cameras already in the scene don't render the designated layer var sceneCameras = FindObjectsOfType(typeof(Camera)) as Camera[]; for (int i = 0; i < sceneCameras.Length; i++) { var sceneCamera = sceneCameras[i]; if (sceneCamera.gameObject.activeInHierarchy && sceneCamera.GetComponent <dfGUICamera>() == null) { sceneCameras[i].cullingMask &= ~(1 << layer); sceneCameras[i].eventMask &= ~(1 << layer); EditorUtility.SetDirty(sceneCameras[i]); } } GameObject go = new GameObject("UI Root"); go.transform.position = new Vector3(-100, 100, 0); go.layer = layer; GameObject cam_go = new GameObject("UI Camera"); cam_go.transform.parent = go.transform; cam_go.transform.localPosition = Vector3.zero; cam_go.transform.localRotation = Quaternion.identity; Camera cam = cam_go.AddComponent <Camera>(); cam.depth = getGuiCameraDepth(); cam.farClipPlane = 5; cam.clearFlags = CameraClearFlags.Depth; cam.cullingMask = (1 << layer); cam.isOrthoGraphic = orthographic; dfGUIManager guiManager = go.AddComponent <dfGUIManager>(); guiManager.RenderCamera = cam; guiManager.PixelPerfectMode = pixelPerfect; dfInputManager inputManager = go.GetComponent <dfInputManager>(); inputManager.RenderCamera = cam; inputManager.UseJoystick = useJoystick; inputManager.JoystickClickButton = joystickClickButton; inputManager.HorizontalAxis = horizontalAxis; inputManager.VerticalAxis = verticalAxis; #if WEB_PLAYER guiManager.FixedHeight = PlayerSettings.defaultWebScreenHeight; guiManager.RenderCamera.aspect = (float)PlayerSettings.defaultWebScreenWidth / (float)PlayerSettings.defaultWebScreenHeight; #else guiManager.FixedHeight = PlayerSettings.defaultScreenHeight; guiManager.RenderCamera.aspect = (float)PlayerSettings.defaultScreenWidth / (float)PlayerSettings.defaultScreenHeight; #endif dfEditorUtil.DelayedInvoke(() => { Selection.activeObject = guiManager; var scene = SceneView.currentDrawingSceneView ?? SceneView.lastActiveSceneView; if (scene != null) { scene.orthographic = true; scene.pivot = guiManager.transform.position; scene.AlignViewToObject(guiManager.transform); } }); this.Close(); }
public void OnEnable() { lastSelected = null; }
/// <summary> /// Initializes any variables or game state before the game starts. /// </summary> public void Awake () { // Get joystick control DFControl = GetComponent<dfControl> (); // Get GUI manager DFGUIManager = DFControl.GetManager (); // Choose input handler #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY CurrentInputHandler = TouchInputHandler; #endif #if UNITY_EDITOR || UNITY_WEBPLAYER || UNITY_STANDALONE CurrentInputHandler = MouseInputHandler; #endif if (IsRemoteTesting) { CurrentInputHandler = TouchInputHandler; } }
public void Update() { if( !Application.isPlaying ) return; if( guiManager == null ) { guiManager = GetComponent<dfGUIManager>(); if( guiManager == null ) { Debug.LogWarning( "No associated dfGUIManager instance", this ); this.enabled = false; return; } } var activeControl = dfGUIManager.ActiveControl; if( this.useTouch && processTouchInput() ) { return; } else if( useMouse ) { processMouseInput(); } if( activeControl == null ) return; #if UNITY_IPHONE || UNITY_ANDROID || UNITY_BLACKBERRY || UNITY_WP8 // Do not process any other control events while the // mobile keyboard is being displayed. Note that this // means that controls which use the mobile keyboard // need to handle that process themselves. if( TouchScreenKeyboard.visible ) { return; } #endif if( processKeyboard() ) return; if( useJoystick ) { #region Eliminate WASD navigation in UI // NOTE: By default, Unity includes the WASD keys in the Horizontal and // Vertical Axis definitions in Input Manager. While it is certainly // possible to either modify those definitions or specify different // axes which do not include those keys, it seems reasonable to try // to simply ignore those keys for UI navigation. // // If this is not the default behavior, then delete or comment out the // following block of code. // // The following code only partially works... If the user holds down // one of the WASD keys, then an arrow keycode will be generated after // they release the key. If this is a problem, then the only solution // appears to be that modifying the axes in the Input Manager is required. // // ADDENDUM: Expanded to include arrow keys after discovering that // incorrectly-configured input axes can also produce spurious arrow // key events for( int i = 0; i < wasd.Length; i++ ) { if( Input.GetKey( wasd[ i ] ) || Input.GetKeyDown( wasd[ i ] ) || Input.GetKeyUp( wasd[ i ] ) ) { return; } } #endregion processJoystick(); } }
// Use this for initialization void Start() { dfManager = GetComponent <dfGUIManager>(); dfManager.UIScaleLegacyMode = false; }