Skip to content
Snippets Groups Projects
StartMenu_mobile.cs 9.03 KiB
Newer Older
MaZiFAU's avatar
MaZiFAU committed
using System;
using UnityEngine;
using UnityEngine.UI; //andr
MaZiFAU's avatar
MaZiFAU committed
using static CommunicationEvents;
using static StreamingAssetLoader;
//using static StreamingAssetLoader;
//using static CheckServer;
//using static CommunicationEvents;
using static UIconfig;
Stefan Richter's avatar
Stefan Richter committed
public class StartMenu_mobile : MonoBehaviour
{


    //public int myUI_ID;
    public GameObject myself_GObj;
    //public GameObject parent_GObj;
    //public int backUI_ID;
    //public int optionsUI_ID;
    //public int failedUI_ID;
    public GameObject child1_GObj;

        ScreenOptimization();
        //GObj_text.text = "1: "+  Application.streamingAssetsPath + " " + Application.persistentDataPath + " " + Application.dataPath;
        if (checkOperationSystemAlreadyDone == false || checkOperationSystemAlreadyDone_check == false)
            start2_CheckOS_CheckConfig();
            checkOperationSystemAlreadyDone = true;
        }
        GObj_text.text = Application.platform + " -> " + CommunicationEvents.Opsys + "";
        //GObj_text.text = "2: " + Application.streamingAssetsPath + " " + Application.persistentDataPath + " " + Application.dataPath;
        //Debug.Log(Application.streamingAssetsPath);
        //CheckServerA[1] = 1;
        //CheckServerA[2] = 1;
        //CheckServerA[3] = 1;
        for(int i=0; i<CheckServerA.Length; i++)
        {
            CheckServerA[i] = 1;
        }

