/// <summary> /// Creates a CNControl by name /// All controls are stored as prefabs in the CNControls/Prefabs folder /// </summary> /// <param name="controlName">A name of the control to create. Should be one of the ones that are in the CNControls/Prefabs folder</param> public static void CreateControlFromPrefabsByName(string controlName) { GameObject cameraGo = CNInputEditorTools.GetControlCamera(); var controlObject = AssetDatabase.LoadAssetAtPath( "Assets/CNControls/Prefabs/" + controlName + ".prefab", typeof(GameObject)) as GameObject; if (controlObject == null) { throw new UnityException("Can't find " + controlName + " prefab. " + "Asset Database may be corrupted, or you could've renamed or moved the folder and/or the prefab. " + "Please reimport the package or change everything back"); } // TODO Check for any CNControls on the scene and change the Anchor property of the new one accordingly GameObject instantiatedControl = GameObject.Instantiate(controlObject, Vector3.zero, Quaternion.identity) as GameObject; instantiatedControl.transform.parent = cameraGo.GetComponent<Transform>(); instantiatedControl.name = controlName; instantiatedControl.GetComponent<CNAbstractController>().OnEnable(); }
private static void CreateCNTouchpad() { CNInputEditorTools.CreateControlFromPrefabsByName("CNThrowableTouchpad"); }
private static void CreateCNJoystick() { CNInputEditorTools.CreateControlFromPrefabsByName("CNJoystick"); }
static void CreateCNButton() { CNInputEditorTools.CreateControlFromPrefabsByName("CNButton"); }