Esempio n. 1
0
    public void ChangePositionObject(string strJSONparameters)
    {
        JsonParametersPositionGameObject jsonParametersPositionGameObject = JsonUtility.FromJson <JsonParametersPositionGameObject>(strJSONparameters);
        GameObject gameObject = GameObject.Find(jsonParametersPositionGameObject.ObjectName);

        if (jsonParametersPositionGameObject.SetNew)
        {
            gameObject.transform.localPosition = jsonParametersPositionGameObject.Position;
        }
        else
        {
            gameObject.transform.localPosition += jsonParametersPositionGameObject.Position;
        }
        gameObject.transform.GetChild(0).GetChild(0).GetComponent <Renderer>().enabled = true;
    }
Esempio n. 2
0
    void Update()
    {
        opendoor.gameObjectForOpen      = null;
        Using1.gameObjectForShader      = null;
        Switch.chosenGameObject         = null;
        ActiveObject.chosenGameObject   = null;
        OnDoor.chosenGameObject         = null;
        ActivateScript.chosenGameObject = null;
        OnChose.chosenGameObject        = null;
        ObjectClicker.chosenGameObject  = null;

        Vector3 Direction = RaycastS.TransformDirection(Vector3.forward);

        if (Physics.Raycast(RaycastS.position, Direction, out Hit, 1000f))
        {
            if (Hit.collider.material.staticFriction == 0.2f)
            {
                //Using1 usingScript = Hit.collider.gameObject.GetComponent<Using1>();
                //if (usingScript)
                //{
                //    Using1.gameObjectForShader = Hit.collider.gameObject;
                //}

                opendoor opendoorScript = Hit.collider.gameObject.GetComponent <opendoor>();
                if (opendoorScript)
                {
                    opendoor.gameObjectForOpen = Hit.collider.gameObject;
                }

                Switch switchScript = Hit.collider.gameObject.GetComponent <Switch>();
                if (switchScript)
                {
                    Switch.chosenGameObject = Hit.collider.gameObject;
                }
            }

            ActiveObject activeObjectScript = Hit.collider.gameObject.GetComponent <ActiveObject>();
            if (activeObjectScript)
            {
                ActiveObject.chosenGameObject = Hit.collider.gameObject;
            }

            OnDoor onDoorScript = Hit.collider.gameObject.GetComponent <OnDoor>();
            if (onDoorScript)
            {
                OnDoor.chosenGameObject = Hit.collider.gameObject;
            }
            OnChose onChoseScript = Hit.collider.gameObject.GetComponent <OnChose>();
            if (onChoseScript)
            {
                OnChose.chosenGameObject = Hit.collider.gameObject;
            }
            ObjectClicker onClikerScript = Hit.collider.gameObject.GetComponent <ObjectClicker>();
            if (onClikerScript)
            {
                ObjectClicker.chosenGameObject = Hit.collider.gameObject;
            }

            ActivateScript activateScript = Hit.collider.gameObject.GetComponent <ActivateScript>();
            if (activateScript)
            {
                ActivateScript.chosenGameObject = Hit.collider.gameObject;
            }
        }
        //  ManageTaskDialog();

        //if (Input.GetMouseButtonDown(0)) //left
        //{
        //    eProject.CallServerMethod_DoAction("1e106acb-e6d3-41f5-865e-4eafb8b329d5", "c176dc43-0a07-4ae7-ba40-556735982901", 1);
        //}
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            //Cursor.visible = !Cursor.visible;

            //if(Cursor.lockState == CursorLockMode.None)
            //    Cursor.lockState = CursorLockMode.Locked;
            //else if (Cursor.lockState == CursorLockMode.Locked)
            //    Cursor.lockState = CursorLockMode.None;

            //MouseLook scriptMouseLook = gameObject.GetComponent<MouseLook>();
            //scriptMouseLook.enabled = !(scriptMouseLook.enabled);

            MouseLook scriptMouseLook = gameObject.GetComponent <MouseLook>();
            if (Cursor.visible == true)
            {
                Cursor.visible          = false;
                Cursor.lockState        = CursorLockMode.Locked;
                scriptMouseLook.enabled = true;
            }
            else
            {
                Cursor.visible          = true;
                Cursor.lockState        = CursorLockMode.None;
                scriptMouseLook.enabled = false;
            }
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            gameObjectLight.SetActive(!gameObjectLight.activeSelf);

            //var listener = new UnityEventListener
            //{
            //    EventType = "keyDown",
            //    IdObject = Guid.Empty,
            //    KeyCode = "L"
            //};
            //listener.SendEvent();

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

            JsonParametersRotateGameObject jsonParametersRotateGameObject = new JsonParametersRotateGameObject
            {
                ObjectName = "Door_Дверь РУВН",
                Angle      = new Vector3(0, 20, 0),
                IsSpecific = true
            };
            string json = JsonUtility.ToJson(jsonParametersRotateGameObject);

            unityApiScript.RotateGameObject(json);


            //List<JsonButton> btns = new List<JsonButton>();
            //for (int i=0; i<5; i++)
            //{
            //    JsonButton jsonButton = new JsonButton
            //    {
            //        Name = "Команда № " + i.ToString(),
            //        Value = i
            //    };
            //    btns.Add(jsonButton);
            //}

            //unityApiScript.CreateDialog(btns);


            List <CodeValuePair>     codeValuePairs = new List <CodeValuePair>();
            List <int>               codes          = new List <int>();
            List <string>            values         = new List <string>();
            Dictionary <int, string> keyValuePairs  = new Dictionary <int, string>();
            for (int i = 0; i < 5; i++)
            {
                int    key   = i;
                string value = "Команда № " + i.ToString();
                keyValuePairs.Add(key, value);
                codeValuePairs.Add(new CodeValuePair {
                    Code = key, Value = value
                });
                codes.Add(key);
                values.Add(value);
            }


            DialogData jsonDialog = new DialogData
            {
                DialogCode  = 1,
                DialogTitle = "Сумка с причиндалами",
                //    KeyValuePairs = keyValuePairs,
                //   CodeValuePairs = codeValuePairs
                Codes  = codes,
                Values = values
            };
            string strJsonDialog = JsonUtility.ToJson(jsonDialog);


            unityApiScript.CreateDialog(strJsonDialog);
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            //GameObject gameObjectUnityApi = GameObject.Find("UnityAPI");
            //UnityApiScript unityApiScript = gameObjectUnityApi.GetComponent<UnityApiScript>();

            //JsonParametersRotateGameObject jsonParametersRotateGameObject = new JsonParametersRotateGameObject
            //{
            //    ObjectName = "Door_Дверь РУВН",
            //    Angle = 135f,
            //    IsSpecific = true
            //};
            //string json = JsonUtility.ToJson(jsonParametersRotateGameObject);

            //unityApiScript.RotateGameObject(json);

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

            JsonParametersLightGameObject jsonParametersLightGameObject = new JsonParametersLightGameObject
            {
                ObjectName = "Твердое тело1 818",
                IsLight    = true
            };
            string json1 = JsonUtility.ToJson(jsonParametersLightGameObject);

            unityApiScript.LightGameObject(json1);
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            //GameObject gameObjectUnityApi = GameObject.Find("UnityAPI");
            //UnityApiScript unityApiScript = gameObjectUnityApi.GetComponent<UnityApiScript>();

            //JsonParametersRotateGameObject jsonParametersRotateGameObject = new JsonParametersRotateGameObject
            //{
            //    ObjectName = "Door_Дверь РУВН",
            //    Angle = 135f,
            //    IsSpecific = true
            //};
            //string json = JsonUtility.ToJson(jsonParametersRotateGameObject);

            //unityApiScript.RotateGameObject(json);

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

            //JsonParametersLightGameObject jsonParametersLightGameObject = new JsonParametersLightGameObject
            //{
            //    ObjectName = "Твердое тело1 818",
            //    IsLight = false
            //};
            //string json1 = JsonUtility.ToJson(jsonParametersLightGameObject);

            //unityApiScript.LightGameObject(json1);

            GameObject            AssetManager          = GameObject.Find("AssetManager");
            NonCachingLoadExample NonCachingLoadExample = AssetManager.GetComponent <NonCachingLoadExample>();
            AddAssetParameter     addAssetParameter     = new AddAssetParameter
            {
                bundleURL = "D:/Training3dProjects/Training_v7/Assets/AssetBundles/cubeasset",
                assetName = "D:/Training3dProjects/Training_v7/Assets/Scenes/Resources_2018.12.26/Cube.prefab"//"A20", };
            };

            string json1 = JsonUtility.ToJson(addAssetParameter);
            NonCachingLoadExample.LoadAsset(json1);
        }

        if (Input.GetKeyDown(KeyCode.G))
        {
            //GameObject gameObjectUnityApi = GameObject.Find("UnityAPI");
            //UnityApiScript unityApiScript = gameObjectUnityApi.GetComponent<UnityApiScript>();

            //JsonParametersRotateGameObject jsonParametersRotateGameObject = new JsonParametersRotateGameObject
            //{
            //    ObjectName = "Door_Дверь РУВН",
            //    Angle = 135f,
            //    IsSpecific = true
            //};
            //string json = JsonUtility.ToJson(jsonParametersRotateGameObject);

            //unityApiScript.RotateGameObject(json);

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

            JsonParametersPositionGameObject jsonParametersPositionGameObject = new JsonParametersPositionGameObject
            {
                ObjectName = "Твердое тело1 88",
                Position   = new Vector3(0.5f, 0f, 0f),
                SetNew     = false
            };
            string json = JsonUtility.ToJson(jsonParametersPositionGameObject);

            unityApiScript.ChangePositionObject(json);
        }

        if (Input.GetKeyDown(KeyCode.J))
        {
            MouseLook scriptMouseLook = gameObject.GetComponent <MouseLook>();
            Zoom      scriptZoom      = GameObject.Find("Player").GetComponent <Zoom>();


            GameObject mainCamera     = GameObject.Find("Main Camera");
            Dialogue   dialogueScript = mainCamera.GetComponent <Dialogue>();

            if (dialogueScript.ShowDialogue == true)
            {
                //Cursor.visible = false;
                //Cursor.lockState = CursorLockMode.Locked;
                scriptMouseLook.enabled = true;
                scriptZoom.enabled      = true;
            }
            else
            {
                // Cursor.visible = true;
                // Cursor.lockState = CursorLockMode.None;
                scriptMouseLook.enabled = false;
                scriptZoom.enabled      = false;
            }



            if (dialogueScript.ShowDialogue == true)
            {
                dialogueScript.ShowDialogue = false;
            }
            else
            {
                DialogueNode node0 = new DialogueNode();
                node0.NpcText  = "Я: -Здравствуйте, диспетчерская?\n";
                node0.NpcText += "Диспетчер: -Здравствуйте, диспетчер Иванов, слушаю.";
                Answer ans0_1 = new Answer
                {
                    Text     = "Я: - Прошу снять напряжение с КТП-10/0,4 с номером 86732. Потребители уведомлены о снятии напряжения.\nДиспетчер: - Снимаю напряжение с КТП-10/0,4 с номером 86732.",
                    ToNode   = 0,
                    SpeakEnd = true,

                    ActionRef        = "e9477766-93dc-497d-a7e0-91ab73dcaab5",
                    ElementRef       = Guid.Empty.ToString(),
                    InventoryItemRef = "41a454ad-e7cb-4785-a4d5-d969f42abb81"
                };
                Answer ans0_2 = new Answer
                {
                    Text     = "Я: - Вы сняли напряжение?\nДиспетчер: - Да, напряжение с КТП-10/0,4 снято.",
                    ToNode   = 0,
                    SpeakEnd = true,

                    ActionRef        = "e474abb8-b273-48ec-b138-131c28ca0826",
                    ElementRef       = Guid.Empty.ToString(),
                    InventoryItemRef = "41a454ad-e7cb-4785-a4d5-d969f42abb81"
                };
                Answer ans0_3 = new Answer
                {
                    Text     = "Я: - Прошу подать напряжение на КТП 10/0,4. с номером 86732 \"Считаю, КТП 10/0.4 под напряжением\"\nДиспетчер: - Напряжение подано",
                    ToNode   = 0,
                    SpeakEnd = true,

                    ActionRef        = "e20b60e8-b7a1-4ed0-ba4b-c315c0d20149",
                    ElementRef       = Guid.Empty.ToString(),
                    InventoryItemRef = "41a454ad-e7cb-4785-a4d5-d969f42abb81"
                };
                Answer ans0_4 = new Answer
                {
                    Text     = "Я: - Прошу снять напряжение с КТП-10/0,4 с номером 843432. Потребители уведомлены о снятии напряжения.\nДиспетчер: - Снимаю напряжение с КТП-10/0,4 с номером 843432.",
                    ToNode   = 0,
                    SpeakEnd = true,

                    ActionRef        = "06a9e850-b562-4209-b98d-765fa8b7d071",
                    ElementRef       = "",
                    InventoryItemRef = "41a454ad-e7cb-4785-a4d5-d969f42abb81"
                };
                Answer ans0_5 = new Answer
                {
                    Text     = "Я: - Прошу подать напряжение на КТП-10/0,4 с номером 321455. \"Считаю, КТП 10 / 0.4 под напряжением\"\nДиспетчер: - Напряжение подано",
                    ToNode   = 0,
                    SpeakEnd = true,

                    ActionRef        = "604640b3-f525-4e48-a051-8e008d9dd286",
                    ElementRef       = "",
                    InventoryItemRef = "41a454ad-e7cb-4785-a4d5-d969f42abb81"
                };
                node0.PlayerAnswer = new Answer[] { ans0_1, ans0_2, ans0_3, ans0_4, ans0_5 };

                //DialogueNode node1 = new DialogueNode();
                //node1.NpcText = "Выполняю снятие напряжения с КТП-10/0,4.";
                //node1.PlayerAnswer = new Answer[] { ans0_2, ans0_3, ans0_4, ans0_5 };

                //DialogueNode node2 = new DialogueNode();
                //node2.NpcText = "Подтверждаю о снятии напряжения с КТП-10/0,4.";
                //node2.PlayerAnswer = new Answer[] { ans0_3, ans0_4, ans0_5 };

                //DialogueNode node3 = new DialogueNode();
                //node3.NpcText = "Подано напряжение на КТП 10/0,4.";
                //node3.PlayerAnswer = new Answer[] { ans0_5 };

                dialogueScript._currentNode = 0;
                dialogueScript.node         = new DialogueNode[] { node0 };
                dialogueScript.ShowDialogue = true;
            }
        }

        //if (Input.GetKeyDown(KeyCode.Space))
        //{
        //    MouseLook scriptMouseLook = gameObject.GetComponent<MouseLook>();
        //    if (Cursor.visible == true)
        //    {
        //        Cursor.visible = false;
        //        Cursor.lockState = CursorLockMode.Locked;
        //        scriptMouseLook.enabled = true;
        //    }
        //    else
        //    {
        //        Cursor.visible = true;
        //        Cursor.lockState = CursorLockMode.None;
        //        scriptMouseLook.enabled = false;
        //    }
        //
        //
        //    GameObject gameObjectUnityApi = GameObject.Find("UnityAPI");
        //    Actions unityApiScript = gameObjectUnityApi.GetComponent<Actions>();
        //    Actions.show = !Actions.show;
        //
        //}
    }
Esempio n. 3
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;
    }