Exemplo n.º 1
0
        /// <summary>
        /// Initialize the X-Device SDK library.
        /// </summary>
        public static int Init()
        {
            // Initialization Lock.
            if (s_IsInited)
            {
                return(0);
            }
            s_IsInited = true;
            //
            NativeMethods.XDeviceExit();
            //
            NativeMethods.XDeviceGetContext(true);
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            //
            string pluginPath = UnityEngine.Application.dataPath + "\\Plugins\\"
#if UNITY_EDITOR_WIN
                                + (GetInt(-1, /*FieldID::*/ kField_CtxPlatformVersion, 0) % 2 == 0?"x86":"x86_64");
#elif UNITY_STANDALONE_WIN
            ;
#endif
            string path = System.Environment.GetEnvironmentVariable("PATH");
            if (path.IndexOf(pluginPath) == -1)
            {
                System.Environment.SetEnvironmentVariable("PATH", path + ";" + pluginPath);
            }
#endif
            NativeMethods.XDeviceSetInt(-1, kField_CtxDeviceVersion, PlayerPrefsEx.GetInt("XimmerseDevice.type", 0x4000));
            int ret = NativeMethods.XDeviceInit();
            // Add Unity objects into X-Device plugin.
            AddExternalControllerDevice("VRDevice", VRContext.s_OnHmdUpdate, VRContext.s_OnHmdMessage);
            return(ret);
        }
Exemplo n.º 2
0
            public static int XDeviceInit()
            {
                if (s_XDeviceApi == null)
                {
                    s_XDeviceApi = new AndroidJavaClass("com.ximmerse.sdk.XDeviceApi");
                }
                int ret = -1;

                if (DeviceVersion == XIM_DK4_DIS01)
                {
                    using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){
                        using (AndroidJavaObject currentActivity = jc.GetStatic <AndroidJavaObject>("currentActivity")){
                            ret = s_XDeviceApi.CallStatic <int>("init", currentActivity, XIM_DK4_DIS01, 4);
                            SetBool(ID_CONTEXT, kField_CtxCanProcessInputEventBool, false);
                        }
                    }
                }
                else if (PlayerPrefsEx.GetBool("xdevice.noServicesInAndroid", false))
                {
                    using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){
                        using (AndroidJavaObject currentActivity = jc.GetStatic <AndroidJavaObject>("currentActivity")){
                            ret = s_XDeviceApi.CallStatic <int>("init", currentActivity, 0x0, 1);
                            SetBool(ID_CONTEXT, kField_CtxCanProcessInputEventBool, false);
                        }
                    }
                }
                else
                {
                    ret = s_XDeviceApi.CallStatic <int>("initInUnity");
                }
                return(ret);
            }
Exemplo n.º 3
0
    public static void Save(int score, Vector2 origin)
    {
        var data = new SaveData();

        data.score  = score;
        data.origin = origin;

        foreach (var item in InGameItem.all)
        {
            if (item is InGameItemBall)
            {
                data.items.Add(new ItemData()
                {
                    type = 1, pos = item.rowColumn
                });
            }
            else if (item is InGameItemBrick)
            {
                data.items.Add(new ItemData()
                {
                    type = 2, pos = item.rowColumn, health = item.As <InGameItemBrick>().Health
                });
            }
        }

        var json = JsonUtility.ToJson(data);

        PlayerPrefsEx.SetString("ingame_save_data", json);
    }
Exemplo n.º 4
0
    public static bool SetData(string json)
    {
#if UNITY_EDITOR
        if (Instance.offline)
        {
            SeganX.Console.Logger.Enabled = true;
            return(true);
        }
#endif

        var newdata = JsonUtilityEx.FromJson <Data>(json, false);
        if (newdata == null)
        {
            return(false);
        }

        //  set new data
        Instance.data = newdata;
        SaveData(newdata);
        SeganX.Console.Logger.Enabled = DebugMode;

        // select cohort
        Cohort = PlayerPrefsEx.GetInt("GlobalConfig.Cohort", -1);
        if (Cohort < 0)
        {
            Cohort = Random.Range(0, 100) % 2;
            PlayerPrefsEx.SetInt("GlobalConfig.Cohort", Cohort);
        }
        return(true);
    }
