public void InitCurrentFrame() { if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.BlackBerryPlayer || Application.platform == RuntimePlatform.WP8Player) return; currentResult = new HumanInputProviderData(); currentResult.providerType = this.GetType().Name; currentResult.basicInput = GetMouseCommands(); }
//--------------- Serialize / Deserialize -------------------- public static byte[] Serialize(HumanInputProviderData input) { if (input == null) return null; ComposedByteStream stream = ComposedByteStream.FetchStream(); stream.AddStream(input.providerType); if (input.basicInput != null && input.basicInput.Length > 0) { ComposedByteStream subStream = ComposedByteStream.FetchStream(); for (int i = 0; i < input.basicInput.Length; i++) InputCommand.Serialize(input.basicInput[i], ref subStream); stream.AddStream(subStream.Compose()); } else { stream.AddEmptyStream(); } return stream.Compose(); }
public static HumanInputProviderData Deserialize(byte[] input) { if (input == null || input.Length == 0) return null; HumanInputProviderData result = new HumanInputProviderData(); ComposedByteStream stream = ComposedByteStream.FromByteArray(input); result.providerType = stream.ReadNextStream(); ComposedByteStream basic = ComposedByteStream.FromByteArray(stream.ReadNextStream<byte>()); if (basic != null && basic.streamCount > 0) { int iMax = basic.streamCount / 2; result.basicInput = new InputCommand[iMax]; for (int i = 0; i < iMax; i++) result.basicInput[i] = InputCommand.Deserialize(ref basic); basic.Dispose(); } stream.Dispose(); return result; }
public void Dispose() { currentResult = new HumanInputProviderData(); }
private void DrawMouseQuads(HumanInputProviderData provider, Transform parent, float screenWidth, float screenHeight) { if (provider.basicInput.Length > 0) { //--------------- Check if any has mouse down / up -------------------- bool wasDown = false; for (int i = 0; i < provider.basicInput.Length; i++) { HumanInputState state = provider.basicInput[i].state; if (state == HumanInputState.down || state == HumanInputState.downHold || state == HumanInputState.downMove || state == HumanInputState.up) { wasDown = true; break; } } //VisualResources.DrawIcon(wasDown ? EditorIcon.mouseDown : EditorIcon.mouseNormal, pos, scale); mouseNormal.SetActive(!wasDown); mouseDown.SetActive(wasDown); //--------------- Check if any has mouse down / up -------------------- Vector2 pos = provider.basicInput[0].position; float maxValue = Mathf.Max(screenWidth, screenHeight); pos.x = (pos.x - (screenWidth / 2)) / maxValue; pos.y = ((screenHeight / 2) - pos.y) / maxValue; for (int i = 0; i < provider.basicInput.Length; i++) { InputCommand command = provider.basicInput[i]; bool doDraw = false; Color color = Color.white; switch (command.state) { case HumanInputState.down: doDraw = true; color = Color.white; break; case HumanInputState.downMove: doDraw = true; color = new Color(0.666f, 0.666f, 0.666f); break; case HumanInputState.downHold: doDraw = true; color = new Color(0.333f, 0.333f, 0.333f); break; case HumanInputState.up: doDraw = true; color = Color.white; break; } if (mouseBtns.Length > i) { mouseBtns[i].SetActive(doDraw); if (doDraw) SetQuadColor(mouseBtns[i], color); } } for (int i = 0; i < allQuads.Count; i++) { Transform transform = allQuads[i].transform; transform.parent = parent; transform.localRotation = Quaternion.identity; transform.localPosition = new Vector3(pos.x, pos.y);//, i * -0.001f); } } else { DestroyAllQuads(); } }
private void DrawVirtualController(HumanInputProviderData data, vBugBaseWindow parent) { //Rect xboxRect = VisualResources.DrawXBoxControllerBG(); }
public void Reset() { caughtCommands.Clear(); currentResult = new HumanInputProviderData(); }
public HumanInputSnapshot(HumanInputProviderData[] providersData) { this.providersData = providersData; }
private Texture2D GetKeyColor(KeyCode keyCode1, KeyCode keyCode2, HumanInputProviderData data, Texture2D normal, Texture2D down, Texture2D hold, Texture2D up) { if (data == null || data.basicInput == null || data.basicInput.Length == 0) return normal; if(indexedKeyCodes == null) { KeyCode[] keyCodes = (KeyCode[])Enum.GetValues(typeof(KeyCode)); indexedKeyCodes = new Dictionary<string, KeyCode>(); foreach (KeyCode key in keyCodes) { string sKey = key.ToString(); if (!indexedKeyCodes.ContainsKey(sKey)) indexedKeyCodes.Add(sKey, key); } } foreach(InputCommand command in data.basicInput) { if (indexedKeyCodes[command.id] == keyCode1 || indexedKeyCodes[command.id] == keyCode2) { switch (command.state) { case HumanInputState.down: return down; case HumanInputState.hold: return hold; case HumanInputState.up: return up; } break; } } return normal; }
private void DrawVirtualKeyboard(HumanInputProviderData data, vBugBaseWindow parent) { Texture2D normal = VisualResources.keyboardNormal; Texture2D down = VisualResources.keyboardDown; Texture2D hold = VisualResources.keyboardHold; Texture2D up = VisualResources.keyboardUp; float x = 0; float y = 0; float halfHeight = buttonSizeY / 2; Rect minRect = GUILayoutUtility.GetRect(parent.position.width, (spacing + buttonSizeY) * (layout.Length + 1)); float maxWidth = buttonSizeX * 17.5f; float startX = (minRect.width / 2f) - (maxWidth / 2f); float startY = minRect.y + (halfHeight); GUIStyle style = EditorHelper.styleLabelKeyboard; for (int r = 0; r < layout.Length; r++) { Key[] row = layout[r]; for (int e = 0; e < row.Length; e++) { Key key = row[e]; float width = Mathf.Floor(buttonSizeX * key.scale); if (e == row.Length - 1) width = maxWidth - x; if (!string.IsNullOrEmpty(key.primLabel) && key.primCode != KeyCode.None) { Rect btnRect = new Rect(startX + x, startY + y, width, buttonSizeY); VisualResources.DrawTexture(btnRect, GetKeyColor(key.primCode, key.secCode, data, normal, down, hold, up)); if(!string.IsNullOrEmpty(key.secLabel)) { GUI.contentColor = new Color(0.75f, 0.75f, 0.75f); GUI.Label(new Rect(startX + x, startY + y, width, halfHeight), key.secLabel, style); GUI.contentColor = Color.white; GUI.Label(new Rect(startX + x, startY + y + halfHeight, width, halfHeight), key.primLabel, style); } else { GUI.Label(btnRect, key.primLabel, style); } } x += width + spacing; } x = 0; y += buttonSizeY + spacing; } }