Ejemplo n.º 1
0
        private void CreateMenu()
        {
            Debug.Log("Easy spawner: Loading menu prefab");

            if (!menuAssetBundle)
            {
                Debug.Log("EasySpawner: Asset bundle not loaded");
                return;
            }

            if (!menuPrefab)
            {
                menuPrefab = menuAssetBundle.LoadAsset <GameObject>("EasySpawnerMenu");
            }

            if (!menuPrefab)
            {
                Debug.Log("Easy spawner: Loading menu prefab failed");
                return;
            }
            Debug.Log("Easy spawner: Successfully loaded menu prefab");

            //Add script to make menu mouse draggable as assetbundle cannot contain script
            if (!menuPrefab.GetComponent <UIElementDragger>())
            {
                menuPrefab.AddComponent <UIElementDragger>();
            }

            menuGameObject = Instantiate(menuPrefab);

            //Attach menu to Valheims UI gameobject
            var uiGO = GameObject.Find("IngameGui(Clone)");

            if (!uiGO)
            {
                Debug.Log("Easy spawner: Couldnt find UI gameobject");
                return;
            }

            menuGameObject.transform.SetParent(uiGO.transform);
            menuGameObject.transform.localScale    = new Vector3(1f, 1f, 1f);
            menuGameObject.transform.localPosition = new Vector3(-650, 0, 0);

            playerNames = GetPlayerNames();

            menu.CreateMenu(menuGameObject);
            Style.ApplyAll(menuGameObject, menu);

            //Attach CheckForNewPlayersCoroutine to UIElementdragger on the menu Gameobject so if it gets destroyed it also stops the coroutine
            menuGameObject.GetComponent <UIElementDragger>().StartCoroutine(CheckForNewPlayersCoroutine());
        }