static void AddTouchController(vp_UITouchController.vp_TouchControllerType type, string name) { Undo.RegisterSceneUndo("Create UI Controller"); GameObject controllerGO = new GameObject("Controller (" + name + ")"); controllerGO.MakeChild(); GameObject panel = new GameObject("Panel"); panel.MakeChild(controllerGO.transform); GameObject knob = new GameObject("Knob", typeof(MeshFilter), typeof(MeshRenderer), typeof(BoxCollider), typeof(ParticleSystem)); knob.MakeChild(panel.transform); SetupRenderer(knob); GameObject background = new GameObject("Background", typeof(MeshFilter), typeof(MeshRenderer)); background.MakeChild(panel.transform); SetupRenderer(background); vp_UITouchController controller = controllerGO.AddComponent <vp_UITouchController>(); controller.ControllerType = type; controller.Knob = knob.transform; controller.Background = background.transform; Selection.activeGameObject = controllerGO; }
/// <summary> /// Raises the controller type changed event. /// </summary> protected virtual void OnControllerTypeChanged(vp_UITouchController.vp_TouchControllerType type) { if (!Application.isPlaying) { return; } Color backgroundOnColor = BackgroundOnColor; Color backgroundOffColor = BackgroundOffColor; Color knobOnColor = KnobOnColor; Color knobOffColor = KnobOffColor; m_PanelTransform.localPosition = m_DefaultPanelPosition; MeshRenderer knobMeshRenderer = Knob.GetComponent <MeshRenderer>(); MeshRenderer bgMeshRenderer = Background.GetComponent <MeshRenderer>(); if (m_ControllerType == vp_UITouchController.vp_TouchControllerType.TouchPad) { backgroundOnColor = Color.clear; backgroundOffColor = Color.clear; knobOnColor = Color.clear; knobOffColor = Color.clear; if (knobMeshRenderer != null) { knobMeshRenderer.enabled = false; } if (bgMeshRenderer != null) { bgMeshRenderer.enabled = false; } } else { if (knobMeshRenderer != null) { knobMeshRenderer.enabled = true; } if (bgMeshRenderer != null) { bgMeshRenderer.enabled = true; } } KnobColor = m_ControllerType == vp_UITouchController.vp_TouchControllerType.StaticJoystick ? knobOnColor : knobOffColor; BackgroundColor = m_ControllerType == vp_UITouchController.vp_TouchControllerType.StaticJoystick ? backgroundOnColor : backgroundOffColor; if (m_PadParticles != null) { m_PadParticles.enableEmission = false; } if (ControllerTypeChanged != null) { ControllerTypeChanged(m_ControllerType); } }