예제 #1
0
        public bool UpdateTu_SoLuongHienTai(string id, ActionWithObject action)
        {
            int soluong = 0;
            var tu      = _tuService.GetById(id);

            if (tu == null)
            {
                return(false);
            }

            soluong = Compute.ComputeAmountWithAction(tu.SoLuongHienTai, action);

            if (soluong > tu.SoLuongMax)
            {
                ViewBag.Tus = SelectListItemFromDomain.SelectListItem_Tu(_tuService.GetAll(m => m.OrderBy(t => t.Ten)));
                return(false);
            }
            else
            {
                tu.SoLuongHienTai = soluong;

                _tuService.Update(tu);
                return(true);
            }
        }
예제 #2
0
        private string ActionString(ActionWithObject actionWithObject)
        {
            string result = "";

            switch (actionWithObject)
            {
            case ActionWithObject.Create:
                result = "Tạo mới ";
                break;

            case ActionWithObject.Update:
                result = "Cập nhật ";
                break;

            case ActionWithObject.Delete:
                result = "Xóa ";
                break;

            case ActionWithObject.ChangeStatus:
                result = "Thay Đổi ";
                break;

            default:
                break;
            }
            return(result);
        }
예제 #3
0
        public void Create(ActionWithObject hoatDong, string userId, string chiTietHoatDong)
        {
            var lichSuHoatDong = new LichSuHoatDong()
            {
                HoatDong        = ActionString(hoatDong),
                ChiTietHoatDong = ActionString(hoatDong) + chiTietHoatDong,
                UserId          = userId
            };

            _lichSuHoatDongService.Insert(lichSuHoatDong);
        }
        public bool UpdateTu_SoHopHienTai(string id, ActionWithObject action)
        {
            var ke = _keService.GetById(id);

            if (ke == null)
            {
                return(false);
            }

            var soluong = Compute.ComputeAmountWithAction(ke.SoHopHienTai, action);

            if (soluong > ke.SoHopToiDa)
            {
                DropDownList();
                return(false);
            }
            else
            {
                ke.SoHopHienTai = soluong;
                _keService.Update(ke);
                return(true);
            }
        }
        public static int ComputeAmountWithAction(int amount, ActionWithObject action)
        {
            int result = 0;

            switch (action)
            {
            case ActionWithObject.Create:
                result = amount;
                break;

            case ActionWithObject.Update:
                result = amount + 1;
                break;

            case ActionWithObject.Delete:
                result = amount - 1;
                break;

            default:
                break;
            }
            return(result);
        }
