ToggleGroup in Unity3D, which is the active one? - user-interface

How do we know which toggle is active from the toggle groups?
Unity Doc says use ToggleGroup.ActiveToggles but I can't understand how to use it?

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Linq;
private void Example()
{
Toggle theActiveToggle = yourToggleGroup.ActiveToggles().FirstOrDefault();
Debug.Log("It worked! " + theActiveToggle.gameObject.name);
}

Related

WPF Designer Extensibility: how to get the current designer zoom value?

I created a simple custom control with design-time support like the one described here
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using System.ComponentModel;
namespace CustomControlLibrary
{
public class ButtonWithDesignTime : Button
{
public ButtonWithDesignTime()
{
// The GetIsInDesignMode check and the following design-time
// code are optional and shown only for demonstration.
if (DesignerProperties.GetIsInDesignMode(this))
{
Content = "Design mode active";
}
}
}
}
Now I need to know what is the zoom factor set at design time by Visual Studio, but I cannot figure out how.
Is there an event that I can listen to for finding out this? Or is there a property that could reveal this?
I'm not sure if this is the most elegant way of doing it, but this is what I came up with. This problem has been thwarting me for ages!
private Point GetScaleFactor()
{
var rootVisual = PresentationSource.FromVisual(this)?.RootVisual;
if (rootVisual != null)
{
var transformToRoot = TransformToAncestor(rootVisual);
if (transformToRoot is Transform t)
{
return new Point(t.Value.M11, t.Value.M22);
}
}
return new Point(1, 1);
}

Unity WebGL - Is there a way to clear all errors on build?

I am wondering if there's a way to clear the error that pops up in the browser after the game is built?
I tried this code I found online, but it doesn't work as expected. I tried to put the script below in the Editor folder, but it didn't work as well.
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEngine;
using System.Reflection;
//using UnityEditor;
public class ClearConsole : MonoBehaviour
{
public void ClearLog()
{
var assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor));
var type = assembly.GetType("UnityEditor.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
void Update()
{
ClearLog();
}
}
#endif
Sorry for my English. Thanks in advance.

LINQ not working on IEnumerable

I'm using Autofac (I've registered the base nuget package in a console app) and want to take a look at a list of registrations.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// First, create your application-level defaults using a standard
// ContainerBuilder, just as you are used to.
var builder = new ContainerBuilder();
var appContainer = builder.Build();
appContainer.ComponentRegistry.Registrations.Where(x => true);
}
}
}
The problem is the line
appContainer.ComponentRegistry.Registrations.Where(x => true);
Here intellisense is not giving me the Where linq method however it does compile as far as I can tell without any warnings, errors in messages.
I tried this further down
IEnumerable<string> list = new List<string>();
list.Where(x => true);
And intellisense is working correctly and giving me all the standard list methods.
I've tried this in a few different apps from scratch and I'm getting the same behaviour.
Any ideas as to whats going on?
EDIT:
The following works and shows correctly in intellisense
IEnumerable<IComponentRegistration> test = new List<IComponentRegistration>();
test.Where(x => true);
I'm using
<package id="Autofac" version="3.0.1" targetFramework="net45" /> from nuget.
and hovering over the ComponentRegistrations gives
and in this case scope is defined as
ILifetimeScope _scope;
However I get the same thing if i try directly off this
var builder = new ContainerBuilder();
var appContainer = builder.Build();
appContainer.ComponentRegistry.Registrations.Where(x => true);
Also IComponentRegistry is defined as (in Autofac)
public interface IComponentRegistry : IDisposable
{
...
IEnumerable<IComponentRegistration> Registrations { get; }
...
}
Comment copied to answer.
If I've understood you correctly and your problem is that intellisense isn't working on the line
appContainer.ComponentRegistry.Registrations.Where(x => true);
You should probably try and disable your addons and see if that takes care of it as it's working fine for me. Since you say you had someone else confirm it, maybe start with any addons that your installations have in common.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// First, create your application-level defaults using a standard
// ContainerBuilder, just as you are used to.
var builder = new ContainerBuilder();
var appContainer = builder.Build();
var registrations = appContainer.ComponentRegistry.Registrations.Where(x => x.Target.Equals("test"));
}
}
}
Try assigning the linq expression to a variable and see if it works

How to know if it is the Windows console?

Is there any safe way to know whether the actual window is the windows console?
GetConsoleTitle does not works since the title can be changed.
When you run CMD (or any console based programs) from your program via CreateProcess or ShellExecuteEx functions, you'll get its process ID. Use it with EnumWindows and GetWindowThreadProcessId to find its console window.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Process[] processes = Process.GetProcessesByName("cmd");
foreach (Process p in processes)
{
var window = p.MainWindowHandle;
// Do something
}
}
}
}

Problem getting started with FluentValidation

I am attempting to use FluentValidation 2.0 with an MVC 3 project. I have followed the instructions here to install FV within the project.
This is my validator class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluentValidation;
namespace HandicapTracker.Models.Validation
{
public class TournamentValidator : AbstractValidator<Tournament>
{
public TournamentValidator()
{
RuleFor(x => x.CourseId).NotEmpty();
RuleFor(x => x.TournamentDate).NotEmpty().NotEqual(new DateTime());
}
}
}
Here is where I attempt to use the attribute:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using HandicapTracker.Configuration;
using HandicapTracker.Models.Validation;
using Omu.ValueInjecter;
using FluentValidation;
using HandicapTracker.Models.Validation;
namespace HandicapTracker.Models
{
[Validator(typeof(TournamentValidator))]
public class Tournament : HandicapTrackerModelBase
{
private const int VisitingTeamIndex = 0;
private const int HomeTeamIndex = 1;
public Tournament() : this (new League())
{
}
....
}
However, the attribute is not being recognized. When I build I get the following error message:
"System.ComponentModel.DataAnnotations.Validator" is not an attribute class.
I have actually tried this on two different solutions and am having the same problem on both. It's probably something trivial, but I can't figure it out.
Can someone tell me what i am doing wrong?
Thanks.
It looks like your [Validator] attribute is picking up on another class called Validator in the System.ComponentModel.DataAnnotations namespace. Try fully qualifying the attribute.
[FluentValidation.Attributes.Validator(typeof(TournamentValidator))]
Otherwise, revise your using statements to avoid the Validator name collision.
Dont use the FluentVallidation namespace directly, it should be implemented from servicestack. So you can write it as
using Servicestack.FluentValidation;

Resources