在上一节中,我觉得数据还是有些零散,所以重新规划了一下。
我们新建一个专门属于小姐姐的数据类型的集合,将其命名为PlayerBaseData,我们在其中创建一个结构体数据类型。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//这里用于创建player对象的一些需要的类型。
public struct PlayerBaseData {
float walkSpeed;
public float WalkSpeed {
get { return walkSpeed; }
}
float runSpeed;
public float RunSpeed {
get { return runSpeed; }
}
float jumpSpeed;
public float JumpSpeed {
get { return jumpSpeed; }
}
int hp_Max;
public int HP_Max {
get { return hp_Max; }
}
int hp;
public int HP {
get { return hp; }
}
public PlayerBaseData(float walkSpeed, float runspeed, float jumSpeed, int Hp_MAX, int HP) {
this.walkSpeed = walkSpeed;
this.runSpeed = runspeed;
this.jumpSpeed = jumSpeed;
this.hp_Max = Hp_MAX;
this.hp = HP;
}
}
signal修改
public class PlayerBaseDataSignal : Signal<PlayerBaseData>
{//models向playerView发送基础数据。
}
在IPlayerModel进行修改
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface IPlayerModel {
PlayerBaseData RequestGetPlayerModel();
CallMadelPlyerBaseDataSignal callMadelPlyerBaseDataSignal { get; }
}
在PlayerModel中进行修改
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerModel:IPlayerModel {
PlayerBaseData playerBaseData;
[Inject]
public CallMadelPlyerBaseDataSignal callMadelPlyerBaseDataSignal { get; set; }
public PlayerModel() {
playerBaseData = new PlayerBaseData(1, 3, 3.5f, 5, 5);
}
public PlayerBaseData RequestGetPlayerModel() {
return playerBaseData;
}
}
在PlayerCommand中进行修改。
private void onComplete() {
Debug.Log("获得通知,开始找寻model中的数据转发给playerBaseDataSignal监听");
playerBaseDataSignal.Dispatch(model.RequestGetPlayerModel());
// Release();
}
}
在PlayerTestMediator进行修改:
void setPlayerData(PlayerBaseData playerBD) {
Debug.Log("接收到player基础数据");
playerView.updateBaseData(playerBD);
}
最后在PlayerTestView的修改
PlayerBaseData playerBaseData;
public void updateBaseData(PlayerBaseData PBD) {
this.playerBaseData = PBD;
}
最后在使用数据的地方通过这个结构体的数据进行修改。
网友评论