Photon Server advanced & production of a new game (i)

Source: Internet
Author: User

For a long time did not write, today free to have nothing to do with the sex some, summarize the recent game experience (write the game)

Photon Server's Advanced ~

The distance from the previous estimate is also over one months, for photon really love and hate.

It's easy to write in love with it.

Hate the course of its sparse total detours, but finally do not know that love does not love.

As a server, you have to say something high-cornered.

Old routines to the tutorial. My experience is the understanding of other tutorials or sublimation, want to self-sublimation of the decisive point to finish the tutorial and then the upper right corner bar.

Http://search.jikexueyuan.com/course/?q=Photon//Geek College's explanation of Photon is more clear

And the link I made in my last article.

http://www.cnblogs.com/liusuqi/category/447143.html//seems to be the official demo of the translation, now go to the official see some have no, all very useful value

Combine the two together to see how it will work wonders Oh ~ (about o_o)

It's been a long time talking nonsense, uh. Get to the Chase!

I have divided the photon into two parts: 1. Use of Lite 2.Peer

Let's say this 1th, in fact, quite pit, tutorial this said a lite use Ah, another room. At the beginning do not know how to use these things, in fact, this is the official writing of a lite Demo in the Lite/bin under the deploy has a Lite.dll this is often said in the Tutorial Lite pull, find this is really laborious ah ~

This DLL only needs to be imported to the server, Unity3d's DLL comes with this command, so it is not required.

Now let's take a look at the server-side code, and our inheritance is going to change.

 Public class // Inheritance change of application class  Public class Mypeer:litepeer  //Peer class inheritance change

In this way we can use the function of lite, in fact, Lite is the original peerbase and application package, joined the room, convenient broadcast data and rooms distribution

The concept of Lite here explains Http://www.cnblogs.com/liusuqi/archive/2013/05/15/3079713.html

There are several more important things to do:

Join join: Enter the name of any room, if it does not exist, it will be created, when added will implicitly leave the previous room (if any), return the specified actornumber.

Leave leave: Leave the room (but stay connected).

RaiseEvent Trigger event: Tell the room to send an event to the other peer. The event has a eventcode that can carry the data provided by the client. Lite does not store events.

GetProperties Get Properties: In Lite, attributes can be attached to the room and the player, and along with this operation, they will be acquired.

SetProperties Setting Properties: The height of any key-value pair, a room or a single player, Lite does not use the data, so the client can send arbitrary data, code in accordance with the Convention.

It also mentions a more important concept room (rooms), to give a few examples:

For example, the game has a Team System, you can only team when you speak to see and others see, this is the function of the room.

Having said so much, how can these operations and methods be used? Perhaps you would say that there are no examples in that blog, but it is not the same thing.

We say that these operations are used in the client, and the server is a transfer, the implementation of the method Lite.dll have helped us to achieve, very convenient.

Now let's talk about the wording in the client:

usingUnityengine;usingExitGames.Client.Photon.Lite;usingExitGames.Client.Photon;usingSystem.Collections;usingSystem.Collections.Generic; Public classTest:monobehaviour, iphotonpeerlistener{Litepeer peer;  Public voidSendMessage (byteEventCode, Hashtable customeventcontent) {Peer. Opraiseevent (EventCode, Customeventcontent,true); Send events to all players currently on the server} Public voidJoinroom (stringroomname) {Peer. Opjoin (Roomname); Send a message to join the room} Public voidLeaveroom () {peer. Opleave (); Send a message leaving the room} Public voidRadioroomevent (byteCustomopcode, dictionary<byte,Object>customopparameters) {Peer. Opcustom (Customopcode, Customopparameters,true); Mass events in the room} Public voidDebugreturn (DebugLevel level,stringmessage)    {Debug.Log (message); }     Public voidOnEvent (EventData EventData) {//handling events forwarded back by the server           }     Public voidonoperationresponse (Operationresponse operationresponse) {//processing messages sent back by the server            }     Public voidonstatuschanged (StatusCode StatusCode) {Switch(statusCode) { CaseStatusCode.Connect:Debug.Log ("Connect");  Break;  CaseStatusCode.Disconnect:Debug.Log ("Disconnect");  Break; }    }    //Use this for initialization    voidStart () {Peer=NewLitepeer ( This, CONNECTIONPROTOCOL.UDP); Peer. Connect ("localhost:5055","MyServer"); }        //Update is called once per frame    voidUpdate () {peer.    Service (); }}

A few notes:

Package name using ExitGames.Client.Photon.Lite;

Send join room peer. Opjoin (Roomname); It's very convenient.

It's also very convenient to leave.

And how to deal with the event sent by lite to the client-the next p in the explanation.

Photon Server advanced & production of a new game (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.