Exemplo n.º 5
0
 public override bool InitInternal()
 {
     if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0x4000) & 0xF000) != 0x4000)
     {
         return(false);
     }
     //
     if (true)
     {
         Vector3 position = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].position");
         Vector3 rotation = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].rotation");
         XDevicePlugin.SetTrackerPose(m_Handle, position.y, position.z, rotation.x);
         //
         XDevicePlugin.GetTrackerPose(m_Handle, out position.y, out position.z, out rotation.x);
         //
         int i = m_Controllers.Length; while (i-- > 0)
         {
             XDevicePlugin.SetBool(XDevicePlugin.GetInputDeviceHandle(m_Controllers[i].key), XDevicePlugin.kField_IsAbsRotationBool, true);
         }
         //
         //PlayerPrefsEx.SetBool("VRDevice.forceFadeOnBadTracking",true);
         XDevicePlugin.NativeMethods.XDeviceSetDecoderFeature(XDevicePlugin.FEATURE_BLOB_AUTO);
     }
     return(base.InitInternal());
 }
Exemplo n.º 6
0
        protected virtual void SetVRDeviceTypeIndex(int id)
        {
            Ximmerse.VR.VRDevice d = s_VRDeviceTypeSources[id];
            PlayerPrefsEx.SetObject("VRDevice.source", d == null?null:d.gameObject);
            //
#if UNITY_ANDROID
            if (d == null)
            {
                if (File.Exists(Application.dataPath + "/Plugins/Android/AndroidManifest.xml") &&
                    EditorUtility.DisplayDialog("Change To UnityManaged", "Remove AndroidManifest.xml?", "Yes,do it", "No,Thanks"))
                {
                    File.Delete(Application.dataPath + "/Plugins/Android/AndroidManifest.xml");
                    AssetDatabase.Refresh();
                }
            }
            else if (d.androidManifest != null)
            {
                if (EditorUtility.DisplayDialog("Change To " + d.androidTargetName, "Replace AndroidManifest.xml?", "Yes,do it", "No,Thanks"))
                {
                    File.WriteAllText(Application.dataPath + "/Plugins/Android/AndroidManifest.xml", d.androidManifest.text);
                    AssetDatabase.Refresh();
                }
            }
#endif
            if (d == null)
            {
            }
            else
            {
                PlayerSettings.virtualRealitySupported = d.useUnityVR;
            }
        }
Exemplo n.º 7
0
    protected virtual void OnVRContextInited(VRContext context)
    {
        //
        if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x4000)
        {
            Destroy(this);
            Ximmerse.Log.w("TrackedHead", "TrackedHead only works in Outside-in!!!");
            return;
        }
        else
        {
            VRDevice vrDevice = context.vrDevice;
            if (vrDevice.outsideInMarkPose.position != Vector3.zero)
            {
                markTransform.localPosition = vrDevice.outsideInMarkPose.position;
            }
        }
        //
        if (eyeContainer == null)
        {
            eyeContainer = new GameObject("Rotate-Pivot").transform;
            eyeContainer.SetParent(transform);
            //
            eyeContainer.localPosition = Vector3.zero;
            eyeContainer.localRotation = Quaternion.identity;
            eyeContainer.localScale    = Vector3.one;
            //
            if (context.vrDevice != null && context.vrDevice.family != "Dummy")
            {
                markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckToEye;
                eyeContainer.localPosition  = context.vrDevice.neckToEye;
#if UNITY_EDITOR
                // Editor features.
                if (m_Gizmos.Length > 0 && m_Gizmos[0] != null)
                {
                    m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckToEye;
                }
#endif
            }
        }
        //
        for (int i = 0; i < 3; ++i)
        {
            Transform eye = context.GetAnchor(VRNode.LeftEye + i, null);
            if (eye != null)
            {
                eye.SetParent(eyeContainer, false);
            }
        }
        //
        switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0))
        {
        // No head tracking.
        case 0x1010:
            source            = ControllerType.None;
            m_ControllerInput = null;
            break;
        }
    }
