I want to disable everyplay, built in unity, when running iphone4/3G/3GS
but I'm not sure of the easiest place to just globally disable it. Any suggestions?
if (iPhone.generation == iPhoneGeneration.iPhone4 || iPhone.generation == iPhoneGeneration.iPhone3G || iPhone.generation == iPhoneGeneration.iPhone3GS )
You can easily disable single core devices (3GS/4/iPad1) by calling Everyplay.SharedInstance.SetDisableSingleCoreDevices(true) in the first scene of your game. After that you don't have to worry if you are calling StartRecording on a single core device since the calls are ignored by Everyplay. 3G (and Unity editor) does not support the recording in the first place.
In case you need to support recording on iPad 1 one approach is to create an Everyplay singleton wrapper which simply does not call recording functions on devices which you have have defined to be not supported.
Simple wrapper example (untested but gives you the idea):
using UnityEngine;
public static class MyEveryplayWrapper {
private static iPhoneGeneration[] unsupportedDevices = {
iPhoneGeneration.iPad1Gen,
iPhoneGeneration.iPhone,
iPhoneGeneration.iPhone3G,
iPhoneGeneration.iPhone3GS,
iPhoneGeneration.iPodTouch1Gen,
iPhoneGeneration.iPodTouch2Gen,
iPhoneGeneration.iPodTouch3Gen
};
private static bool CheckIfRecordingSupported() {
bool recordingSupported = !Application.isEditor;
foreach(iPhoneGeneration device in unsupportedDevices) {
if(device == iPhone.generation) {
recordingSupported = false;
break;
}
}
Debug.Log ("Everyplay recording support: " + recordingSupported);
return recordingSupported;
}
public static bool IsRecordingSupported = CheckIfRecordingSupported();
public static void StartRecording() {
if(IsRecordingSupported) {
Everyplay.SharedInstance.StartRecording();
}
}
public static void StopRecording() {
if(IsRecordingSupported) {
Everyplay.SharedInstance.StopRecording();
}
}
}
To use it you just call MyEveryplayWrapper.MethodName instead of Everyplay.SharedInstance.MethodName. When rendering your UI you can take the IsRecordingSupported into account to show/hide Everplay related buttons etc.
Related
I need to find a way to get an instance of DataProcessingEngine without calling it's constractor.
I am trying to find a way to do so using the registered DataProcessingEngine in composition object (please see the following code). But I could not find a way to do so.
Anyone have a suggestion? Thanks in advance.
public class Composer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Register<IDataProcessingEngine, DataProcessingEngine>(Lifetime.Singleton);
//DataProcessingEngine dataProcessing = compostion.Resolve<IDataProcessingEngine>()??//no resolve function exists in Umbraco.Core.Composing
SaveImagesThread(dataProcessingEngine);
}
public Task SaveImagesThread(IDataProcessingEngine dataProcessingEngine)//TODO - decide async
{
string dataTimerTime = WebConfig.SaveProductsDataTimer;
double time = GetTimeForTimer(dataTimerTime);
if (time > 0)
{
var aTimer = new System.Timers.Timer(time);
aTimer.Elapsed += new ElapsedEventHandler(dataProcessingEngine.SaveImages);
aTimer.Start();
}
return default;
}
}
For all of you who are looking for a way to call a function (that's defined in another class in your code, an Engine or ...) from the composer(where the app starts) and want to avoid calling this function's class' constractor. I've found another way to do so:
public class QueuePollingHandler
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class SubscribeToQueuePollingHandlerComponentComposer :
ComponentComposer<SubscribeToQueuePollingHandler>
{ }
public class SubscribeToQueuePollingHandler : IComponent
{
private readonly IDataProcessingEngine _dataProcessingEngine;
public SubscribeToQueuePollingHandler(IDataProcessingEngine
dataProcessingEngine)
{
_dataProcessingEngine = dataProcessingEngine;
SaveImagesThread(_dataProcessingEngine);
}
public void SaveImagesThread(IDataProcessingEngine
dataProcessingEngine)
{
....
}
}
And the logic explenation: You create a class (SubscribeToQueuePollingHandlerComponentComposer from the example) and define its base class to be ComponentComposer<Class_that_inherits_IComponent>.
And when you start the application you could see that it gets to the registered class' constractor (SubscribeToQueuePollingHandler constructor).
That's the way that I found to be able to call a function right when the application starts without needing to call its class constractor and actualy use dependency injection.
I am little new to dart. I am trying to understand the difference between these two methods. Are both methods different or same? Where should I use one above another? Can someone explain it to me?
class A {
A.executor1() {
print('executor one is called');
}
static executor2() {
print('executor two is called');
}
}
Meanwhile neither of the method call is required to make a new instance? both are called using the class name.
void main() {
A.executor1(); // Will print "executor one is called"
A.executor2(); // Will print "executor two is called"
}
A.executor1() is a named constructor. static executor2() is a static method.
With an IDE (or dartpad.dev) you can see the different return types when you are placing the cursor over each method:
void main() {
A.executor1(); // (new) A A.executor1()
A.executor2(); // dynamic executor2()
}
static methods can be called without creating an instance of the class. executor1 will have access to this and so on because it's attached to an actual instance, but static methods will not because they aren't attached to anything.
Consider (in Javascript):
class Bicycle {
static numWheels = 2;
constructor(color) {
this.color = color;
}
static numberOfWheels() {
console.log(`Every bike has ${this.numWheels} wheels.`);
}
myColor() {
console.log(`This bike is ${this.color}.`);
}
}
// property of an instance
new Bicycle('red').myColor();
// available for anyone!
Bicycle.numberOfWheels();
I am new to Dart programming. I am trying to figure out what is the proper way (what everyone will do) to handle/guard those functions which are login required. The following is my first trial:
$ vim login_sample.dart:
var isLoggedIn;
class LoginRequiredException implements Exception {
String cause;
LoginRequiredException(this.cause);
}
Function loginRequired(Function f) {
if (!isLoggedIn) {
throw new LoginRequiredException("Login is reuiqred.");
}
return f;
}
void secretPrint() {
print("This is a secret");
}
void main(List<String> args) {
if (args.length != 1) return null;
isLoggedIn = (args[0] == '1') ? true : false;
try {
loginRequired(secretPrint)();
} on LoginRequiredException {
print("Login is required!");
}
}
then, run it with $ dart login_sample.dart 1 and $ dart login_sample.dart 2.
I am wondering if this is the recommended way to guard login required functions or not.
Thank you very much for your help.
Edited:
My question is more about general programming skills in Dart than how to use a plugin. In python, I just need to add #login_required decorator in the front of the function to protect it. I am wondering if this decorator function way is recommended in dart or not.
PS: All firebase/google/twitter/facebook etc... are blocked in my country.
I like the functional approach. I'd only avoid using globals, you can wrap it in a Context so you can mock then for tests and use Futures as Monads: https://dartpad.dartlang.org/ac24a5659b893e8614f3c29a8006a6cc
Passing the function is not buying much value. In a typical larger Dart project using a framework there will be some way to guard at a higher level than a function - such as an entire page or component/widget.
If you do want to guard at a per-function level you first need to decide with it should be the function or the call site that decides what needs to be guarded. In your example it is the call site making the decision. After that decision you can implement a throwIfNotAuthenticated and add a call at either the definition or call site.
void throwIfNotAuthenticated() {
if (!userIsAuthenticated) {
throw new LoginRequiredException();
}
}
// Function decides authentication is required:
void secretPrint() {
throwIfNotAuthenticated();
print('This is a secret');
}
// Call site decides authentication is required:
void main() {
// do stuff...
throwIfNotAuthenticated();
anotherSecreteMethod();
}
I have created a xamarin forms application. I want to check if the status of the bluetooth in iOS. I have used the below code, but the if (state == CBCentralManagerState.PoweredOn) is returning me Unknown. It is not providing the actual status of bluetooth state. Could somebody please help me to figure out what is wrong ? Thanks.
The reference of this method is here : https://developer.xamarin.com/api/type/MonoMac.CoreBluetooth.CBCentralManagerState/
private CBCentralManagerState state;
public bool CheckBluetoothStatus()
{
bool status;
if (state == CBCentralManagerState.PoweredOn)
{
status= true;
}
else
{
status = false;
}
return status;
}
As described here in apple documentation, you need to initialise CBCentralManager before you can actually use it.
If you look at Xamarin Documentation for CBCentralManager, they provide you a list of all constructors it takes. Implement the 2nd one from the bottom
CBCentralManager(CBCentralManagerDelegate, DispatchQueue, CBCentralInitOptions)
But before you implement this, you need to implement the CBCentralManagerDelegate. It could be as simple as this
public class CbCentralDelegate : CBCentralManagerDelegate
{
public override void UpdatedState(CBCentralManager central)
{
if(central.State == CBCentralManagerState.PoweredOn)
{
System.Console.WriteLine("Powered On");
}
}
}
Now that you have implemented the delegate, you should be able to fetch the state of the bluetooth from the CBCentralManager like this
var bluetoothManager = new CBCentralManager(new CbCentralDelegate(),DispatchQueue.DefaultGlobalQueue,
new CBCentralInitOptions{ShowPowerAlert = true});
return bluetoothManager.State == CBCentralManagerState.PoweredOn;
I know its been a while since this was asked, but hopefully this will help you.(Or anyone else)
You should subscript the UpdatedState event in CBCentralManager
_mgr = new CBCentralManager();
_mgr.UpdatedState += CBCentralManager_UpdatedState;
void CBCentralManager_UpdatedState(object sender, EventArgs e){
switch (_mgr.State)
}
How do you make a robust AI/scripting system for a game?
1) For all NPC's/environment/entities do you give them a SEPARATE single behavior tree (etc. patrolBehavior, allyBehavior, vendorBehavior, doorBehavior)? If there are 500 units on the screen, should I do a full pass on the tree (going from root -> node/action) or should I do 1-node progress for all the units?
2) I am doing the AI logic in the update() function... but I heard some games have their separate AI thread, any ideas?
3) I'm wondering how to divide my game into sections/chapters... do I use a simple variable (EVENT="Mission 3") to denote how for the player's been, and make it all linear? And then utilize variable in the trees above?
I'll try to answer your question.
I do all branching logic and behavior trees in a static class for example:
public static class Behavior
{
//Branch
public static Action Selector(Func<bool> cond, Action ifTrue, Action ifFalse) {
return () => { if (cond()) { ifTrue(); } else { ifFalse(); } };
}
public static Action Sequencer(Action a, Action b) {
return () => { a(); b(); }
}
//Example trees
public static Func<bool> ifPlayerIsInSight = () => { return true; /*...true iff WorldState shows guard can see player...*/};
public static Action shootAtPlayer = () => { /*...aim guard's weapon at player and fire...*/ };
public static Func<bool> ifUnderFire = () => { return true; /*...true iff WorldState shows guard hears player gunfire...*/};
public static Action takeCover = () => { /*...guard runs for nearest shelter... */};
public static Action walkBackAndForthGuardingDoorway = () => { /*...default guard patrol behaviour...*/ };
public static Action patrollingGuardBehaviour =
Selector(Behavior.ifPlayerIsInSight, Behavior.shootAtPlayer,
Selector(Behavior.ifUnderFire, Behavior.takeCover,
Behavior.walkBackAndForthGuardingDoorway));
}
Do it in LateUpdate() or last so it does not lag the main loop.
It is upto you. You could implement a "State" in each behavior tree or split it out and manage which get used at what time.
each NPC/Agent has its own behavior tree. The tree is updated and it 'knows' where to continue, so the efficiency is usually quite good.
AIs can be updated in the main thread, it can also be updated in a separated thead. it depends and up to you.
it depends and up to you.
behaviac is a really excellent one.
behaviac supports the behavior tree, finite state machine and hierarchical task network. Behaviors can be designed and debugged in the designer, exported and executed by the game.
The C++ version is suitable for the client and server side.
and, it is open sourced!