Skip to content

Instantly share code, notes, and snippets.

View ariok's full-sized avatar
🧠
CodeLoving

Yari @bitwaker ariok

🧠
CodeLoving
View GitHub Profile
@ariok
ariok / EnvQueryGenerator_GridOffset.cpp
Created June 1, 2019 10:17
Custom UE4 EQS Generators
// Fill out your copyright notice in the Description page of Project Settings.
#include "EnvQueryGenerator_GridOffset.h"
#include "AI/Navigation/NavigationTypes.h"
#include "EnvironmentQuery/Contexts/EnvQueryContext_Querier.h"
#define LOCTEXT_NAMESPACE "EnvQueryGenerator"
UEnvQueryGenerator_GridOffset::UEnvQueryGenerator_GridOffset()
{
@ariok
ariok / AAIControllerTeam.cpp
Last active February 22, 2024 18:12
UE4 Perception AI System: Detect By Affiliation
#include "AIControllerTeam.h"
// A Tutorial for this code is available here:
// https://www.thinkandbuild.it/ue4-ai-perception-system/
AAIControllerTeam::AAIControllerTeam()
{
SetGenericTeamId(FGenericTeamId(5));
}
@ariok
ariok / MyAIController.cpp
Created May 20, 2019 19:10
How to run EQS in C++
#include "MyAIController.h"
#include "EnvironmentQuery/EnvQueryManager.h"
void AMyAIController::FindHidingSpot()
{
FEnvQueryRequest HidingSpotQueryRequest = FEnvQueryRequest(FindHidingSpotEQS, this);
HidingSpotQueryRequest.Execute(EEnvQueryRunMode::SingleResult, this, &AMyAIController::MoveToQueryResult);
}
@ariok
ariok / [CoreData]EntriesBetweenDates.m
Created November 29, 2013 17:01
Get Core Data entries between a date range
+ (NSArray*)allEntriesInContext:(NSManagedObjectContext*)context fromDate:(NSDate*)fromDate toDate:(NSDate*)toDate{
// Create the request
NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"];
// Build the predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"date >= %@ && date <= %@ ", fromDate, toDate];
request.predicate = predicate;
// Define sorting
NSSortDescriptor *sortDesc = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES];
request.sortDescriptors = @[sortDesc];
@ariok
ariok / [Date]MonthFirstLastDays.m
Created November 29, 2013 17:18
Get the NSDate representations of the first and last days of the given month in the specified year
// Return an array:
// Index 0: NSDate for the First day of the month
// Index 1: NSDate for the Last day of the month
+ (NSArray *)dateRangeForYear:(NSInteger)year Month:(NSInteger)month{
// Build calendar and date components
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* dateComps = [[NSDateComponents alloc] init];
// Set the month
@ariok
ariok / [CustomContainers]SingleChildAnimated.m
Last active October 18, 2017 18:31
Add/Remove a single child ViewController
// Add Remove child controllers to a custom container controller with Animations
// ADD THE CHILD CONTROLLER
self.childController = theChildController;
self.childController.view.frame = setupInitialChildControllerFrame();
[self addChildViewController:self.childController];
[self.view addSubview:self.childController.view];
[self.childController didMoveToParentViewController:self];
[UIView animateWithDuration:1.0
delay:0.0
@ariok
ariok / [swift]NSBundle-version-build.swift
Created July 7, 2015 09:40
[swift] Extend NSBundle to get Version and Build info
extension NSBundle {
class var versionNumber: String {
if let version = NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"] as? String {
return version
}
return "N.D."
}
class var buildNumber: String {
@ariok
ariok / [Localization]ForceFallbackLanguage.m
Created December 11, 2013 11:25
Force the translation to a defined language. (I use this function to force the fallback language to Italian. I didn't find a way to make NSLocalizedString work with italian as fallback. your comments/suggestions are welcome :) )
NSString * L(NSString * translation_key, NSString * lang) {
NSString * s = NSLocalizedString(translation_key, nil);
// Force translation as "Lang" language if no translations are found
if ([s isEqualToString:translation_key]) {
NSString * path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj"];
NSBundle * languageBundle = [NSBundle bundleWithPath:path];
s = [languageBundle localizedStringForKey:translation_key value:@"" table:nil];
}
@ariok
ariok / [CoreAnimation]AnimationGroup.m
Created December 30, 2013 21:49
Group of animations in CA
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.fromValue = @(0.0);
anim.toValue = @(1.0);
CGPoint point = [self createPosition]
CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"position"];
anim2.fromValue = [NSValue valueWithCGPoint:label.position];
anim2.toValue = [NSValue valueWithCGPoint:point];
CAAnimationGroup *group = [CAAnimationGroup animation];
@ariok
ariok / [CoreAnimation]PropertiesAnimation.m
Created December 30, 2013 18:14
Animate a property of a layer and implicitly animate the result.
@dynamic theProperty; //The property should set as dynamic
- (id)initWithLayer:(id)layer {
if (self = [super initWithLayer:layer]) {
if ([layer isKindOfClass:[PieMask class]]) {
YourLayer *currentPresentation = (YourLayer *)layer;
self.theProperty = currentPresentation.theProperty;