public System.Collections.IEnumerator HighLightSelectedObjectCorutine(UnityEngine.GameObject gameObject, UnityEngine.Color color, float width, UnityEngine.Vector2 size, AltClientSocketHandler handler) { destroyHightlight = false; UnityEngine.Renderer renderer = gameObject.GetComponent <UnityEngine.Renderer>(); System.Collections.Generic.List <UnityEngine.Shader> originalShaders = new System.Collections.Generic.List <UnityEngine.Shader>(); if (renderer != null) { foreach (var material in renderer.materials) { originalShaders.Add(material.shader); material.shader = outlineShader; material.SetColor("_OutlineColor", color); material.SetFloat("_OutlineWidth", width); } yield return(null); new GetScreenshotCommand(size, handler).Execute(); yield return(null); for (var i = 0; i < renderer.materials.Length; i++) { renderer.materials[i].shader = originalShaders[0]; } } else { var rectTransform = gameObject.GetComponent <UnityEngine.RectTransform>(); if (rectTransform != null) { var panelHighlight = Instantiate(panelHightlightPrefab, rectTransform); panelHighlight.GetComponent <UnityEngine.UI.Image>().color = color; yield return(null); new GetScreenshotCommand(size, handler).Execute(); while (!destroyHightlight) { yield return(null); } Destroy(panelHighlight); destroyHightlight = false; } else { var response = new GetScreenshotCommand(size, handler).Execute(); handler.SendResponse(response); } } }
public void ClientSocketHandlerDidReadMessage(AltClientSocketHandler handler, string message) { string[] separator = new string[] { requestSeparatorString }; string[] pieces = message.Split(separator, System.StringSplitOptions.None); AltUnityComponent altComponent; AltUnityObject altUnityObject; string methodParameters; UnityEngine.Vector2 size; PLayerPrefKeyType option; Command command = null; try { switch (pieces[0]) { case "findAllObjects": methodParameters = pieces[1] + requestSeparatorString + pieces[2]; command = new FindAllObjectsCommand(methodParameters); break; case "findObjectByName": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3]; command = new FindObjectByNameCommand(methodParameters); break; case "findObjectWhereNameContains": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3]; command = new FindObjectWhereNameContainsCommand(methodParameters); break; case "tapObject": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new TapCommand(altUnityObject); break; case "findObjectsByName": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3]; command = new FindObjectsByNameCommand(methodParameters); break; case "findObjectsWhereNameContains": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3]; command = new FindObjectsWhereNameContainsCommand(methodParameters); break; case "getCurrentScene": command = new GetCurrentSceneCommand(); break; case "findObjectByComponent": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3] + requestSeparatorString + pieces[4]; command = new FindObjectByComponentCommand(methodParameters); break; case "findObjectsByComponent": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3] + requestSeparatorString + pieces[4]; command = new FindObjectsByComponentCommand(methodParameters); break; case "getObjectComponentProperty": command = new GetComponentPropertyCommand(pieces[1], pieces[2]); break; case "setObjectComponentProperty": command = new SetObjectComponentPropertyCommand(pieces[1], pieces[2], pieces[3]); break; case "callComponentMethodForObject": command = new CallComponentMethodForObjectCommand(pieces[1], pieces[2]); break; case "closeConnection": UnityEngine.Debug.Log("Socket connection closed!"); _socketServer.StartListeningForConnections(); break; case "clickEvent": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new ClickEventCommand(altUnityObject); break; case "tapScreen": command = new ClickOnScreenAtXyCommand(pieces[1], pieces[2]); break; case "dragObject": UnityEngine.Vector2 positionVector2 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]); altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[2]); command = new DragObjectCommand(positionVector2, altUnityObject); break; case "dropObject": UnityEngine.Vector2 positionDropVector2 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]); altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[2]); command = new DropObjectCommand(positionDropVector2, altUnityObject); break; case "pointerUpFromObject": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new PointerUpFromObjectCommand(altUnityObject); break; case "pointerDownFromObject": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new PointerDownFromObjectCommand(altUnityObject); break; case "pointerEnterObject": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new PointerEnterObjectCommand(altUnityObject); break; case "pointerExitObject": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new PointerExitObjectCommand(altUnityObject); break; case "tilt": UnityEngine.Vector3 vector3 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector3>(pieces[1]); command = new TiltCommand(vector3); break; case "movingTouch": UnityEngine.Vector2 start2 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]); UnityEngine.Vector2 end2 = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[2]); command = new SetMovingTouchCommand(start2, end2, pieces[3]); break; case "loadScene": command = new Assets.AltUnityTester.AltUnityServer.Commands.LoadSceneCommand(pieces[1]); break; case "setTimeScale": float timeScale = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[1]); command = new SetTimeScaleCommand(timeScale); break; case "getTimeScale": command = new GetTimeScaleCommand(); break; case "deletePlayerPref": command = new DeletePlayerPrefCommand(); break; case "deleteKeyPlayerPref": command = new DeleteKeyPlayerPrefCommand(pieces[1]); break; case "setKeyPlayerPref": option = (PLayerPrefKeyType)System.Enum.Parse(typeof(PLayerPrefKeyType), pieces[3]); command = new SetKeyPlayerPrefCommand(option, pieces[1], pieces[2]); break; case "getKeyPlayerPref": option = (PLayerPrefKeyType)System.Enum.Parse(typeof(PLayerPrefKeyType), pieces[2]); command = new GetKeyPlayerPrefCommand(option, pieces[1]); break; case "actionFinished": command = new ActionFinishedCommand(); break; case "getAllComponents": command = new GetAllComponentsCommand(pieces[1]); break; case "getAllFields": altComponent = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityComponent>(pieces[2]); command = new GetAllFieldsCommand(pieces[1], altComponent); break; case "getAllMethods": altComponent = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityComponent>(pieces[1]); command = new GetAllMethodsCommand(altComponent); break; case "getAllScenes": command = new GetAllScenesCommand(); break; case "getAllCameras": command = new GetAllCamerasCommand(); break; case "getScreenshot": size = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]); command = new GetScreenshotCommand(size, handler); break; case "hightlightObjectScreenshot": var id = System.Convert.ToInt32(pieces[1]); size = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[3]); command = new HighlightSelectedObjectCommand(id, pieces[2], size, handler); break; case "hightlightObjectFromCoordinatesScreenshot": var coordinates = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]); size = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[3]); command = new HightlightObjectFromCoordinatesCommand(coordinates, pieces[2], size, handler); break; case "pressKeyboardKey": var piece = pieces[1]; UnityEngine.KeyCode keycode = (UnityEngine.KeyCode)System.Enum.Parse(typeof(UnityEngine.KeyCode), piece); float power = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[2]); float duration = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[3]); command = new HoldButtonCommand(keycode, power, duration); break; case "moveMouse": UnityEngine.Vector2 location = Newtonsoft.Json.JsonConvert.DeserializeObject <UnityEngine.Vector2>(pieces[1]); duration = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[2]); command = new MoveMouseCommand(location, duration); break; case "scrollMouse": var scrollValue = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[1]); duration = Newtonsoft.Json.JsonConvert.DeserializeObject <float>(pieces[2]); command = new ScrollMouseCommand(scrollValue, duration); break; case "findObject": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3]; command = new FindObjectCommand(methodParameters); break; case "findObjects": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3]; command = new FindObjectsCommand(methodParameters); break; case "findActiveObjectByName": methodParameters = pieces[1] + requestSeparatorString + pieces[2] + requestSeparatorString + pieces[3]; command = new FindActiveObjectsByNameCommand(methodParameters); break; case "enableLogging": var enableLogging = bool.Parse(pieces[1]); command = new EnableLoggingCommand(enableLogging); break; case "getText": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new GetTextCommand(altUnityObject); break; case "setText": altUnityObject = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(pieces[1]); command = new SetTextCommand(altUnityObject, pieces[2]); break; case "getPNGScreenshot": command = new GetScreenshotPNGCommand(handler); break; default: command = new UnknowStringCommand(); break; } } catch (Newtonsoft.Json.JsonException exception) { UnityEngine.Debug.Log(exception); handler.SendResponse(errorCouldNotParseJsonString); } if (command != null) { command.SendResponse(handler); } }