示例#1
0
        // ----------------------------------
        static public UnityEngine.EventSystems.EventSystem CreateEventSystem(
            string name,
            CreationMode creationMode,
            string undoName = null)
        {
            int eventSysPresence = IsThereEventSystemInTheScene();

            if ((eventSysPresence != 0) && (creationMode == CreationMode.OnlyIfNotPresent))
            {
                return(null);
            }

            if ((eventSysPresence != 0) && (creationMode == CreationMode.AskIfPresent))
            {
                if (!EditorUtility.DisplayDialog("Control Freak 2 - Create Event System", (eventSysPresence == 1) ?
                                                 "There's a CF2 Event System in the scene already. Do you want to create a new one anyway?" :
                                                 "There's an Event System in the scene, but it isn't using CF2 Input Module. Do you want to create a new one anyway?", "Yes", "No"))
                {
                    return(null);
                }
            }

            UnityEngine.EventSystems.EventSystem eventSys =
                (UnityEngine.EventSystems.EventSystem)TouchControlWizardUtils.CreateObjectWithComponent(name, typeof(UnityEngine.EventSystems.EventSystem));

            eventSys.gameObject.AddComponent(typeof(ControlFreak2.GamepadInputModule));
            //eventSys.gameObject.AddComponent(typeof(ControlFreak2.MouseInputModule));

#if UNITY_PRE_5_3
            eventSys.gameObject.AddComponent(typeof(UnityEngine.EventSystems.TouchInputModule));
#endif

            UnityEngine.EventSystems.StandaloneInputModule standaloneModule =
                (UnityEngine.EventSystems.StandaloneInputModule)eventSys.gameObject.AddComponent(typeof(UnityEngine.EventSystems.StandaloneInputModule));

            standaloneModule.horizontalAxis = InputRig.CF_EMPTY_AXIS;
            standaloneModule.verticalAxis   = InputRig.CF_EMPTY_AXIS;
            standaloneModule.submitButton   = InputRig.CF_EMPTY_AXIS;
            standaloneModule.cancelButton   = InputRig.CF_EMPTY_AXIS;


            if (undoName != null)
            {
                Undo.RegisterCreatedObjectUndo(eventSys.gameObject, undoName);
            }

            return(eventSys);
        }
示例#2
0
        // ----------------------
        static public ControlFreak2.GamepadManager CreateGamepadManager(
            bool withNotifier,
            CreationMode creationMode,
            string undoLabel = null)
        {
            int gmPresence = IsThereGamepadManagerInTheScene();

            if ((gmPresence != 0) && (creationMode == CreationMode.OnlyIfNotPresent))
            {
                return(null);
            }

            if ((gmPresence != 0) && (creationMode == CreationMode.AskIfPresent))
            {
                string msg = null;
                msg = "There's a CF2 Gamepad Manager in the scene already. Do you want to create a new one anyway?";
                if (!EditorUtility.DisplayDialog("Control Freak 2 - Create Gamepad Manager", msg, "Yes", "No"))
                {
                    return(null);
                }
            }

            GamepadManager gm = null;

            gm = (GamepadManager)TouchControlWizardUtils.CreateObjectWithComponent("CF2-Gamepad-Manager", typeof(ControlFreak2.GamepadManager));
            if (gm == null)
            {
                return(null);
            }

            if (withNotifier)
            {
                ControlFreak2.GamepadNotifier gn = CreateGamepadNotifer("CF2-Gamepad-Notifier", null);
                if (gn != null)
                {
                    gn.transform.SetParent(gm.transform, false);
                }
            }

            if (undoLabel != null)
            {
                Undo.RegisterCreatedObjectUndo(gm.gameObject, undoLabel);
            }

            return(gm);
        }