MaZiFAU's avatar
MaZiFAU committed

    }

    void start2_CheckOS_CheckConfig()
    {
        //Try to find existing Config:
        int configExists = 0;
        //Debug.Log("Load Streaming Asset");
MaZiFAU's avatar
MaZiFAU committed
        try { NetworkJSON_Load_0(); configExists = 1; }
        catch (Exception e)
        {
MaZiFAU's avatar
MaZiFAU committed
            Debug.Log(e);
        }
        //Debug.Log("Load Streaming Asset finished");
        //Debug.Log(checkPersistentDataPath());
        {
            NetworkJSON_Load();
            configExists = 2;
        }
MaZiFAU's avatar
MaZiFAU committed
        catch (Exception e)
        {
            Debug.Log(e);
MaZiFAU's avatar
MaZiFAU committed

        if (configExists == 0)
        {
            Debug.Log(configExists + "No Config found");
            checkOS2();
            try
            {
                ResetPlayerConfig();
                NetworkJSON_Load();
                configExists = 3;
            }
            catch (Exception e)
            {
                Debug.Log(e);
            }
        }
        else
        {
            //Debug.Log(configExists + "Config found");
            checkOS();
        }
MaZiFAU's avatar
MaZiFAU committed
        if (!checkPersistentDataPath() || configExists < 1)
        {
            //Debug.Log("initialReset_PDP");
            ResetPersistentDataPath();
            //Debug.Log("Reset_PDP_finished");
            NetworkJSON_Load();
            changeSettingsToOS();
            NetworkJSON_Save();
        }
        //Save CheckOS
        NetworkJSON_Save();
MaZiFAU's avatar
MaZiFAU committed

        //Debug.Log("StartAdaption");
        {
            changeSettingsToOS();
            NetworkJSON_Save();
        //Debug.Log("EndAdaption");
        NetworkJSON_Load();
MaZiFAU's avatar
MaZiFAU committed

        if (!checkDataPath() && false)
            Debug.Log("Todo: Pr�fen auf Bugs bzl DataPath");

        if (!checkDataPath() || true)
        {
            ResetDataPath();
        //Debug.Log("DataPath finished");
        if (UIconfig.MouseKeepingInWindow == true)
        {
            Cursor.lockState = CursorLockMode.Confined;
        }
        else
        {
            Cursor.lockState = CursorLockMode.None;
        }
MaZiFAU's avatar
MaZiFAU committed

MaZiFAU's avatar
MaZiFAU committed

MaZiFAU's avatar
MaZiFAU committed
        if (CommunicationEvents.autoOSrecognition == true)
        {
            //CommunicationEvents.Opsys = CommunicationEvents.Opsys_Default;
MaZiFAU's avatar
MaZiFAU committed
        if (Opsys == OperationSystem.Android)
    }

    void checkOS2()
    {
        //https://docs.unity3d.com/ScriptReference/RuntimePlatform.html
MaZiFAU's avatar
MaZiFAU committed

        if (Application.platform == RuntimePlatform.WindowsPlayer)
        {
MaZiFAU's avatar
MaZiFAU committed

            //Debug.Log("Windows OS detected");
            CommunicationEvents.Opsys = OperationSystem.Windows;
MaZiFAU's avatar
MaZiFAU committed

            return;
        }
        if (Application.platform == RuntimePlatform.Android)
        {
            //Debug.Log("Android OS detected");
            CommunicationEvents.Opsys = OperationSystem.Android;
MaZiFAU's avatar
MaZiFAU committed

        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            CommunicationEvents.Opsys = OperationSystem.Windows;
            return;
        }
        if (Application.platform == RuntimePlatform.OSXPlayer)
        {
            CommunicationEvents.Opsys = OperationSystem.iOS;
            return;
        }
        if (Application.platform == RuntimePlatform.WindowsPlayer)
        {
            CommunicationEvents.Opsys = OperationSystem.WindowsStoreApps;
            return;
        }
        Debug.Log("Detecting OS: " + Application.platform + " -> " + CommunicationEvents.Opsys);
        //CommunicationEvents.Opsys = CommunicationEvents.Opsys_Default;
    void changeSettingsToOS()
    {
        switch (Opsys)
        {
            case OperationSystem.Windows:
                UIconfig.controlMode = ControlMode.Keyboard;
                if (autoSettingsAdaption == 2) { UIconfig.FrameITUIversion = 1; }
                UIconfig.scrollViewVersion = ScrollViewVersion.ScrollWebView;
                break;
            case OperationSystem.Android:
                UIconfig.controlMode = ControlMode.Mobile;
                if (autoSettingsAdaption == 2) { UIconfig.FrameITUIversion = 2; }
                UIconfig.scrollViewVersion = ScrollViewVersion.ScrollShow;
MaZiFAU's avatar
MaZiFAU committed
    public void setMouse()
MaZiFAU's avatar
MaZiFAU committed
        updateMouseCursor.setMouse();
    }


    void ScreenOptimization()
    {
        Screen.orientation = ScreenOrientation.LandscapeLeft;
MaZiFAU's avatar
MaZiFAU committed

        UIconfig.screHeight = Screen.height;
        UIconfig.screWidth = Screen.width;
        CommunicationEvents.lastIP = CommunicationEvents.selecIP;


        /* //ScreenMatchMode.MatchWidthOrHeight:
            // If one axis has twice resolution and the other has half, it should even out if widthOrHeight value is at 0.5.
            // In normal space the average would be (0.5 + 2) / 2 = 1.25
            // In logarithmic space the average is (-1 + 1) / 2 = 0
            float scaleFactor = Mathf.Max(screenSize.x / m_ReferenceResolution.x, screenSize.y / m_ReferenceResolution.y);

             float logWidth = Mathf.Log(screenSize.x / m_ReferenceResolution.x, kLogBase);
             float logHeight = Mathf.Log(screenSize.y / m_ReferenceResolution.y, kLogBase);
             float logWeightedAverage = Mathf.Lerp(logWidth, logHeight, m_MatchWidthOrHeight);
             scaleFactor = Mathf.Pow(kLogBase, logWeightedAverage);


Stefan Richter's avatar
Stefan Richter committed
            //GameObject.Find("ASMenu").GetComponent;
            //Camera;


            //mainInputField.text = "Enter IP Here...";

        */

        UnityEngine.UI.CanvasScaler c = myself_GObj.GetComponent<UnityEngine.UI.CanvasScaler>();
        c.uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize;

        UIconfig.refWidth = (int)Mathf.Round(c.referenceResolution[0]);
        UIconfig.refHeight = (int)Mathf.Round(c.referenceResolution[1]);
        //CommunicationEvents.scaleMatch = 0.5f;

        /*
            //float kLogBase=10;
            //CommunicationEvents.scaleMatch = Mathf.Max(CommunicationEvents.screWidth / CommunicationEvents.refWidth, CommunicationEvents.screHeight / CommunicationEvents.refHeight);
            //float logWidth = Mathf.Log(CommunicationEvents.screWidth / CommunicationEvents.refWidth, kLogBase);
            //float logHeight = Mathf.Log(CommunicationEvents.screHeight / CommunicationEvents.refHeight, kLogBase);
            //float logWeightedAverage = Mathf.Lerp(logWidth, logHeight, 0.5f);
            //CommunicationEvents.scaleMatch = Mathf.Pow(kLogBase, logWeightedAverage);

            //c.matchWidthOrHeight = CommunicationEvents.scaleMatch;
         /*
                RectTransform rt = GetComponent<RectTransform>();

                Vector3 screenSize = Camera.main.ViewportToWorldPoint(Vector3.up + Vector3.right);

                screenSize *= 02;

                float sizeY = screenSize.y / rt.rect.height;
                float sizeX = screenSize.x / rt.rect.width;

                rt.localScale = new Vector3(sizeX, sizeY, 1);
        */
MaZiFAU's avatar
MaZiFAU committed

Stefan Richter's avatar
Stefan Richter committed
        UIconfig.Andr_Start_menu_counter = 1;
MaZiFAU's avatar
MaZiFAU committed

    /// <summary>
    /// Deactivates all Pages.
    /// </summary>
    private void ClearUIC()
    {
MaZiFAU's avatar
MaZiFAU committed

        for (int i = 0; i < myself_GObj.transform.childCount; i++)
        {
            myself_GObj.transform.GetChild(i).gameObject.SetActive(false);
        }
    }