Skip to content

Instantly share code, notes, and snippets.

View HiromichiYamada's full-sized avatar

Hiromichi Yamada HiromichiYamada

View GitHub Profile
@HiromichiYamada
HiromichiYamada / SimplePropertyForARC
Created February 20, 2013 04:38
Objective-Cで一番簡単なプロパティ設定(w/ ARC)
// Foo.h
#import <UIKit/UIKit.h>
@interface Foo : NSObject
// 外部から見えるように、ヘッダーに宣言.
@property NSDictionary* dicInfo;
@end
@implementation Foo
@synthesize dicInfo=_dicInfo;
// ..
@end
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
#if __has_feature(objc_arc)
// for ARC
#else
// for WITHOUT-ARC
#endif
var pObject:GameObject;
var croot:GameObject = pObject.transform.Find("ChildRoot").gameObject;
if( croot != null ){
var c0:GameObject = Instantiate( prefab );
c0.transform.parent = croot.transform;
c0.transform.localPosition = new Vector3(1, 0, 10);
}
// Unity:ボタン押下時に指定URLページを開く.
if( GUI.Button ( rectTexAd, "[AD]" ) ){
Debug.Log("Jump to the page.");
Application.OpenURL ("http://unity3d.com/");
}
// reference.
// http://docs.unity3d.com/Documentation/ScriptReference/Application.OpenURL.html
function OnGUI () {
GUI.depth = 10; // GUIの重なり指定(数値が少ないほど前面に出る).
GUI.enabled = false; // ボタンの無効設定.
GUI.Box( Rect(10,10, 50,300), "I am not the button." ); // シンプルな枠+文字.
}
private var screenScale : float;
private var scaledMatrix : Matrix4x4; // for scaling.
function Start () {
// for scaling.
screenScale = Screen.width / 320.0f; // for portlait only.
scaledMatrix = Matrix4x4.identity.Scale(Vector3(screenScale,screenScale,screenScale));
}
function OnGUI () {

ショートカットキー

左上の[手のひらツール], [移動ツール], [回転ツール], [スケールツール] はそれぞれ、'Q', 'W', 'E', 'R' が対応.

'OnDidAccelerate'で落ちるとき

XcodeからiPhone 3GS (iOS 4.3)で実行中に、"OnDidAccelerate"で落ちることがあった。 再度Runさせたら何事もなかったように動いたがちょっと心配。 "Build Settings" > "Player Settings..." 内の "Accelerometer Frequency" が 60Hz になっていたので、とりあえず、Disabled にしておいた。

// ref. http://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginScrollView.html
var posScroll : Vector2;
function Start() {
posScroll = Vector2.zero;
}
function OnGUI() {
var rectScroller : Rect = Rect( 0, 0, 320, 400 );