Skip to content

Commit 3aca285

Browse files
committed
up
1 parent 221540b commit 3aca285

File tree

4 files changed

+325
-271
lines changed

4 files changed

+325
-271
lines changed

Assets/Scenes/start.unity

1.56 KB
Binary file not shown.

Assets/Scripts/UI.cs

Lines changed: 9 additions & 271 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
public class UI : MonoBehaviour
1010
{
11+
public static UI inst;
12+
1113
public int ui_state = 0;
1214
private string stringAccount = "";
1315
private string stringPasswd = "";
@@ -20,34 +22,28 @@ public class UI : MonoBehaviour
2022
private bool startCreateAvatar = false;
2123

2224
private UInt64 selAvatarDBID = 0;
23-
24-
private UnityEngine.GameObject terrain = null;
25-
public UnityEngine.GameObject terrainPerfab;
26-
27-
private UnityEngine.GameObject player = null;
28-
public UnityEngine.GameObject entityPerfab;
29-
public UnityEngine.GameObject avatarPerfab;
30-
31-
private bool showReliveGUI = false;
25+
public bool showReliveGUI = false;
3226

3327
void Awake()
3428
{
29+
inst = this;
3530
DontDestroyOnLoad(transform.gameObject);
3631
}
3732

3833
// Use this for initialization
39-
void Start () {
34+
void Start ()
35+
{
4036
installEvents();
4137
Application.LoadLevel("login");
4238
}
4339

4440
void installEvents()
4541
{
46-
CancelInvoke("installEvents");
47-
4842
// common
4943
KBEngine.Event.registerOut("onKicked", this, "onKicked");
50-
44+
KBEngine.Event.registerOut("onDisableConnect", this, "onDisableConnect");
45+
KBEngine.Event.registerOut("onConnectStatus", this, "onConnectStatus");
46+
5147
// login
5248
KBEngine.Event.registerOut("onCreateAccountResult", this, "onCreateAccountResult");
5349
KBEngine.Event.registerOut("onLoginFailed", this, "onLoginFailed");
@@ -68,30 +64,6 @@ void installEvents()
6864
KBEngine.Event.registerOut("onReqAvatarList", this, "onReqAvatarList");
6965
KBEngine.Event.registerOut("onCreateAvatarResult", this, "onCreateAvatarResult");
7066
KBEngine.Event.registerOut("onRemoveAvatar", this, "onRemoveAvatar");
71-
KBEngine.Event.registerOut("onAvatarEnterWorld", this, "onAvatarEnterWorld");
72-
KBEngine.Event.registerOut("onDisableConnect", this, "onDisableConnect");
73-
74-
// in world
75-
KBEngine.Event.registerOut("addSpaceGeometryMapping", this, "addSpaceGeometryMapping");
76-
KBEngine.Event.registerOut("onEnterWorld", this, "onEnterWorld");
77-
KBEngine.Event.registerOut("onLeaveWorld", this, "onLeaveWorld");
78-
KBEngine.Event.registerOut("set_position", this, "set_position");
79-
KBEngine.Event.registerOut("set_direction", this, "set_direction");
80-
KBEngine.Event.registerOut("update_position", this, "update_position");
81-
KBEngine.Event.registerOut("set_HP", this, "set_HP");
82-
KBEngine.Event.registerOut("set_MP", this, "set_MP");
83-
KBEngine.Event.registerOut("set_HP_Max", this, "set_HP_Max");
84-
KBEngine.Event.registerOut("set_MP_Max", this, "set_MP_Max");
85-
KBEngine.Event.registerOut("set_level", this, "set_level");
86-
KBEngine.Event.registerOut("set_name", this, "set_entityName");
87-
KBEngine.Event.registerOut("set_state", this, "set_state");
88-
KBEngine.Event.registerOut("set_moveSpeed", this, "set_moveSpeed");
89-
KBEngine.Event.registerOut("set_modelScale", this, "set_modelScale");
90-
KBEngine.Event.registerOut("set_modelID", this, "set_modelID");
91-
KBEngine.Event.registerOut("recvDamage", this, "recvDamage");
92-
KBEngine.Event.registerOut("otherAvatarOnJump", this, "otherAvatarOnJump");
93-
KBEngine.Event.registerOut("onAddSkill", this, "onAddSkill");
94-
KBEngine.Event.registerOut("onConnectStatus", this, "onConnectStatus");
9567
}
9668

9769
void OnDestroy()
@@ -254,7 +226,6 @@ void onLoginUI()
254226

255227
void onWorldUI()
256228
{
257-
createPlayer();
258229
if(showReliveGUI)
259230
{
260231
if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2, 200, 30), "Relive(复活)"))
@@ -466,237 +437,4 @@ public void onRemoveAvatar(UInt64 dbid, Dictionary<UInt64, Dictionary<string, ob
466437
public void onDisableConnect()
467438
{
468439
}
469-
470-
public void addSpaceGeometryMapping(string respath)
471-
{
472-
Debug.Log("loading scene(" + respath + ")...");
473-
info("scene(" + respath + "), spaceID=" + KBEngineApp.app.spaceID);
474-
if(terrain == null)
475-
terrain = Instantiate(terrainPerfab) as UnityEngine.GameObject;
476-
477-
player.GetComponent<GameEntity>().enable();
478-
}
479-
480-
public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar)
481-
{
482-
if(!avatar.isPlayer())
483-
{
484-
return;
485-
}
486-
487-
info("loading scene...(加载场景中...)");
488-
Debug.Log("loading scene...");
489-
490-
object speed = avatar.getDefinedPropterty("moveSpeed");
491-
if(speed != null)
492-
set_moveSpeed(avatar, speed);
493-
494-
object state = avatar.getDefinedPropterty("state");
495-
if(state != null)
496-
set_state(avatar, state);
497-
498-
object modelScale = avatar.getDefinedPropterty("modelScale");
499-
if(modelScale != null)
500-
set_modelScale(avatar, modelScale);
501-
502-
object name = avatar.getDefinedPropterty("name");
503-
if(name != null)
504-
set_entityName(avatar, (string)name);
505-
506-
object hp = avatar.getDefinedPropterty("HP");
507-
if(hp != null)
508-
set_HP(avatar, hp);
509-
}
510-
511-
public void createPlayer()
512-
{
513-
if (player != null)
514-
return;
515-
516-
if (KBEngineApp.app.entity_type != "Avatar") {
517-
return;
518-
}
519-
520-
KBEngine.Avatar avatar = (KBEngine.Avatar)KBEngineApp.app.player();
521-
if(avatar == null)
522-
{
523-
Debug.Log("wait create(palyer)!");
524-
return;
525-
}
526-
527-
float y = avatar.position.y;
528-
if(avatar.isOnGound)
529-
y = 1.3f;
530-
531-
player = Instantiate(avatarPerfab, new Vector3(avatar.position.x, y, avatar.position.z),
532-
Quaternion.Euler(new Vector3(avatar.direction.y, avatar.direction.z, avatar.direction.x))) as UnityEngine.GameObject;
533-
534-
player.GetComponent<GameEntity>().disable();
535-
avatar.renderObj = player;
536-
((UnityEngine.GameObject)avatar.renderObj).GetComponent<GameEntity>().isPlayer = true;
537-
}
538-
539-
public void onAddSkill(KBEngine.Entity entity)
540-
{
541-
Debug.Log("onAddSkill");
542-
}
543-
544-
public void onEnterWorld(KBEngine.Entity entity)
545-
{
546-
if(entity.isPlayer())
547-
return;
548-
549-
float y = entity.position.y;
550-
if(entity.isOnGound)
551-
y = 1.3f;
552-
553-
entity.renderObj = Instantiate(entityPerfab, new Vector3(entity.position.x, y, entity.position.z),
554-
Quaternion.Euler(new Vector3(entity.direction.y, entity.direction.z, entity.direction.x))) as UnityEngine.GameObject;
555-
556-
((UnityEngine.GameObject)entity.renderObj).name = entity.classtype + entity.id;
557-
558-
object speed = entity.getDefinedPropterty("moveSpeed");
559-
if(speed != null)
560-
set_moveSpeed(entity, speed);
561-
562-
object state = entity.getDefinedPropterty("state");
563-
if(state != null)
564-
set_state(entity, state);
565-
566-
object modelScale = entity.getDefinedPropterty("modelScale");
567-
if(modelScale != null)
568-
set_modelScale(entity, modelScale);
569-
570-
object name = entity.getDefinedPropterty("name");
571-
if(name != null)
572-
set_entityName(entity, (string)name);
573-
574-
object hp = entity.getDefinedPropterty("HP");
575-
if(hp != null)
576-
set_HP(entity, hp);
577-
}
578-
579-
public void onLeaveWorld(KBEngine.Entity entity)
580-
{
581-
if(entity.renderObj == null)
582-
return;
583-
584-
UnityEngine.GameObject.Destroy((UnityEngine.GameObject)entity.renderObj);
585-
entity.renderObj = null;
586-
}
587-
588-
public void set_position(KBEngine.Entity entity)
589-
{
590-
if(entity.renderObj == null)
591-
return;
592-
593-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().destPosition = entity.position;
594-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().position = entity.position;
595-
}
596-
597-
public void update_position(KBEngine.Entity entity)
598-
{
599-
if(entity.renderObj == null)
600-
return;
601-
602-
GameEntity gameEntity = ((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>();
603-
gameEntity.destPosition = entity.position;
604-
gameEntity.isOnGound = entity.isOnGound;
605-
}
606-
607-
public void set_direction(KBEngine.Entity entity)
608-
{
609-
if(entity.renderObj == null)
610-
return;
611-
612-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().destDirection =
613-
new Vector3(entity.direction.y, entity.direction.z, entity.direction.x);
614-
}
615-
616-
public void set_HP(KBEngine.Entity entity, object v)
617-
{
618-
if(entity.renderObj != null)
619-
{
620-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().hp = "" + (Int32)v + "/" + (Int32)entity.getDefinedPropterty("HP_Max");
621-
}
622-
}
623-
624-
public void set_MP(KBEngine.Entity entity, object v)
625-
{
626-
}
627-
628-
public void set_HP_Max(KBEngine.Entity entity, object v)
629-
{
630-
if(entity.renderObj != null)
631-
{
632-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().hp = (Int32)entity.getDefinedPropterty("HP") + "/" + (Int32)v;
633-
}
634-
}
635-
636-
public void set_MP_Max(KBEngine.Entity entity, object v)
637-
{
638-
}
639-
640-
public void set_level(KBEngine.Entity entity, object v)
641-
{
642-
}
643-
644-
public void set_entityName(KBEngine.Entity entity, object v)
645-
{
646-
if(entity.renderObj != null)
647-
{
648-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().entity_name = (string)v;
649-
}
650-
}
651-
652-
public void set_state(KBEngine.Entity entity, object v)
653-
{
654-
if(entity.renderObj != null)
655-
{
656-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().set_state((SByte)v);
657-
}
658-
659-
if(entity.isPlayer())
660-
{
661-
Debug.Log("player->set_state: " + v);
662-
663-
if(((SByte)v) == 1)
664-
showReliveGUI = true;
665-
else
666-
showReliveGUI = false;
667-
668-
return;
669-
}
670-
}
671-
672-
public void set_moveSpeed(KBEngine.Entity entity, object v)
673-
{
674-
float fspeed = ((float)(Byte)v) / 10f;
675-
676-
if(entity.renderObj != null)
677-
{
678-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().speed = fspeed;
679-
}
680-
}
681-
682-
public void set_modelScale(KBEngine.Entity entity, object v)
683-
{
684-
}
685-
686-
public void set_modelID(KBEngine.Entity entity, object v)
687-
{
688-
}
689-
690-
public void recvDamage(KBEngine.Entity entity, KBEngine.Entity attacker, Int32 skillID, Int32 damageType, Int32 damage)
691-
{
692-
}
693-
694-
public void otherAvatarOnJump(KBEngine.Entity entity)
695-
{
696-
Debug.Log("otherAvatarOnJump: " + entity.id);
697-
if(entity.renderObj != null)
698-
{
699-
((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>().OnJump();
700-
}
701-
}
702440
}

0 commit comments

Comments
 (0)