添加uimanager和主场景

This commit is contained in:
suntao committed 2021-03-25 16:53:39 +08:00
1 parent f557e2f5df
commit 4ecf26ec80
34 files changed
+2403 -5

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class App
{
public static string Host = "http://192.168.0.97:5082/";
public static string AppVersion = "1.0.0";
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 28d1b03bb28bb084c8b9576d91546d92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+2 -2
View File
@@ -8,8 +8,8 @@ namespace Assets.Scripts
{
public class ConfigHelper
{
public static string Host = "http://192.168.0.97:5082/";
public static string Host = App.Host;
public static string AppVersion = "1.0.0";
public static string AppVersion = App.AppVersion;
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee0c293ef8874e94e86882286ad5ec98
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+25
View File
@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
UIManager.Instance.MainPanel = (GameObject)this.transform.Find("Panel").gameObject;
//MainMenu.transform.Find("Home").GetComponent<Button>().onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
UIManager.ShowUserInfoPanel();
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 400780dc6cb8d0344ae80c327ba2dbba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b87f41c32aca8b945b61b24929fe8492
guid: 39a2553da07e5664a998dcde082ea86b
folderAsset: yes
DefaultImporter:
externalObjects: {}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9ea8eedb5ac35614d96ac3ac03e4718d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0628d5adfa3a8474b8864a526acd4b9d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserInfoController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
this.transform.localPosition = new Vector3(0, 0, 0);
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d53c11af00252ab409587459f4a0f3f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+107
View File
@@ -0,0 +1,107 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIManager : MonoBehaviour
{
private GameObject mMainPanel;
public GameObject MainPanel
{
get
{
return this.mMainPanel;
}
set
{
this.mMainPanel = value;
}
}
private UserInfoController mUserInfoPanel;
public UserInfoController UserInfoPanel
{
get
{
return this.GetPanelInstance<UserInfoController>("UserInfoPanel", ref this.mUserInfoPanel);
}
}
public static UIManager Instance;
private void Awake()
{
UIManager.Instance = this;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private T GetPanelInstance<T>(string prefabName, ref T internalComponent)
{
if (internalComponent == null)
{
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/" + prefabName);
if (@object != null)
{
GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(@object, base.transform.parent, false);
if (gameObject != null)
{
internalComponent = gameObject.GetComponent<T>();
}
}
}
return internalComponent;
}
public static void Show(MonoBehaviour panelToShow, GameObject parent = null)
{
if (UIManager.Instance == null || panelToShow == null)
{
return;
}
foreach (Transform child in parent.transform)
{
//GameObject.Destroy(child);
//GameObject.Destroy(child.gameObject);
child.gameObject.SetActive(false);
}
//var panel = UIManager.Instance.MainPanel; //UIManager.Instance.MainCanvasTransform.transform.Find("Panel");
//panel.gameObject.AddComponent<GameObject>(panelToShow.gameObject);
panelToShow.transform.SetParent(parent.transform);
panelToShow.gameObject.SetActive(true);
panelToShow.transform.position = new Vector3(0, 0, 0);
}
//public static void ShowHomePanel()
//{
// UIManager.Show(UIManager.Instance.PanelHome, UIManager.Instance.MainPanel);
//}
public static void ShowUserInfoPanel()
{
UIManager.Show(UIManager.Instance.UserInfoPanel, UIManager.Instance.MainPanel);
}
public static void ShowLoadingDialogBox()
{
}
private void OnDestroy()
{
UIManager.Instance = null;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff5927b9099e57740a8e1c1296251a99
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+154
View File
@@ -0,0 +1,154 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using UnityEngine;
/// <summary>
/// 异步线程更新ui工具类
/// </summary>
public class Loom : MonoBehaviour
{
public static int maxThreads = 8;
static int numThreads;
private static Loom _current;
private int _count;
public static Loom Current
{
get
{
Initialize();
return _current;
}
}
void Awake()
{
_current = this;
initialized = true;
}
static bool initialized;
static void Initialize()
{
if (!initialized)
{
if (!Application.isPlaying)
return;
initialized = true;
var g = new GameObject("Loom");
_current = g.AddComponent<Loom>();
}
}
private List<Action> _actions = new List<Action>();
public struct DelayedQueueItem
{
public float time;
public Action action;
}
private List<DelayedQueueItem> _delayed = new List<DelayedQueueItem>();
List<DelayedQueueItem> _currentDelayed = new List<DelayedQueueItem>();
public static void QueueOnMainThread(Action action)
{
QueueOnMainThread(action, 0f);
}
public static void QueueOnMainThread(Action action, float time)
{
if (time != 0)
{
lock (Current._delayed)
{
Current._delayed.Add(new DelayedQueueItem { time = Time.time + time, action = action });
}
}
else
{
lock (Current._actions)
{
Current._actions.Add(action);
}
}
}
public static Thread RunAsync(Action a)
{
Initialize();
while (numThreads >= maxThreads)
{
Thread.Sleep(1);
}
Interlocked.Increment(ref numThreads);
ThreadPool.QueueUserWorkItem(RunAction, a);
return null;
}
private static void RunAction(object action)
{
try
{
((Action)action)();
}
catch
{
}
finally
{
Interlocked.Decrement(ref numThreads);
}
}
void OnDisable()
{
if (_current == this)
{
_current = null;
}
}
// Use this for initialization
void Start()
{
}
List<Action> _currentActions = new List<Action>();
// Update is called once per frame
void Update()
{
lock (_actions)
{
_currentActions.Clear();
_currentActions.AddRange(_actions);
_actions.Clear();
}
foreach (var a in _currentActions)
{
a();
}
lock (_delayed)
{
_currentDelayed.Clear();
_currentDelayed.AddRange(_delayed.Where(d => d.time <= Time.time));
foreach (var item in _currentDelayed)
_delayed.Remove(item);
}
foreach (var delayed in _currentDelayed)
{
delayed.action();
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a5de02bca2137f47a49a488f8b16394
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: