Skip to content

Commit

Permalink
Merge pull request #5 from zsummer/scene
Browse files Browse the repository at this point in the history
Scene-ai
  • Loading branch information
zsummer authored May 11, 2017
2 parents 48756ce + 04dab38 commit 09fd7c5
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 78 deletions.
Binary file modified Assets/InitScenes/main.unity
Binary file not shown.
85 changes: 33 additions & 52 deletions Assets/Resources/Guis/LoginUI/LoginUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,32 @@ public class LoginUI : MonoBehaviour {

// Use this for initialization
public Button _loginButton;
public Toggle _devTonggle;
public InputField _hostInput;
public InputField _portInput;
public InputField _accountInput;
public InputField _passwdInput;

private float _lastClickLogin = 0;
void Start ()
{
if (PlayerPrefs.GetString("account") != null)
{
_accountInput.text = PlayerPrefs.GetString("account");
}
if (PlayerPrefs.GetString("passwd") != null)
{
_passwdInput.text = PlayerPrefs.GetString("passwd");
}

_accountInput.onValueChanged.AddListener(delegate (string text)
void setDefaultValue(ref InputField field, string key, string def)
{
string cache = PlayerPrefs.GetString(key);
if (cache != null && cache.Length> 0)
{
if (text.Length > 0)
{
_accountInput.placeholder.enabled = false;
}
else
{
_accountInput.placeholder.enabled = true;
}
});
_passwdInput.onValueChanged.AddListener(delegate (string text)
{
if (text.Length > 0)
{
_passwdInput.placeholder.enabled = false;
}
else
{
_passwdInput.placeholder.enabled = true;
}
});
field.text = cache;
}
if (field.text.Length == 0 && def.Length > 0)
{
field.text = def;
}

}
void Start ()
{
setDefaultValue(ref _hostInput, "login.host", "beijing.zhonglushicai.com");
setDefaultValue(ref _portInput, "login.port", "26001");
setDefaultValue(ref _accountInput, "login.account", "");
setDefaultValue(ref _passwdInput, "login.passwd", "");



_loginButton.onClick.AddListener(delegate ()
Expand All @@ -53,33 +41,26 @@ void Start ()
{
return;
}
if (_passwdInput.text.Trim().Length > 15 || _passwdInput.text.Trim().Length < 2)
{
return;
}

float now = Time.realtimeSinceStartup;
if (now - _lastClickLogin < 1f)
{
return;
}
_lastClickLogin = now;
if (_devTonggle == null)
{
Debug.LogWarning("why tonggle is null?");
return;
ushort port = 0;
if (!ushort.TryParse(_portInput.text, out port))
{
return;
}
_lastClickLogin = now;

PlayerPrefs.SetString("account", _accountInput.text);
PlayerPrefs.SetString("passwd", _passwdInput.text);
if (_devTonggle.isOn)
{
Facade._serverProxy.Login("localhost", (ushort)26001, _accountInput.text.Trim(), _passwdInput.text.Trim());
}
else
{
Facade._serverProxy.Login("beijing.zhonglushicai.com", (ushort)26001, _accountInput.text.Trim(), _passwdInput.text.Trim());
}

PlayerPrefs.SetString("login.host", _hostInput.text);
PlayerPrefs.SetString("login.port", _portInput.text);
PlayerPrefs.SetString("login.account", _accountInput.text);
PlayerPrefs.SetString("login.passwd", _passwdInput.text);

Facade._serverProxy.Login(_hostInput.text, port, _accountInput.text.Trim(), _passwdInput.text.Trim());
});
}

Expand Down
Binary file modified Assets/Resources/Guis/LoginUI/LoginUI.prefab
Binary file not shown.
18 changes: 17 additions & 1 deletion Assets/Resources/Guis/TouchPanel/TouchPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,26 @@ void CheckStrick(int touchCount)
{
_lastDirt = dir;
}
else if (Time.realtimeSinceStartup - _lastSendMove < 1f)
else if (Time.realtimeSinceStartup - _lastSendMove < 0.5f)
{
return;
}
EntityModel player = Facade._sceneManager.GetEntity(Facade._entityID);
if(false)
// if (player == null || !player.isCanMove())
{
if (player._info.mv.action != (ushort)MOVE_ACTION.MOVE_ACTION_IDLE)
{
var stopMove = new MoveReq();
stopMove.eid = Facade._entityID;
stopMove.action = (ushort)Proto4z.MOVE_ACTION.MOVE_ACTION_IDLE;
stopMove.clientPos = new Proto4z.EPosition(_control.transform.position.x, _control.transform.position.z);
Facade._serverProxy.SendToScene(stopMove);
}
_lastSendMove = Time.realtimeSinceStartup;
return;
}


Vector3 dst = _control.transform.position + _lastDirt;
_lastSendMove = Time.realtimeSinceStartup;
Expand Down
12 changes: 6 additions & 6 deletions Assets/Scripts/Protocol/DictScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ public class DictProp: Proto4z.IProtoObject //战斗属性
public double hp; //血量值
public double attack; //伤害
public double moveSpeed; //移动速度
public double attackSpeed; //攻击速度
public double attackQuick; //攻击加速
public string desc;
public DictProp()
{
id = 0;
hp = 0.0;
attack = 0.0;
moveSpeed = 0.0;
attackSpeed = 0.0;
attackQuick = 0.0;
desc = "";
}
public DictProp(ulong id, double hp, double attack, double moveSpeed, double attackSpeed, string desc)
public DictProp(ulong id, double hp, double attack, double moveSpeed, double attackQuick, string desc)
{
this.id = id;
this.hp = hp;
this.attack = attack;
this.moveSpeed = moveSpeed;
this.attackSpeed = attackSpeed;
this.attackQuick = attackQuick;
this.desc = desc;
}
public System.Collections.Generic.List<byte> __encode()
Expand All @@ -40,7 +40,7 @@ public System.Collections.Generic.List<byte> __encode()
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.hp));
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.attack));
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.moveSpeed));
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.attackSpeed));
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.attackQuick));
data.AddRange(Proto4z.BaseProtoObject.encodeString(this.desc));
return data;
}
Expand All @@ -50,7 +50,7 @@ public int __decode(byte[] binData, ref int pos)
this.hp = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.attack = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.moveSpeed = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.attackSpeed = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.attackQuick = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.desc = Proto4z.BaseProtoObject.decodeString(binData, ref pos);
return pos;
}
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/Protocol/ProtoReflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ static Reflection()
_idToName.Add(4005, "SceneServerCancelSceneIns");
_nameToID.Add("SceneServerGroupStateChangeIns", 4006);
_idToName.Add(4006, "SceneServerGroupStateChangeIns");
_nameToID.Add("SceneServerGroupStateFeedback", 4007);
_idToName.Add(4007, "SceneServerGroupStateFeedback");
_nameToID.Add("DictPairValue", 10000);
_idToName.Add(10000, "DictPairValue");
_nameToID.Add("DictGlobal", 10001);
Expand Down
19 changes: 12 additions & 7 deletions Assets/Scripts/Protocol/ProtoSceneCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ public class EntityState: Proto4z.IProtoObject //EntityState
public ulong avatarID;
public string avatarName;
public ulong modelID;
public double collision; //collision radius
public ushort camp; //阵营
public ulong groupID; //组队ID
public ushort etype; //实体类型
Expand All @@ -599,6 +600,7 @@ public EntityState()
avatarID = 0;
avatarName = "";
modelID = 0;
collision = 0.0;
camp = 0;
groupID = 0;
etype = 0;
Expand All @@ -608,12 +610,13 @@ public EntityState()
curHP = 0.0;
maxHP = 0.0;
}
public EntityState(ulong eid, ulong avatarID, string avatarName, ulong modelID, ushort camp, ulong groupID, ushort etype, ushort state, ulong foe, ulong master, double curHP, double maxHP)
public EntityState(ulong eid, ulong avatarID, string avatarName, ulong modelID, double collision, ushort camp, ulong groupID, ushort etype, ushort state, ulong foe, ulong master, double curHP, double maxHP)
{
this.eid = eid;
this.avatarID = avatarID;
this.avatarName = avatarName;
this.modelID = modelID;
this.collision = collision;
this.camp = camp;
this.groupID = groupID;
this.etype = etype;
Expand All @@ -630,6 +633,7 @@ public System.Collections.Generic.List<byte> __encode()
data.AddRange(Proto4z.BaseProtoObject.encodeUI64(this.avatarID));
data.AddRange(Proto4z.BaseProtoObject.encodeString(this.avatarName));
data.AddRange(Proto4z.BaseProtoObject.encodeUI64(this.modelID));
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.collision));
data.AddRange(Proto4z.BaseProtoObject.encodeUI16(this.camp));
data.AddRange(Proto4z.BaseProtoObject.encodeUI64(this.groupID));
data.AddRange(Proto4z.BaseProtoObject.encodeUI16(this.etype));
Expand All @@ -646,6 +650,7 @@ public int __decode(byte[] binData, ref int pos)
this.avatarID = Proto4z.BaseProtoObject.decodeUI64(binData, ref pos);
this.avatarName = Proto4z.BaseProtoObject.decodeString(binData, ref pos);
this.modelID = Proto4z.BaseProtoObject.decodeUI64(binData, ref pos);
this.collision = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.camp = Proto4z.BaseProtoObject.decodeUI16(binData, ref pos);
this.groupID = Proto4z.BaseProtoObject.decodeUI64(binData, ref pos);
this.etype = Proto4z.BaseProtoObject.decodeUI16(binData, ref pos);
Expand Down Expand Up @@ -1023,7 +1028,7 @@ public class EntitySkillInfo: Proto4z.IProtoObject //技能
public EPosition activeOrg;
public ulong activeOrgEID;
public EPosition activeDst;
public ulong activeDstEID;
public ushort activeFoeFirst;
public double activeTime;
public double lastTriggerTime;
public ushort isFinish;
Expand All @@ -1034,19 +1039,19 @@ public EntitySkillInfo()
activeOrg = new EPosition();
activeOrgEID = 0;
activeDst = new EPosition();
activeDstEID = 0;
activeFoeFirst = 0;
activeTime = 0.0;
lastTriggerTime = 0.0;
isFinish = 0;
activeCount = 0.0;
}
public EntitySkillInfo(ulong skillID, EPosition activeOrg, ulong activeOrgEID, EPosition activeDst, ulong activeDstEID, double activeTime, double lastTriggerTime, ushort isFinish, double activeCount)
public EntitySkillInfo(ulong skillID, EPosition activeOrg, ulong activeOrgEID, EPosition activeDst, ushort activeFoeFirst, double activeTime, double lastTriggerTime, ushort isFinish, double activeCount)
{
this.skillID = skillID;
this.activeOrg = activeOrg;
this.activeOrgEID = activeOrgEID;
this.activeDst = activeDst;
this.activeDstEID = activeDstEID;
this.activeFoeFirst = activeFoeFirst;
this.activeTime = activeTime;
this.lastTriggerTime = lastTriggerTime;
this.isFinish = isFinish;
Expand All @@ -1061,7 +1066,7 @@ public System.Collections.Generic.List<byte> __encode()
data.AddRange(Proto4z.BaseProtoObject.encodeUI64(this.activeOrgEID));
if (this.activeDst == null) this.activeDst = new EPosition();
data.AddRange(this.activeDst.__encode());
data.AddRange(Proto4z.BaseProtoObject.encodeUI64(this.activeDstEID));
data.AddRange(Proto4z.BaseProtoObject.encodeUI16(this.activeFoeFirst));
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.activeTime));
data.AddRange(Proto4z.BaseProtoObject.encodeDouble(this.lastTriggerTime));
data.AddRange(Proto4z.BaseProtoObject.encodeUI16(this.isFinish));
Expand All @@ -1076,7 +1081,7 @@ public int __decode(byte[] binData, ref int pos)
this.activeOrgEID = Proto4z.BaseProtoObject.decodeUI64(binData, ref pos);
this.activeDst = new EPosition();
this.activeDst.__decode(binData, ref pos);
this.activeDstEID = Proto4z.BaseProtoObject.decodeUI64(binData, ref pos);
this.activeFoeFirst = Proto4z.BaseProtoObject.decodeUI16(binData, ref pos);
this.activeTime = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.lastTriggerTime = Proto4z.BaseProtoObject.decodeDouble(binData, ref pos);
this.isFinish = Proto4z.BaseProtoObject.decodeUI16(binData, ref pos);
Expand Down
12 changes: 6 additions & 6 deletions Assets/Scripts/Protocol/ProtoSceneServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,23 @@ public int __decode(byte[] binData, ref int pos)
}
}

public class SceneServerGroupStateChangeIns: Proto4z.IProtoObject //scene ==> world
public class SceneServerGroupStateFeedback: Proto4z.IProtoObject //scene ==> world
{
//proto id
public const ushort protoID = 4006;
static public ushort getProtoID() { return 4006; }
static public string getProtoName() { return "SceneServerGroupStateChangeIns"; }
public const ushort protoID = 4007;
static public ushort getProtoID() { return 4007; }
static public string getProtoName() { return "SceneServerGroupStateFeedback"; }
//members
public ulong sceneID;
public ulong groupID;
public ushort state; //如果是NONE 说明离开场景
public SceneServerGroupStateChangeIns()
public SceneServerGroupStateFeedback()
{
sceneID = 0;
groupID = 0;
state = 0;
}
public SceneServerGroupStateChangeIns(ulong sceneID, ulong groupID, ushort state)
public SceneServerGroupStateFeedback(ulong sceneID, ulong groupID, ushort state)
{
this.sceneID = sceneID;
this.groupID = groupID;
Expand Down
Loading

0 comments on commit 09fd7c5

Please sign in to comment.