This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Unity側 */ | |
using UnityEngine; | |
using System.Collections; | |
using System.Runtime.InteropServices; | |
public class TwitterIcon : TouchAdapter { | |
public Rect screenshotButtonRect; | |
// プラットフォームがiOSの場合はObjective-Cのネイティブコードを読み込むようにする。 | |
#if UNITY_IOS && !UNITY_EDITOR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <Social/Social.h> | |
extern UIViewController *UnityGetGLViewController(); | |
extern "C" void Twitter(char *path); | |
@interface TweetPlugin : NSObject { | |
SLComposeViewController *composeVC; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
using System.Collections.Generic; | |
public class StaminaController : MonoBehaviour { | |
public GameObject staminaBar; // スタミナバーのゲームオブジェクト | |
public int recoveryTimePerStamina = 10; // 1スタミナ回復するのに必要な時間[秒] | |
public int maxStaminaNum; // スタミナの上限数 | |
public int nowStaminaNum; // 現在のスタミナ数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class StaminaBar : MonoBehaviour { | |
private Vector2 afterScale; | |
public float framesNumber; | |
public float minReference; | |
void Update () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayList hoge = new ArrayList(); // ArrayListの初期化 | |
hoge.Add(1); | |
hoge.Add(100); | |
int a = (int)hoge[0] // これはaに1が入ってok! | |
float b = (float)hoge[1] // これはなぜかエラーになる | |
// floatにキャストして取得したい場合は一度intにキャストしてfloatにする | |
float c = (float)(int)[1] // これでfloat型の100が取得できる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hoge : Int = 1 // hogeに1を代入 | |
hoge = 3 // hogeを3にする | |
hoge = nil // hogeをnilにしたいが、これはコンパイルエラーになる | |
// swiftで変数にnilを代入したいときには型の最後に「?」をつける。これが俗にいうOptional型?というものらしい | |
var optionalHoge : Int? = 1 | |
optionalHoge = nil // これはOK!!! | |
// optionalHoge = 3 これは怒られる。元のIntの値を入れたいときには変数名のあとに「!」か「?」をつける | |
optionalHoge! = 100 or optionalHoge? = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// optional valueを使ったif文の書き方 | |
var optionalHoge : Int? // 初期値にnilが入っている | |
if optionalHoge { | |
println("optionalHogeはnilじゃないよ") | |
} else { | |
println("optinalHogeはnilだね") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swiftのメソッドには外部名というか受けとる引数にラベルみたいな説明を付ける必要?があるっぽい | |
// ラベルあり | |
func tax(price p:Int, rate r:Double) -> Int { | |
return Int(Double(p) * (1 + r)) | |
} | |
/* | |
外部名やラベルや受け取る引数の説明であり、直感的に何を示しているのか分かりやすい。 | |
でも、メソッドの引数の部分が長くなって、コード的に読みづらくなるのはいただけない。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 関数の引数のデフォルト値 | |
// rateの値はデフォルトで0.08とする | |
// デフォルト値を設定している場合にはショートハンド(#)を指定する必要はない | |
func tax(#price:Int, rate:Int = 0.08) -> Int { | |
return Int(Double(price) * (1.0 + rate)) | |
} | |
// taxメソッドを呼び出すときにrateの部分は渡しても渡さなくてもいい | |
var cost1 = tax(100) // 108円 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引数の前にinoutを付けることで、渡された引数の値を直接変えることができる。 | |
// inoutの後にショートハンドは可能 | |
func tax(inout #price:Int, #rate:Double = 0.08) -> Void { | |
price = Int(Double(price) * (1.0 + rate)) | |
} | |
var num = 100 | |
tax(&num) // inoutが着いた引数に対して渡す場合は"&"をつける。 | |
println(num) // 108 |
OlderNewer