/// <summary> /// Unity Method /// </summary> private void Awake() { CommandDataEntity entity = new CommandDataEntity(); this.DataEntity = entity; Watch(this); }
/// <summary> /// 注入命令系统 /// </summary> private void Start() { goUndo = GameObject.Find("/Canvas/BtnUndo"); goRedo = GameObject.Find("/Canvas/BtnRedo"); CmdEntity = (CommandDataEntity)FindObjectOfType <CommandDataModel>().DataEntity; InjectService.InjectInto(this); StartCoroutine(UpdateCommandUIState()); }
/// <summary> /// 创建Cube操作 /// </summary> public void OnCreate() { CommandDataEntity cmdEntity = (CommandDataEntity)FindObjectOfType <CommandDataModel>().DataEntity; CreateCommandStr str = new CreateCommandStr(); //随机坐标 str.Position = new Vector3(Random.Range(-7, 11), Random.Range(-4, 6), Random.Range(0, 50)); cmdEntity.CreatePartMessage = str; }
/// <summary> /// 删除Cube操作 /// </summary> public void OnDelete() { if (IsClickedPart) { CommandDataEntity cmdEntity = (CommandDataEntity)FindObjectOfType <CommandDataModel>().DataEntity; DeleteCommandStr str = new DeleteCommandStr(); str.ObjectID = cubeDataEntity.objectID; cmdEntity.DeletePartMessage = str; IsClickedPart = false; } }
/// <summary> /// 改变Cube颜色 /// </summary> public void OnChangeColor() { if (IsClickedPart) { CommandDataEntity cmdEntity = (CommandDataEntity)FindObjectOfType <CommandDataModel>().DataEntity; ColorCommandStr str = new ColorCommandStr(); str.ObjectID = cubeDataEntity.objectID; //记录开始的颜色 str.OldColor = cubeDataModdel.gameObject.GetComponent <MeshRenderer>().material.color; //随机新的颜色 str.NewColor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)); cmdEntity.ColorParMessage = str; IsClickedPart = false; } }
/// <summary> /// Execute操作 /// </summary> public override void Execute() { CommandDataEntity entity = (CommandDataEntity)GameObject.FindObjectOfType <CommandDataModel>().DataEntity; CubeDataModel[] cubes = GameObject.FindObjectsOfType <CubeDataModel>(); foreach (CubeDataModel cube in cubes) { if (((BaseDataModelEntity)cube.DataEntity).objectID.Equals(ObjectId)) { Deleteobj = cube.gameObject; Deleteobj.SetActive(false); return; } } }
/// <summary> /// Execute操作 /// </summary> public override void Execute() { //物体UUID从数据实体(CommanDataEntity)中获得 CommandDataEntity entity = (CommandDataEntity)GameObject.FindObjectOfType <CommandDataModel>().DataEntity; CubeDataModel[] cubes = GameObject.FindObjectsOfType <CubeDataModel>(); foreach (CubeDataModel cube in cubes) { if (((BaseDataModelEntity)cube.DataEntity).objectID.Equals(ColorObjectID)) { Colorobj = cube.gameObject; Colorobj.GetComponent <Renderer>().material.color = NewColor; return; } } }