2013年8月31日 星期六

Unity 輸出到 Facebook 上

最近呢最近呢,出了一個Facebook SDK for Unity,實在是太棒了,對於使用Unity的人來說又是一個方便的工具呢 !!! (插件:https://developers.facebook.com/docs/unity/)

就翻易看來說插件應該可以:
  1. 上傳的分數
  2. 邀請朋友
  3. PO塗鴉牆等等

相當方便,不像以前可能要自己撰寫(雖然說本身還沒碰到=口=) !!

官方也有放置英文的教學網 (https://developers.facebook.com/docs/unity/getting-started/),按照步驟應該是可以成功的!!

1 STEP :
先到 https://developers.facebook.com/ , 如果沒有申請過的話 , 應該要先申請喔 (register as a developers) ,在這個時候呢應該會要求你要使用手機驗證 ,  然後需要開啟FB與你手機的簡訊認證功能 , 用手機簡訊傳 F 到達32665 ,他就會先幫你開通了 , 之後會說會傳簡訊給你 打上 認證碼 , 但是但是這個傳驗證碼的功能根本沒有用吧ˋˊ !!! 所以呢有另一個解決的方式就是,前提是你已經開通簡訊功能了喔,驗證碼這個項目可以用代碼產生器取代喔 !!!
(申請手機)

(申請完手機需要驗證碼時)



(開始手機上的FB點選代碼產生器來看 FB 的代碼 )

當如果成功通過的時候 , 就可以把簡訊功能給取消了 , 傳CANCAEL 到 32665 , 就可以了 , 當這些準備好了之後開始 。

2 STEP : 
(申請你的應用程式名子 , 跟給與的空間 , 這邊我都是亂打 , 如果要打正規一點可以參考官網喔)


(成功申請 , 找尋不到請 點選 上方→ APPS → 顯示)


(接下來就可以隨便新建一個專案)


(將下載的SDK匯入 , 然後打上你的APP ID)

(然後輸出成 web 的版本)



(作者有先上傳致DROPBOX是 PUBLIC 的資料夾喔)

(然後複製上一張圖的 UNITY3D 的公開連結 到 Unity Binary URL 這 然後按下儲存)


就可以TRYTRY了唷將 Canvars Page 的連結 複製前往就大功告成了唷!!!!!!!!

2013年8月29日 星期四

使用Unity內建的Navigation做尋路

學習文章出自 : http://game.ceeger.com/forum/read.php?tid=2874&fid=2

1.準備做六個物件新建,一個Cube 設置大小(10,0.5,10),重命名“plane”;在plane上新建3个cube改名 “obstacle”;新建一個sphere,和一個cube 分别重命名為“player”,“target”。這個时候Hierarchy面板如下图所示


2 Window>Navigation 打开Naviagtion面板,選中3個obstacle設置如下圖:

 選中plane設置如下圖:

3 新建一个C#脚本,如下:

  1. public class NavTest : MonoBehaviour
  2. {
    1. public Transform target;
    2. private NavMeshAgent navMeshAgent;

    1. void Start ()
    2. {
    3. navMeshAgent = GetComponent<NavMeshAgent> ();
    4. }

    1. void Update ()
    2. {
    3. navMeshAgent.destination = target.position;
    4. }
  3. }

4 為player添加component>Naviagtion>Nav Mesh Agent組件,把腳本掛在player上;NavMesh Walkable 層為Deault,target拖拽到NavTest中的Target 設置如下圖:

5 打開Navigation面板下Bake子面板設置一些参數,参數可以參考手册,點選Bake,然後Ctrl+P簡單的尋路就OK了。

當這些設定做完之後,就可以移動看看target此時player會自動往他前進的,不過player行走的距離只侷限在plane因為只拷貝了這個大小,可以玩玩看,蠻簡單的A* !!!


2013年8月18日 星期日

官方教學 : Lessons 01 - Inheritance(繼承)

官方教學網址 : http://unity3d.com/learn/tutorials/modules/intermediate/scripting/inheritance

Fruit Class

using UnityEngine;
using System.Collections;

//This is the base class which is
//also known as the Parent class.
public class Fruit
{
    public string color;
 
    //This is the first constructor for the Fruit class
    //and is not inherited by any derived classes.
    public Fruit()
    {
        color = "orange";
        Debug.Log("1st Fruit Constructor Called");
    }
 
    //This is the second constructor for the Fruit class
    //and is not inherited by any derived classes.
    public Fruit(string newColor)
    {
        color = newColor;
        Debug.Log("2nd Fruit Constructor Called");
    }
 
    public void Chop()
    {
        Debug.Log("The " + color + " fruit has been chopped.");  
    }
 
    public void SayHello()
    {
        Debug.Log("Hello, I am a fruit.");
    }
}

Apple Class


using UnityEngine;
using System.Collections;

//This is the derived class whis is
//also know as the Child class.
public class Apple : Fruit
{
    //This is the first constructor for the Apple class.
    //It calls the parent constructor immediately, even
    //before it runs.
    public Apple()
    {
        //Notice how Apple has access to the public variable
        //color, which is a part of the parent Fruit class.
        color = "red";
        Debug.Log("1st Apple Constructor Called");
    }
 
    //This is the second constructor for the Apple class.
    //It specifies which parent constructor will be called
    //using the "base" keyword.
    public Apple(string newColor) : base(newColor)
    {
        //Notice how this constructor doesn't set the color
        //since the base constructor sets the color that
        //is passed as an argument.
        Debug.Log("2nd Apple Constructor Called");
    }
}

FruitSalad Class

using UnityEngine;
using System.Collections;

public class FruitSalad : MonoBehaviour 
{
    void Start () 
    {
        //Let's illustrate inheritance with the 
        //default constructors.
        Debug.Log("Creating the fruit");
        Fruit myFruit = new Fruit();
        Debug.Log("Creating the apple");
        Apple myApple = new Apple();
        
        //Call the methods of the Fruit class.
        myFruit.SayHello();
        myFruit.Chop();
        
        //Call the methods of the Apple class.
        //Notice how class Apple has access to all
        //of the public methods of class Fruit.
        myApple.SayHello();
        myApple.Chop();
        
        //Now let's illustrate inheritance with the 
        //constructors that read in a string.
        Debug.Log("Creating the fruit");
        myFruit = new Fruit("yellow");
        Debug.Log("Creating the apple");
        myApple = new Apple("green");
        
        //Call the methods of the Fruit class.
        myFruit.SayHello();
        myFruit.Chop();
        
        //Call the methods of the Apple class.
        //Notice how class Apple has access to all
        //of the public methods of class Fruit.
        myApple.SayHello();
        myApple.Chop();
    }
}


好看電影 : 我的PS搭檔



 禮拜五的小周末呢,與女友看了一部電影,實在太好看太好看了,女的正男的帥 !! 不得不記錄一下,影片當中男主角失戀了,女主角則是打錯了電話給男主角,一段際遇就這樣開始了,兩人於是慢慢的成為無話不談的話友(電話的朋友,哈哈自己取的),也慢慢地開始好奇對方的樣貌,相互想約出來見面,可是怕因為見了面,就會打壞了原本的相處模式,也會少一個訴苦的地方了.....
 精彩的地方,當然是要去看影片囉,才會有那種重新想戀愛的悸動喔。


 希望,將來看到此文章的我,也能夠像現在的心情一樣 !!


 放一些劇照 :






預祝大家看片愉快 !!

2013年8月11日 星期日

深入了解伺服器運作與實作(0809)

使用的伺服器 : Photon
開發用的引擎 : Unity 
參考範例: Unity + Photon 線上遊戲開發入門 (紀曲峰 著)

目前進度 page : 4-22 ~ 4-22

3.回到Client端來接收Server端的資料並處理

完成上述階段的程式碼 , 可以來測試我們所寫的 Server 了



下半天,因頭痛病假,所以今天的行程Delay !!!!!!!!!!!

2013年8月8日 星期四

深入了解伺服器運作與實作(0808)

使用的伺服器 : Photon
開發用的引擎 : Unity 
參考範例: Unity + Photon 線上遊戲開發入門 (紀曲峰 著)

目前進度 page : 4-12 ~ 4-21

5.建立client 端測試程式
6.Server端 和 Client端的訊息傳送

大致流程是先在

1.Client端寫,是否有連上server端,若連上後執行登入動作,傳送帳號密碼到server端。




2.Server端寫,處理從Client所傳送過來的資料。(Server端取得該命令之後回傳對應的訊息及結果到Client端)





3.回到Client端來接收資料並處理



2013年8月7日 星期三

階段性測試連線(20130722~0726)
使用的伺服器 : SFS (smartfox server2X)
開發用的引擎 : Unity (使用官方模型和SFS C#範例)


同一設備相互連線
  1.   執行檔與執行檔(EXE & OSX) 
  2.   專案檔與執行檔(Unity &  EXE & OSX)
  3.   加入Web做連線測試
  4.   加入Mobile(Iphone)做連線測試
上述相互連線皆已測試成功!!!

目前的進度只能在本地 127.0.0.1 做相互連線 , 或者是 192.168.XXXX 只能在區域網路上幾台筆電互相
連線WebPlay 和 PC Game 可以直接透過網路同步而在Unity編輯器中執行時 也可以和其他電腦同步 ,
超級酷的拉!!!

主要這之中稍微了解
  1. NET
  2. IP
  3. DMZ
  4. 虛擬伺服器
  5. DHCP  

主要遇到問題是,卡在ip轉址的問題,只能內部連線,外部連不進來(查詢IP,windows是->執行視窗->cmd->ipconfig)
本地:127.0.0.1 
區域:192.168.XXXX (你的電腦被路由器所分配到的IP)
實體:120.96.XXX.XX
路由器:192.168.XXXX

大致登入有三種方式 :

1.輸入 127.0.0.1 用本機連本機 (只適用開伺服器的電腦)
2.輸入 192.168.1.X 用區域網路連 (適用你的室友 免繳網路費喔!)
3.輸入 你實際IP 任何地方連入你電腦 (適用全宇宙!大概..)

主要有分享器可以固定一組IP位址(如圖路由器),然後按照分配下去給此區域所有使用者,就可以省去取得固定IP的動作(浮動IP申請或者轉成固定IP),然後需要公開一組IP位址,給外部連進來,可以直接使用DMZ(DMZ),把IP直接公布,別人只需要知道你的實體IP就可以連進來,不需要再設定port,如果是設定虛擬IP的話,就需要將你設定的port,告訴給將連入的人(如圖虛擬伺服器),大致上這樣!!!就是區域網路伺服器已經設定,和區域網路IP已設定完成以及開放到整個世界網路了吧,這個樣子網路IP這邊就算是設定完成了。

已經具備一款OnlineGame的伺服器了!




接下來的階段就是 了解整個Server , Client ,還有如果要讀資料庫的話該怎麼辦 , 加油!!!!

P.S. 使用SFS 只是大致上了解整個網域IP設定,以及做連線測試!!



抽象類別

宣告為「抽象」的類別 Abstract Class 不能被 new 實體化,如果在程式中去 new 抽象類別,編譯階段就會出現錯誤訊息不給過。
抽象類別只是告知開發者,必須去實作那個類別,亦即:要去「繼承」抽象類別,並且實作子類別出來。

抽像類別唯一目的,就是:讓整個繼承結構更完整。讓"物件導向"更合理化。


舉個例子:

生物(界、門、綱、目、科、屬、種)

動物界、植物界

人類(動物界、脊索動物門、 哺乳綱、靈長目、人科)

abstract class 生物 {
abstract void 基因染色體 () ;
}

// 這個「生物」類別,被宣告為抽象的,無法直接 new,一定要繼承並實作才能使用。

// 它預先宣告了一個「抽象方法」:基因染色體。

// 抽象類別可以整個空白,也可以預先定義一些成員屬性、方法。


class 動物 extends 生物 { }

// 「動物」類別,繼承「生物」抽象類別

// 雖然這個「動物」類別沒有宣告 abstract 抽象,但因為沒有實作「抽象方法」,所以會自動成為「抽象類別」,亦即無法直接 new。

// 凡是子類別繼承「抽象類別」,沒有實作它裡面的「抽象方法」,就會自動成為抽象類別。


class 人類 extends 動物 {
void 基因染色體 (numOfDna) {
System.out.println ( "染色體有" + numOfDna + "對");

}

// 「人類」類別 繼承「動物」類別,並且實作了「抽象方法」,這個類別是可以 new 的。



也許你會覺得奇怪,沒事搞這麼複雜幹嘛?

直接一個「人類」類別不就得了,幹嘛上層還用什麼「生物」「動物」抽象類別?吃飽撐著?

這樣講也是沒錯,所以抽象類別一般很少使用....

但有些人比較龜毛,非得要整個 OO 結構合理完整化。這有助於邏輯思路。

不過其實這才是真正意義上的 OO,因此 JAVA 提供了抽象類別。

另一種用途是:大團隊合作,起先企劃的人,想到一些點子,但是如何實作,企劃的人不管,他只是先行企劃一個大概方向,實作的細節交給其他合作的夥伴去解決。所以企劃就先宣告一些抽象類別,合作的夥伴再去實作細節。分工合作這樣子。


出處:http://www.mobile01.com/topicdetail.php?f=512&t=2971459

2013年8月6日 星期二

製作 apps 連線資料收集(20130717~0719)

  1. 查詢架設伺服器相關資料
  2. 收集與Unity可互相配合之伺服器資料
  3. 查閱網路通訊協定



支援 Unity 架設伺服器:

1.SmartFoxServer
Note:
1.可以運用Unity3D 生成客戶端,發給其他同事或者同學,只要告訴他們製作者的服務器IP,一個簡單得多人連線FPS就算是完成
2.smartfoxserver是多人游戏服务器,具有Zone、房间、好友、聊天、统计等功能


2.M2H


3.Photon
介紹網站:

4.MasterServer



使用 SmartFoxServer , Photon 比較:

server端支援平台
Smart fox Server : Windows, Windows Server, Linux, Mac
Photon Server : Windows, Windows Server

Client端支援平台
Smart fox Server : java, Flash, Unity, iOS, Android
Photon Server : Flash, Unity, javascript, C++, iOS, Android, NDK, Html5, WindowsPhon, Marmalade

使用的scripts : 
Smart fox Server : java
Photon Server : c#

核心 : 
smart fox server : java
photon server : c++

英文網路資源及教學 : 
smart fox server : 多
photon server : 少

中文網路資源及教學 : 
smart fox server : 多
photon server : 幾乎沒有

手冊(英文) : 
smart fox server : 完整
photon server : 寫得不怎麼好

開發難易度 : 
smart fox server : 簡單
photon server : 簡單

資料庫支援 : 
smart fox server : 在windows下效能較差
photon server : 可以直接透過ado連資料庫,效能佳
※ 不過資料庫還是要寫成com+或j2ee或corba較好,因此其實效能就沒差了啦!!但c#要連com+或corba比較簡單

Server-To-Server支援 : 
smart fox server : 有

photon server : 有,而且很強

2013年8月3日 星期六

20130803 (C# -> JS 的值)

A.script (JS) :

public static var hello : String = "This is a string";
public var hello2 : String = "This is a 2 string";


B.script (C#) :

using UnityEngine;
using System.Collections;
public class B : MonoBehaviour
{

 public GameObject A_OB;
 public A A_script;

 void Awake()
 {
  A_script = A_OB.GetComponent<A>();
 }

 void OnGUI()
 {
  if(GUILayout.Button("CS Call JS static"))
  {
   Debug.Log("A" + A.hello);
  }

  if(GUILayout.Button("CS Call JS public"))
  {
   Debug.Log("A2" + A_script.hello2);
  }
 }
}


這里必須要注意的是JS文件必須是在 "Standard Assets"、 "Pro Standard Assets" 和 "Plugins" 這三個目錄中的任何一個里,而CS文件不能與JS文件在一個目錄中。原因是,這三個目錄里的腳本被最先編譯,"Editor"目錄里的稍后編譯,其他的腳本最后編譯。