Exemplo n.º 8
0
 public virtual void AlignHmdFinished()
 {
     if (PlayerPrefsEx.GetBool("VRDevice.forceFadeOnBadTracking"))
     {
         VRContext.main.fadeFx.onBecameInvisible.RemoveListener(AlignHmdFinished);
         m_IsHmdRecentering = false;
     }
 }
Exemplo n.º 9
0
            public static bool Remove(string payload)
            {
                var res = IsValid(payload);

                list.Remove(payload);
                PlayerPrefsEx.SetObject("PurchaseSystem.Payload.list", list);
                return(res);
            }
Exemplo n.º 10
0
            public static string Get(string salt)
            {
                var res = System.DateTime.Now.Ticks.ToString().ComputeMD5(salt);

                list.Add(res);
                PlayerPrefsEx.SetObject("PurchaseSystem.Payload.list", list);
                return(res);
            }
Exemplo n.º 11
0
    public virtual PlayerPrefsEx LoadPlayerPrefs(string key)
    {
        PlayerPrefsEx ret = mapPlayerPrefsEx.Get(key, null);

        if (ret != null)
        {
            ret.parent = this;
        }
        return(ret);
    }
Exemplo n.º 12
0
 public static void Load(PlayerPrefsEx playerPrefs)
 {
     s_MainCached = true;
     s_Main       = playerPrefs;
     //
     if (s_Main != null)
     {
         s_Main.parent = null;
     }
 }
Exemplo n.º 13
0
    private static void SyncProfile(bool sendProfile, Online.Profile.Data serverProfile, System.Action <bool> nextTask)
    {
        // check to see if local data is empty then ther are 2 states
        // 1- we are in first run
        // 2- we lost our cache files
        if (Username.IsNullOrEmpty())
        {
            // check to see if we are in first run
            if (serverProfile.datahash.IsNullOrEmpty())
            {
                data.info = serverProfile;
                RunFirstSission();
                SendProfileData(sendProfile, nextTask);
            }
            // we have data on server but we have lost data on local
            // so try to load from server to local
            else
            {
                data.info = serverProfile;
                Online.Userdata.Get((sucess, privateStr, publicStr) =>
                {
                    if (sucess)
                    {
                        data.privateData = JsonUtility.FromJson <ProfileData.PrivateData>(Utilities.DecompressString(privateStr, "{}"));
                        data.publicData  = JsonUtility.FromJson <ProfileData.PublicData>(Utilities.DecompressString(publicStr, "{}"));
                        SaveLocal();
                        nextTask(true);
                    }
                    else
                    {
                        nextTask(false);
                    }
                });
            }
        }
        // local data is not empty
        else
        {
            data.info = serverProfile;

            // check to see if player is marked as hacher?
            if (serverProfile.datahash == "shame")
            {
                PlayerPrefs.DeleteAll();
                PlayerPrefsEx.ClearData();
                data.privateData = new ProfileData.PrivateData();
                data.publicData  = new ProfileData.PublicData();
                StartSession();
                SaveLocal();
            }

            // finally just send data to server
            SendProfileData(sendProfile, nextTask);
        }
    }
Exemplo n.º 14
0
        protected static bool DrawToggle(string label, string key, bool value)
        {
            value = PlayerPrefsEx.GetBool(key, value);
            bool newValue = EditorGUILayout.Toggle(label, value);

            if (newValue != value)
            {
                PlayerPrefsEx.SetBool(key, newValue);
            }
            return(newValue);
        }
