├── .gitignore ├── .gitmodules ├── Assets ├── Plugins.meta ├── Plugins │ ├── kbengine_unity3d_plugins.meta │ └── kbengine_unity3d_plugins │ │ ├── AccountBase.cs │ │ ├── AccountBase.cs.meta │ │ ├── AvatarBase.cs │ │ ├── AvatarBase.cs.meta │ │ ├── Blowfish.cs │ │ ├── Blowfish.cs.meta │ │ ├── Bundle.cs │ │ ├── Bundle.cs.meta │ │ ├── ClientSDKUpdater.cs │ │ ├── ClientSDKUpdater.cs.meta │ │ ├── CustomDataTypes.cs │ │ ├── CustomDataTypes.cs.meta │ │ ├── DataTypes.cs │ │ ├── DataTypes.cs.meta │ │ ├── Dbg.cs │ │ ├── Dbg.cs.meta │ │ ├── EncryptionFilter.cs │ │ ├── EncryptionFilter.cs.meta │ │ ├── Entity.cs │ │ ├── Entity.cs.meta │ │ ├── EntityCall.cs │ │ ├── EntityCall.cs.meta │ │ ├── EntityCallAccountBase.cs │ │ ├── EntityCallAccountBase.cs.meta │ │ ├── EntityCallAvatarBase.cs │ │ ├── EntityCallAvatarBase.cs.meta │ │ ├── EntityCallGateBase.cs │ │ ├── EntityCallGateBase.cs.meta │ │ ├── EntityCallMonsterBase.cs │ │ ├── EntityCallMonsterBase.cs.meta │ │ ├── EntityCallNPCBase.cs │ │ ├── EntityCallNPCBase.cs.meta │ │ ├── EntityCallSpaceBase.cs │ │ ├── EntityCallSpaceBase.cs.meta │ │ ├── EntityCallSpaceDuplicateBase.cs │ │ ├── EntityCallSpaceDuplicateBase.cs.meta │ │ ├── EntityCallSpacesBase.cs │ │ ├── EntityCallSpacesBase.cs.meta │ │ ├── EntityCallSpawnPointBase.cs │ │ ├── EntityCallSpawnPointBase.cs.meta │ │ ├── EntityCallTestBase.cs │ │ ├── EntityCallTestBase.cs.meta │ │ ├── EntityCallTestNoBaseBase.cs │ │ ├── EntityCallTestNoBaseBase.cs.meta │ │ ├── EntityComponent.cs │ │ ├── EntityComponent.cs.meta │ │ ├── EntityDef.cs │ │ ├── EntityDef.cs.meta │ │ ├── Event.cs │ │ ├── Event.cs.meta │ │ ├── GateBase.cs │ │ ├── GateBase.cs.meta │ │ ├── KBEMain.cs │ │ ├── KBEMain.cs.meta │ │ ├── KBETypes.cs │ │ ├── KBETypes.cs.meta │ │ ├── KBEngine.cs │ │ ├── KBEngine.cs.meta │ │ ├── KBEngineArgs.cs │ │ ├── KBEngineArgs.cs.meta │ │ ├── Math.cs │ │ ├── Math.cs.meta │ │ ├── MemoryStream.cs │ │ ├── MemoryStream.cs.meta │ │ ├── MessageReaderBase.cs │ │ ├── MessageReaderBase.cs.meta │ │ ├── MessageReaderKCP.cs │ │ ├── MessageReaderKCP.cs.meta │ │ ├── MessageReaderTCP.cs │ │ ├── MessageReaderTCP.cs.meta │ │ ├── Messages.cs │ │ ├── Messages.cs.meta │ │ ├── Method.cs │ │ ├── Method.cs.meta │ │ ├── MonsterBase.cs │ │ ├── MonsterBase.cs.meta │ │ ├── NPCBase.cs │ │ ├── NPCBase.cs.meta │ │ ├── NetworkInterfaceBase.cs │ │ ├── NetworkInterfaceBase.cs.meta │ │ ├── NetworkInterfaceKCP.cs │ │ ├── NetworkInterfaceKCP.cs.meta │ │ ├── NetworkInterfaceTCP.cs │ │ ├── NetworkInterfaceTCP.cs.meta │ │ ├── ObjectPool.cs │ │ ├── ObjectPool.cs.meta │ │ ├── PacketReceiverBase.cs │ │ ├── PacketReceiverBase.cs.meta │ │ ├── PacketReceiverKCP.cs │ │ ├── PacketReceiverKCP.cs.meta │ │ ├── PacketReceiverTCP.cs │ │ ├── PacketReceiverTCP.cs.meta │ │ ├── PacketSenderBase.cs │ │ ├── PacketSenderBase.cs.meta │ │ ├── PacketSenderKCP.cs │ │ ├── PacketSenderKCP.cs.meta │ │ ├── PacketSenderTCP.cs │ │ ├── PacketSenderTCP.cs.meta │ │ ├── Profile.cs │ │ ├── Profile.cs.meta │ │ ├── Property.cs │ │ ├── Property.cs.meta │ │ ├── README.md │ │ ├── README.md.meta │ │ ├── ScriptModule.cs │ │ ├── ScriptModule.cs.meta │ │ ├── ServerErrorDescrs.cs │ │ ├── ServerErrorDescrs.cs.meta │ │ ├── SpaceBase.cs │ │ ├── SpaceBase.cs.meta │ │ ├── SpaceDuplicateBase.cs │ │ ├── SpaceDuplicateBase.cs.meta │ │ ├── SpacesBase.cs │ │ ├── SpacesBase.cs.meta │ │ ├── SpawnPointBase.cs │ │ ├── SpawnPointBase.cs.meta │ │ ├── TestBase.cs │ │ ├── TestBase.cs.meta │ │ ├── TestNoBaseBase.cs │ │ ├── TestNoBaseBase.cs.meta │ │ ├── deps.meta │ │ └── deps │ │ ├── KCP.cs │ │ └── KCP.cs.meta ├── Resources.meta ├── Resources │ ├── entity.prefab │ ├── entity.prefab.meta │ ├── player.prefab │ ├── player.prefab.meta │ ├── terrain.prefab │ └── terrain.prefab.meta ├── Scenes.meta ├── Scenes │ ├── login.unity │ ├── login.unity.meta │ ├── selavatars.unity │ ├── selavatars.unity.meta │ ├── world.unity │ └── world.unity.meta ├── Scripts.meta ├── Scripts │ ├── kbe_scripts.meta │ ├── kbe_scripts │ │ ├── Account.cs │ │ ├── Account.cs.meta │ │ ├── Avatar.cs │ │ ├── Avatar.cs.meta │ │ ├── Gate.cs │ │ ├── Gate.cs.meta │ │ ├── Monster.cs │ │ ├── Monster.cs.meta │ │ ├── NPC.cs │ │ ├── NPC.cs.meta │ │ ├── README.md │ │ ├── README.md.meta │ │ ├── SkillBox.cs │ │ ├── SkillBox.cs.meta │ │ ├── clientapp.cs │ │ ├── clientapp.cs.meta │ │ ├── components.meta │ │ ├── components │ │ │ ├── .gitignore │ │ │ ├── Test.cs │ │ │ ├── Test.cs.meta │ │ │ ├── TestNoBase.cs │ │ │ └── TestNoBase.cs.meta │ │ ├── skills.meta │ │ └── skills │ │ │ ├── Skill.cs │ │ │ ├── Skill.cs.meta │ │ │ ├── SkillObject.cs │ │ │ └── SkillObject.cs.meta │ ├── u3d_scripts.meta │ └── u3d_scripts │ │ ├── GameEntity.cs │ │ ├── GameEntity.cs.meta │ │ ├── ShowFPS.cs │ │ ├── ShowFPS.cs.meta │ │ ├── UI.cs │ │ ├── UI.cs.meta │ │ ├── World.cs │ │ └── World.cs.meta ├── Standard Assets.meta ├── Standard Assets │ ├── Character Controllers.meta │ ├── Character Controllers │ │ ├── First Person Controller.prefab │ │ ├── First Person Controller.prefab.meta │ │ ├── Sources.meta │ │ └── Sources │ │ │ ├── PrototypeCharacter.meta │ │ │ ├── PrototypeCharacter │ │ │ ├── Constructor.FBX │ │ │ ├── Constructor.FBX.meta │ │ │ ├── Materials.meta │ │ │ ├── Materials │ │ │ │ ├── constructor_done.mat │ │ │ │ └── constructor_done.mat.meta │ │ │ ├── Textures.meta │ │ │ └── Textures │ │ │ │ ├── capsuleUV.psd │ │ │ │ ├── capsuleUV.psd.meta │ │ │ │ ├── constructor_diffuse.png │ │ │ │ ├── constructor_diffuse.png.meta │ │ │ │ ├── constructor_normals.png │ │ │ │ └── constructor_normals.png.meta │ │ │ ├── Scripts.meta │ │ │ └── Scripts │ │ │ ├── CharacterMotor.cs │ │ │ ├── CharacterMotor.cs.meta │ │ │ ├── FPSInputController.cs │ │ │ ├── FPSInputController.cs.meta │ │ │ ├── MouseLook.cs │ │ │ └── MouseLook.cs.meta │ ├── Terrain Assets.meta │ └── Terrain Assets │ │ ├── Terrain Grass.meta │ │ ├── Terrain Grass │ │ ├── Grass.psd │ │ ├── Grass.psd.meta │ │ ├── Grass2.psd │ │ └── Grass2.psd.meta │ │ ├── Terrain Textures.meta │ │ ├── Terrain Textures │ │ ├── Cliff (Layered Rock).psd │ │ ├── Cliff (Layered Rock).psd.meta │ │ ├── GoodDirt.psd │ │ ├── GoodDirt.psd.meta │ │ ├── Grass (Hill).psd │ │ ├── Grass (Hill).psd.meta │ │ ├── Grass&Rock.psd │ │ └── Grass&Rock.psd.meta │ │ ├── Trees Ambient-Occlusion.meta │ │ └── Trees Ambient-Occlusion │ │ ├── Palm.meta │ │ └── Palm │ │ ├── Materials.meta │ │ ├── Materials │ │ ├── palmbark.mat │ │ ├── palmbark.mat.meta │ │ ├── palmbranch.mat │ │ └── palmbranch.mat.meta │ │ ├── Palm.fbx │ │ ├── Palm.fbx.meta │ │ ├── PalmBark.psd │ │ ├── PalmBark.psd.meta │ │ ├── PalmBranch.psd │ │ └── PalmBranch.psd.meta ├── start.unity └── start.unity.meta ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset └── UnityConnectSettings.asset ├── README.md └── README_CN.md /.gitignore: -------------------------------------------------------------------------------- 1 | # ---------------[ Unity generated ]------------------ # 2 | /Temp 3 | /obj 4 | /UnityGenerated 5 | /Library 6 | 7 | # ----[ Visual Studio / MonoDevelop generated ]------- # 8 | 9 | ExportedObj/ 10 | *.svd 11 | *.userprefs 12 | *.csproj 13 | *.pidb 14 | *.suo 15 | *.sln 16 | *.user 17 | *.unityproj 18 | *.booproj 19 | 20 | # -------------[ OS generated ]------------------------ # 21 | .DS_Store 22 | .DS_Store? 23 | ._* 24 | .Spotlight-V100 25 | .Trashes 26 | Icon? 27 | ehthumbs.db 28 | Thumbs.db 29 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "kbengine_demos_assets"] 2 | path = kbengine_demos_assets 3 | url = https://github.com/kbengine/kbengine_demos_assets.git 4 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da6e44fb73181ca4987fff29d2e4a63d 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4134584ab91c184449fac144cd68f793 3 | folderAsset: yes 4 | timeCreated: 1547085094 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/AccountBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00ce159568924944d93e882ffd3c5c6e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/AvatarBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c10a27029579a474994c79bd193036de 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Blowfish.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a192bcacf981bb14b90749a1f03c3271 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Bundle.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | /* 9 | 这个模块将多个数据包打捆在一起 10 | 由于每个数据包都有最大上限, 向Bundle中写入大量数据将会在内部产生多个MemoryStream 11 | 在send时会全部发送出去 12 | */ 13 | public class Bundle : ObjectPool 14 | { 15 | public MemoryStream stream = new MemoryStream(); 16 | public List streamList = new List(); 17 | public int numMessage = 0; 18 | public int messageLength = 0; 19 | public Message msgtype = null; 20 | private int _curMsgStreamIndex = 0; 21 | 22 | public Bundle() 23 | { 24 | } 25 | 26 | public void clear() 27 | { 28 | // 把不用的MemoryStream放回缓冲池,以减少垃圾回收的消耗 29 | for (int i = 0; i < streamList.Count; ++i) 30 | { 31 | if (stream != streamList[i]) 32 | streamList[i].reclaimObject(); 33 | } 34 | 35 | streamList.Clear(); 36 | 37 | if(stream != null) 38 | stream.clear(); 39 | else 40 | stream = MemoryStream.createObject(); 41 | 42 | numMessage = 0; 43 | messageLength = 0; 44 | msgtype = null; 45 | _curMsgStreamIndex = 0; 46 | } 47 | 48 | /// 49 | /// 把自己放回缓冲池 50 | /// 51 | public void reclaimObject() 52 | { 53 | clear(); 54 | reclaimObject(this); 55 | } 56 | 57 | public void newMessage(Message mt) 58 | { 59 | fini(false); 60 | 61 | msgtype = mt; 62 | numMessage += 1; 63 | 64 | writeUint16(msgtype.id); 65 | 66 | if(msgtype.msglen == -1) 67 | { 68 | writeUint16(0); 69 | messageLength = 0; 70 | } 71 | 72 | _curMsgStreamIndex = 0; 73 | } 74 | 75 | public void writeMsgLength() 76 | { 77 | if(msgtype.msglen != -1) 78 | return; 79 | 80 | MemoryStream stream = this.stream; 81 | if(_curMsgStreamIndex > 0) 82 | { 83 | stream = streamList[streamList.Count - _curMsgStreamIndex]; 84 | } 85 | stream.data()[2] = (Byte)(messageLength & 0xff); 86 | stream.data()[3] = (Byte)(messageLength >> 8 & 0xff); 87 | } 88 | 89 | public void fini(bool issend) 90 | { 91 | if(numMessage > 0) 92 | { 93 | writeMsgLength(); 94 | 95 | streamList.Add(stream); 96 | stream = MemoryStream.createObject(); 97 | } 98 | 99 | if(issend) 100 | { 101 | numMessage = 0; 102 | msgtype = null; 103 | } 104 | 105 | _curMsgStreamIndex = 0; 106 | } 107 | 108 | public void send(NetworkInterfaceBase networkInterface) 109 | { 110 | fini(true); 111 | 112 | if(networkInterface.valid()) 113 | { 114 | for(int i=0; i stream.space()) 136 | { 137 | streamList.Add(stream); 138 | stream = MemoryStream.createObject(); 139 | ++ _curMsgStreamIndex; 140 | } 141 | 142 | messageLength += v; 143 | } 144 | 145 | //--------------------------------------------------------------------------------- 146 | public void writeInt8(SByte v) 147 | { 148 | checkStream(1); 149 | stream.writeInt8(v); 150 | } 151 | 152 | public void writeInt16(Int16 v) 153 | { 154 | checkStream(2); 155 | stream.writeInt16(v); 156 | } 157 | 158 | public void writeInt32(Int32 v) 159 | { 160 | checkStream(4); 161 | stream.writeInt32(v); 162 | } 163 | 164 | public void writeInt64(Int64 v) 165 | { 166 | checkStream(8); 167 | stream.writeInt64(v); 168 | } 169 | 170 | public void writeUint8(Byte v) 171 | { 172 | checkStream(1); 173 | stream.writeUint8(v); 174 | } 175 | 176 | public void writeUint16(UInt16 v) 177 | { 178 | checkStream(2); 179 | stream.writeUint16(v); 180 | } 181 | 182 | public void writeUint32(UInt32 v) 183 | { 184 | checkStream(4); 185 | stream.writeUint32(v); 186 | } 187 | 188 | public void writeUint64(UInt64 v) 189 | { 190 | checkStream(8); 191 | stream.writeUint64(v); 192 | } 193 | 194 | public void writeFloat(float v) 195 | { 196 | checkStream(4); 197 | stream.writeFloat(v); 198 | } 199 | 200 | public void writeDouble(double v) 201 | { 202 | checkStream(8); 203 | stream.writeDouble(v); 204 | } 205 | 206 | public void writeString(string v) 207 | { 208 | checkStream(v.Length + 1); 209 | stream.writeString(v); 210 | } 211 | 212 | public void writeUnicode(string v) 213 | { 214 | writeBlob(System.Text.Encoding.UTF8.GetBytes((string)v)); 215 | } 216 | 217 | public void writeBlob(byte[] v) 218 | { 219 | checkStream(v.Length + 4); 220 | stream.writeBlob(v); 221 | } 222 | 223 | public void writePython(byte[] v) 224 | { 225 | writeBlob(v); 226 | } 227 | 228 | public void writeVector2(Vector2 v) 229 | { 230 | checkStream(8); 231 | stream.writeVector2(v); 232 | } 233 | 234 | public void writeVector3(Vector3 v) 235 | { 236 | checkStream(12); 237 | stream.writeVector3(v); 238 | } 239 | 240 | public void writeVector4(Vector4 v) 241 | { 242 | checkStream(16); 243 | stream.writeVector4(v); 244 | } 245 | 246 | public void writeEntitycall(byte[] v) 247 | { 248 | checkStream(16); 249 | 250 | UInt64 cid = 0; 251 | Int32 id = 0; 252 | UInt16 type = 0; 253 | UInt16 utype = 0; 254 | 255 | stream.writeUint64(cid); 256 | stream.writeInt32(id); 257 | stream.writeUint16(type); 258 | stream.writeUint16(utype); 259 | } 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Bundle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92a3925a9aa2c6441b48903c3b914b65 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/ClientSDKUpdater.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | #if UNITY_EDITOR 4 | using UnityEngine; 5 | using UnityEditor; 6 | using System.Collections; 7 | using System; 8 | using System.IO; 9 | using KBEngine; 10 | 11 | public class ClientSDKUpdater : MonoBehaviour 12 | { 13 | string warnUpdateSDK = ""; 14 | MemoryStream sdkFileStream = null; 15 | int downloadFiles = 0; 16 | string sdkPath = ""; 17 | string sdkTempPath = ""; 18 | string sdkBakPath = ""; 19 | 20 | void Start() 21 | { 22 | string kbengineCoreFile = "KBEngine.cs"; 23 | string[] res = System.IO.Directory.GetFiles(Application.dataPath, kbengineCoreFile, SearchOption.AllDirectories); 24 | sdkPath = res[0].Replace(kbengineCoreFile, "").Replace("\\", "/"); 25 | sdkPath = sdkPath.Remove(sdkPath.Length - 1, 1); 26 | 27 | sdkTempPath = sdkPath + "_temp"; 28 | sdkBakPath = sdkPath + "_bak"; 29 | 30 | warnUpdateSDK = "Version does not match the server.\nClick to update KBEnginePlugin!\nPull from: " + KBEngineApp.app.getInitArgs().ip + ":" + KBEngineApp.app.getInitArgs().port; 31 | installEvents(); 32 | 33 | GameObject[] objs = FindObjectsOfType(typeof(GameObject)) as GameObject[]; 34 | foreach (GameObject child in objs) 35 | { 36 | if (!child.gameObject.GetComponent() && 37 | !child.gameObject.GetComponent() && 38 | !child.gameObject.GetComponent()) 39 | { 40 | child.gameObject.SetActive(false); 41 | } 42 | } 43 | } 44 | 45 | public virtual void installEvents() 46 | { 47 | Event.registerIn("onImportClientSDK", this, "onImportClientSDK"); 48 | } 49 | 50 | protected virtual void OnDestroy() 51 | { 52 | KBEngine.Event.deregisterOut(this); 53 | } 54 | 55 | public void onImportClientSDK(int remainingFiles, string fileName, int fileSize, byte[] fileDatas) 56 | { 57 | if (sdkFileStream == null) 58 | sdkFileStream = MemoryStream.createObject(); 59 | 60 | sdkFileStream.append(fileDatas, (uint)sdkFileStream.rpos, (uint)fileDatas.Length); 61 | 62 | warnUpdateSDK = "Download:" + fileName + " -> " + sdkFileStream.length() + "/" + fileSize + "bytes! " + (int)(((float)downloadFiles / (float)(downloadFiles + remainingFiles)) * 100) + "%"; 63 | Debug.Log(warnUpdateSDK); 64 | 65 | if (sdkFileStream.length() == fileSize) 66 | { 67 | Debug.Log("onImportClientSDK: " + fileName + "->" + fileSize + "bytes success!"); 68 | 69 | string path = Path.GetDirectoryName(sdkTempPath + "//" + fileName); 70 | if (!Directory.Exists(path)) 71 | Directory.CreateDirectory(path); 72 | 73 | StreamWriter sw; 74 | FileInfo t = new FileInfo(sdkTempPath + "//" + fileName); 75 | string data = System.Text.Encoding.UTF8.GetString(sdkFileStream.data(), 0, fileSize); 76 | sw = t.CreateText(); 77 | sw.WriteLine(data); 78 | sw.Close(); 79 | sw.Dispose(); 80 | 81 | sdkFileStream.reclaimObject(); 82 | sdkFileStream = null; 83 | downloadFiles += 1; 84 | 85 | if (remainingFiles == 0) 86 | { 87 | warnUpdateSDK = ""; 88 | downloadFiles = 0; 89 | replaceNewSDK(); 90 | } 91 | } 92 | } 93 | 94 | void downloadSDKFromServer() 95 | { 96 | downloadFiles = 0; 97 | 98 | if (Directory.Exists(sdkTempPath)) 99 | Directory.Delete(sdkTempPath, true); 100 | 101 | Directory.CreateDirectory(sdkTempPath); 102 | 103 | if (sdkFileStream != null) 104 | { 105 | sdkFileStream.reclaimObject(); 106 | sdkFileStream = null; 107 | } 108 | 109 | // kbcmd options 110 | string tool_options = "Unity"; 111 | string callbackIP = ""; 112 | UInt16 callbackPort = 0; 113 | int clientWindowSize = (int)KBEngineApp.app.getInitArgs().TCP_RECV_BUFFER_MAX; 114 | 115 | Bundle bundle = Bundle.createObject(); 116 | bundle.newMessage(Messages.messages["Loginapp_importClientSDK"]); 117 | bundle.writeString(tool_options); 118 | bundle.writeInt32(clientWindowSize); 119 | bundle.writeString(callbackIP); 120 | bundle.writeUint16(callbackPort); 121 | bundle.send(KBEngineApp.app.networkInterface()); 122 | } 123 | 124 | void replaceNewSDK() 125 | { 126 | System.IO.Directory.Move(sdkPath, sdkBakPath); 127 | System.IO.Directory.Move(sdkTempPath, sdkPath); 128 | 129 | // 删除旧的SKD文件夹 130 | Directory.Delete(sdkBakPath, true); 131 | 132 | EditorApplication.isPlaying = false; 133 | AssetDatabase.Refresh(); 134 | } 135 | 136 | void OnGUI() 137 | { 138 | if (warnUpdateSDK.Length > 0) 139 | { 140 | GUI.contentColor = Color.red; 141 | GUI.backgroundColor = Color.red; 142 | 143 | if (GUI.Button(new Rect(Screen.width * 0.25f, Screen.height * 0.4f, Screen.width * 0.5f, Screen.height * 0.2f), warnUpdateSDK)) 144 | { 145 | // 从服务器下载新的SDK 146 | downloadSDKFromServer(); 147 | } 148 | } 149 | } 150 | 151 | void Update() 152 | { 153 | 154 | 155 | } 156 | } 157 | #endif 158 | } 159 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/ClientSDKUpdater.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6af73cc460764dc4286f224e03d33dc7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/CustomDataTypes.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | tools = kbcmd 5 | */ 6 | 7 | namespace KBEngine 8 | { 9 | using UnityEngine; 10 | using System; 11 | using System.Collections; 12 | using System.Collections.Generic; 13 | 14 | 15 | 16 | public class DATATYPE_ENTITY_FORBID_COUNTER : DATATYPE_BASE 17 | { 18 | public ENTITY_FORBID_COUNTER createFromStreamEx(MemoryStream stream) 19 | { 20 | UInt32 size = stream.readUint32(); 21 | ENTITY_FORBID_COUNTER datas = new ENTITY_FORBID_COUNTER(); 22 | 23 | while(size > 0) 24 | { 25 | --size; 26 | datas.Add(stream.readInt8()); 27 | }; 28 | 29 | return datas; 30 | } 31 | 32 | public void addToStreamEx(Bundle stream, ENTITY_FORBID_COUNTER v) 33 | { 34 | stream.writeUint32((UInt32)v.Count); 35 | for(int i=0; i 0) 52 | { 53 | --size; 54 | datas.Add(stream.readInt32()); 55 | }; 56 | 57 | return datas; 58 | } 59 | 60 | public void addToStreamEx(Bundle stream, ENTITYID_LIST v) 61 | { 62 | stream.writeUint32((UInt32)v.Count); 63 | for(int i=0; i createFromStreamEx(MemoryStream stream) 126 | { 127 | UInt32 size = stream.readUint32(); 128 | List datas = new List(); 129 | 130 | while(size > 0) 131 | { 132 | --size; 133 | datas.Add(itemType.createFromStreamEx(stream)); 134 | }; 135 | 136 | return datas; 137 | } 138 | 139 | public void addToStreamEx(Bundle stream, List v) 140 | { 141 | stream.writeUint32((UInt32)v.Count); 142 | for(int i=0; i createFromStreamEx(MemoryStream stream) 175 | { 176 | UInt32 size = stream.readUint32(); 177 | List datas = new List(); 178 | 179 | while(size > 0) 180 | { 181 | --size; 182 | datas.Add(stream.readInt64()); 183 | }; 184 | 185 | return datas; 186 | } 187 | 188 | public void addToStreamEx(Bundle stream, List v) 189 | { 190 | stream.writeUint32((UInt32)v.Count); 191 | for(int i=0; i> createFromStreamEx(MemoryStream stream) 199 | { 200 | UInt32 size = stream.readUint32(); 201 | List> datas = new List>(); 202 | 203 | while(size > 0) 204 | { 205 | --size; 206 | datas.Add(itemType.createFromStreamEx(stream)); 207 | }; 208 | 209 | return datas; 210 | } 211 | 212 | public void addToStreamEx(Bundle stream, List> v) 213 | { 214 | stream.writeUint32((UInt32)v.Count); 215 | for(int i=0; i createFromStreamEx(MemoryStream stream) 259 | { 260 | UInt32 size = stream.readUint32(); 261 | List datas = new List(); 262 | 263 | while(size > 0) 264 | { 265 | --size; 266 | datas.Add(stream.readInt32()); 267 | }; 268 | 269 | return datas; 270 | } 271 | 272 | public void addToStreamEx(Bundle stream, List v) 273 | { 274 | stream.writeUint32((UInt32)v.Count); 275 | for(int i=0; i _profiles = new Dictionary(); 25 | #endif 26 | 27 | public static string getHead() 28 | { 29 | return "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") + "] "; 30 | } 31 | 32 | public static void INFO_MSG(object s) 33 | { 34 | if (DEBUGLEVEL.INFO >= debugLevel) 35 | Debug.Log(getHead() + s); 36 | } 37 | 38 | public static void DEBUG_MSG(object s) 39 | { 40 | if (DEBUGLEVEL.DEBUG >= debugLevel) 41 | Debug.Log(getHead() + s); 42 | } 43 | 44 | public static void WARNING_MSG(object s) 45 | { 46 | if (DEBUGLEVEL.WARNING >= debugLevel) 47 | Debug.LogWarning(getHead() + s); 48 | } 49 | 50 | public static void ERROR_MSG(object s) 51 | { 52 | if (DEBUGLEVEL.ERROR >= debugLevel) 53 | Debug.LogError(getHead() + s); 54 | } 55 | 56 | public static void profileStart(string name) 57 | { 58 | #if UNITY_EDITOR 59 | Profile p = null; 60 | if(!_profiles.TryGetValue(name, out p)) 61 | { 62 | p = new Profile(name); 63 | _profiles.Add(name, p); 64 | } 65 | 66 | p.start(); 67 | #endif 68 | } 69 | 70 | public static void profileEnd(string name) 71 | { 72 | #if UNITY_EDITOR 73 | _profiles[name].end(); 74 | #endif 75 | } 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Dbg.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b11dea249324a154fb6a45f172eb36c9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EncryptionFilter.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | public abstract class EncryptionFilter 9 | { 10 | public abstract void encrypt(MemoryStream stream); 11 | 12 | public abstract void decrypt(MemoryStream stream); 13 | public abstract void decrypt(byte[] buffer, int startIndex, int length); 14 | 15 | public abstract bool send(PacketSenderBase sender, MemoryStream stream); 16 | public abstract bool recv(MessageReaderBase reader, byte[] buffer, UInt32 rpos, UInt32 len); 17 | } 18 | 19 | 20 | class BlowfishFilter : EncryptionFilter 21 | { 22 | private Blowfish _blowfish = new Blowfish(); 23 | 24 | private MemoryStream _packet = new MemoryStream(); 25 | MemoryStream _enctyptStrem = new MemoryStream(); 26 | 27 | private UINT8 _padSize = 0; 28 | private UInt16 _packLen = 0; 29 | const UInt32 BLOCK_SIZE = 8; 30 | const UInt32 MIN_PACKET_SIZE = sizeof(UInt16) + 1 + BLOCK_SIZE; 31 | 32 | public BlowfishFilter() 33 | { 34 | } 35 | 36 | ~BlowfishFilter() 37 | { 38 | } 39 | 40 | public byte[] key() 41 | { 42 | return _blowfish.key(); 43 | } 44 | 45 | public override void encrypt(MemoryStream stream) 46 | { 47 | int padSize = 0; 48 | if (stream.length() % BLOCK_SIZE != 0) 49 | { 50 | padSize = (int)(BLOCK_SIZE - (stream.length() % BLOCK_SIZE)); 51 | stream.wpos += padSize; 52 | 53 | if(stream.wpos > MemoryStream.BUFFER_MAX) 54 | Debug.LogError("BlowfishFilter::encrypt: stream.wpos(" + stream.wpos + ") > MemoryStream.BUFFER_MAX(" + MemoryStream.BUFFER_MAX + ")!"); 55 | } 56 | 57 | _blowfish.encipher(stream.data(), (int)stream.length()); 58 | 59 | UInt16 packLen = (UInt16)(stream.length() + 1); 60 | _enctyptStrem.writeUint16(packLen); 61 | _enctyptStrem.writeUint8((UINT8)padSize); 62 | _enctyptStrem.append(stream.data(), (UInt32)stream.rpos, stream.length()); 63 | 64 | stream.swap(_enctyptStrem); 65 | _enctyptStrem.clear(); 66 | } 67 | 68 | public override void decrypt(MemoryStream stream) 69 | { 70 | _blowfish.decipher(stream.data(), stream.rpos, (int)stream.length()); 71 | } 72 | 73 | public override void decrypt(byte[] buffer, int startIndex, int length) 74 | { 75 | _blowfish.decipher(buffer, startIndex, length); 76 | } 77 | 78 | public override bool send(PacketSenderBase sender, MemoryStream stream) 79 | { 80 | if(!_blowfish.isGood()) 81 | { 82 | Dbg.ERROR_MSG("BlowfishFilter::send: Dropping packet, due to invalid filter"); 83 | return false; 84 | } 85 | 86 | encrypt(stream); 87 | return sender.send(stream); 88 | } 89 | 90 | public override bool recv(MessageReaderBase reader, byte[] buffer, UInt32 rpos, UInt32 len) 91 | { 92 | if (!_blowfish.isGood()) 93 | { 94 | Dbg.ERROR_MSG("BlowfishFilter::recv: Dropping packet, due to invalid filter"); 95 | return false; 96 | } 97 | 98 | if (_packet.length() == 0 && len >= MIN_PACKET_SIZE && BitConverter.ToUInt16(buffer, (int)rpos) - 1 == len - 3) 99 | { 100 | int packLen = BitConverter.ToUInt16(buffer, (int)rpos) - 1; 101 | int padSize = buffer[rpos + 2]; 102 | 103 | decrypt(buffer, (int)(rpos + 3), (int)(len - 3)); 104 | 105 | int length = packLen - padSize; 106 | if (reader != null) 107 | { 108 | reader.process(buffer, rpos + 3, (UInt32)length); 109 | } 110 | 111 | return true; 112 | } 113 | 114 | _packet.append(buffer, rpos, len); 115 | 116 | while(_packet.length() > 0) 117 | { 118 | UInt32 currLen = 0; 119 | int oldwpos = 0; 120 | if (_packLen <= 0) 121 | { 122 | // 如果满足一个最小包则尝试解包, 否则缓存这个包待与下一个包合并然后解包 123 | if (_packet.length() >= MIN_PACKET_SIZE) 124 | { 125 | _packLen = _packet.readUint16(); 126 | _padSize = _packet.readUint8(); 127 | 128 | _packLen -= 1; 129 | 130 | if (_packet.length() > _packLen) 131 | { 132 | currLen = (UInt32)(_packet.rpos + _packLen); 133 | oldwpos = _packet.wpos; 134 | _packet.wpos = (int)currLen; 135 | } 136 | else if (_packet.length() < _packLen) 137 | { 138 | return false; 139 | } 140 | } 141 | else 142 | { 143 | return false; 144 | } 145 | } 146 | else 147 | { 148 | // 如果上一次有做过解包行为但包还没有完整则继续处理 149 | // 如果包是完整的下面流程会解密, 如果有多余的内容需要将其剪裁出来待与下一个包合并 150 | if (_packet.length() > _packLen) 151 | { 152 | currLen = (UInt32)(_packet.rpos + _packLen); 153 | oldwpos = _packet.wpos; 154 | _packet.wpos = (int)currLen; 155 | } 156 | else if (_packet.length() < _packLen) 157 | { 158 | return false; 159 | } 160 | } 161 | 162 | decrypt(_packet); 163 | _packet.wpos -= _padSize; 164 | 165 | // 上面的流程能保证wpos之后不会有多余的包 166 | // 如果有多余的包数据会放在_recvStream 167 | if (reader != null) 168 | { 169 | reader.process(_packet.data(), (UInt32)_packet.rpos, _packet.length()); 170 | } 171 | 172 | if (currLen > 0) 173 | { 174 | _packet.rpos = (int)currLen; 175 | _packet.wpos = oldwpos; 176 | } 177 | else 178 | { 179 | _packet.clear(); 180 | } 181 | 182 | _packLen = 0; 183 | _padSize = 0; 184 | } 185 | 186 | return true; 187 | } 188 | } 189 | } 190 | 191 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EncryptionFilter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd4b0ffb0bf2df04eb071833df18c15b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Entity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fda3cf613809d294dac07a1cbdf9615e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCall.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | /* 9 | 实体的EntityCall 10 | 关于EntityCall请参考API手册中对它的描述 11 | https://github.com/kbengine/kbengine/tree/master/docs/api 12 | */ 13 | public class EntityCall 14 | { 15 | // EntityCall的类别 16 | public enum ENTITYCALL_TYPE 17 | { 18 | ENTITYCALL_TYPE_CELL = 0, // CELL_ENTITYCALL_TYPE 19 | ENTITYCALL_TYPE_BASE = 1 // BASE_ENTITYCALL_TYPE 20 | } 21 | 22 | public Int32 id = 0; 23 | public string className = ""; 24 | public ENTITYCALL_TYPE type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 25 | 26 | public Bundle bundle = null; 27 | 28 | public EntityCall(Int32 eid, string ename) 29 | { 30 | id = eid; 31 | className = ename; 32 | } 33 | 34 | public virtual void __init__() 35 | { 36 | } 37 | 38 | public virtual bool isBase() 39 | { 40 | return type == ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 41 | } 42 | 43 | public virtual bool isCell() 44 | { 45 | return type == ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 46 | } 47 | 48 | /* 49 | 创建新的mail 50 | */ 51 | public Bundle newCall() 52 | { 53 | if(bundle == null) 54 | bundle = Bundle.createObject(); 55 | 56 | if(isCell()) 57 | bundle.newMessage(Messages.messages["Baseapp_onRemoteCallCellMethodFromClient"]); 58 | else 59 | bundle.newMessage(Messages.messages["Entity_onRemoteMethodCall"]); 60 | 61 | bundle.writeInt32(this.id); 62 | 63 | return bundle; 64 | } 65 | 66 | /* 67 | 向服务端发送这个mail 68 | */ 69 | public void sendCall(Bundle inbundle) 70 | { 71 | if(inbundle == null) 72 | inbundle = bundle; 73 | 74 | inbundle.send(KBEngineApp.app.networkInterface()); 75 | 76 | if(inbundle == bundle) 77 | bundle = null; 78 | } 79 | 80 | public Bundle newCall(string methodName, UInt16 entitycomponentPropertyID = 0) 81 | { 82 | if(KBEngineApp.app.currserver == "loginapp") 83 | { 84 | Dbg.ERROR_MSG(className + "::newCall(" + methodName + "), currserver=!" + KBEngineApp.app.currserver); 85 | return null; 86 | } 87 | 88 | ScriptModule module = null; 89 | if(!EntityDef.moduledefs.TryGetValue(className, out module)) 90 | { 91 | Dbg.ERROR_MSG(className + "::newCall: entity-module(" + className + ") error, can not find from EntityDef.moduledefs"); 92 | return null; 93 | } 94 | 95 | Method method = null; 96 | 97 | if(isCell()) 98 | { 99 | method = module.cell_methods[methodName]; 100 | } 101 | else 102 | { 103 | method = module.base_methods[methodName]; 104 | } 105 | 106 | UInt16 methodID = method.methodUtype; 107 | 108 | newCall(); 109 | 110 | bundle.writeUint16(entitycomponentPropertyID); 111 | bundle.writeUint16(methodID); 112 | return bundle; 113 | } 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCall.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f41ba7330f78b3409519d8af46f7247 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallAccountBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Account.def 16 | public class EntityBaseEntityCall_AccountBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_AccountBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | public void reqAvatarList() 25 | { 26 | Bundle pBundle = newCall("reqAvatarList", 0); 27 | if(pBundle == null) 28 | return; 29 | 30 | sendCall(null); 31 | } 32 | 33 | public void reqCreateAvatar(Byte arg1, string arg2) 34 | { 35 | Bundle pBundle = newCall("reqCreateAvatar", 0); 36 | if(pBundle == null) 37 | return; 38 | 39 | bundle.writeUint8(arg1); 40 | bundle.writeUnicode(arg2); 41 | sendCall(null); 42 | } 43 | 44 | public void reqRemoveAvatar(string arg1) 45 | { 46 | Bundle pBundle = newCall("reqRemoveAvatar", 0); 47 | if(pBundle == null) 48 | return; 49 | 50 | bundle.writeUnicode(arg1); 51 | sendCall(null); 52 | } 53 | 54 | public void reqRemoveAvatarDBID(UInt64 arg1) 55 | { 56 | Bundle pBundle = newCall("reqRemoveAvatarDBID", 0); 57 | if(pBundle == null) 58 | return; 59 | 60 | bundle.writeUint64(arg1); 61 | sendCall(null); 62 | } 63 | 64 | public void selectAvatarGame(UInt64 arg1) 65 | { 66 | Bundle pBundle = newCall("selectAvatarGame", 0); 67 | if(pBundle == null) 68 | return; 69 | 70 | bundle.writeUint64(arg1); 71 | sendCall(null); 72 | } 73 | 74 | } 75 | 76 | public class EntityCellEntityCall_AccountBase : EntityCall 77 | { 78 | 79 | public EntityCellEntityCall_AccountBase(Int32 eid, string ename) : base(eid, ename) 80 | { 81 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallAccountBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 385a18d60b36b9a42808bef7ff8adc53 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallAvatarBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Avatar.def 16 | public class EntityBaseEntityCall_AvatarBase : EntityCall 17 | { 18 | public EntityBaseEntityCall_TestBase component1 = null; 19 | public EntityBaseEntityCall_TestBase component2 = null; 20 | public EntityBaseEntityCall_TestNoBaseBase component3 = null; 21 | 22 | public EntityBaseEntityCall_AvatarBase(Int32 eid, string ename) : base(eid, ename) 23 | { 24 | component1 = new EntityBaseEntityCall_TestBase(16, id); 25 | component2 = new EntityBaseEntityCall_TestBase(21, id); 26 | component3 = new EntityBaseEntityCall_TestNoBaseBase(22, id); 27 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 28 | } 29 | 30 | } 31 | 32 | public class EntityCellEntityCall_AvatarBase : EntityCall 33 | { 34 | public EntityCellEntityCall_TestBase component1 = null; 35 | public EntityCellEntityCall_TestBase component2 = null; 36 | public EntityCellEntityCall_TestNoBaseBase component3 = null; 37 | 38 | public EntityCellEntityCall_AvatarBase(Int32 eid, string ename) : base(eid, ename) 39 | { 40 | component1 = new EntityCellEntityCall_TestBase(16, id); 41 | component2 = new EntityCellEntityCall_TestBase(21, id); 42 | component3 = new EntityCellEntityCall_TestNoBaseBase(22, id); 43 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 44 | } 45 | 46 | public void dialog(Int32 arg1, UInt32 arg2) 47 | { 48 | Bundle pBundle = newCall("dialog", 0); 49 | if(pBundle == null) 50 | return; 51 | 52 | bundle.writeInt32(arg1); 53 | bundle.writeUint32(arg2); 54 | sendCall(null); 55 | } 56 | 57 | public void jump() 58 | { 59 | Bundle pBundle = newCall("jump", 0); 60 | if(pBundle == null) 61 | return; 62 | 63 | sendCall(null); 64 | } 65 | 66 | public void relive(Byte arg1) 67 | { 68 | Bundle pBundle = newCall("relive", 0); 69 | if(pBundle == null) 70 | return; 71 | 72 | bundle.writeUint8(arg1); 73 | sendCall(null); 74 | } 75 | 76 | public void requestPull() 77 | { 78 | Bundle pBundle = newCall("requestPull", 0); 79 | if(pBundle == null) 80 | return; 81 | 82 | sendCall(null); 83 | } 84 | 85 | public void useTargetSkill(Int32 arg1, Int32 arg2) 86 | { 87 | Bundle pBundle = newCall("useTargetSkill", 0); 88 | if(pBundle == null) 89 | return; 90 | 91 | bundle.writeInt32(arg1); 92 | bundle.writeInt32(arg2); 93 | sendCall(null); 94 | } 95 | 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallAvatarBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf96cbea9fc6161428cde3526c2495df 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallGateBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Gate.def 16 | public class EntityBaseEntityCall_GateBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_GateBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | } 25 | 26 | public class EntityCellEntityCall_GateBase : EntityCall 27 | { 28 | 29 | public EntityCellEntityCall_GateBase(Int32 eid, string ename) : base(eid, ename) 30 | { 31 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallGateBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b264709e805426e4aad1f0a6bc8311db 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallMonsterBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Monster.def 16 | public class EntityBaseEntityCall_MonsterBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_MonsterBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | } 25 | 26 | public class EntityCellEntityCall_MonsterBase : EntityCall 27 | { 28 | 29 | public EntityCellEntityCall_MonsterBase(Int32 eid, string ename) : base(eid, ename) 30 | { 31 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallMonsterBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 20ea76de3ca34d2478addb5da4bd0c3d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallNPCBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/NPC.def 16 | public class EntityBaseEntityCall_NPCBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_NPCBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | } 25 | 26 | public class EntityCellEntityCall_NPCBase : EntityCall 27 | { 28 | 29 | public EntityCellEntityCall_NPCBase(Int32 eid, string ename) : base(eid, ename) 30 | { 31 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallNPCBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed641cfb63362f444b2ef1172a27ec55 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpaceBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Space.def 16 | public class EntityBaseEntityCall_SpaceBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_SpaceBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | } 25 | 26 | public class EntityCellEntityCall_SpaceBase : EntityCall 27 | { 28 | 29 | public EntityCellEntityCall_SpaceBase(Int32 eid, string ename) : base(eid, ename) 30 | { 31 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpaceBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9250d51471244948a0c7e44bac925f9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpaceDuplicateBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/SpaceDuplicate.def 16 | public class EntityBaseEntityCall_SpaceDuplicateBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_SpaceDuplicateBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | } 25 | 26 | public class EntityCellEntityCall_SpaceDuplicateBase : EntityCall 27 | { 28 | 29 | public EntityCellEntityCall_SpaceDuplicateBase(Int32 eid, string ename) : base(eid, ename) 30 | { 31 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpaceDuplicateBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf5e5fef101c4f9408d0337250adada4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpacesBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Spaces.def 16 | public class EntityBaseEntityCall_SpacesBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_SpacesBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | } 25 | 26 | public class EntityCellEntityCall_SpacesBase : EntityCall 27 | { 28 | 29 | public EntityCellEntityCall_SpacesBase(Int32 eid, string ename) : base(eid, ename) 30 | { 31 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpacesBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f6cd804f463e20c4d99bd55701b67f24 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpawnPointBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/SpawnPoint.def 16 | public class EntityBaseEntityCall_SpawnPointBase : EntityCall 17 | { 18 | 19 | public EntityBaseEntityCall_SpawnPointBase(Int32 eid, string ename) : base(eid, ename) 20 | { 21 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 22 | } 23 | 24 | } 25 | 26 | public class EntityCellEntityCall_SpawnPointBase : EntityCall 27 | { 28 | 29 | public EntityCellEntityCall_SpawnPointBase(Int32 eid, string ename) : base(eid, ename) 30 | { 31 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallSpawnPointBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4cc30709972eeca44a4dca8795a4b2cd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallTestBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Test.def 16 | public class EntityBaseEntityCall_TestBase : EntityCall 17 | { 18 | public UInt16 entityComponentPropertyID = 0; 19 | 20 | public EntityBaseEntityCall_TestBase(UInt16 ecpID, Int32 eid) : base(eid, "Test") 21 | { 22 | entityComponentPropertyID = ecpID; 23 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 24 | } 25 | 26 | public void say(Int32 arg1) 27 | { 28 | Bundle pBundle = newCall("say", entityComponentPropertyID); 29 | if(pBundle == null) 30 | return; 31 | 32 | bundle.writeInt32(arg1); 33 | sendCall(null); 34 | } 35 | 36 | } 37 | 38 | public class EntityCellEntityCall_TestBase : EntityCall 39 | { 40 | public UInt16 entityComponentPropertyID = 0; 41 | 42 | public EntityCellEntityCall_TestBase(UInt16 ecpID, Int32 eid) : base(eid, "Test") 43 | { 44 | entityComponentPropertyID = ecpID; 45 | className = "Test"; 46 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 47 | } 48 | 49 | public void hello(Int32 arg1) 50 | { 51 | Bundle pBundle = newCall("hello", entityComponentPropertyID); 52 | if(pBundle == null) 53 | return; 54 | 55 | bundle.writeInt32(arg1); 56 | sendCall(null); 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallTestBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f11acab330724b54a918e69b20b72253 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallTestNoBaseBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/TestNoBase.def 16 | public class EntityBaseEntityCall_TestNoBaseBase : EntityCall 17 | { 18 | public UInt16 entityComponentPropertyID = 0; 19 | 20 | public EntityBaseEntityCall_TestNoBaseBase(UInt16 ecpID, Int32 eid) : base(eid, "TestNoBase") 21 | { 22 | entityComponentPropertyID = ecpID; 23 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE; 24 | } 25 | 26 | } 27 | 28 | public class EntityCellEntityCall_TestNoBaseBase : EntityCall 29 | { 30 | public UInt16 entityComponentPropertyID = 0; 31 | 32 | public EntityCellEntityCall_TestNoBaseBase(UInt16 ecpID, Int32 eid) : base(eid, "TestNoBase") 33 | { 34 | entityComponentPropertyID = ecpID; 35 | className = "TestNoBase"; 36 | type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL; 37 | } 38 | 39 | public void hello(Int32 arg1) 40 | { 41 | Bundle pBundle = newCall("hello", entityComponentPropertyID); 42 | if(pBundle == null) 43 | return; 44 | 45 | bundle.writeInt32(arg1); 46 | sendCall(null); 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityCallTestNoBaseBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73e8a8c8a667efe4e9435edd5447f51b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityComponent.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Threading; 8 | 9 | /* 10 | 实体组件模块基础类 11 | */ 12 | public class EntityComponent 13 | { 14 | public UInt16 entityComponentPropertyID = 0; 15 | public UInt16 componentType = 0; 16 | public Int32 ownerID = 0; 17 | public Entity owner = null; 18 | public string name_ = ""; 19 | 20 | public virtual void onAttached(Entity ownerEntity) 21 | { 22 | 23 | } 24 | 25 | public virtual void onDetached(Entity ownerEntity) 26 | { 27 | 28 | } 29 | 30 | public virtual void onEnterworld() 31 | { 32 | } 33 | 34 | public virtual void onLeaveworld() 35 | { 36 | } 37 | 38 | public virtual void onGetBase() 39 | { 40 | // 动态生成 41 | } 42 | 43 | public virtual void onGetCell() 44 | { 45 | // 动态生成 46 | } 47 | 48 | public virtual void onLoseCell() 49 | { 50 | // 动态生成 51 | } 52 | 53 | public virtual ScriptModule getScriptModule() 54 | { 55 | // 动态生成 56 | return null; 57 | } 58 | 59 | public virtual void onRemoteMethodCall(UInt16 methodUtype, MemoryStream stream) 60 | { 61 | // 动态生成 62 | } 63 | 64 | public virtual void onUpdatePropertys(UInt16 propUtype, MemoryStream stream, int maxCount) 65 | { 66 | // 动态生成 67 | } 68 | 69 | public virtual void callPropertysSetMethods() 70 | { 71 | // 动态生成 72 | } 73 | 74 | public virtual void createFromStream(MemoryStream stream) 75 | { 76 | componentType = (UInt16)stream.readInt32(); 77 | ownerID = stream.readInt32(); 78 | 79 | //UInt16 ComponentDescrsType; 80 | stream.readUint16(); 81 | 82 | UInt16 count = stream.readUint16(); 83 | 84 | if(count > 0) 85 | onUpdatePropertys(0, stream, count); 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityComponent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e6ee1e6ba791f848aa0454cab39a69e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/EntityDef.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df581ee7bf4eb144f93c2c8378493832 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Event.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a53438d582f483408f4bade85969039 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/GateBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 60121f9afc82ba246a14ef5b44d28956 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/KBEMain.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | using KBEngine; 5 | 6 | /* 7 | 可以理解为插件的入口模块 8 | 在这个入口中安装了需要监听的事件(installEvents),同时初始化KBEngine(initKBEngine) 9 | */ 10 | 11 | public class KBEMain : MonoBehaviour 12 | { 13 | public KBEngineApp gameapp = null; 14 | 15 | // 在unity3d界面中可见选项 16 | public DEBUGLEVEL debugLevel = DEBUGLEVEL.DEBUG; 17 | public bool isMultiThreads = false; 18 | public string ip = "127.0.0.1"; 19 | public int port = 20013; 20 | public KBEngineApp.CLIENT_TYPE clientType = KBEngineApp.CLIENT_TYPE.CLIENT_TYPE_MINI; 21 | public KBEngineApp.NETWORK_ENCRYPT_TYPE networkEncryptType = KBEngineApp.NETWORK_ENCRYPT_TYPE.ENCRYPT_TYPE_NONE; 22 | public int syncPlayerMS = 1000 / 10; 23 | 24 | public int threadUpdateHZ = 10 * 2; 25 | public int serverHeartbeatTick = 60; 26 | public int TCP_SEND_BUFFER_MAX = (int)KBEngine.NetworkInterfaceBase.TCP_PACKET_MAX; 27 | public int TCP_RECV_BUFFER_MAX = (int)KBEngine.NetworkInterfaceBase.TCP_PACKET_MAX; 28 | public int UDP_SEND_BUFFER_MAX = (int)KBEngine.NetworkInterfaceBase.UDP_PACKET_MAX; 29 | public int UDP_RECV_BUFFER_MAX = (int)KBEngine.NetworkInterfaceBase.UDP_PACKET_MAX; 30 | public bool useAliasEntityID = true; 31 | public bool isOnInitCallPropertysSetMethods = true; 32 | public bool forceDisableUDP = false; 33 | 34 | public bool automaticallyUpdateSDK = true; 35 | 36 | protected virtual void Awake() 37 | { 38 | DontDestroyOnLoad(transform.gameObject); 39 | } 40 | 41 | // Use this for initialization 42 | protected virtual void Start () 43 | { 44 | MonoBehaviour.print("clientapp::start()"); 45 | installEvents(); 46 | initKBEngine(); 47 | } 48 | 49 | public virtual void installEvents() 50 | { 51 | KBEngine.Event.registerOut(EventOutTypes.onVersionNotMatch, this, "onVersionNotMatch"); 52 | KBEngine.Event.registerOut(EventOutTypes.onScriptVersionNotMatch, this, "onScriptVersionNotMatch"); 53 | } 54 | 55 | public void onVersionNotMatch(string verInfo, string serVerInfo) 56 | { 57 | #if UNITY_EDITOR 58 | if(automaticallyUpdateSDK) 59 | gameObject.AddComponent(); 60 | #endif 61 | } 62 | 63 | public void onScriptVersionNotMatch(string verInfo, string serVerInfo) 64 | { 65 | #if UNITY_EDITOR 66 | if(automaticallyUpdateSDK) 67 | gameObject.AddComponent(); 68 | #endif 69 | } 70 | 71 | public virtual void initKBEngine() 72 | { 73 | // 如果此处发生错误,请查看 Assets\Scripts\kbe_scripts\if_Entity_error_use______git_submodule_update_____kbengine_plugins_______open_this_file_and_I_will_tell_you.cs 74 | 75 | Dbg.debugLevel = debugLevel; 76 | 77 | KBEngineArgs args = new KBEngineArgs(); 78 | 79 | args.ip = ip; 80 | args.port = port; 81 | args.clientType = clientType; 82 | args.networkEncryptType = networkEncryptType; 83 | args.syncPlayerMS = syncPlayerMS; 84 | args.threadUpdateHZ = threadUpdateHZ; 85 | args.serverHeartbeatTick = serverHeartbeatTick / 2; 86 | args.useAliasEntityID = useAliasEntityID; 87 | args.isOnInitCallPropertysSetMethods = isOnInitCallPropertysSetMethods; 88 | args.forceDisableUDP = forceDisableUDP; 89 | 90 | args.TCP_SEND_BUFFER_MAX = (UInt32)TCP_SEND_BUFFER_MAX; 91 | args.TCP_RECV_BUFFER_MAX = (UInt32)TCP_RECV_BUFFER_MAX; 92 | args.UDP_SEND_BUFFER_MAX = (UInt32)UDP_SEND_BUFFER_MAX; 93 | args.UDP_RECV_BUFFER_MAX = (UInt32)UDP_RECV_BUFFER_MAX; 94 | 95 | args.isMultiThreads = isMultiThreads; 96 | 97 | if(isMultiThreads) 98 | gameapp = new KBEngineAppThread(args); 99 | else 100 | gameapp = new KBEngineApp(args); 101 | } 102 | 103 | protected virtual void OnDestroy() 104 | { 105 | MonoBehaviour.print("clientapp::OnDestroy(): begin"); 106 | if (KBEngineApp.app != null) 107 | { 108 | KBEngineApp.app.destroy(); 109 | KBEngineApp.app = null; 110 | } 111 | KBEngine.Event.clear(); 112 | MonoBehaviour.print("clientapp::OnDestroy(): end"); 113 | } 114 | 115 | protected virtual void FixedUpdate () 116 | { 117 | KBEUpdate(); 118 | } 119 | 120 | public virtual void KBEUpdate() 121 | { 122 | // 单线程模式必须自己调用 123 | if(!isMultiThreads) 124 | gameapp.process(); 125 | 126 | KBEngine.Event.processOutEvents(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/KBEMain.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad6b5538ac439864b90304b81f7c0a9b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/KBETypes.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0da90f7dba4d20049b98494402cb9506 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/KBEngine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 408d2189a5f3723438f7e9bb9bda0b6b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/KBEngineArgs.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using System; 4 | 5 | using MessageLengthEx = System.UInt32; 6 | 7 | /* 8 | 初始化KBEngine的参数类 9 | */ 10 | public class KBEngineArgs 11 | { 12 | // 登录ip和端口 13 | public string ip = "127.0.0.1"; 14 | public int port = 20013; 15 | 16 | // 客户端类型 17 | // Reference: http://www.kbengine.org/docs/programming/clientsdkprogramming.html, client types 18 | public KBEngineApp.CLIENT_TYPE clientType = KBEngineApp.CLIENT_TYPE.CLIENT_TYPE_MINI; 19 | 20 | //加密通信类型 21 | public KBEngineApp.NETWORK_ENCRYPT_TYPE networkEncryptType = KBEngineApp.NETWORK_ENCRYPT_TYPE.ENCRYPT_TYPE_NONE; 22 | 23 | // Allow synchronization role position information to the server 24 | // 是否开启自动同步玩家信息到服务端,信息包括位置与方向,毫秒 25 | // 非高实时类游戏不需要开放这个选项 26 | public int syncPlayerMS = 100; 27 | 28 | // 是否使用别名机制 29 | // 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致 30 | public bool useAliasEntityID = true; 31 | 32 | // 在Entity初始化时是否触发属性的set_*事件(callPropertysSetMethods) 33 | public bool isOnInitCallPropertysSetMethods = true; 34 | 35 | // 发送缓冲大小 36 | public MessageLengthEx TCP_SEND_BUFFER_MAX = NetworkInterfaceBase.TCP_PACKET_MAX; 37 | public MessageLengthEx UDP_SEND_BUFFER_MAX = 128; 38 | 39 | // 接收缓冲区大小 40 | public MessageLengthEx TCP_RECV_BUFFER_MAX = NetworkInterfaceBase.TCP_PACKET_MAX; 41 | public MessageLengthEx UDP_RECV_BUFFER_MAX = 128; 42 | 43 | // 是否多线程启动 44 | public bool isMultiThreads = false; 45 | 46 | // 只在多线程模式启用 47 | // 线程主循环处理频率 48 | public int threadUpdateHZ = 10; 49 | 50 | // 强制禁用UDP通讯 51 | public bool forceDisableUDP = false; 52 | 53 | // 心跳频率(tick数) 54 | public int serverHeartbeatTick = 15; 55 | 56 | public int getTCPRecvBufferSize() 57 | { 58 | return (int)TCP_RECV_BUFFER_MAX; 59 | } 60 | 61 | public int getTCPSendBufferSize() 62 | { 63 | return (int)TCP_SEND_BUFFER_MAX; 64 | } 65 | 66 | public int getUDPRecvBufferSize() 67 | { 68 | return (int)UDP_RECV_BUFFER_MAX; 69 | } 70 | 71 | public int getUDPSendBufferSize() 72 | { 73 | return (int)UDP_SEND_BUFFER_MAX; 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/KBEngineArgs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3b08dd03df3322478018d976df639e2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Math.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using KBEngine; 3 | using System; 4 | using System.Collections; 5 | 6 | namespace KBEngine 7 | { 8 | 9 | /* 10 | KBEngine的数学相关模块 11 | */ 12 | public class KBEMath 13 | { 14 | public static float KBE_FLT_MAX = float.MaxValue; 15 | 16 | public static float int82angle(SByte angle, bool half) 17 | { 18 | float halfv = 128f; 19 | if(half == true) 20 | halfv = 254f; 21 | 22 | halfv = ((float)angle) * ((float)System.Math.PI / halfv); 23 | return halfv; 24 | } 25 | 26 | public static bool almostEqual(float f1, float f2, float epsilon) 27 | { 28 | return Math.Abs( f1 - f2 ) < epsilon; 29 | } 30 | 31 | public static bool isNumeric(object v) 32 | { 33 | return v is sbyte || v is byte || 34 | v is short || v is ushort || 35 | v is int || v is uint || 36 | v is long || v is ulong || 37 | v is char || v is decimal || v is float || 38 | v is double || v is Int16 || v is Int64 || 39 | v is UInt16 || v is UInt64 || 40 | v is Boolean || v is bool; 41 | } 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Math.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a0c0f6a7aa107d4286c6ab2261d0367 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MemoryStream.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88ca295c95e2ae34cbdf9875b80a9697 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MessageReaderBase.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | 6 | using MessageID = System.UInt16; 7 | using MessageLength = System.UInt16; 8 | using MessageLengthEx = System.UInt32; 9 | 10 | /* 11 | 消息阅读模块 12 | 从数据包流中分析出所有的消息包并将其交给对应的消息处理函数 13 | */ 14 | public abstract class MessageReaderBase 15 | { 16 | public abstract void process(byte[] datas, MessageLengthEx offset, MessageLengthEx length); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MessageReaderBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4e0d601a8214744d9ae2797665f8843 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MessageReaderKCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | 6 | using MessageID = System.UInt16; 7 | using MessageLength = System.UInt16; 8 | using MessageLengthEx = System.UInt32; 9 | 10 | /* 11 | 消息阅读模块 12 | 从数据包流中分析出所有的消息包并将其交给对应的消息处理函数 13 | 由于KCP是模拟的TCP流,一个UDP包中可能包含一个或者多个包,并且最后一个包可能是不完整的,因此直接继承MessageReaderTCP 14 | */ 15 | public class MessageReaderKCP : MessageReaderTCP 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MessageReaderKCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce4cc52cacccf584abc6697985d41542 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MessageReaderTCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | 6 | using MessageID = System.UInt16; 7 | using MessageLength = System.UInt16; 8 | using MessageLengthEx = System.UInt32; 9 | 10 | /* 11 | 消息阅读模块 12 | 从数据包流中分析出所有的消息包并将其交给对应的消息处理函数 13 | */ 14 | public class MessageReaderTCP : MessageReaderBase 15 | { 16 | enum READ_STATE 17 | { 18 | // 消息ID 19 | READ_STATE_MSGID = 0, 20 | 21 | // 消息的长度65535以内 22 | READ_STATE_MSGLEN = 1, 23 | 24 | // 当上面的消息长度都无法到达要求时使用扩展长度 25 | // uint32 26 | READ_STATE_MSGLEN_EX = 2, 27 | 28 | // 消息的内容 29 | READ_STATE_BODY = 3 30 | } 31 | 32 | private MessageID msgid = 0; 33 | private MessageLength msglen = 0; 34 | private MessageLengthEx expectSize = 2; 35 | private READ_STATE state = READ_STATE.READ_STATE_MSGID; 36 | private MemoryStream stream = new MemoryStream(); 37 | 38 | public MessageReaderTCP() 39 | { 40 | } 41 | 42 | public override void process(byte[] datas, MessageLengthEx offset, MessageLengthEx length) 43 | { 44 | MessageLengthEx totallen = offset; 45 | 46 | while(length > 0 && expectSize > 0) 47 | { 48 | if(state == READ_STATE.READ_STATE_MSGID) 49 | { 50 | if(length >= expectSize) 51 | { 52 | Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); 53 | totallen += expectSize; 54 | stream.wpos += (int)expectSize; 55 | length -= expectSize; 56 | msgid = stream.readUint16(); 57 | stream.clear(); 58 | 59 | Message msg = Messages.clientMessages[msgid]; 60 | 61 | if(msg.msglen == -1) 62 | { 63 | state = READ_STATE.READ_STATE_MSGLEN; 64 | expectSize = 2; 65 | } 66 | else if(msg.msglen == 0) 67 | { 68 | // 如果是0个参数的消息,那么没有后续内容可读了,处理本条消息并且直接跳到下一条消息 69 | #if UNITY_EDITOR 70 | Dbg.profileStart(msg.name); 71 | #endif 72 | 73 | msg.handleMessage(stream); 74 | 75 | #if UNITY_EDITOR 76 | Dbg.profileEnd(msg.name); 77 | #endif 78 | 79 | state = READ_STATE.READ_STATE_MSGID; 80 | expectSize = 2; 81 | } 82 | else 83 | { 84 | expectSize = (MessageLengthEx)msg.msglen; 85 | state = READ_STATE.READ_STATE_BODY; 86 | } 87 | } 88 | else 89 | { 90 | Array.Copy(datas, totallen, stream.data(), stream.wpos, length); 91 | stream.wpos += (int)length; 92 | expectSize -= length; 93 | break; 94 | } 95 | } 96 | else if(state == READ_STATE.READ_STATE_MSGLEN) 97 | { 98 | if(length >= expectSize) 99 | { 100 | Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); 101 | totallen += expectSize; 102 | stream.wpos += (int)expectSize; 103 | length -= expectSize; 104 | 105 | msglen = stream.readUint16(); 106 | stream.clear(); 107 | 108 | // 长度扩展 109 | if(msglen >= 65535) 110 | { 111 | state = READ_STATE.READ_STATE_MSGLEN_EX; 112 | expectSize = 4; 113 | } 114 | else 115 | { 116 | state = READ_STATE.READ_STATE_BODY; 117 | expectSize = msglen; 118 | } 119 | } 120 | else 121 | { 122 | Array.Copy(datas, totallen, stream.data(), stream.wpos, length); 123 | stream.wpos += (int)length; 124 | expectSize -= length; 125 | break; 126 | } 127 | } 128 | else if(state == READ_STATE.READ_STATE_MSGLEN_EX) 129 | { 130 | if(length >= expectSize) 131 | { 132 | Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); 133 | totallen += expectSize; 134 | stream.wpos += (int)expectSize; 135 | length -= expectSize; 136 | 137 | expectSize = stream.readUint32(); 138 | stream.clear(); 139 | 140 | state = READ_STATE.READ_STATE_BODY; 141 | } 142 | else 143 | { 144 | Array.Copy(datas, totallen, stream.data(), stream.wpos, length); 145 | stream.wpos += (int)length; 146 | expectSize -= length; 147 | break; 148 | } 149 | } 150 | else if(state == READ_STATE.READ_STATE_BODY) 151 | { 152 | if(length >= expectSize) 153 | { 154 | stream.append (datas, totallen, expectSize); 155 | totallen += expectSize; 156 | length -= expectSize; 157 | 158 | Message msg = Messages.clientMessages[msgid]; 159 | 160 | #if UNITY_EDITOR 161 | Dbg.profileStart(msg.name); 162 | #endif 163 | 164 | msg.handleMessage(stream); 165 | 166 | #if UNITY_EDITOR 167 | Dbg.profileEnd(msg.name); 168 | #endif 169 | 170 | stream.clear(); 171 | 172 | state = READ_STATE.READ_STATE_MSGID; 173 | expectSize = 2; 174 | } 175 | else 176 | { 177 | stream.append (datas, totallen, length); 178 | expectSize -= length; 179 | break; 180 | } 181 | } 182 | } 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MessageReaderTCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5850c20a68853be4796b04c56aa42165 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Messages.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfb32370343d2004c9de86018507b9aa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Method.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | /* 9 | 实体定义的方法模块 10 | 抽象出一个def文件中定义的方法,改模块类提供了该方法的相关描述信息 11 | 例如:方法的参数、方法的id、方法对应脚本的handler 12 | */ 13 | public class Method 14 | { 15 | public string name = ""; 16 | public UInt16 methodUtype = 0; 17 | public Int16 aliasID = -1; 18 | public List args = null; 19 | 20 | public Method() 21 | { 22 | 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Method.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 580c3e7331c42ac4385a6065dadc2bae 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/MonsterBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5789c493eb32f0e40aec2d97201ef6b8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/NPCBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f15a9cfdc931cd54ebef20859fa544bb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/NetworkInterfaceBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e0fe4fa3e32d6543b277127e00e7d00 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/NetworkInterfaceKCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Net.Sockets; 6 | using System.Net; 7 | using System.Collections; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using System.Text.RegularExpressions; 11 | using System.Threading; 12 | 13 | using MessageID = System.UInt16; 14 | using MessageLength = System.UInt16; 15 | 16 | /// 17 | /// 网络模块 18 | /// 处理连接、收发数据 19 | /// 20 | public class NetworkInterfaceKCP : NetworkInterfaceBase 21 | { 22 | private Deps.KCP kcp_ = null; 23 | public UInt32 connID; 24 | public UInt32 nextTickKcpUpdate = 0; 25 | public EndPoint remoteEndPint = null; 26 | 27 | protected override Socket createSocket() 28 | { 29 | Socket pSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); 30 | return pSocket; 31 | } 32 | 33 | protected override PacketReceiverBase createPacketReceiver() 34 | { 35 | return new PacketReceiverKCP(this); 36 | } 37 | 38 | protected override PacketSenderBase createPacketSender() 39 | { 40 | return new PacketSenderKCP(this); 41 | } 42 | 43 | public override void reset() 44 | { 45 | finiKCP(); 46 | base.reset(); 47 | } 48 | 49 | public override void close() 50 | { 51 | finiKCP(); 52 | base.close(); 53 | } 54 | 55 | public override bool valid() 56 | { 57 | return ((kcp_ != null) && (_socket != null) && connected); 58 | } 59 | 60 | protected void outputKCP(byte[] data, int size, object userData) 61 | { 62 | if (!valid()) 63 | { 64 | throw new ArgumentException("invalid socket!"); 65 | } 66 | 67 | if (_packetSender == null) 68 | _packetSender = createPacketSender(); 69 | 70 | ((PacketSenderKCP)_packetSender).sendto(data, size); 71 | } 72 | 73 | bool initKCP() 74 | { 75 | kcp_ = new Deps.KCP(connID, this); 76 | kcp_.SetOutput(outputKCP); 77 | 78 | kcp_.SetMTU(1400); 79 | kcp_.WndSize(KBEngineApp.app.getInitArgs().getUDPSendBufferSize(), KBEngineApp.app.getInitArgs().getUDPRecvBufferSize()); 80 | kcp_.NoDelay(1, 10, 2, 1); 81 | kcp_.SetMinRTO(10); 82 | 83 | nextTickKcpUpdate = 0; 84 | return true; 85 | } 86 | 87 | bool finiKCP() 88 | { 89 | if(kcp_ != null) 90 | { 91 | kcp_.SetOutput(null); 92 | kcp_.Release(); 93 | kcp_ = null; 94 | } 95 | 96 | remoteEndPint = null; 97 | connID = 0; 98 | nextTickKcpUpdate = 0; 99 | return true; 100 | } 101 | 102 | public Deps.KCP kcp() 103 | { 104 | return kcp_; 105 | } 106 | 107 | public override bool send(MemoryStream stream) 108 | { 109 | if (!valid()) 110 | { 111 | throw new ArgumentException("invalid socket!"); 112 | } 113 | 114 | if(_filter != null) 115 | { 116 | _filter.encrypt(stream); 117 | } 118 | 119 | nextTickKcpUpdate = 0; 120 | return kcp_.Send(stream.data(), stream.rpos, (int)stream.length()) >= 0; 121 | } 122 | 123 | public override void process() 124 | { 125 | if (!valid()) 126 | return; 127 | 128 | uint current = Deps.KCP.TimeUtils.iclock(); 129 | if(current >= nextTickKcpUpdate) 130 | { 131 | kcp_.Update(current); 132 | nextTickKcpUpdate = kcp_.Check(current); 133 | } 134 | 135 | if (_packetReceiver != null) 136 | _packetReceiver.process(); 137 | } 138 | 139 | protected override void onAsyncConnectCB(ConnectState state) 140 | { 141 | if(state.error.Length > 0 || !initKCP()) 142 | return; 143 | 144 | connected = true; 145 | remoteEndPint = new IPEndPoint(IPAddress.Parse(state.connectIP), state.connectPort); 146 | } 147 | 148 | protected override void onAsyncConnect(ConnectState state) 149 | { 150 | try 151 | { 152 | //state.socket.Connect(state.connectIP, state.connectPort); 153 | 154 | byte[] helloPacket = System.Text.Encoding.ASCII.GetBytes(UDP_HELLO); 155 | state.socket.SendTo(helloPacket, helloPacket.Length, SocketFlags.None, new IPEndPoint(IPAddress.Parse(state.connectIP), state.connectPort)); 156 | 157 | ArrayList readList = new ArrayList(); 158 | readList.Add(state.socket); 159 | Socket.Select(readList, null, null, 3000000); 160 | 161 | if(readList.Count > 0) 162 | { 163 | byte[] buffer = new byte[UDP_PACKET_MAX]; 164 | int length = state.socket.Receive(buffer); 165 | 166 | if (length <= 0) 167 | { 168 | Dbg.ERROR_MSG(string.Format("NetworkInterfaceKCP::_asyncConnect(), failed to connect to '{0}:{1}'! receive hello-ack error!", state.connectIP, state.connectPort)); 169 | state.error = "receive hello-ack error!"; 170 | } 171 | else 172 | { 173 | MemoryStream stream = new MemoryStream(); 174 | Array.Copy(buffer, 0, stream.data(), stream.wpos, length); 175 | stream.wpos = length; 176 | string helloAck = stream.readString(); 177 | string versionString = stream.readString(); 178 | uint conv = stream.readUint32(); 179 | 180 | if (helloAck != UDP_HELLO_ACK) 181 | { 182 | Dbg.ERROR_MSG(string.Format("NetworkInterfaceKCP::_asyncConnect(), failed to connect to '{0}:{1}'! receive hello-ack({2}!={3}) mismatch!", 183 | state.connectIP, state.connectPort, helloAck, UDP_HELLO_ACK)); 184 | 185 | state.error = "hello-ack mismatch!"; 186 | } 187 | else if(KBEngineApp.app.serverVersion != versionString) 188 | { 189 | Dbg.ERROR_MSG(string.Format("NetworkInterfaceKCP::_asyncConnect(), failed to connect to '{0}:{1}'! version({2}!={3}) mismatch!", 190 | state.connectIP, state.connectPort, versionString, KBEngineApp.app.serverVersion)); 191 | 192 | state.error = "version mismatch!"; 193 | } 194 | else if(conv == 0) 195 | { 196 | Dbg.ERROR_MSG(string.Format("NetworkInterfaceKCP::_asyncConnect(), failed to connect to '{0}:{1}'! conv is 0!", 197 | state.connectIP, state.connectPort)); 198 | 199 | state.error = "kcp conv error!"; 200 | } 201 | 202 | ((NetworkInterfaceKCP)state.networkInterface).connID = conv; 203 | } 204 | } 205 | else 206 | { 207 | Dbg.ERROR_MSG(string.Format("NetworkInterfaceKCP::_asyncConnect(), connect to '{0}:{1}' timeout!'", state.connectIP, state.connectPort)); 208 | state.error = "timeout!"; 209 | } 210 | } 211 | catch (Exception e) 212 | { 213 | Dbg.ERROR_MSG(string.Format("NetworkInterfaceKCP::_asyncConnect(), connect to '{0}:{1}' fault! error = '{2}'", state.connectIP, state.connectPort, e)); 214 | state.error = e.ToString(); 215 | } 216 | } 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/NetworkInterfaceKCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13aaf1bccbe7a5c4e96d4c09665770ed 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/NetworkInterfaceTCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Net.Sockets; 6 | using System.Net; 7 | using System.Collections; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using System.Text.RegularExpressions; 11 | using System.Threading; 12 | 13 | using MessageID = System.UInt16; 14 | using MessageLength = System.UInt16; 15 | 16 | /// 17 | /// 网络模块 18 | /// 处理连接、收发数据 19 | /// 20 | public class NetworkInterfaceTCP : NetworkInterfaceBase 21 | { 22 | public override bool valid() 23 | { 24 | return ((_socket != null) && (_socket.Connected == true)); 25 | } 26 | 27 | protected override Socket createSocket() 28 | { 29 | // Security.PrefetchSocketPolicy(ip, 843); 30 | Socket pSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 31 | pSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, KBEngineApp.app.getInitArgs().getTCPRecvBufferSize() * 2); 32 | pSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, SocketOptionName.SendBuffer, KBEngineApp.app.getInitArgs().getTCPSendBufferSize() * 2); 33 | pSocket.NoDelay = true; 34 | //pSocket.Blocking = false; 35 | return pSocket; 36 | } 37 | 38 | protected override PacketReceiverBase createPacketReceiver() 39 | { 40 | return new PacketReceiverTCP(this); 41 | } 42 | 43 | protected override PacketSenderBase createPacketSender() 44 | { 45 | return new PacketSenderTCP(this); 46 | } 47 | 48 | protected override void onAsyncConnect(ConnectState state) 49 | { 50 | try 51 | { 52 | state.socket.Connect(state.connectIP, state.connectPort); 53 | } 54 | catch (Exception e) 55 | { 56 | Dbg.ERROR_MSG(string.Format("NetworkInterfaceTCP::_asyncConnect(), connect to '{0}:{1}' fault! error = '{2}'", state.connectIP, state.connectPort, e)); 57 | state.error = e.ToString(); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/NetworkInterfaceTCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e0383fe75c02e746992acc6c45efb0c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/ObjectPool.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | 7 | 8 | namespace KBEngine 9 | { 10 | /// 11 | /// 简单的对象池 12 | /// 13 | /// 对象类型 14 | public class ObjectPool where T : new() 15 | { 16 | private static Stack _objects = new Stack(); 17 | private static T v; 18 | 19 | public static T createObject() 20 | { 21 | lock (_objects) 22 | { 23 | if (_objects.Count > 0) 24 | { 25 | v = _objects.Pop(); 26 | return v; 27 | } 28 | else 29 | { 30 | return new T(); 31 | } 32 | } 33 | } 34 | 35 | public static void reclaimObject(T item) 36 | { 37 | lock (_objects) 38 | { 39 | _objects.Push(item); 40 | } 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/ObjectPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7195f5414262cbd48a325ddb65ec7986 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketReceiverBase.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using System; 4 | using System.Net.Sockets; 5 | using System.Net; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading; 11 | 12 | using MessageID = System.UInt16; 13 | using MessageLength = System.UInt16; 14 | 15 | /* 16 | 包接收模块(与服务端网络部分的名称对应) 17 | 处理网络数据的接收 18 | */ 19 | public abstract class PacketReceiverBase 20 | { 21 | public delegate void AsyncReceiveMethod(); 22 | protected MessageReaderBase _messageReader = null; 23 | protected NetworkInterfaceBase _networkInterface = null; 24 | 25 | public PacketReceiverBase(NetworkInterfaceBase networkInterface) 26 | { 27 | _networkInterface = networkInterface; 28 | } 29 | 30 | ~PacketReceiverBase() 31 | { 32 | } 33 | 34 | public NetworkInterfaceBase networkInterface() 35 | { 36 | return _networkInterface; 37 | } 38 | 39 | public abstract void process(); 40 | 41 | public virtual void startRecv() 42 | { 43 | AsyncReceiveMethod asyncReceiveMethod = new AsyncReceiveMethod(this._asyncReceive); 44 | asyncReceiveMethod.BeginInvoke(new AsyncCallback(_onRecv), asyncReceiveMethod); 45 | } 46 | 47 | protected abstract void _asyncReceive(); 48 | 49 | private void _onRecv(IAsyncResult ar) 50 | { 51 | try 52 | { 53 | AsyncReceiveMethod caller = (AsyncReceiveMethod)ar.AsyncState; 54 | caller.EndInvoke(ar); 55 | } 56 | catch(ObjectDisposedException) 57 | { 58 | //通常出现这个错误, 是因为longin_baseapp时, networkInterface已经reset, _packetReceiver被置为null, 而之后刚好该回调被调用 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketReceiverBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26615527d652bca4b8cd9d1e144fb66a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketReceiverKCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using System; 4 | using System.Net.Sockets; 5 | using System.Net; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading; 11 | 12 | using MessageID = System.UInt16; 13 | using MessageLength = System.UInt16; 14 | using MessageLengthEx = System.UInt32; 15 | 16 | /* 17 | 包接收模块(与服务端网络部分的名称对应) 18 | 处理网络数据的接收 19 | */ 20 | public class PacketReceiverKCP : PacketReceiverBase 21 | { 22 | private byte[] _buffer; 23 | private Deps.KCP kcp_ = null; 24 | 25 | public PacketReceiverKCP(NetworkInterfaceBase networkInterface) : base(networkInterface) 26 | { 27 | _buffer = new byte[MessageLength.MaxValue + (Deps.KCP.IKCP_OVERHEAD * 2)]; 28 | _messageReader = new MessageReaderKCP(); 29 | 30 | kcp_ = ((NetworkInterfaceKCP)networkInterface).kcp(); 31 | } 32 | 33 | ~PacketReceiverKCP() 34 | { 35 | kcp_ = null; 36 | Dbg.DEBUG_MSG("PacketReceiverKCP::~PacketReceiverKCP(), destroyed!"); 37 | } 38 | 39 | public override void process() 40 | { 41 | Socket socket = _networkInterface.sock(); 42 | 43 | while (socket.Available > 0) 44 | { 45 | int length = 0; 46 | 47 | try 48 | { 49 | length = socket.Receive(_buffer); 50 | } 51 | catch (Exception e) 52 | { 53 | Dbg.ERROR_MSG("PacketReceiverKCP::process: " + e.ToString()); 54 | Event.fireIn("_closeNetwork", new object[] { _networkInterface }); 55 | return; 56 | } 57 | 58 | if (length <= 0) 59 | { 60 | Dbg.WARNING_MSG("PacketReceiverKCP::_asyncReceive(): KCP Receive <= 0!"); 61 | return; 62 | } 63 | 64 | ((NetworkInterfaceKCP)_networkInterface).nextTickKcpUpdate = 0; 65 | if(kcp_.Input(_buffer, 0, length) < 0) 66 | { 67 | Dbg.WARNING_MSG(string.Format("PacketReceiverKCP::_asyncReceive(): KCP Input get {0}!", length)); 68 | return; 69 | } 70 | 71 | while (true) 72 | { 73 | length = kcp_.Recv(_buffer, 0, _buffer.Length); 74 | if (length < 0) 75 | { 76 | break; 77 | } 78 | 79 | if (_networkInterface.fileter() != null) 80 | { 81 | _networkInterface.fileter().recv(_messageReader, _buffer, 0, (MessageLengthEx)length); 82 | } 83 | else 84 | { 85 | _messageReader.process(_buffer, 0, (MessageLengthEx)length); 86 | } 87 | } 88 | } 89 | } 90 | 91 | public override void startRecv() 92 | { 93 | //var v = new AsyncReceiveMethod(this._asyncReceive); 94 | //v.BeginInvoke(new AsyncCallback(_onRecv), null); 95 | } 96 | 97 | protected override void _asyncReceive() 98 | { 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketReceiverKCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9ee5825e49510349af2b1e721ec571b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketReceiverTCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using System; 4 | using System.Net.Sockets; 5 | using System.Net; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading; 11 | 12 | using MessageID = System.UInt16; 13 | using MessageLength = System.UInt16; 14 | 15 | /* 16 | 包接收模块(与服务端网络部分的名称对应) 17 | 处理网络数据的接收 18 | */ 19 | public class PacketReceiverTCP : PacketReceiverBase 20 | { 21 | private byte[] _buffer; 22 | 23 | // socket向缓冲区写的起始位置 24 | int _wpos = 0; 25 | 26 | // 主线程读取数据的起始位置 27 | int _rpos = 0; 28 | 29 | public PacketReceiverTCP(NetworkInterfaceBase networkInterface) : base(networkInterface) 30 | { 31 | _buffer = new byte[KBEngineApp.app.getInitArgs().TCP_RECV_BUFFER_MAX]; 32 | _messageReader = new MessageReaderTCP(); 33 | } 34 | 35 | ~PacketReceiverTCP() 36 | { 37 | Dbg.DEBUG_MSG("PacketReceiverTCP::~PacketReceiverTCP(), destroyed!"); 38 | } 39 | 40 | public override void process() 41 | { 42 | int t_wpos = Interlocked.Add(ref _wpos, 0); 43 | 44 | if (_rpos < t_wpos) 45 | { 46 | if (_networkInterface.fileter() != null) 47 | { 48 | _networkInterface.fileter().recv(_messageReader, _buffer, (UInt32)_rpos, (UInt32)(t_wpos - _rpos)); 49 | } 50 | else 51 | { 52 | _messageReader.process(_buffer, (UInt32)_rpos, (UInt32)(t_wpos - _rpos)); 53 | } 54 | 55 | Interlocked.Exchange(ref _rpos, t_wpos); 56 | } 57 | else if (t_wpos < _rpos) 58 | { 59 | if (_networkInterface.fileter() != null) 60 | { 61 | _networkInterface.fileter().recv(_messageReader, _buffer, (UInt32)_rpos, (UInt32)(_buffer.Length - _rpos)); 62 | _networkInterface.fileter().recv(_messageReader, _buffer, (UInt32)0, (UInt32)t_wpos); 63 | } 64 | else 65 | { 66 | _messageReader.process(_buffer, (UInt32)_rpos, (UInt32)(_buffer.Length - _rpos)); 67 | _messageReader.process(_buffer, (UInt32)0, (UInt32)t_wpos); 68 | } 69 | 70 | Interlocked.Exchange(ref _rpos, t_wpos); 71 | } 72 | else 73 | { 74 | // 没有可读数据 75 | } 76 | } 77 | 78 | int _free() 79 | { 80 | int t_rpos = Interlocked.Add(ref _rpos, 0); 81 | 82 | if (_wpos == _buffer.Length) 83 | { 84 | if (t_rpos == 0) 85 | { 86 | return 0; 87 | } 88 | 89 | Interlocked.Exchange(ref _wpos, 0); 90 | } 91 | 92 | if (t_rpos <= _wpos) 93 | { 94 | return _buffer.Length - _wpos; 95 | } 96 | 97 | return t_rpos - _wpos - 1; 98 | } 99 | 100 | protected override void _asyncReceive() 101 | { 102 | if (_networkInterface == null || !_networkInterface.valid()) 103 | { 104 | Dbg.WARNING_MSG("PacketReceiverTCP::_asyncReceive(): network interface invalid!"); 105 | return; 106 | } 107 | 108 | var socket = _networkInterface.sock(); 109 | 110 | while (true) 111 | { 112 | // 必须有空间可写,否则我们阻塞在线程中直到有空间为止 113 | int first = 0; 114 | int space = _free(); 115 | 116 | while (space == 0) 117 | { 118 | if (first > 0) 119 | { 120 | if (first > 1000) 121 | { 122 | Dbg.ERROR_MSG("PacketReceiverTCP::_asyncReceive(): no space!"); 123 | Event.fireIn("_closeNetwork", new object[] { _networkInterface }); 124 | return; 125 | } 126 | 127 | Dbg.WARNING_MSG("PacketReceiverTCP::_asyncReceive(): waiting for space, Please adjust 'RECV_BUFFER_MAX'! retries=" + first); 128 | System.Threading.Thread.Sleep(5); 129 | } 130 | 131 | first += 1; 132 | space = _free(); 133 | } 134 | 135 | int bytesRead = 0; 136 | try 137 | { 138 | bytesRead = socket.Receive(_buffer, _wpos, space, 0); 139 | } 140 | catch (SocketException se) 141 | { 142 | Dbg.ERROR_MSG(string.Format("PacketReceiverTCP::_asyncReceive(): receive error, disconnect from '{0}'! error = '{1}'", socket.RemoteEndPoint, se)); 143 | Event.fireIn("_closeNetwork", new object[] { _networkInterface }); 144 | return; 145 | } 146 | 147 | if (bytesRead > 0) 148 | { 149 | // 更新写位置 150 | Interlocked.Add(ref _wpos, bytesRead); 151 | } 152 | else 153 | { 154 | Dbg.WARNING_MSG(string.Format("PacketReceiverTCP::_asyncReceive(): receive 0 bytes, disconnect from '{0}'!", socket.RemoteEndPoint)); 155 | Event.fireIn("_closeNetwork", new object[] { _networkInterface }); 156 | return; 157 | } 158 | } 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketReceiverTCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d9ebc916dceed448aabbcc244504a01 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketSenderBase.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using System; 4 | using System.Net.Sockets; 5 | using System.Net; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading; 11 | 12 | using MessageID = System.UInt16; 13 | using MessageLength = System.UInt16; 14 | 15 | /* 16 | 包发送模块(与服务端网络部分的名称对应) 17 | 处理网络数据的发送 18 | */ 19 | public abstract class PacketSenderBase 20 | { 21 | public delegate void AsyncSendMethod(); 22 | 23 | protected NetworkInterfaceBase _networkInterface = null; 24 | AsyncCallback _asyncCallback = null; 25 | AsyncSendMethod _asyncSendMethod; 26 | 27 | public PacketSenderBase(NetworkInterfaceBase networkInterface) 28 | { 29 | _networkInterface = networkInterface; 30 | _asyncSendMethod = new AsyncSendMethod(this._asyncSend); 31 | _asyncCallback = new AsyncCallback(_onSent); 32 | } 33 | 34 | ~PacketSenderBase() 35 | { 36 | } 37 | 38 | public NetworkInterfaceBase networkInterface() 39 | { 40 | return _networkInterface; 41 | } 42 | 43 | public abstract bool send(MemoryStream stream); 44 | 45 | protected void _startSend() 46 | { 47 | // 由于socket用的是非阻塞式,因此在这里不能直接使用socket.send()方法 48 | // 必须放到另一个线程中去做 49 | 50 | _asyncSendMethod.BeginInvoke(_asyncCallback, _asyncSendMethod); 51 | } 52 | 53 | protected abstract void _asyncSend(); 54 | 55 | protected static void _onSent(IAsyncResult ar) 56 | { 57 | AsyncSendMethod caller = (AsyncSendMethod)ar.AsyncState; 58 | caller.EndInvoke(ar); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketSenderBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 31463b5131a461c4b8be6da64d653eb4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketSenderKCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using System; 4 | using System.Net.Sockets; 5 | using System.Net; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading; 11 | 12 | using MessageID = System.UInt16; 13 | using MessageLength = System.UInt16; 14 | 15 | /* 16 | 包发送模块(与服务端网络部分的名称对应) 17 | 处理网络数据的发送 18 | */ 19 | public class PacketSenderKCP : PacketSenderBase 20 | { 21 | Socket socket_; 22 | EndPoint remoteEndPint_; 23 | 24 | public PacketSenderKCP(NetworkInterfaceBase networkInterface) : base(networkInterface) 25 | { 26 | socket_ = _networkInterface.sock(); 27 | remoteEndPint_ = ((NetworkInterfaceKCP)_networkInterface).remoteEndPint; 28 | } 29 | 30 | ~PacketSenderKCP() 31 | { 32 | Dbg.DEBUG_MSG("PacketSenderKCP::~PacketSenderKCP(), destroyed!"); 33 | } 34 | 35 | public override bool send(MemoryStream stream) 36 | { 37 | //MemoryStream udpPacket = MemoryStream.createObject(); 38 | //udpPacket.swap(stream); 39 | return true; 40 | } 41 | 42 | public bool sendto(byte[] packet, int size) 43 | { 44 | try 45 | { 46 | socket_.SendTo(packet, size, SocketFlags.None, remoteEndPint_); 47 | } 48 | catch (SocketException se) 49 | { 50 | Dbg.ERROR_MSG(string.Format("PacketSenderKCP::sendto(): send data error, disconnect from '{0}'! error = '{1}'", socket_.RemoteEndPoint, se)); 51 | Event.fireIn("_closeNetwork", new object[] { _networkInterface }); 52 | return false; 53 | } 54 | 55 | return true; 56 | } 57 | 58 | protected override void _asyncSend() 59 | { 60 | /* 61 | if (_networkInterface == null || !_networkInterface.valid()) 62 | { 63 | Dbg.WARNING_MSG("PacketSenderKCP::_asyncSend(): network interface invalid!"); 64 | return; 65 | } 66 | 67 | var socket = _networkInterface.sock(); 68 | EndPoint remoteEndPint = ((NetworkInterfaceKCP)_networkInterface).remoteEndPint; 69 | 70 | while (true) 71 | { 72 | socket.SendTo(data, size, SocketFlags.None, remoteEndPint); 73 | } 74 | */ 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketSenderKCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7ceceeab28e1ab4688c274fcfaf5e20 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketSenderTCP.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using System; 4 | using System.Net.Sockets; 5 | using System.Net; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading; 11 | 12 | using MessageID = System.UInt16; 13 | using MessageLength = System.UInt16; 14 | 15 | /* 16 | 包发送模块(与服务端网络部分的名称对应) 17 | 处理网络数据的发送 18 | */ 19 | public class PacketSenderTCP : PacketSenderBase 20 | { 21 | private byte[] _buffer; 22 | 23 | int _wpos = 0; // 写入的数据位置 24 | int _spos = 0; // 发送完毕的数据位置 25 | 26 | object _sendingObj = new object(); 27 | Boolean _sending = false; 28 | 29 | public PacketSenderTCP(NetworkInterfaceBase networkInterface) : base(networkInterface) 30 | { 31 | _buffer = new byte[KBEngineApp.app.getInitArgs().TCP_SEND_BUFFER_MAX]; 32 | 33 | _wpos = 0; 34 | _spos = 0; 35 | _sending = false; 36 | } 37 | 38 | ~PacketSenderTCP() 39 | { 40 | Dbg.DEBUG_MSG("PacketSenderTCP::~PacketSenderTCP(), destroyed!"); 41 | } 42 | 43 | public override bool send(MemoryStream stream) 44 | { 45 | int dataLength = (int)stream.length(); 46 | if (dataLength <= 0) 47 | return true; 48 | 49 | Monitor.Enter(_sendingObj); 50 | if (!_sending) 51 | { 52 | if (_wpos == _spos) 53 | { 54 | _wpos = 0; 55 | _spos = 0; 56 | } 57 | } 58 | 59 | int t_spos =_spos; 60 | int space = 0; 61 | int tt_wpos = _wpos % _buffer.Length; 62 | int tt_spos = t_spos % _buffer.Length; 63 | 64 | if(tt_wpos >= tt_spos) 65 | space = _buffer.Length - tt_wpos + tt_spos - 1; 66 | else 67 | space = tt_spos - tt_wpos - 1; 68 | 69 | if (dataLength > space) 70 | { 71 | Dbg.ERROR_MSG("PacketSenderTCP::send(): no space, Please adjust 'SEND_BUFFER_MAX'! data(" + dataLength 72 | + ") > space(" + space + "), wpos=" + _wpos + ", spos=" + t_spos); 73 | 74 | return false; 75 | } 76 | 77 | int expect_total = tt_wpos + dataLength; 78 | if(expect_total <= _buffer.Length) 79 | { 80 | Array.Copy(stream.data(), stream.rpos, _buffer, tt_wpos, dataLength); 81 | } 82 | else 83 | { 84 | int remain = _buffer.Length - tt_wpos; 85 | Array.Copy(stream.data(), stream.rpos, _buffer, tt_wpos, remain); 86 | Array.Copy(stream.data(), stream.rpos + remain, _buffer, 0, expect_total - _buffer.Length); 87 | } 88 | 89 | _wpos += dataLength; 90 | 91 | if (!_sending) 92 | { 93 | _sending = true; 94 | Monitor.Exit(_sendingObj); 95 | 96 | _startSend(); 97 | } 98 | else 99 | { 100 | Monitor.Exit(_sendingObj); 101 | } 102 | 103 | return true; 104 | } 105 | 106 | protected override void _asyncSend() 107 | { 108 | if (_networkInterface == null || !_networkInterface.valid()) 109 | { 110 | Dbg.WARNING_MSG("PacketSenderTCP::_asyncSend(): network interface invalid!"); 111 | return; 112 | } 113 | 114 | var socket = _networkInterface.sock(); 115 | 116 | while (true) 117 | { 118 | Monitor.Enter(_sendingObj); 119 | 120 | int sendSize = _wpos - _spos; 121 | int t_spos = _spos % _buffer.Length; 122 | if (t_spos == 0) 123 | t_spos = sendSize; 124 | 125 | if (sendSize > _buffer.Length - t_spos) 126 | sendSize = _buffer.Length - t_spos; 127 | 128 | int bytesSent = 0; 129 | try 130 | { 131 | bytesSent = socket.Send(_buffer, _spos % _buffer.Length, sendSize, 0); 132 | } 133 | catch (SocketException se) 134 | { 135 | Dbg.ERROR_MSG(string.Format("PacketSenderTCP::_asyncSend(): send data error, disconnect from '{0}'! error = '{1}'", socket.RemoteEndPoint, se)); 136 | Event.fireIn("_closeNetwork", new object[] { _networkInterface }); 137 | 138 | Monitor.Exit(_sendingObj); 139 | return; 140 | } 141 | 142 | _spos += bytesSent; 143 | 144 | // 所有数据发送完毕了 145 | if (_spos == _wpos) 146 | { 147 | _sending = false; 148 | Monitor.Exit(_sendingObj); 149 | return; 150 | } 151 | 152 | Monitor.Exit(_sendingObj); 153 | } 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/PacketSenderTCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 20a3d2aeecd2cc04883ba9ed72f643b8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Profile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Sockets; 3 | using System.Net; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using System.Threading; 9 | 10 | namespace KBEngine 11 | { 12 | public class Profile 13 | { 14 | System.DateTime startTime; 15 | string _name = ""; 16 | 17 | public Profile(string name) 18 | { 19 | _name = name; 20 | } 21 | 22 | ~Profile() 23 | { 24 | } 25 | 26 | public void start() 27 | { 28 | startTime = System.DateTime.Now; 29 | } 30 | 31 | public void end() 32 | { 33 | System.TimeSpan time = System.DateTime.Now - startTime; 34 | 35 | if(time.TotalMilliseconds >= 100) 36 | Dbg.WARNING_MSG("Profile::profile(): '" + _name + "' took " + time.TotalMilliseconds + " ms"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Profile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c22d139d303b4e4aa1bd1f77db4f3a8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Property.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | 6 | /* 7 | 抽象出一个entitydef中定义的属性 8 | 该模块描述了属性的id以及数据类型等信息 9 | */ 10 | public class Property 11 | { 12 | public enum EntityDataFlags 13 | { 14 | ED_FLAG_UNKOWN = 0x00000000, // 未定义 15 | ED_FLAG_CELL_PUBLIC = 0x00000001, // 相关所有cell广播 16 | ED_FLAG_CELL_PRIVATE = 0x00000002, // 当前cell 17 | ED_FLAG_ALL_CLIENTS = 0x00000004, // cell广播与所有客户端 18 | ED_FLAG_CELL_PUBLIC_AND_OWN = 0x00000008, // cell广播与自己的客户端 19 | ED_FLAG_OWN_CLIENT = 0x00000010, // 当前cell和客户端 20 | ED_FLAG_BASE_AND_CLIENT = 0x00000020, // base和客户端 21 | ED_FLAG_BASE = 0x00000040, // 当前base 22 | ED_FLAG_OTHER_CLIENTS = 0x00000080, // cell广播和其他客户端 23 | }; 24 | 25 | public string name = ""; 26 | public UInt16 properUtype = 0; 27 | public UInt32 properFlags = 0; 28 | public Int16 aliasID = -1; 29 | public object defaultVal = null; 30 | 31 | public Property() 32 | { 33 | 34 | } 35 | 36 | public bool isBase() 37 | { 38 | return properFlags == (UInt32)EntityDataFlags.ED_FLAG_BASE_AND_CLIENT || 39 | properFlags == (UInt32)EntityDataFlags.ED_FLAG_BASE; 40 | } 41 | 42 | public bool isOwnerOnly() 43 | { 44 | return properFlags == (UInt32)EntityDataFlags.ED_FLAG_CELL_PUBLIC_AND_OWN || 45 | properFlags == (UInt32)EntityDataFlags.ED_FLAG_OWN_CLIENT; 46 | } 47 | 48 | public bool isOtherOnly() 49 | { 50 | return properFlags == (UInt32)EntityDataFlags.ED_FLAG_OTHER_CLIENTS || 51 | properFlags == (UInt32)EntityDataFlags.ED_FLAG_OTHER_CLIENTS; 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/Property.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d46f82469529d6f409b05a27df8ead1a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35d8c19bdd407cd42b038bb4b47d5b86 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/ScriptModule.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Reflection; 8 | 9 | /* 10 | 一个entitydef中定义的脚本模块的描述类 11 | 包含了某个entity定义的属性与方法以及该entity脚本模块的名称与模块ID 12 | */ 13 | public class ScriptModule 14 | { 15 | public string name; 16 | public bool usePropertyDescrAlias; 17 | public bool useMethodDescrAlias; 18 | 19 | public Dictionary propertys = new Dictionary(); 20 | public Dictionary idpropertys = new Dictionary(); 21 | 22 | public Dictionary methods = new Dictionary(); 23 | public Dictionary base_methods = new Dictionary(); 24 | public Dictionary cell_methods = new Dictionary(); 25 | 26 | public Dictionary idmethods = new Dictionary(); 27 | public Dictionary idbase_methods = new Dictionary(); 28 | public Dictionary idcell_methods = new Dictionary(); 29 | 30 | public Type entityScript = null; 31 | 32 | public ScriptModule(string modulename) 33 | { 34 | name = modulename; 35 | 36 | foreach (System.Reflection.Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) 37 | { 38 | entityScript = ass.GetType("KBEngine." + modulename); 39 | if(entityScript == null) 40 | { 41 | entityScript = ass.GetType(modulename); 42 | } 43 | 44 | if(entityScript != null) 45 | break; 46 | } 47 | 48 | usePropertyDescrAlias = false; 49 | useMethodDescrAlias = false; 50 | 51 | if(entityScript == null) 52 | Dbg.ERROR_MSG("can't load(KBEngine." + modulename + ")!"); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/ScriptModule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e18ad8026708a0445b3b6022d78cdad3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/ServerErrorDescrs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 451557aebf8ad124fa57c504c376499f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/SpaceBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6365dd5c0940695498a2cc1c6ac12edb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/SpaceDuplicateBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b5a9c493ba683443bb8deb3ff0186fd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/SpacesBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75df76f2e6b3c0444a58f6560fc2d8ac 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/SpawnPointBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bea9089d74f16cc489ce96d2fd67ae5a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/TestBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | Please inherit this module, such as: (class Test : TestBase) 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/Test.def 16 | public abstract class TestBase : EntityComponent 17 | { 18 | public EntityBaseEntityCall_TestBase baseEntityCall = null; 19 | public EntityCellEntityCall_TestBase cellEntityCall = null; 20 | 21 | public Int32 own = 1001; 22 | public virtual void onOwnChanged(Int32 oldValue) {} 23 | public Int32 state = 100; 24 | public virtual void onStateChanged(Int32 oldValue) {} 25 | 26 | public abstract void helloCB(Int32 arg1); 27 | 28 | public override void createFromStream(MemoryStream stream) 29 | { 30 | base.createFromStream(stream); 31 | } 32 | 33 | public override void onGetBase() 34 | { 35 | ownerID = owner.id; 36 | baseEntityCall = new EntityBaseEntityCall_TestBase(entityComponentPropertyID, ownerID); 37 | } 38 | 39 | public override void onGetCell() 40 | { 41 | ownerID = owner.id; 42 | cellEntityCall = new EntityCellEntityCall_TestBase(entityComponentPropertyID, ownerID); 43 | } 44 | 45 | public override void onLoseCell() 46 | { 47 | cellEntityCall = null; 48 | } 49 | 50 | public override ScriptModule getScriptModule() 51 | { 52 | return EntityDef.moduledefs["Test"]; 53 | } 54 | 55 | public override void onRemoteMethodCall(UInt16 methodUtype, MemoryStream stream) 56 | { 57 | ScriptModule sm = EntityDef.moduledefs["Test"]; 58 | 59 | Method method = sm.idmethods[methodUtype]; 60 | switch(method.methodUtype) 61 | { 62 | case 28: 63 | Int32 helloCB_arg1 = stream.readInt32(); 64 | helloCB(helloCB_arg1); 65 | break; 66 | default: 67 | break; 68 | }; 69 | } 70 | 71 | public override void onUpdatePropertys(UInt16 propUtype, MemoryStream stream, int maxCount) 72 | { 73 | ScriptModule sm = EntityDef.moduledefs["Test"]; 74 | Dictionary pdatas = sm.idpropertys; 75 | 76 | while(stream.length() > 0 && maxCount-- != 0) 77 | { 78 | UInt16 _t_utype = 0; 79 | UInt16 _t_child_utype = propUtype; 80 | 81 | if(_t_child_utype == 0) 82 | { 83 | if(sm.usePropertyDescrAlias) 84 | { 85 | _t_utype = stream.readUint8(); 86 | _t_child_utype = stream.readUint8(); 87 | } 88 | else 89 | { 90 | _t_utype = stream.readUint16(); 91 | _t_child_utype = stream.readUint16(); 92 | } 93 | } 94 | 95 | Property prop = null; 96 | 97 | prop = pdatas[_t_child_utype]; 98 | 99 | switch(prop.properUtype) 100 | { 101 | case 18: 102 | Int32 oldval_own = own; 103 | own = stream.readInt32(); 104 | 105 | if(prop.isBase()) 106 | { 107 | if(owner.inited) 108 | onOwnChanged(oldval_own); 109 | } 110 | else 111 | { 112 | if(owner.inWorld) 113 | onOwnChanged(oldval_own); 114 | } 115 | 116 | break; 117 | case 17: 118 | Int32 oldval_state = state; 119 | state = stream.readInt32(); 120 | 121 | if(prop.isBase()) 122 | { 123 | if(owner.inited) 124 | onStateChanged(oldval_state); 125 | } 126 | else 127 | { 128 | if(owner.inWorld) 129 | onStateChanged(oldval_state); 130 | } 131 | 132 | break; 133 | default: 134 | break; 135 | }; 136 | } 137 | } 138 | 139 | public override void callPropertysSetMethods() 140 | { 141 | ScriptModule sm = EntityDef.moduledefs["Test"]; 142 | Dictionary pdatas = sm.idpropertys; 143 | 144 | Int32 oldval_own = own; 145 | Property prop_own = pdatas[4]; 146 | if(prop_own.isBase()) 147 | { 148 | if(owner.inited && !owner.inWorld) 149 | onOwnChanged(oldval_own); 150 | } 151 | else 152 | { 153 | if(owner.inWorld) 154 | { 155 | if(prop_own.isOwnerOnly() && !owner.isPlayer()) 156 | { 157 | } 158 | else 159 | { 160 | onOwnChanged(oldval_own); 161 | } 162 | } 163 | } 164 | 165 | Int32 oldval_state = state; 166 | Property prop_state = pdatas[5]; 167 | if(prop_state.isBase()) 168 | { 169 | if(owner.inited && !owner.inWorld) 170 | onStateChanged(oldval_state); 171 | } 172 | else 173 | { 174 | if(owner.inWorld) 175 | { 176 | if(prop_state.isOwnerOnly() && !owner.isPlayer()) 177 | { 178 | } 179 | else 180 | { 181 | onStateChanged(oldval_state); 182 | } 183 | } 184 | } 185 | 186 | } 187 | } 188 | } -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/TestBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ffec40471ea0114384ec5d6161f6c69 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/TestNoBaseBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by KBEngine! 3 | Please do not modify this file! 4 | Please inherit this module, such as: (class TestNoBase : TestNoBaseBase) 5 | tools = kbcmd 6 | */ 7 | 8 | namespace KBEngine 9 | { 10 | using UnityEngine; 11 | using System; 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | 15 | // defined in */scripts/entity_defs/TestNoBase.def 16 | public abstract class TestNoBaseBase : EntityComponent 17 | { 18 | public EntityBaseEntityCall_TestNoBaseBase baseEntityCall = null; 19 | public EntityCellEntityCall_TestNoBaseBase cellEntityCall = null; 20 | 21 | public Int32 own = 1001; 22 | public virtual void onOwnChanged(Int32 oldValue) {} 23 | public Int32 state = 100; 24 | public virtual void onStateChanged(Int32 oldValue) {} 25 | 26 | public abstract void helloCB(Int32 arg1); 27 | 28 | public override void createFromStream(MemoryStream stream) 29 | { 30 | base.createFromStream(stream); 31 | } 32 | 33 | public override void onGetBase() 34 | { 35 | ownerID = owner.id; 36 | baseEntityCall = new EntityBaseEntityCall_TestNoBaseBase(entityComponentPropertyID, ownerID); 37 | } 38 | 39 | public override void onGetCell() 40 | { 41 | ownerID = owner.id; 42 | cellEntityCall = new EntityCellEntityCall_TestNoBaseBase(entityComponentPropertyID, ownerID); 43 | } 44 | 45 | public override void onLoseCell() 46 | { 47 | cellEntityCall = null; 48 | } 49 | 50 | public override ScriptModule getScriptModule() 51 | { 52 | return EntityDef.moduledefs["TestNoBase"]; 53 | } 54 | 55 | public override void onRemoteMethodCall(UInt16 methodUtype, MemoryStream stream) 56 | { 57 | ScriptModule sm = EntityDef.moduledefs["TestNoBase"]; 58 | 59 | Method method = sm.idmethods[methodUtype]; 60 | switch(method.methodUtype) 61 | { 62 | case 30: 63 | Int32 helloCB_arg1 = stream.readInt32(); 64 | helloCB(helloCB_arg1); 65 | break; 66 | default: 67 | break; 68 | }; 69 | } 70 | 71 | public override void onUpdatePropertys(UInt16 propUtype, MemoryStream stream, int maxCount) 72 | { 73 | ScriptModule sm = EntityDef.moduledefs["TestNoBase"]; 74 | Dictionary pdatas = sm.idpropertys; 75 | 76 | while(stream.length() > 0 && maxCount-- != 0) 77 | { 78 | UInt16 _t_utype = 0; 79 | UInt16 _t_child_utype = propUtype; 80 | 81 | if(_t_child_utype == 0) 82 | { 83 | if(sm.usePropertyDescrAlias) 84 | { 85 | _t_utype = stream.readUint8(); 86 | _t_child_utype = stream.readUint8(); 87 | } 88 | else 89 | { 90 | _t_utype = stream.readUint16(); 91 | _t_child_utype = stream.readUint16(); 92 | } 93 | } 94 | 95 | Property prop = null; 96 | 97 | prop = pdatas[_t_child_utype]; 98 | 99 | switch(prop.properUtype) 100 | { 101 | case 24: 102 | Int32 oldval_own = own; 103 | own = stream.readInt32(); 104 | 105 | if(prop.isBase()) 106 | { 107 | if(owner.inited) 108 | onOwnChanged(oldval_own); 109 | } 110 | else 111 | { 112 | if(owner.inWorld) 113 | onOwnChanged(oldval_own); 114 | } 115 | 116 | break; 117 | case 23: 118 | Int32 oldval_state = state; 119 | state = stream.readInt32(); 120 | 121 | if(prop.isBase()) 122 | { 123 | if(owner.inited) 124 | onStateChanged(oldval_state); 125 | } 126 | else 127 | { 128 | if(owner.inWorld) 129 | onStateChanged(oldval_state); 130 | } 131 | 132 | break; 133 | default: 134 | break; 135 | }; 136 | } 137 | } 138 | 139 | public override void callPropertysSetMethods() 140 | { 141 | ScriptModule sm = EntityDef.moduledefs["TestNoBase"]; 142 | Dictionary pdatas = sm.idpropertys; 143 | 144 | Int32 oldval_own = own; 145 | Property prop_own = pdatas[4]; 146 | if(prop_own.isBase()) 147 | { 148 | if(owner.inited && !owner.inWorld) 149 | onOwnChanged(oldval_own); 150 | } 151 | else 152 | { 153 | if(owner.inWorld) 154 | { 155 | if(prop_own.isOwnerOnly() && !owner.isPlayer()) 156 | { 157 | } 158 | else 159 | { 160 | onOwnChanged(oldval_own); 161 | } 162 | } 163 | } 164 | 165 | Int32 oldval_state = state; 166 | Property prop_state = pdatas[5]; 167 | if(prop_state.isBase()) 168 | { 169 | if(owner.inited && !owner.inWorld) 170 | onStateChanged(oldval_state); 171 | } 172 | else 173 | { 174 | if(owner.inWorld) 175 | { 176 | if(prop_state.isOwnerOnly() && !owner.isPlayer()) 177 | { 178 | } 179 | else 180 | { 181 | onStateChanged(oldval_state); 182 | } 183 | } 184 | } 185 | 186 | } 187 | } 188 | } -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/TestNoBaseBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 282cff8120eddfc40ac6e6432ef75c91 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/deps.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c7fd64fa742cb74a81d01733527ec53 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/kbengine_unity3d_plugins/deps/KCP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0312ad6e584b78a4e9be39cefd8773c9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 03b04c400a367984f9a612967c82a6cc 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Resources/entity.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Resources/entity.prefab -------------------------------------------------------------------------------- /Assets/Resources/entity.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69418c059e60c4b418e8ed3d9300aaa6 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Resources/player.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Resources/player.prefab -------------------------------------------------------------------------------- /Assets/Resources/player.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61c69563d8a9a8a4494d1564324338e4 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Resources/terrain.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Resources/terrain.prefab -------------------------------------------------------------------------------- /Assets/Resources/terrain.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00bbc30e2e42b66408c774204a194c0a 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6652586753ad95542beeca624f784d02 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Scenes/login.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Scenes/login.unity -------------------------------------------------------------------------------- /Assets/Scenes/login.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67cdf6f24e7c3964d8cde03a48cad958 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Scenes/selavatars.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Scenes/selavatars.unity -------------------------------------------------------------------------------- /Assets/Scenes/selavatars.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4d0ae019e9ef95459e84a5626e69ced 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Scenes/world.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Scenes/world.unity -------------------------------------------------------------------------------- /Assets/Scenes/world.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28f316b63b69c8c499309769b2c0efac 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b31f16bde94b2e549a1bcca7bd535d9c 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5fad36c0d25cf23468ae880e74a5f7f3 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Account.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | public class Account : AccountBase 10 | { 11 | public Dictionary avatars = new Dictionary(); 12 | 13 | public Account() : base() 14 | { 15 | } 16 | 17 | public override void __init__() 18 | { 19 | // 注册事件 20 | Event.registerIn("reqCreateAvatar", this, "reqCreateAvatar"); 21 | Event.registerIn("reqRemoveAvatar", this, "reqRemoveAvatar"); 22 | Event.registerIn("selectAvatarGame", this, "selectAvatarGame"); 23 | 24 | // 触发登陆成功事件 25 | Event.fireOut("onLoginSuccessfully", new object[]{KBEngineApp.app.entity_uuid, id, this}); 26 | 27 | // 向服务端请求获得角色列表 28 | baseEntityCall.reqAvatarList(); 29 | } 30 | 31 | public override void onDestroy () 32 | { 33 | KBEngine.Event.deregisterIn(this); 34 | } 35 | 36 | public override void onCreateAvatarResult(Byte retcode, AVATAR_INFOS info) 37 | { 38 | if(retcode == 0) 39 | { 40 | avatars.Add(info.dbid, info); 41 | Dbg.DEBUG_MSG("Account::onCreateAvatarResult: name=" + info.name); 42 | } 43 | else 44 | { 45 | Dbg.ERROR_MSG("Account::onCreateAvatarResult: retcode=" + retcode); 46 | } 47 | 48 | // ui event 49 | Event.fireOut("onCreateAvatarResult", new object[]{retcode, info, avatars}); 50 | } 51 | 52 | public override void onRemoveAvatar(UInt64 dbid) 53 | { 54 | Dbg.DEBUG_MSG("Account::onRemoveAvatar: dbid=" + dbid); 55 | 56 | avatars.Remove(dbid); 57 | 58 | // ui event 59 | Event.fireOut("onRemoveAvatar", new object[]{dbid, avatars}); 60 | } 61 | 62 | public override void onReqAvatarList(AVATAR_INFOS_LIST infos) 63 | { 64 | avatars.Clear(); 65 | 66 | Dbg.DEBUG_MSG("Account::onReqAvatarList: avatarsize=" + infos.values.Count); 67 | for(int i=0; i< infos.values.Count; i++) 68 | { 69 | AVATAR_INFOS info = infos.values[i]; 70 | Dbg.DEBUG_MSG("Account::onReqAvatarList: name" + i + "=" + info.name); 71 | avatars.Add(info.dbid, info); 72 | } 73 | 74 | // ui event 75 | Dictionary avatarList = new Dictionary(avatars); 76 | Event.fireOut("onReqAvatarList", new object[]{avatarList}); 77 | 78 | if(infos.values.Count == 0) 79 | return; 80 | 81 | // selectAvatarGame(avatars.Keys.ToList()[0]); 82 | } 83 | 84 | public void reqCreateAvatar(Byte roleType, string name) 85 | { 86 | Dbg.DEBUG_MSG("Account::reqCreateAvatar: roleType=" + roleType); 87 | baseEntityCall.reqCreateAvatar(roleType, name); 88 | } 89 | 90 | public void reqRemoveAvatar(string name) 91 | { 92 | Dbg.DEBUG_MSG("Account::reqRemoveAvatar: name=" + name); 93 | baseEntityCall.reqRemoveAvatar(name); 94 | } 95 | 96 | public void selectAvatarGame(UInt64 dbid) 97 | { 98 | Dbg.DEBUG_MSG("Account::selectAvatarGame: dbid=" + dbid); 99 | baseEntityCall.selectAvatarGame(dbid); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Account.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86ae9883cc34db4488fd36e3a200e01e 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Avatar.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Scripts/kbe_scripts/Avatar.cs -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Avatar.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6bb1a5aeebdb6c4387813adf10c5425 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Gate.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | public class Gate : GateBase 9 | { 10 | public Gate() : base() 11 | { 12 | } 13 | 14 | public override void onNameChanged(string oldValue) 15 | { 16 | // Dbg.DEBUG_MSG(className + "::set_name: " + old + " => " + v); 17 | Event.fireOut("set_name", new object[]{this, name}); 18 | } 19 | 20 | public override void onModelScaleChanged(Byte oldValue) 21 | { 22 | // Dbg.DEBUG_MSG(className + "::set_modelScale: " + old + " => " + v); 23 | Event.fireOut("set_modelScale", new object[]{this, modelScale}); 24 | } 25 | 26 | public override void onModelIDChanged(UInt32 oldValue) 27 | { 28 | // Dbg.DEBUG_MSG(className + "::set_modelID: " + old + " => " + v); 29 | Event.fireOut("set_modelID", new object[]{this, modelID}); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Gate.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b044d64eabf8d8f4d90c5913bcdc3411 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Monster.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | public class Monster : MonsterBase 9 | { 10 | public Monster() : base() 11 | { 12 | } 13 | 14 | public override void recvDamage(Int32 attackerID, Int32 skillID, Int32 damageType, Int32 damage) 15 | { 16 | // Dbg.DEBUG_MSG(className + "::recvDamage: attackerID=" + attackerID + ", skillID=" + skillID + ", damageType=" + damageType + ", damage=" + damage); 17 | 18 | Entity entity = KBEngineApp.app.findEntity(attackerID); 19 | 20 | Event.fireOut("recvDamage", new object[]{this, entity, skillID, damageType, damage}); 21 | } 22 | 23 | public override void onHPChanged(Int32 oldValue) 24 | { 25 | // Dbg.DEBUG_MSG(className + "::set_HP: " + old + " => " + v); 26 | Event.fireOut("set_HP", new object[]{this, HP, HP_Max}); 27 | } 28 | 29 | public override void onMPChanged(Int32 oldValue) 30 | { 31 | // Dbg.DEBUG_MSG(className + "::set_MP: " + old + " => " + v); 32 | Event.fireOut("set_MP", new object[]{this, MP, MP_Max}); 33 | } 34 | 35 | public override void onHP_MaxChanged(Int32 oldValue) 36 | { 37 | // Dbg.DEBUG_MSG(className + "::set_HP_Max: " + old + " => " + v); 38 | Event.fireOut("set_HP_Max", new object[]{this, HP_Max, HP}); 39 | } 40 | 41 | public override void onMP_MaxChanged(Int32 oldValue) 42 | { 43 | // Dbg.DEBUG_MSG(className + "::set_MP_Max: " + old + " => " + v); 44 | Event.fireOut("set_MP_Max", new object[]{this, MP_Max, MP}); 45 | } 46 | 47 | public override void onNameChanged(string oldValue) 48 | { 49 | // Dbg.DEBUG_MSG(className + "::set_name: " + old + " => " + v); 50 | Event.fireOut("set_name", new object[]{this, name}); 51 | } 52 | 53 | public override void onStateChanged(SByte oldValue) 54 | { 55 | // Dbg.DEBUG_MSG(className + "::set_state: " + old + " => " + v); 56 | Event.fireOut("set_state", new object[]{this, state}); 57 | } 58 | 59 | public override void onMoveSpeedChanged(Byte oldValue) 60 | { 61 | // Dbg.DEBUG_MSG(className + "::set_moveSpeed: " + old + " => " + v); 62 | Event.fireOut("set_moveSpeed", new object[]{this, moveSpeed}); 63 | } 64 | 65 | public override void onModelScaleChanged(Byte oldValue) 66 | { 67 | // Dbg.DEBUG_MSG(className + "::set_modelScale: " + old + " => " + v); 68 | Event.fireOut("set_modelScale", new object[]{this, modelScale}); 69 | } 70 | 71 | public override void onModelIDChanged(UInt32 oldValue) 72 | { 73 | // Dbg.DEBUG_MSG(className + "::set_modelID: " + old + " => " + v); 74 | Event.fireOut("set_modelID", new object[]{this, modelID}); 75 | } 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/Monster.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0302e13591ff31044b9cac56c935c4f7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/NPC.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | public class NPC : NPCBase 9 | { 10 | public NPC() : base() 11 | { 12 | } 13 | 14 | public override void onNameChanged(string oldValue) 15 | { 16 | // Dbg.DEBUG_MSG(className + "::set_name: " + old + " => " + v); 17 | Event.fireOut("set_name", new object[]{this, name}); 18 | } 19 | 20 | public override void onMoveSpeedChanged(Byte oldValue) 21 | { 22 | // Dbg.DEBUG_MSG(className + "::set_moveSpeed: " + old + " => " + v); 23 | Event.fireOut("set_moveSpeed", new object[]{this, moveSpeed}); 24 | } 25 | 26 | public override void onModelScaleChanged(Byte oldValue) 27 | { 28 | // Dbg.DEBUG_MSG(className + "::set_modelScale: " + old + " => " + v); 29 | Event.fireOut("set_modelScale", new object[]{this, modelScale}); 30 | } 31 | 32 | public override void onModelIDChanged(UInt32 oldValue) 33 | { 34 | // Dbg.DEBUG_MSG(className + "::set_modelID: " + old + " => " + v); 35 | Event.fireOut("set_modelID", new object[]{this, modelID}); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/NPC.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 63547b43d5d34ad4088365427f0dd241 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/README.md: -------------------------------------------------------------------------------- 1 | 请注意,如果KBEngine插件使用的是多线程模式,kbe_scripts默认在子线程处理与插件处于同一线程,请不要和u3d_scripts直接交互,应该通过KBE提供的事件机制交互。 2 | 3 | 这个文件夹(kbe_scripts)中的脚本类似于KBEngine资产库中(https://github.com/kbengine_ogre_demo/kbengine/kbengine_demos_assets)scripts/client文件夹的Python逻辑脚本。 4 | KBEngine的理想环境是服务端和客户端都使用Python实现游戏逻辑,Ogre例子中kbengine_demos_assets中scripts之下存在client、base、cell三个文件夹分别对应client(客户端)、baseapp(服务器)、cellapp(服务器)进程的逻辑脚本。 5 | https://github.com/kbengine/kbengine_ogre_demo例子演示了KBE的客户端理想逻辑开发环境,客户端插件(kbengine.dll封装的client_lib)由C++编写,自带了Python解释器与entitydef的分析模块还有网络与消息协议处理等等, 6 | 由C++客户端插件驱动来scripts/client中的脚本逻辑。 7 | 8 | 但这种理想环境在Unity3d中无法很好的实现,因此实现了轻量级的Unity3d专用插件(协议与entitydef由服务端网络导入),在Unity3d中使用主流的C#来完成客户端部分的脚本逻辑, 9 | 此时KBEngine资产库可以不需要client文件夹。如果没有scripts/client文件夹需要注意一些事项http://www.kbengine.org/cn/docs/configuration/entities.html。 10 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 05ec695af78171c488a07724f70d3b3c 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Scripts/kbe_scripts/SkillBox.cs: -------------------------------------------------------------------------------- 1 | namespace KBEngine 2 | { 3 | using UnityEngine; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | public class SkillBox 9 | { 10 | public static SkillBox inst = null; 11 | 12 | public List skills = new List(); 13 | 14 | public SkillBox() 15 | { 16 | inst = this; 17 | } 18 | 19 | public void pull() 20 | { 21 | clear(); 22 | 23 | KBEngine.Entity player = KBEngineApp.app.player(); 24 | if(player != null) 25 | player.cellCall("requestPull"); 26 | } 27 | 28 | public void clear() 29 | { 30 | skills.Clear(); 31 | } 32 | 33 | public void add(Skill skill) 34 | { 35 | for(int i=0; i(); 48 | } 49 | 50 | void OnGUI() 51 | { 52 | if(!gameObject.transform.Find ("Graphics").GetComponent ().GetComponent().isVisible) 53 | return; 54 | 55 | Vector3 worldPosition = new Vector3 (transform.position.x , transform.position.y + npcHeight, transform.position.z); 56 | 57 | if(playerCamera == null) 58 | playerCamera = Camera.main; 59 | 60 | //根据NPC头顶的3D坐标换算成它在2D屏幕中的坐标 61 | Vector2 uiposition = playerCamera.WorldToScreenPoint(worldPosition); 62 | 63 | //得到真实NPC头顶的2D坐标 64 | uiposition = new Vector2 (uiposition.x, Screen.height - uiposition.y); 65 | 66 | //计算NPC名称的宽高 67 | Vector2 nameSize = GUI.skin.label.CalcSize (new GUIContent(entity_name)); 68 | 69 | //设置显示颜色为黄色 70 | GUI.color = Color.yellow; 71 | 72 | //绘制NPC名称 73 | GUI.Label(new Rect(uiposition.x - (nameSize.x / 2), uiposition.y - nameSize.y - 5.0f, nameSize.x, nameSize.y), entity_name); 74 | 75 | //计算NPC名称的宽高 76 | Vector2 hpSize = GUI.skin.label.CalcSize (new GUIContent(hp)); 77 | 78 | //设置显示颜色为红 79 | GUI.color = Color.red; 80 | 81 | //绘制HP 82 | GUI.Label(new Rect(uiposition.x - (hpSize.x / 2), uiposition.y - hpSize.y - 30.0f, hpSize.x, hpSize.y), hp); 83 | } 84 | 85 | public Vector3 position { 86 | get 87 | { 88 | return _position; 89 | } 90 | 91 | set 92 | { 93 | _position = value; 94 | 95 | if(gameObject != null) 96 | gameObject.transform.position = _position; 97 | } 98 | } 99 | 100 | public Vector3 eulerAngles { 101 | get 102 | { 103 | return _eulerAngles; 104 | } 105 | 106 | set 107 | { 108 | _eulerAngles = value; 109 | 110 | if(gameObject != null) 111 | { 112 | gameObject.transform.eulerAngles = _eulerAngles; 113 | } 114 | } 115 | } 116 | 117 | public Quaternion rotation { 118 | get 119 | { 120 | return Quaternion.Euler(_eulerAngles); 121 | } 122 | 123 | set 124 | { 125 | eulerAngles = value.eulerAngles; 126 | } 127 | } 128 | 129 | public Vector3 scale { 130 | get 131 | { 132 | return _scale; 133 | } 134 | 135 | set 136 | { 137 | _scale = value; 138 | 139 | if(gameObject != null) 140 | gameObject.transform.localScale = _scale; 141 | } 142 | } 143 | 144 | public float speed { 145 | get 146 | { 147 | return _speed; 148 | } 149 | 150 | set 151 | { 152 | _speed = value; 153 | } 154 | } 155 | 156 | public UInt32 spaceID { 157 | get 158 | { 159 | return _spaceID; 160 | } 161 | 162 | set 163 | { 164 | _spaceID = value; 165 | } 166 | } 167 | 168 | public void entityEnable() 169 | { 170 | entityEnabled = true; 171 | } 172 | 173 | public void entityDisable() 174 | { 175 | entityEnabled = false; 176 | } 177 | 178 | public void set_state(sbyte v) 179 | { 180 | if (v == 3) 181 | { 182 | if(isPlayer) 183 | gameObject.transform.Find ("Graphics").GetComponent ().material.color = Color.green; 184 | else 185 | gameObject.transform.Find ("Graphics").GetComponent ().material.color = Color.red; 186 | } else if (v == 0) 187 | { 188 | if(isPlayer) 189 | gameObject.transform.Find ("Graphics").GetComponent ().material.color = Color.blue; 190 | else 191 | gameObject.transform.Find ("Graphics").GetComponent ().material.color = Color.white; 192 | } else if (v == 1) { 193 | gameObject.transform.Find ("Graphics").GetComponent ().material.color = Color.black; 194 | } 195 | } 196 | 197 | void FixedUpdate () 198 | { 199 | if (!entityEnabled || KBEngineApp.app == null) 200 | return; 201 | 202 | if(isPlayer == isControlled) 203 | return; 204 | 205 | KBEngine.Event.fireIn("updatePlayer", spaceID, gameObject.transform.position.x, 206 | gameObject.transform.position.y, gameObject.transform.position.z, gameObject.transform.rotation.eulerAngles.y); 207 | } 208 | 209 | void Update () 210 | { 211 | if (!entityEnabled) 212 | { 213 | position = destPosition; 214 | return; 215 | } 216 | 217 | float deltaSpeed = (speed * Time.deltaTime); 218 | 219 | if(isPlayer == true && isControlled == false) 220 | { 221 | characterController.stepOffset = deltaSpeed; 222 | 223 | if(isOnGround != characterController.isGrounded) 224 | { 225 | KBEngine.Entity player = KBEngineApp.app.player(); 226 | player.isOnGround = characterController.isGrounded; 227 | isOnGround = characterController.isGrounded; 228 | } 229 | 230 | return; 231 | } 232 | 233 | if(Vector3.Distance(eulerAngles, destDirection) > 0.0004f) 234 | { 235 | rotation = Quaternion.Slerp(rotation, Quaternion.Euler(destDirection), 8f * Time.deltaTime); 236 | } 237 | 238 | float dist = 0.0f; 239 | 240 | // 如果isOnGround为true,服务端同步其他实体到客户端时为了节省流量并不同步y轴,客户端需要强制将实体贴在地面上 241 | // 由于这里的地面位置就是0,所以直接填入0,如果是通过navmesh不规则地表高度寻路则需要想办法得到地面位置 242 | if(isOnGround) 243 | { 244 | dist = Vector3.Distance(new Vector3(destPosition.x, 0f, destPosition.z), 245 | new Vector3(position.x, 0f, position.z)); 246 | } 247 | else 248 | { 249 | dist = Vector3.Distance(destPosition, position); 250 | } 251 | 252 | if(jumpState > 0) 253 | { 254 | if(jumpState == 1) 255 | { 256 | currY += 0.05f; 257 | 258 | if(currY > 2.0f) 259 | jumpState = 2; 260 | } 261 | else 262 | { 263 | currY -= 0.05f; 264 | if(currY < 1.0f) 265 | { 266 | jumpState = 0; 267 | currY = 1.0f; 268 | } 269 | } 270 | 271 | Vector3 pos = position; 272 | pos.y = currY; 273 | position = pos; 274 | } 275 | 276 | if(dist > 0.01f) 277 | { 278 | Vector3 pos = position; 279 | 280 | Vector3 movement = destPosition - pos; 281 | movement.y = 0f; 282 | movement.Normalize(); 283 | 284 | movement *= deltaSpeed; 285 | 286 | if(dist > deltaSpeed || movement.magnitude > deltaSpeed) 287 | pos += movement; 288 | else 289 | pos = destPosition; 290 | 291 | if(isOnGround) 292 | pos.y = currY; 293 | 294 | position = pos; 295 | } 296 | else 297 | { 298 | position = destPosition; 299 | } 300 | } 301 | 302 | public void OnJump() 303 | { 304 | Debug.Log("jumpState: " + jumpState); 305 | 306 | if(jumpState != 0) 307 | return; 308 | 309 | jumpState = 1; 310 | } 311 | } 312 | 313 | -------------------------------------------------------------------------------- /Assets/Scripts/u3d_scripts/GameEntity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d63d7061260693149bb47d190bbc62df 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/u3d_scripts/ShowFPS.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class ShowFPS : MonoBehaviour { 5 | 6 | public float f_UpdateInterval = 0.5F; 7 | 8 | private float f_LastInterval; 9 | 10 | private int i_Frames = 0; 11 | 12 | private float f_Fps; 13 | 14 | void Start() 15 | { 16 | //Application.targetFrameRate=60; 17 | 18 | f_LastInterval = Time.realtimeSinceStartup; 19 | 20 | i_Frames = 0; 21 | } 22 | 23 | void OnGUI() 24 | { 25 | GUI.Label(new Rect(Screen.width - 40, 1, 200, 200), f_Fps.ToString("f2")); 26 | } 27 | 28 | void Update() 29 | { 30 | ++i_Frames; 31 | 32 | if (Time.realtimeSinceStartup > f_LastInterval + f_UpdateInterval) 33 | { 34 | f_Fps = i_Frames / (Time.realtimeSinceStartup - f_LastInterval); 35 | 36 | i_Frames = 0; 37 | 38 | f_LastInterval = Time.realtimeSinceStartup; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Assets/Scripts/u3d_scripts/ShowFPS.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4611d02438abdf546ad3278c62ee2f3c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/u3d_scripts/UI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7c6ffeca05ab703418584311523a29ce 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/u3d_scripts/World.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5044df79cb476104a909857048b8c3af 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Standard Assets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 790c9a6bcf9415f4e9bfe08c2e830bfb 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 54216e9ed42974e30967824b7f0b2806 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/First Person Controller.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Character Controllers/First Person Controller.prefab -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/First Person Controller.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d4133d5d30b644bd87802a347eaccbe 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e0b0a994d8934541a387e092630b5db 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c81df2918c80c054ca3d436e62090893 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Constructor.FBX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Constructor.FBX -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e53c8c3dcc4ff59438bc9e86cb45c3f6 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Materials/constructor_done.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Materials/constructor_done.mat -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Materials/constructor_done.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca49380a71a2bb64c830d06bd421b9d1 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b365e6042890d4b1987423ed6bb8a08c 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/capsuleUV.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/capsuleUV.psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/capsuleUV.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32eff2be837ea404ab93c114ecb895ef 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: -1 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/constructor_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/constructor_diffuse.png -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/constructor_diffuse.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97b050d43ac7c4d2b9f6cbb587650761 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: -1 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/constructor_normals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/constructor_normals.png -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/PrototypeCharacter/Textures/constructor_normals.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 531c14f8d5cdc4e5baa83ee6e16f783a 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 1 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 1 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 1 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f781c091d1c8647c380d5230adfaee54 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4ef466013242744c8749b7003922f2c 3 | timeCreated: 1550197061 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/Scripts/FPSInputController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | [RequireComponent(typeof(CharacterMotor))] 6 | [AddComponentMenu("Character/FPS Input Controller")] 7 | 8 | public class FPSInputController : MonoBehaviour 9 | { 10 | private CharacterMotor motor; 11 | // Start is called before the first frame update 12 | 13 | private void Awake() 14 | { 15 | motor = gameObject.GetComponent(); 16 | } 17 | 18 | void Start() 19 | { 20 | 21 | } 22 | 23 | // Update is called once per frame 24 | void Update() 25 | { 26 | var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); 27 | 28 | if (directionVector != Vector3.zero) 29 | { 30 | // Get the length of the directon vector and then normalize it 31 | // Dividing by the length is cheaper than normalizing when we already have the length anyway 32 | var directionLength = directionVector.magnitude; 33 | directionVector = directionVector / directionLength; 34 | 35 | // Make sure the length is no bigger than 1 36 | directionLength = Mathf.Min(1, directionLength); 37 | 38 | // Make the input vector more sensitive towards the extremes and less sensitive in the middle 39 | // This makes it easier to control slow speeds when using analog sticks 40 | directionLength = directionLength * directionLength; 41 | 42 | // Multiply the normalized direction vector by the modified length 43 | directionVector = directionVector * directionLength; 44 | } 45 | 46 | // Apply the direction to the CharacterMotor 47 | motor.inputMoveDirection = transform.rotation * directionVector; 48 | motor.inputJump = Input.GetButton("Jump"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/Scripts/FPSInputController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b963c2a776b02174bb6b64fe0818abb8 3 | timeCreated: 1550197061 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/Scripts/MouseLook.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | /// MouseLook rotates the transform based on the mouse delta. 5 | /// Minimum and Maximum values can be used to constrain the possible rotation 6 | 7 | /// To make an FPS style character: 8 | /// - Create a capsule. 9 | /// - Add the MouseLook script to the capsule. 10 | /// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it) 11 | /// - Add FPSInputController script to the capsule 12 | /// -> A CharacterMotor and a CharacterController component will be automatically added. 13 | 14 | /// - Create a camera. Make the camera a child of the capsule. Reset it's transform. 15 | /// - Add a MouseLook script to the camera. 16 | /// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.) 17 | [AddComponentMenu("Camera-Control/Mouse Look")] 18 | public class MouseLook : MonoBehaviour { 19 | 20 | public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 } 21 | public RotationAxes axes = RotationAxes.MouseXAndY; 22 | public float sensitivityX = 15F; 23 | public float sensitivityY = 15F; 24 | 25 | public float minimumX = -360F; 26 | public float maximumX = 360F; 27 | 28 | public float minimumY = -60F; 29 | public float maximumY = 60F; 30 | 31 | float rotationY = 0F; 32 | 33 | void Update () 34 | { 35 | if (Input.GetMouseButton (1)) 36 | { 37 | if (axes == RotationAxes.MouseXAndY) { 38 | float rotationX = transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX; 39 | 40 | rotationY += Input.GetAxis ("Mouse Y") * sensitivityY; 41 | rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); 42 | 43 | transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0); 44 | } else if (axes == RotationAxes.MouseX) { 45 | transform.Rotate (0, Input.GetAxis ("Mouse X") * sensitivityX, 0); 46 | } else { 47 | rotationY += Input.GetAxis ("Mouse Y") * sensitivityY; 48 | rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); 49 | 50 | transform.localEulerAngles = new Vector3 (-rotationY, transform.localEulerAngles.y, 0); 51 | } 52 | } 53 | } 54 | 55 | void Start () 56 | { 57 | // Make the rigid body not change rotation 58 | if (GetComponent()) 59 | GetComponent().freezeRotation = true; 60 | } 61 | } -------------------------------------------------------------------------------- /Assets/Standard Assets/Character Controllers/Sources/Scripts/MouseLook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68ec2fe99d1108b9d0006a298d76c639 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e6f84bf81c8d4de280f1133cff7e601 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Grass.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f2af333648c334319bd43c214449ab50 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Grass/Grass.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Terrain Grass/Grass.psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Grass/Grass.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c528fec5d95e4ac28cf46399b887662 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 2 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 0 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Grass/Grass2.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Terrain Grass/Grass2.psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Grass/Grass2.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6cdc79ec19714fcd980ca3f6ac01a0a 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 0 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: -1 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cba4562cece794697b418ce8e7c04b3c 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/Cliff (Layered Rock).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Terrain Textures/Cliff (Layered Rock).psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/Cliff (Layered Rock).psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18214e9d6af6248559d501391856f1c7 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 2 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 0 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 0 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/GoodDirt.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Terrain Textures/GoodDirt.psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/GoodDirt.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bfd675cc0db1d4656b75dc6d6ba91142 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 2 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 0 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 0 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass (Hill).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass (Hill).psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass (Hill).psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6e0767b1f8c34890ac245217f4b9731 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 2 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 512 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 0 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 0 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass&Rock.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass&Rock.psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass&Rock.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 440eb36db91ca410f800ff3cfe43572f 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 2 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 0 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 0 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac865f55780124eeabc4a99d6d0b0115 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5710a1f47af2947699139509aae39149 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 527393b10fb66418bbaa072e104f5a30 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Materials/palmbark.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Materials/palmbark.mat -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Materials/palmbark.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5bdb6135a74b444d8cebd065dbf9d08 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Materials/palmbranch.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Materials/palmbranch.mat -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Materials/palmbranch.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3186f38ca67e7441e8299da2e169f9f9 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Palm.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Palm.fbx -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/Palm.fbx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c85abd0a4d974473b97e81d10a3a6bc 3 | ModelImporter: 4 | serializedVersion: 16 5 | fileIDToRecycleName: 6 | 100000: //RootNode 7 | 400000: //RootNode 8 | 2300000: //RootNode 9 | 3300000: //RootNode 10 | 4300000: polySurface1 11 | 11100000: //RootNode 12 | materials: 13 | importMaterials: 1 14 | materialName: 3 15 | materialSearch: 1 16 | animations: 17 | legacyGenerateAnimations: 0 18 | bakeSimulation: 0 19 | optimizeGameObjects: 0 20 | animationCompression: 1 21 | animationRotationError: .5 22 | animationPositionError: .5 23 | animationScaleError: .5 24 | animationWrapMode: 0 25 | extraExposedTransformPaths: [] 26 | clipAnimations: [] 27 | isReadable: 1 28 | meshes: 29 | lODScreenPercentages: [] 30 | globalScale: 1 31 | meshCompression: 0 32 | addColliders: 0 33 | importBlendShapes: 1 34 | swapUVChannels: 0 35 | generateSecondaryUV: 0 36 | useFileUnits: 1 37 | optimizeMeshForGPU: 1 38 | weldVertices: 1 39 | secondaryUVAngleDistortion: 8 40 | secondaryUVAreaDistortion: 15.000001 41 | secondaryUVHardAngle: 88 42 | secondaryUVPackMargin: 4 43 | tangentSpace: 44 | normalSmoothAngle: 60 45 | splitTangentsAcrossUV: 0 46 | normalImportMode: 0 47 | tangentImportMode: 1 48 | importAnimation: 1 49 | copyAvatar: 0 50 | humanDescription: 51 | human: [] 52 | skeleton: [] 53 | armTwist: .5 54 | foreArmTwist: .5 55 | upperLegTwist: .5 56 | legTwist: .5 57 | armStretch: .0500000007 58 | legStretch: .0500000007 59 | feetSpacing: 0 60 | rootMotionBoneName: 61 | lastHumanDescriptionAvatarSource: {instanceID: 0} 62 | animationType: 1 63 | additionalBone: 1 64 | userData: 65 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/PalmBark.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/PalmBark.psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/PalmBark.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f7d5f039a8e7848e889e1546d37dc39e 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 2 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 1 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 0 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 0 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/PalmBranch.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/PalmBranch.psd -------------------------------------------------------------------------------- /Assets/Standard Assets/Terrain Assets/Trees Ambient-Occlusion/Palm/PalmBranch.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 54e03e659ab274dd9b12c0538a9c4983 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 2 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 1 27 | aniso: 1 28 | mipBias: 0 29 | wrapMode: 0 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 0 40 | textureType: 0 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /Assets/start.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/Assets/start.unity -------------------------------------------------------------------------------- /Assets/start.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 955690c9d3d289a43818f18004ba5455 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2018.3.5f1 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbengine/kbengine_unity3d_demo/6db595e5094c2bdb9e80e9749a2f17b8390be48f/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | KBEngine_unity3d_demo 2 | ============= 3 | 4 | ## This client-project is written for KBEngine(a MMOG engine of server) 5 | 6 | http://www.kbengine.org 7 | 8 | ## 中文 9 | 10 | [Demo搭建文档](https://github.com/kbengine/kbengine_unity3d_demo/blob/master/README_CN.md),QQ交流群:461368412,[论坛](http://bbs.kbengine.org) 11 | 12 | ## Releases 13 | 14 | sources : https://github.com/kbengine/kbengine_unity3d_demo/releases/latest 15 | 16 | 17 | ## KBE-Plugins docs 18 | 19 | kbengine_unity3d_demo\Assets\Plugins\kbengine_unity3d_plugins\README.md 20 | 21 | 22 | ## Start: 23 | 1. Download KBEngine(a MMOG engine of server): 24 | Download(KBEngine): 25 | https://github.com/kbengine/kbengine/releases/latest 26 | 27 | Build(KBEngine): 28 | http://kbengine.github.io/docs/build.html 29 | 30 | Installation(KBEngine): 31 | http://kbengine.github.io/docs/installation.html 32 | 33 | 2. Use git to get the demo-assets(server): 34 | 35 | In the kbengine_unity3d_demo directory: 36 | 37 | * Git command: git submodule update --init --remote 38 | ![submodule_update1](http://kbengine.github.io/assets/img/screenshots/gitbash_submodule.png) 39 | 40 | * Or use TortoiseGit(menu): TortoiseGit -> Submodule Update: 41 | ![submodule_update2](http://kbengine.github.io/assets/img/screenshots/unity3d_plugins_submodule_update.jpg) 42 | 43 | * Or manually get the demo-assets(server) 44 | 45 | Download demo-assets(server): 46 | https://github.com/kbengine/kbengine_demos_assets/releases/latest 47 | unzip and copy to "kbengine/" (The root directory server engine, such as $KBE_ROOT) 48 | 49 | 3. Copy "kbengine_unity3d_demo\kbengine_demos_assets" to "kbengine\" root directory 50 | ![demo_configure](http://kbengine.github.io/assets/img/screenshots/demo_copy_kbengine.jpg) 51 | 52 | 53 | 4. Generate a Client plugins from the server-side asset library (optional, one by default unless the server-assets is modified) 54 | 1: Double-click to run kbengine/kbengine_demos_asset/gensdk.bat 55 | 2: Copy kbengine_unity3d_plugins to kbengine_unity3d_demo\Assets\Plugins\ 56 | 57 | 58 | ## Configure Demo(Optional): 59 | 60 | Change the login address: 61 | ![demo_configure](http://kbengine.github.io/assets/img/screenshots/demo_configure.jpg) 62 | 63 | kbengine_unity3d_demo\Scripts\kbe_scripts\clientapp.cs -> ip 64 | kbengine_unity3d_demo\Scripts\kbe_scripts\clientapp.cs -> port 65 | 66 | 67 | ## Start the Servers: 68 | 69 | Ensure that the "kbengine_unity3d_demo\kbengine_demos_assets" has been copied to the "kbengine\" directory 70 | Reference:Start 71 | 72 | Check the startup status: 73 | If successful will find log "Components::process(): Found all the components!". 74 | Otherwise, please search the "ERROR" keyword in logs, according to the error description to try to solve. 75 | (More: http://kbengine.github.io/docs/startup_shutdown.html) 76 | 77 | Start server: 78 | Windows: 79 | kbengine\kbengine_demos_assets\start_server.bat 80 | 81 | Linux: 82 | kbengine\kbengine_demos_assets\start_server.sh 83 | 84 | (More: http://kbengine.github.io/docs/startup_shutdown.html) 85 | 86 | 87 | ## Start the Client: 88 | 89 | Directly start(U3DEditor or Executable file). 90 | (Build Client:Unity Editor -> File -> Build Settings -> PC, MAC & Linux Standalone.) 91 | 92 | 93 | ## Navmesh-navigation(Optional): 94 | 95 | The server to use recastnavigation navigation. 96 | Recastnavigation generated navigation mesh (Navmeshs) placed on the: 97 | kbengine\kbengine_demos_assets\res\spaces\* 98 | 99 | Generation Navmeshs: 100 | https://github.com/kbengine/unity3d_nav_critterai 101 | 102 | 103 | ## Structure and interpretation: 104 | 105 | The relationship between plug-ins(KBE) and U3D and servers: 106 | Plug-in and servers: Responsible for processing and server network packet. account login/logout process. 107 | By server notification logic entities are created and destroyed. Processing synchronous logical entity attribute data. etc. 108 | Plug-in and U3D: The plug-in will trigger some events to the U3D graphics layer, the graphics layer determines whether to capture some events, 109 | get data to render performance (for example: create a monster, a NPC move-speed increase, HP changes). 110 | U3D graphics layer will input the event trigger to the plug-in layer (for example: the player moved, hit the relive button UI), 111 | the plug-in logic script layer determines whether the need to transfer to the server. etc. 112 | 113 | 114 | Plugins\kbengine\kbengine_unity3d_plugins: 115 | Client plug-in core codes. 116 | 117 | Scripts\kbe_scripts: 118 | KBE client logic scripts(in this implementation of the server side of the entity script, the entity's bag data structure, skills in client condition checks, etc.). 119 | 120 | Scripts\kbe_scripts\Account.cs: 121 | Corresponds to the client side of the KBE server account entity. 122 | 123 | Scripts\kbe_scripts\Avatar.cs: 124 | Corresponds to the client side of the KBE server avatar entity. 125 | 126 | Scripts\kbe_scripts\Monster.cs: 127 | Corresponds to the client side of the KBE server monster entity. 128 | 129 | Scripts\kbe_scripts\clientapp.cs: 130 | In the system of KBE abstraction of a client APP, which contains the KBE client plug-in initialization and destruction, etc. 131 | 132 | Scripts\kbe_scripts\interfaces: 133 | Corresponding to the module defined in KBE(entity_defs\interfaces). 134 | 135 | Scripts\u3d_scripts: 136 | Unity graphics layer (including scene rendering, UI, object, character model, monster model). 137 | 138 | Scripts\u3d_scripts\GameEntity.cs: 139 | Monster/NPC or player script (management model and animation, etc.). 140 | 141 | Scripts\u3d_scripts\World.cs: 142 | Manage a map of the game script, for example: to create a specific 3D monster into the scene. 143 | 144 | Scripts\u3d_scripts\UI.cs: 145 | the game's UI processing script. 146 | 147 | start.unity: 148 | Start the scene, which starts to enter the game. 149 | 150 | Scenes\login.unity: 151 | login map. 152 | 153 | Scenes\selavatars.unity: 154 | Game character selection map. 155 | 156 | Scenes\world.unity: 157 | A map of the scene in the game. 158 | 159 | ## Screenshots: 160 | 161 | ![screenshots1](http://kbengine.github.io/assets/img/screenshots/unity3d_demo9.jpg) 162 | ![screenshots2](http://kbengine.github.io/assets/img/screenshots/unity3d_demo10.jpg) 163 | ![screenshots3](http://kbengine.github.io/assets/img/screenshots/unity3d_demo11.jpg) 164 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | KBEngine_unity3d_demo 2 | ============= 3 | 4 | ## 本项目作为KBEngine服务端引擎的客户端演示而写 5 | 6 | http://www.kbengine.org 7 | 8 | ## 官方论坛 9 | 10 | http://bbs.kbengine.org 11 | 12 | 13 | ## QQ交流群 14 | 15 | 461368412 16 | 17 | 18 | ## Releases 19 | 20 | sources : https://github.com/kbengine/kbengine_unity3d_demo/releases/latest 21 | 22 | 23 | ## KBE插件文档 24 | 25 | kbengine_unity3d_demo\Assets\Plugins\kbengine_unity3d_plugins\README.md 26 | 27 | 28 | ## 开始: 29 | 1. 确保已经下载过KBEngine服务端引擎,如果没有下载请先下载 30 | 下载服务端源码(KBEngine): 31 | https://github.com/kbengine/kbengine/releases/latest 32 | 33 | 编译(KBEngine): 34 | http://kbengine.github.io/docs/build.html 35 | 36 | 安装(KBEngine): 37 | http://kbengine.github.io/docs/installation.html 38 | 39 | 2. 下载服务端Demo资产库: 40 | 41 | * 使用git命令行,进入到kbengine_unity3d_demo目录执行: 42 | 43 | git submodule update --init --remote 44 | ![submodule_update1](http://kbengine.github.io/assets/img/screenshots/gitbash_submodule.png) 45 | 46 | * 或者使用 TortoiseGit(选择菜单): TortoiseGit -> Submodule Update: 47 | ![submodule_update2](http://kbengine.github.io/assets/img/screenshots/unity3d_plugins_submodule_update.jpg) 48 | 49 | * 也可以手动下载服务端Demo资产库 50 | 51 | 服务端资产库下载: 52 | https://github.com/kbengine/kbengine_demos_assets/releases/latest 53 | 下载后请将其解压缩,并将目录文件放置于服务端引擎根目录"kbengine/"之下,如下图: 54 | 55 | 3. 拷贝服务端资产库"kbengine_demos_assets"到服务端引擎根目录"kbengine/"之下,如下图: 56 | ![demo_configure](http://kbengine.github.io/assets/img/screenshots/demo_copy_kbengine.jpg) 57 | 58 | 59 | 4. 通过服务端资产库生成KBE客户端插件(可选,默认已经带有一份,除非服务器有相关改动才需要再次生成) 60 | 1: 双击运行 kbengine/kbengine_demos_asset/gensdk.bat 61 | 2: 拷贝kbengine_unity3d_plugins到kbengine_unity3d_demo\Assets\Plugins\ 62 | 63 | 64 | ## 配置Demo(可选): 65 | 66 | 改变登录IP地址与端口(注意:关于服务端端口部分参看http://kbengine.github.io/cn/docs/installation.html): 67 | ![demo_configure](http://kbengine.github.io/assets/img/screenshots/demo_configure.jpg) 68 | 69 | kbengine_unity3d_demo\Scripts\kbe_scripts\clientapp.cs -> ip 70 | kbengine_unity3d_demo\Scripts\kbe_scripts\clientapp.cs -> port 71 | 72 | 73 | ## 启动服务器: 74 | 75 | 确保“kbengine_unity3d_demo\kbengine_demos_assets”已经拷贝到KBEngine根目录: 76 | 参考上方章节:开始 77 | 78 | 使用启动脚本启动服务端: 79 | Windows: 80 | kbengine\kbengine_demos_assets\start_server.bat 81 | 82 | Linux: 83 | kbengine\kbengine_demos_assets\start_server.sh 84 | 85 | 检查启动状态: 86 | 如果启动成功将会在日志中找到"Components::process(): Found all the components!"。 87 | 任何其他情况请在日志中搜索"ERROR"关键字,根据错误描述尝试解决。 88 | (更多参考: http://kbengine.github.io/docs/startup_shutdown.html) 89 | 90 | 91 | ## 启动客户端: 92 | 93 | 直接在Unity3D编辑器启动或者编译后启动 94 | (编译客户端:Unity Editor -> File -> Build Settings -> PC, MAC & Linux Standalone.) 95 | 96 | 97 | ## 生成导航网格(可选): 98 | 99 | 服务端使用Recastnavigation在3D世界寻路,recastnavigation生成的导航网格(Navmeshs)放置于: 100 | kbengine\kbengine_demos_assets\res\spaces\* 101 | 102 | 在Unity3D中使用插件生成导航网格(Navmeshs): 103 | https://github.com/kbengine/unity3d_nav_critterai 104 | 105 | 106 | ## 结构与释义: 107 | 108 | KBE插件与U3D和服务器之间的关系: 109 | 插件与服务器:负责处理与服务端之间的网络消息包、账号登陆/登出流程、由服务端通知创建和销毁逻辑实体、维护同步的逻辑实体属性数据等等。 110 | 插件与U3D:插件将某些事件触发给U3D图形层,图形层决定是否需要捕获某些事件获得数据进行渲染表现(例如:创建怪物、某个NPC的移动速度增加、HP变化)、 111 | U3D图形层将输入事件触发到插件层(例如:玩家移动了、点击了复活按钮UI),插件逻辑脚本层决定是否需要中转到服务器等等。 112 | 113 | Plugins\kbengine\kbengine_unity3d_plugins: 114 | KBE客户端插件的核心层代码。 115 | 116 | Scripts\kbe_scripts: 117 | KBE客户端的逻辑脚本(在此实现对应服务端的实体脚本、实体的背包数据结构、技能客户端判断等)。 118 | 119 | Scripts\kbe_scripts\Account.cs: 120 | 对应KBE服务端的账号实体的客户端部分。 121 | 122 | Scripts\kbe_scripts\Avatar.cs: 123 | 对应KBE服务端的账游戏中玩家实体的客户端部分。 124 | 125 | Scripts\kbe_scripts\Monster.cs: 126 | 对应KBE服务端的怪物实体的客户端部分。 127 | 128 | Scripts\kbe_scripts\clientapp.cs: 129 | 在KBE的体系中抽象出一个客户端APP,其中包含KBE客户端插件的初始化和销毁等等。 130 | 131 | Scripts\kbe_scripts\interfaces: 132 | 对应KBE中entity_defs\interfaces中所声明的模块。 133 | 134 | Scripts\u3d_scripts: 135 | Unity3D图形层(包括场景渲染、UI、物体部件、人物模型、怪物模型、一切关于显示的东西等等)。 136 | 137 | Scripts\u3d_scripts\GameEntity.cs: 138 | 无论是怪物还是玩家都由此脚本负责模型动画等表现部分。 139 | 140 | Scripts\u3d_scripts\World.cs: 141 | 管理游戏中大地图或副本的渲染层脚本,例如:负责将具体的3D怪物创建到场景中。 142 | 143 | Scripts\u3d_scripts\UI.cs: 144 | 维护游戏的UI处理脚本。 145 | 146 | start.unity: 147 | 起始场景,由此启动进入游戏。 148 | 149 | Scenes\login.unity: 150 | 登陆场景。 151 | 152 | Scenes\selavatars.unity: 153 | 角色选取场景。 154 | 155 | Scenes\world.unity: 156 | 游戏中大地图/副本场景。 157 | 158 | ## 演示截图: 159 | 160 | ![screenshots1](http://kbengine.github.io/assets/img/screenshots/unity3d_demo9.jpg) 161 | ![screenshots2](http://kbengine.github.io/assets/img/screenshots/unity3d_demo10.jpg) 162 | ![screenshots3](http://kbengine.github.io/assets/img/screenshots/unity3d_demo11.jpg) 163 | --------------------------------------------------------------------------------