예제 #1
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);
        }
예제 #2
0
        // ---------------------
        static public ControlFreak2.GamepadNotifier CreateGamepadNotifer(string name, string undoLabel = null)
        {
            ControlFreak2.GamepadNotifier
                gn = (ControlFreak2.GamepadNotifier)UnityEditor.AssetDatabase.LoadAssetAtPath(NOTIFIER_PREFAB_PATH, typeof(ControlFreak2.GamepadNotifier));

            if (gn == null)
            {
                Debug.LogError("Can't load default Gamepad Notifier Prefab from [" + NOTIFIER_PREFAB_PATH + "]! Reimport Control Freak 2 package to fix the issue.");
                return(null);
            }


            //gn = (ControlFreak2.GamepadNotifier)ControlFreak2.GamepadNotifier.Instantiate(gn);
            gn = (ControlFreak2.GamepadNotifier)PrefabUtility.InstantiatePrefab(gn);

            gn.name = name;

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

            return(gn);
        }