Exemplo n.º 15
0
        protected static Vector3 DrawVector3Field(string label, string key, Vector3 value)
        {
            value = PlayerPrefsEx.GetVector3(key, value);
            Vector3 newValue = EditorGUILayout.Vector3Field(label, value);

            if (newValue != value)
            {
                PlayerPrefsEx.SetVector3(key, newValue);
            }
            return(newValue);
        }
Exemplo n.º 16
0
        protected static Color DrawColorField(string label, string key, Color value)
        {
            value = PlayerPrefsEx.GetColor(key, value);
            Color newValue = EditorGUILayout.ColorField(label, value);

            if (newValue != value)
            {
                PlayerPrefsEx.SetColor(key, newValue);
            }
            return(newValue);
        }
Exemplo n.º 17
0
        protected static float DrawSlider(string label, string key, float value, float min, float max)
        {
            value = PlayerPrefsEx.GetFloat(key, value);
            float newValue = EditorGUILayout.Slider(label, value, min, max);

            if (newValue != value)
            {
                PlayerPrefsEx.SetFloat(key, newValue);
            }
            return(newValue);
        }
Exemplo n.º 18
0
        protected static T DrawObjectField <T>(string label, string key, T value) where T : Object
        {
            value = PlayerPrefsEx.GetObject(key, value) as T;
            T newValue = EditorGUILayout.ObjectField(label, value, typeof(T), false) as T;

            if (newValue != value)
            {
                PlayerPrefsEx.SetObject(key, newValue);
            }
            return(newValue);
        }
Exemplo n.º 19
0
        protected static int DrawIntPopup(string label, string key, int value, string[] displayedOptions, int[] optionValues)
        {
            value = PlayerPrefsEx.GetInt(key, value);
            int newValue = EditorGUILayout.IntPopup(label, value, displayedOptions, optionValues);

            if (newValue != value)
            {
                PlayerPrefsEx.SetInt(key, newValue);
            }
            return(newValue);
        }
Exemplo n.º 20
0
 public static PlayerPrefsEx GetPlayerPrefsEx(string key, PlayerPrefsEx defaultValue = null)
 {
     if (main.mapPlayerPrefsEx.Exists(key))
     {
         return(main.mapPlayerPrefsEx.Get(key, defaultValue));
     }
     else if (main.parent != null)
     {
         return(main.parent.mapPlayerPrefsEx.Get(key, defaultValue));
     }
     return(defaultValue);
 }
Exemplo n.º 21
0
        public virtual void LoadHandConfigs()
        {
            int i = 0;

            //
            m_HandPosition[i] = PlayerPrefsEx.GetVector3("Daydream.leftHand.position", new Vector3(-0.2f, -0.5f, 0.0f));
            m_HandLength[i]   = PlayerPrefsEx.GetFloat("Daydream.leftHand.length", 0.0f);
            ++i;
            m_HandPosition[i] = PlayerPrefsEx.GetVector3("Daydream.rightHand.position", new Vector3(0.2f, -0.5f, 0.0f));
            m_HandLength[i]   = PlayerPrefsEx.GetFloat("Daydream.rightHand.length", 0.0f);
            ++i;
        }
Exemplo n.º 22
0
 public virtual void AlignHmdDelayed()
 {
     if (PlayerPrefsEx.GetBool("VRDevice.forceFadeOnBadTracking"))
     {
         m_GameStartTime = Time.timeSinceLevelLoad;
         //
         VRContext.main.fadeFx.onBecameVisible.RemoveListener(AlignHmdDelayed);
         VRContext.main.fadeFx.onBecameInvisible.AddListener(AlignHmdFinished);
         VRContext.FadeOut(1.0f, 0.15f);
         //
         StartCoroutine(RecenterAllControllersDelayed(0.99f, GetRawYaw() + m_YawOffset));
     }
 }
