--- title: 'createGuild' disqus: hackmd tags: 'so' --- ## **Create/ Delete Guild** How to create and delete a guild. 點擊Guild。 Click Guild. ![](https://i.imgur.com/rBFkCee.jpg) Enter guild’s name and note and click CreateGuild to create a guild. ![](https://i.imgur.com/9a0J9MT.jpg) Click DeleteGuild to delete a guild. ![](https://i.imgur.com/vGkYCeb.jpg) ``` C# using UnityEngine; using System.Collections; public class Sample_GetItemClass : MonoBehaviour { /******************************************************************* * Copyright © 2022 SPKITA Game Cloud. All Rights Reserved * *******************************************************************/ //enter the gguid shown in the developer backstage here private const string gguid = ""; //enter the verification shown in the developer backstage here byte[] certificate = {}; //declare CloudGame and this Class will be in charge of the communication with Cloud Server public CloudGame ag = null; string userAcc; //user’s account string userPwd; //user’s password void Start() { CloudSystem.UnityEnvironment(); CloudSystem.ServerProvider("sgc-api-us.spkita.com"); // set the server } void OnApplicationQuit() { //When the program is closed, the user’s account will not be logged out. Here we can add a mechanism that allows automatic logging out. if(ag!=null) ag.Dispose(); } public void LoginBtnClick() { userAcc = login_input_acc.text; userPwd = login_input_pwd.text; //the parameters needed when logging in, which are (account, password, gguid, certificate) ag = new CloudGame(userAcc, userPwd, gguid, certificate); //designate the way of management and start the detection on whether the connection is successful ag.onCompletion += CloudLaunch; ag.UnityLaunch(); } /******************************************************************* // After CloudGame finishes its execution, in CallBack there will be a message about whether the login is successful. // When the code is 0, the login succeeds and when the code is not 0, the login fails. // refer the errors in login to Error Code // *******************************************************************/ void CloudLaunch(int code, CloudGame game) { if (code == 0) { Debug.Log("Login Success! My poid : " + ag.poid + " NickName : " + ag.nickname); } else { Debug.LogWarning("Login Fail! Code : " + code); } } /******************************************************************* * Create a guild *******************************************************************/ public void CreateGuildBtn() { string name = Guild_input_name.text; //公會名稱 guild’s name string note = Guild_input_note.text; //公會介紹 guild’s note CloudGuild.CreateGuild(ag, name, note, 50, 0, 0, 0, 0, 0, 0, CB_CreateGuild, null); } /******************************************************************* // Create guild’s CallBack. When the code is 0, the creation succeeds and when the code is not 0, the creation fails. *******************************************************************/ void CB_CreateGuild(int code, object data, object token) { if (code == 0) { Guild_MsgText.text += "Create Guild Success! Guild ID : " + (uint)data + "\n"; } else { Guild_MsgText.text += "Create Guild Fail! Code : " + code + "\n"; } } /******************************************************************* * Delete guild *******************************************************************/ public void DeleteGuildBtn() { CloudGuild.DeleteGuild(ag, CB_DeleteGuild, null); } /******************************************************************* * Delete guild’s CallBack. When the code is 0, the deletion succeeds and when the code is not 0, the deletion fails. *******************************************************************/ void CB_DeleteGuild(int code, object token) { if (code == 0) { Guild_MsgText.text += "Delete Guild Success!\n"; } else { Guild_MsgText.text += "Delete Guild Fail! Code : " + code + "\n"; } } } ```