void BeginGame() { eventSystem = EventSystem.current; inputModule = eventSystem.gameObject.GetComponent <StandaloneInputModule>(); inputModule.ActivateModule(); var player1Name = !string.IsNullOrEmpty(PlayerPrefs.GetString("p1Selection")) ? PlayerPrefs.GetString("p1Selection") : "Crazy Doc"; var player2Name = !string.IsNullOrEmpty(PlayerPrefs.GetString("p2Selection")) ? PlayerPrefs.GetString("p2Selection") : "Crazy Doc"; GameObject player1 = Instantiate(Array.Find(playerList, p1 => p1.name == player1Name), player1SpawPoint); GameObject player2 = Instantiate(Array.Find(playerList, p2 => p2.name == player2Name), player2SpawnPoint); if (player1Name == player2Name) { player2.GetComponent <SpriteRenderer>().color = secondaryColor; } if (playerLightPrefab != null) { GameObject player1Light = Instantiate(playerLightPrefab, player1.transform); GameObject player2Light = Instantiate(playerLightPrefab, player2.transform); player1Light.transform.parent = player1.transform; player2Light.transform.parent = player2.transform; } player1.AddComponent <PlayerMovementHandler>(); player1.AddComponent <PlayerAnimationHandler>(); player2.AddComponent <Player2MovementHandler>(); player2.AddComponent <Player2AnimationHandler>(); player2.GetComponent <SpriteRenderer>().flipX = true; player2.GetComponent <SpriteRenderer>().sortingOrder -= 1; }
public void Start() { GameObject tmp = GameObject.Find("EventSystem"); if (tmp) { eventSystem = tmp.GetComponent <EventSystem> (); standInputModule = tmp.GetComponent <StandaloneInputModule> (); } if (txt_PlayerInfo) { txt_PlayerInfoTextProp = txt_PlayerInfo.GetComponent <TextProperties> (); } if (!PlayerPrefs.HasKey("InputList")) { for (var i = 0; i < 4; i++) { defaultInputs(i); } } else { defaultInputsAlreadyExist(); } }
protected override void OnCreate() { EventSystem eventSystem = FindObjectOfType <EventSystem>(); StandaloneInputModule input = FindObjectOfType <StandaloneInputModule>(); GameObject defaultSelection = null; if (eventSystem != null) { defaultSelection = eventSystem.firstSelectedGameObject; } if (input != null) { Destroy(input); } if (eventSystem != null) { Destroy(eventSystem); } EventSystem newEventSystem = gameObject.AddComponent <EventSystem>(); newEventSystem.firstSelectedGameObject = defaultSelection; this.inputModule = gameObject.AddComponent <GameCreatorStandaloneInputModule>(); SceneManager.sceneLoaded += this.OnSceneLoad; }
void Awake() { instance = this; Screen.sleepTimeout = SleepTimeout.NeverSleep; GameObject uiGo = GameObject.Find("UI").gameObject; GameObject.DontDestroyOnLoad(uiGo); GameObject setupUIGo = uiGo.transform.Find("Canvas/SetupUI").gameObject; setupUIGo.AddComponent <SetupUI>(); setupUIGo.SetActive(true); GameObject msgUIGo = uiGo.transform.Find("Canvas/MessageNoticeUI").gameObject; msgUIGo.SetActive(true); msgUIGo.AddComponent <MessageNoticeUI>(); #if UNITY_STANDALONE || UNITY_EDITOR || UNITY_WEBPLAYER StandaloneInputModule inputModule = GameObject.Find("EventSystem").GetComponent <StandaloneInputModule>(); inputModule.forceModuleActive = true; #endif Application.targetFrameRate = 30; InitEnvironment(); }
// Start is called before the first frame update void Start() { Time.timeScale = 0; evSys = EventSystem.current; inputModule = evSys.gameObject.GetComponent <StandaloneInputModule>(); int numOfPlayers = 1; playerControl = PlayerControl.instance; if (playerControl.players[1]) { numOfPlayers++; } if (playerControl.players[2]) { numOfPlayers++; } if (playerControl.players[3]) { numOfPlayers++; } traps = new GameObject[numOfPlayers]; }
///Initialization //void Reset(){} //void Awake (){} void OnEnable() { instance = this; StandaloneInputModule o = GetComponent <StandaloneInputModule> (); input = o.input; }
/// <summary> /// Initialise the game control menu. /// </summary> /// <remarks> /// Sets up the unity don't destroy and locks the main menu open when in the lobby scene. /// </remarks> void Start() { // input handling inputModule = FindObjectOfType <StandaloneInputModule>(); // ensure this script is moved between scenes if (dontDestroyOnLoad) { DontDestroyOnLoad(gameObject); } // force main menu open when scene is the lobby if (!isNotLobby) { // fill dropdown lists on new character AxisDropDown.ClearOptions(); AxisDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseAxis)))); AlignDropDown.ClearOptions(); AlignDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseAlignment)))); RaceDropDown.ClearOptions(); RaceDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseRace)))); ClassDropDown.ClearOptions(); ClassDropDown.AddOptions(new List <string>(Enum.GetNames(typeof(BaseClass)))); ValidationLabel.text = ""; // show the continue button and cache the most recent save game GlobalFuncs.TheDatabase().FindMostRecentSaveGameID(ref LatestSaveSlotID, ref LatestSaveGameID); ContinueButton.SetActive(LatestSaveGameID > 0 && LatestSaveSlotID > 0); LoadGameButton.SetActive(LatestSaveGameID > 0 && LatestSaveSlotID > 0); // lock the main menu open StartCoroutine(forceMenuOpen()); } }
private void OnEnable() { StandaloneInputModule sip = GetComponent <StandaloneInputModule>(); switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: sip.horizontalAxis = HorizontalAxisMacOS; sip.verticalAxis = VerticalAxisMacOS; break; default: case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: sip.horizontalAxis = HorizontalAxisWindows; sip.verticalAxis = VerticalAxisWindows; break; case RuntimePlatform.LinuxEditor: case RuntimePlatform.LinuxPlayer: sip.horizontalAxis = HorizontalAxisLinux; sip.verticalAxis = VerticalAxisLinux; break; } }
IEnumerator ReloadEquipment() { yield return(new WaitForEndOfFrame()); inputModule = FindObjectOfType <StandaloneInputModule>(); isOpen = true; for (int i = 0; i < equipAreas.Length; i++) { var equipArea = equipAreas[i]; for (int a = 0; a < equipArea.equipSlots.Count; a++) { var slot = equipArea.equipSlots[a]; if (equipArea.currentEquipedItem == null) { OnUnequipItem(equipArea, slot.item); equipArea.UnequipItem(slot); } else { equipArea.UnequipItem(slot); } } } isOpen = false; }
public void configureVRControlability() { bool enableVRcontrol = XRDevice.isPresent; // configure whether elements shall be clicked by vr controlers or mouse hudvr.SetActive(enableVRcontrol); hudmouse.SetActive(!enableVRcontrol); gameMenuvr.SetActive(enableVRcontrol); gameMenumouse.SetActive(!enableVRcontrol); modVoteMenuvr.SetActive(enableVRcontrol); modVoteMenumouse.SetActive(!enableVRcontrol); voteMenuvr.SetActive(enableVRcontrol); voteMenumouse.SetActive(!enableVRcontrol); StandaloneInputModule mouseInput = (StandaloneInputModule)eventSystem.GetComponent("StandaloneInputModule"); if (null != mouseInput) { mouseInput.enabled = !enableVRcontrol; } ControllerSelection.OVRInputModule vrInput = (ControllerSelection.OVRInputModule)eventSystem.GetComponent("OVRInputModule"); if (null != vrInput) { vrInput.enabled = enableVRcontrol; } }
public IEnumerator enableVrMode(bool isVrEnabled) { string newDevice = (isVrEnabled) ? initialVrDevice : ""; // Disable controller before disabling VR if (!isVrEnabled) { enableGvrController(false); } // Load VR device VRSettings.LoadDeviceByName(newDevice); if (!VRSettings.loadedDeviceName.Equals(newDevice)) { yield return(null); } // Toggle VR mode VRSettings.enabled = isVrEnabled; if (VRSettings.enabled != isVrEnabled) { yield return(null); } Debug.Log("Switched to device [" + newDevice + "], vr=" + isVrEnabled); // Enable controller after enabling VR if (isVrEnabled) { StandaloneInputModule inputModule = FindObjectOfType <StandaloneInputModule>(); if (inputModule != null) { Destroy(inputModule); } enableGvrController(true); } }
//Add EventSystem private void addEventSystemAndInputModule() { //Check if EventSystem exist. If it does not create and add it EventSystem eventSys = FindObjectOfType <EventSystem>(); if (eventSys == null) { GameObject evObj = new GameObject("EventSystem"); EventSystem evs = evObj.AddComponent <EventSystem>(); evs.firstSelectedGameObject = null; evs.sendNavigationEvents = true; evs.pixelDragThreshold = 5; eventSys = evs; } //Check if StandaloneInputModule exist. If it does not create and add it StandaloneInputModule sdlIpModl = FindObjectOfType <StandaloneInputModule>(); if (sdlIpModl == null) { sdlIpModl = eventSys.gameObject.AddComponent <StandaloneInputModule>(); sdlIpModl.horizontalAxis = "Horizontal"; sdlIpModl.verticalAxis = "Vertical"; sdlIpModl.submitButton = "Submit"; sdlIpModl.cancelButton = "Cancel"; sdlIpModl.inputActionsPerSecond = 10f; sdlIpModl.repeatDelay = 0.5f; sdlIpModl.forceModuleActive = false; } }
public void TestSetup() { // Camera | Canvas (Image) | Event System m_Canvas = new GameObject("Canvas").AddComponent <Canvas>(); m_Canvas.renderMode = RenderMode.ScreenSpaceOverlay; m_Canvas.gameObject.AddComponent <GraphicRaycaster>(); m_Image = new GameObject("Image").AddComponent <Image>(); m_Image.gameObject.transform.SetParent(m_Canvas.transform); RectTransform imageRectTransform = m_Image.GetComponent <RectTransform>(); imageRectTransform.sizeDelta = new Vector2(400f, 400f); imageRectTransform.localPosition = Vector3.zero; GameObject go = new GameObject("Event System"); m_StandaloneInputModule = go.AddComponent <StandaloneInputModule>(); m_FakeBaseInput = go.AddComponent <FakeBaseInput>(); // Override input with FakeBaseInput so we can send fake mouse/keyboards button presses and touches m_StandaloneInputModule.inputOverride = m_FakeBaseInput; m_EventSystem = go.AddComponent <EventSystem>(); m_EventSystem.pixelDragThreshold = 1; Cursor.lockState = CursorLockMode.None; }
void Awake() { DontDestroyOnLoad(this); EventSystem eventSystem = gameObject.AddComponent(typeof(EventSystem)) as EventSystem; StandaloneInputModule inputModule = gameObject.AddComponent(typeof(StandaloneInputModule)) as StandaloneInputModule; GameObject hudManagerGO = Instantiate(Resources.Load <GameObject>("UI/HUD")); hudManager = hudManagerGO.GetComponent <HUDManager>(); hudManager.transform.SetParent(transform); hudManager.SetVisible(false); GameObject mainMenuGO = Instantiate(Resources.Load <GameObject>("UI/MainMenu")); mainMenu = mainMenuGO.GetComponent <MainMenu>(); mainMenu.transform.SetParent(transform); mainMenu.SetVisible(false); GameObject dialogManagerGO = Instantiate(Resources.Load <GameObject>("UI/DialogManager")); dialogManager = dialogManagerGO.GetComponent <DialogManager>(); dialogManager.transform.SetParent(transform); dialogManager.SetVisible(false); GameObject blackOverlayGO = Instantiate(Resources.Load <GameObject>("UI/BlackOverlay")); blackOverlay = blackOverlayGO.GetComponent <TransitionOverlay>(); blackOverlay.transform.SetParent(transform); blackOverlay.SetVisible(false); }
void Start() { if (confFile != null) { RegisterListeners(); if (Application.isPlaying) { MergeCubeCore.instance.StartCore(confFile.licenseKey, confFile.chosenScaleFactor); } } //We only want the configuration file setup to run in edit mode, the rest of the setup is for runtime. if (Application.isPlaying) { //unity base settings setup: Application.targetFrameRate = 60; MergeCubeScreenRotateManager.instance.OnOrientationEvent += HandleCanvasScalerOnOrientation; //unity base scene setup: if (GameObject.Find("EventSystem") == null) { GameObject tmp = new GameObject("EventSystem"); EventSystem evnSys = tmp.AddComponent <EventSystem>(); StandaloneInputModule inpModule = tmp.AddComponent <StandaloneInputModule>(); } //our setup: Initialize(); } InitValidClick(); }
IEnumerator ReloadEquipment() { yield return(new WaitForEndOfFrame()); inputModule = FindObjectOfType <StandaloneInputModule>(); isOpen = true; foreach (ChangeEquipmentControl changeEquip in changeEquipmentControllers) { if (changeEquip.equipArea != null) { foreach (EquipSlot slot in changeEquip.equipArea.equipSlots) { if (changeEquip.equipArea.currentEquipedItem == null) { UnequipItem(changeEquip.equipArea, slot.item); changeEquip.equipArea.RemoveItem(slot); } else { changeEquip.equipArea.RemoveItem(slot); } } } } isOpen = false; }
void Start() { // manage if you can equip a item or not canEquip = true; // search for a StandaloneInputModule in the scene inputModule = FindObjectOfType <StandaloneInputModule>(); // if there is none, a new EventSystem is created if (inputModule == null) { inputModule = (new GameObject("EventSystem")).AddComponent <StandaloneInputModule>(); } // get equipAreas in this Inventory equipAreas = GetComponentsInChildren <vEquipArea>(true); // initialize every equipArea foreach (vEquipArea equipArea in equipAreas) { equipArea.Init(); equipArea.onEquipItem.AddListener(OnEquipItem); equipArea.onUnequipItem.AddListener(OnUnequipItem); equipArea.onSelectEquipArea.AddListener(SetCurrentSelectedArea); } //if (dontDestroyOnLoad) // DontDestroyOnLoad(gameObject); //if (vGameController.instance) // vGameController.instance.OnReloadGame.AddListener(OnReloadGame); }
static GameObject SetupUI() { // Canvas GameObject canvas = GameObject.Find("EasyTouchControlsCanvas"); if (canvas == null) { canvas = AddCanvas(); } // Event system if (GameObject.FindObjectOfType(typeof(EventSystem)) == null) { AddEventSystem(); } // TouchInput if (GameObject.FindObjectOfType(typeof(StandaloneInputModule))) { StandaloneInputModule tm = (StandaloneInputModule)GameObject.FindObjectOfType(typeof(StandaloneInputModule)); tm.forceModuleActive = true; } return(canvas); }
private Vector2 GetScreenCoords(GraphicRaycaster ray, StandaloneInputModule input) { var mousepos = Input.mousePosition; var relativeToDisplayPosition = Display.RelativeMouseAt(mousepos); if (relativeToDisplayPosition != Vector3.zero) { if (ray.eventCamera.targetDisplay == (int)relativeToDisplayPosition.z) { mousepos = relativeToDisplayPosition; } else { return(new Vector2(-1, -1)); //this click not on our display } } Vector2 localPos; // Mouse position RectTransformUtility.ScreenPointToLocalPointInRectangle(transform as RectTransform, mousepos, ray.eventCamera, out localPos); // local pos is the mouse position. RectTransform trns = transform as RectTransform; localPos.y = trns.rect.height - localPos.y; //Debug.Log("x:"+localPos.x+",y:"+localPos.y); //now recalculate to texture localPos.x = (localPos.x * Width) / trns.rect.width; localPos.y = (localPos.y * Height) / trns.rect.height; return(localPos); }
private void Start() { _inputSystem = gameObject.GetComponent <StandaloneInputModule>(); _eventSystem = gameObject.GetComponent <EventSystem>(); SettingsComponent.variableUpdatesEvent += UpdateVariables; UpdateVariables(); }
private void Awake() { DontDestroyOnLoad(gameObject); mCacheTrans = gameObject.transform; mCam = mCacheTrans.Find("UICamera").GetComponent <Camera>(); mCam.nearClipPlane = MainCamMinDepth; mCam.farClipPlane = MainCamMaxDepth; int invisible_mask = 1 << LayerMask.NameToLayer("Hide"); mCam.cullingMask = ~invisible_mask & mCam.cullingMask; // 获取后处理的相机组件 var post_camera_trans = mCacheTrans.Find("PostCamera"); if (post_camera_trans != null) { mPostCamera = post_camera_trans.GetComponent <Camera>(); } EventSystemCom = mCacheTrans.Find("EventSystem").GetComponent <EventSystem>(); InputModule = mCacheTrans.Find("EventSystem").GetComponent <StandaloneInputModule>(); mHudRoot = mCacheTrans.Find("HudRoot"); mNormalRoot = mCacheTrans.Find("NormalRoot"); mLoadingRoot = mCacheTrans.Find("LoadingRoot"); mPopRoot = mCacheTrans.Find("PopRoot"); }
IEnumerator ReloadEquipment() { yield return(new WaitForEndOfFrame()); inputModule = FindObjectOfType <StandaloneInputModule>(); isOpen = true; foreach (ChangeEquipmentControl changeEquip in changeEquipmentControllers) { if (changeEquip.equipArea != null) { foreach (vEquipSlot slot in changeEquip.equipArea.equipSlots) { //if (slot.item != null && items.Find(i => i.id == slot.item.id) != null) //{ // EquipItem(changeEquip.equipArea, slot.item); //} //else if (changeEquip.equipArea.currentEquipedItem == null) { UnequipItem(changeEquip.equipArea, slot.item); changeEquip.equipArea.UnequipItem(slot); } else { changeEquip.equipArea.UnequipItem(slot); } } } } isOpen = false; }
public static void ChangeController(ControllerMode controllerMode) { mode = controllerMode; inputThreshold = mode == ControllerMode.mobile ? 0f : 0.25f; //This is to eliminate joysticks that have inaccurate/worn down analogue sticks. TODO: Automatically measure the idle readings and base the threshold off of that. modeAsString = mode.ToString(); horizontalString = "Horizontal_" + modeAsString; verticalString = "Vertical_" + modeAsString; inventoryString = "Inventory_" + modeAsString; inventorySelectString = "InventorySelect_" + modeAsString; useString = "Use_" + modeAsString; actionString = "Action_" + modeAsString; menuString = "Menu_" + modeAsString; mouseXString = "MouseX_" + modeAsString; mouseYString = "MouseY_" + modeAsString; sprintString = "Sprint_" + modeAsString; StandaloneInputModule currentModule = GameObject.Find("EventSystem").GetComponent <StandaloneInputModule>(); currentModule.horizontalAxis = horizontalString; currentModule.verticalAxis = verticalString; if (OnControlChange != null) { OnControlChange(); } }
private void Start() { pegaInputs = FindObjectOfType(typeof(StandaloneInputModule)) as StandaloneInputModule; audioSource = GetComponent <AudioSource>(); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; selectedObj = EventSystem.current.currentSelectedGameObject; }
private void Awake() { eventSystem = GetComponent <EventSystem>(); menuInputHandler = GetComponent <StandaloneInputModule>(); differentWindows = GetComponentsInChildren <MenuWindow>(true); //SortMenus(); }
public override void Init() { if (Module == null) { Module = GOEventSystem.GetComponent <StandaloneInputModule>(); Module.forceModuleActive = true; } }
public static WindowManager GetSingleton() { if (mInstance == null) { uiLayer = LayerMask.NameToLayer("UI"); blurLayer = LayerMask.NameToLayer("Blur"); //如果没有该层请创建 GameObject go = new GameObject(typeof(WindowManager).ToString()); DontDestroyOnLoad(go); go.layer = uiLayer; mInstance = go.AddComponent <WindowManager>(); GameObject cameraGo = new GameObject("Camera"); cameraGo.layer = uiLayer; cameraGo.transform.SetParent(go.transform); mInstance.mCamera = cameraGo.AddComponent <Camera>(); mInstance.mCamera.clearFlags = CameraClearFlags.Depth; mInstance.mCamera.depth = 10; mInstance.mCamera.orthographic = true; mInstance.mCamera.orthographicSize = 5; mInstance.mCamera.cullingMask = 1 << uiLayer; GameObject canvasGo = new GameObject("Canvas"); canvasGo.layer = uiLayer; canvasGo.transform.SetParent(go.transform); canvasGo.AddComponent <RectTransform>(); mInstance.mCanvas = canvasGo.AddComponent <Canvas>(); mInstance.mCanvas.renderMode = RenderMode.ScreenSpaceCamera; mInstance.mCanvas.worldCamera = mInstance.mCamera; CanvasScaler scaler = canvasGo.AddComponent <CanvasScaler>(); scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; scaler.scaleFactor = 1; scaler.referenceResolution = new Vector2(DESIGN_WIDTH, DESIGN_HEIGHT); scaler.referencePixelsPerUnit = 100; GraphicRaycaster raycaster = canvasGo.AddComponent <GraphicRaycaster>(); raycaster.ignoreReversedGraphics = true; GameObject eventGo = new GameObject("EventSystem"); eventGo.layer = uiLayer; eventGo.transform.SetParent(go.transform); mInstance.mEventSystem = eventGo.AddComponent <EventSystem>(); mInstance.mEventSystem.sendNavigationEvents = true; mInstance.mEventSystem.pixelDragThreshold = 5; StandaloneInputModule inputModule = eventGo.AddComponent <StandaloneInputModule>(); } return(mInstance); }
void Init() { if (initialized) { return; } sim = GetComponent <StandaloneInputModule>(); initialized = true; }
void InitEventSystemByCode(Transform parent) { GameObject EventSystem = new GameObject("EventSystem"); _eventSystem = EventSystem.AddComponent <EventSystem>(); _InputMd = EventSystem.AddComponent <StandaloneInputModule>(); EventSystem.transform.SetParent(parent, true); }
private void Init_UI_system() { //Enable Eventsystem VR input, disable PC input pcInput = MyEventSystem.GetComponent <StandaloneInputModule>(); vrInput = MyEventSystem.GetComponent <ControllerSelection.OVRInputModule>(); pcInput.enabled = false; vrInput.enabled = true; MyEventSystem.GetComponent <EventSystem>().UpdateModules(); }