Exemplo n.º 23
0
    void HandleLog(string logString, string stackTrace, LogType type)
    {
        if (type == LogType.Error || type == LogType.Exception)
        {
            string md5str = HashSecurity.Encrypt(logString + stackTrace);
            if (m_logList.Contains(md5str) == false)
            {
                string platform = "win";
#if UNITY_IPHONE
                platform = "ios";
#elif UNITY_ANDROID
                platform = "android";
#endif
                PluginTool pluginTools = PluginTool.SharedInstance();
                string     gameId      = pluginTools.GetPlatformConfig(PluginTool.GAMEID_KEY, "0");
                string     userIdStr   = PlayerPrefsEx.GetString("userId");
                long       userId      = 0;
                if (!string.IsNullOrEmpty(userIdStr))
                {
                    userId = long.Parse(userIdStr);
                }
                long   roleId   = 0;
                string roleName = "";

                LuaState lua = LuaInstance.instance.Get();
                lua.GetGlobal("Client");
                lua.GetField(-1, "RoleInfo");
                if (!lua.IsNil(-1))
                {
                    lua.GetField(-1, "RoleID");
                    roleId = lua.ToInteger(-1);
                    lua.Pop(1);
                    lua.GetField(-1, "RoleName");
                    roleName = lua.ToString(-1);
                    lua.Pop(1);
                }
                lua.Pop(1);
                lua.GetField(-1, "ClientVersion");
                string version = lua.ToString(-1);
                lua.Pop(2);

                string request = string.Format("{0}?GameID={1}&PlayerID={2}&RoleId={3}&logString={4}&StackTrace={5}&LogType={6}&RoleName={7}&platform={8}&servernum={9}&gateway_id={10}&machine={11}&version={12}&GameName={13}",
                                               PluginTool.SharedInstance().logUrl, gameId, userId, roleId, System.Uri.EscapeDataString(logString), System.Uri.EscapeDataString(stackTrace), System.Uri.EscapeDataString(type.ToString()),
                                               System.Uri.EscapeDataString(roleName), platform, PlayerPrefs.GetInt("lastServerNum", 0),
                                               PlayerPrefs.GetInt("lastServerID", 0), SystemInfo.deviceModel, version, "hzmj");

                PluginTool.SharedInstance().logStr = request;
                StartCoroutine(SendException(request, md5str));
            }
        }
    }
Exemplo n.º 24
0
    protected override void OnInitialize()
    {
#if UNITY_EDITOR
        if (offline)
        {
            SaveData(data);
            PlayerPrefsEx.SetInt("GlobalConfig.Group", offlineGroup);
        }
#else
        data = LoadData(data);
        if (DebugMode)
        {
            Console.Enabled = true;
        }
#endif
    }
Exemplo n.º 25
0
 public static void Reset()
 {
     Loading.Show();
     Online.Profile.SetNickname(string.Empty, successName =>
                                Online.Profile.SetStatus(string.Empty, successStatus =>
                                                         Online.Profile.SetAvatar(string.Empty, successAvatar =>
     {
         Application.Quit();
         PlayerPrefs.DeleteAll();
         PlayerPrefsEx.ClearData();
         data.privateData = new ProfileData.PrivateData();
         data.publicData  = new ProfileData.PublicData();
         data.avatar      = new ProfileData.AvatarData();
         data.info.avatar = JsonUtility.ToJson(data.avatar);
         StartSession();
         SaveLocal();
     })));
 }
Exemplo n.º 26
0
        protected virtual int GetVRDeviceTypeIndex()
        {
            Ximmerse.VR.VRDevice d  = null;
            GameObject           go = (GameObject)PlayerPrefsEx.GetObject("VRDevice.source");

            if (go != null)
            {
                d = go.GetComponent <Ximmerse.VR.VRDevice>();
            }
            //
            for (int i = 0, imax = s_VRDeviceTypeSources.Length; i < imax; ++i)
            {
                if (s_VRDeviceTypeSources[i] == d)
                {
                    return(i);
                }
            }
            return(0);
        }