예제 #6
0
    public static void DoAction(ActionWithObject action)
    {
        Stopwatch SW = new Stopwatch();

        SW.Start();

        MouseLook scriptMouseLook = GameObject.Find("Player").GetComponent <MouseLook>();
        Zoom      scriptZoom      = GameObject.Find("Player").GetComponent <Zoom>();

        scriptMouseLook.enabled = true;
        scriptZoom.enabled      = true;
        //Cursor.visible = false;
        //Cursor.lockState = CursorLockMode.Locked;

        GameObject     gameObjectUnityApi = GameObject.Find("UnityAPI");
        UnityApiScript unityApiScript     = gameObjectUnityApi.GetComponent <UnityApiScript>();

        var     gameObject = GameObject.Find("UnityAPI");
        Logging log        = gameObject.GetComponent <Logging>();

        switch (action.typeEvent)
        {
        case "Rotate":
            var jsonParametersRotateGameObject = new JsonParametersRotateGameObject
            {
                ObjectName = action.objectName,
                Angle      = JsonUtility.FromJson <Vector3>(action.parameter),
                IsSpecific = true,
                IsLocal    = true
            };

            string json = JsonUtility.ToJson(jsonParametersRotateGameObject);
            unityApiScript.RotateGameObject(json);

            SW.Stop();

            break;

        case "ChangeShader":
            var jsonParametersShaderGameObject = new JsonParametersShaderGameObject
            {
                ObjectName = action.objectName,
                shaderName = action.parameter
            };

            string json1 = JsonUtility.ToJson(jsonParametersShaderGameObject);
            unityApiScript.ChangeShader(json1);

            SW.Stop();

            break;

        case "ChangePositionObject":
            var param = JsonUtility.FromJson <Vector3>(action.parameter);
            var jsonParametersPositionGameObject = new JsonParametersPositionGameObject
            {
                ObjectName = action.objectName,
                Position   = param,
                SetNew     = true
            };

            string json2 = JsonUtility.ToJson(jsonParametersPositionGameObject);
            unityApiScript.ChangePositionObject(json2);

            SW.Stop();

            break;

        case "HideObject":
            var jsonParametersHideGameObject = new BaseJsonParametrs
            {
                ObjectName = action.objectName
            };

            string json3 = JsonUtility.ToJson(jsonParametersHideGameObject);

            unityApiScript.HighGameObject(json3);

            SW.Stop();

            break;

        case "UnHideObject":
            var jsonParametersUnHideGameObject = new BaseJsonParametrs
            {
                ObjectName = action.objectName
            };

            string json4 = JsonUtility.ToJson(jsonParametersUnHideGameObject);

            unityApiScript.UnHighGameObject(json4);

            SW.Stop();

            break;

        case "UseTable":
            //var param1 = JsonUtility.FromJson<Vector3[]>(action.parameter);
            //var jsonParametersUseGameObject = new JsonParametersUseTableGameObject
            //{
            //    Angle = param1[1],
            //    Position = param1[0]
            //};

            //string json4 = JsonUtility.ToJson(jsonParametersUseGameObject);

            //unityApiScript.RotateGameObject(json4);
            //GameObject.Find(action.parameter).transform.eulerAngles
            var          targetGO     = GameObject.Find(action.parameter);
            TablesScript tablesScript = targetGO.GetComponent <TablesScript>();

            if (GameObject.Find(action.objectName + action.parameter) != null)
            {
                break;
            }
            GameObject newTable = Instantiate(GameObject.Find(action.objectName));
            newTable.name             = action.objectName + " " + action.parameter;
            newTable.transform.parent = targetGO.transform;
            // BoxCollider box = newTable.AddComponent<BoxCollider>();
            OnChose onChose = newTable.transform.GetChild(0).GetChild(0).GetComponent <OnChose>();
            if (onChose)
            {
                onChose.enabled = false;
            }

            var boxCollider = newTable.transform.GetChild(0).GetChild(0).transform.GetComponent <BoxCollider>();
            //boxCollider.enabled = false;

            //newTable.transform.eulerAngles = new Vector3(-90f, -90f, 270f);
            //newTable.transform.eulerAngles = new Vector3(-0,3641f, 0,2124f, 0,102f);

            var jsonParametersRotateGameObject1 = new JsonParametersRotateGameObject
            {
                ObjectName = newTable.name,              //action.objectName,
                Angle      = tablesScript.localRotation, //new Vector3(-180f, -1.525879e-05f, -1.525879e-05f),//GameObject.Find(action.parameter).transform.eulerAngles
                IsSpecific = true,
                IsLocal    = true
            };

            string json5 = JsonUtility.ToJson(jsonParametersRotateGameObject1);
            unityApiScript.RotateGameObject(json5);

            var jsonParametersPositionGameObject1 = new JsonParametersPositionGameObject
            {
                ObjectName = newTable.name,              //action.objectName,
                Position   = tablesScript.localPosition, //new Vector3(-0.121457f, 1.350971f, 3.714326f),//GameObject.Find(action.parameter).transform.position
                SetNew     = true
            };



            string json6 = JsonUtility.ToJson(jsonParametersPositionGameObject1);
            unityApiScript.ChangePositionObject(json6);

            InitSceneScript scriptSetActive = GameObject.Find("Player").GetComponent <InitSceneScript>();
            EProject        eProject        = scriptSetActive.eProject;

            eProject.InventoryItemCurrent = null;
            if (eProject.GameObjectInventoryItemCurrent)
            {
                GameObject.Destroy(eProject.GameObjectInventoryItemCurrent);
            }

            //InitSceneScript scriptSetActive = GameObject.Find("Player").GetComponent<InitSceneScript>();
            //EProject eProject = scriptSetActive.eProject;
            //eProject.InventoryItemCurrent = null;

            SW.Stop();

            break;

        case "DestroyObject":
            var jsonParametersDestroyGameObject = new BaseJsonParametrs
            {
                ObjectName = action.objectName
            };

            string json7 = JsonUtility.ToJson(jsonParametersDestroyGameObject);

            unityApiScript.DestroyGameObject(json7);

            SW.Stop();

            break;

        case "Check":


            UnityEngine.Debug.Log("ПРОВЕРКА");

            break;
        }

        InitSceneScript initSceneScript = GameObject.Find("Player").GetComponent <InitSceneScript>();

        initSceneScript._eventListener.SendMessageToSR(action.ElementRef, action.ActionRef, action.InventoryItemRef);

        log.logs.Add(new LogElement
        {
            dataTime      = DateTime.Now,
            name          = action.logName,
            objName       = action.objectName,
            timeExecution = SW.ElapsedMilliseconds.ToString()
        });

        showAction = false;

        //Cursor.visible = true;
        //Cursor.lockState = CursorLockMode.None;
    }