Exemplo n.º 27
0
 public virtual void AlignHmd()
 {
     if (m_IsHmdRecentering)
     {
         return;
     }
     m_IsHmdRecentering = true;
     //
     if (PlayerPrefsEx.GetBool("VRDevice.forceFadeOnBadTracking"))
     {
         VRContext.main.fadeFx.onBecameVisible.AddListener(AlignHmdDelayed);
         VRContext.FadeIn(0.0f, 0.15f);
     }
     else
     {
         m_ForceRecenterHmdFrameCount = Time.frameCount + 1;
         m_IsHmdRecentering           = false;
     }
 }
    protected virtual void Start()
    {
        TrackedObject obj = GetComponent <TrackedObject>();

        if (obj != null)
        {
            controller = obj.source;
        }
        if (controller == ControllerType.None)
        {
            m_ControllerInput = ControllerInputManager.instance.GetControllerInput(name);
        }
        else
        {
            m_ControllerInput = ControllerInputManager.instance.GetControllerInput(controller);
        }
        //
        if (PlayerPrefsEx.GetBool("UINotification-OutOfRange.enabled", false))
        {
            uiOutOfRange = PlayerPrefsEx.GetObject("UINotification-OutOfRange-" + controller.ToString(), null) as GameObject;
            if (uiOutOfRange != null)
            {
                Transform uiRoot = VRContext.uiRootVR;
                if (uiRoot != null)
                {
                    GameObject go = Instantiate(uiOutOfRange);
                    Transform  t = go.transform, raw = uiOutOfRange.transform;
                    t.SetParent(uiRoot);
                    t.localPosition  = raw.localPosition;
                    t.localRotation  = raw.localRotation;
                    t.localScale     = raw.localScale;
                    uiOutOfRange     = go;
                    m_FadeOutOfRange = uiOutOfRange.GetComponent <Ximmerse.UI.UIFade>();
                    //
                    if (m_FadeOutOfRange != null)
                    {
                        m_FadeOutOfRange.alpha = 0.0f;
                    }
                    SetUiOutOfRange(false);
                }
            }
        }
    }
Exemplo n.º 29
0
    protected virtual void OnVRContextInited(VRContext context)
    {
        if (eyeContainer == null)
        {
            eyeContainer = new GameObject("Rotate-Pivot").transform;
            eyeContainer.SetParent(transform);
            //
            eyeContainer.localPosition = Vector3.zero;
            eyeContainer.localRotation = Quaternion.identity;
            eyeContainer.localScale    = Vector3.one;
            //
            if (context.vrDevice != null && context.vrDevice.family != "Dummy")
            {
                markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckOffset;
                eyeContainer.localPosition  = context.vrDevice.neckOffset;
#if UNITY_EDITOR
                // Editor features.
                if (m_Gizmos.Length > 0 && m_Gizmos[0] != null)
                {
                    m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckOffset;
                }
#endif
            }
        }
        //
        for (int i = 0; i < 3; ++i)
        {
            Transform eye = context.GetAnchor(VRNode.LeftEye + i, null);
            if (eye != null)
            {
                eye.SetParent(eyeContainer, false);
            }
        }
        //
        switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0))
        {
        // No head tracking.
        case 0x1010:
            source            = ControllerType.None;
            m_ControllerInput = null;
            break;
        }
    }
Exemplo n.º 30
0
        protected static string DrawPopup(string label, string key, string value, string[] displayedOptions)
        {
            value = PlayerPrefsEx.GetString(key, value);
            //
            int intValue = System.Array.IndexOf(displayedOptions, value);

            if (intValue < 0)
            {
                intValue = 0;
            }
            //
            int newValue = EditorGUILayout.Popup(label, intValue, displayedOptions);

            if (newValue != intValue)
            {
                PlayerPrefsEx.SetString(key, displayedOptions[newValue]);
            }
            return(displayedOptions[newValue]);
        }