void Awake() { if (_Instance != null) { CBase.Assert(_Instance == this); } }
public T this[int index] { get { CBase.Assert(index < MaxCount); IntPtr p = (IntPtr)(SourceBytesPtr.ToInt32() + Marshal.SizeOf(typeof(T)) * index); return((T)Marshal.PtrToStructure(p, typeof(T))); } }
/// <summary> /// Engine entry.... all begins from here /// </summary> public static CCosmosEngine New(GameObject gameObjectToAttach, ICModule[] modules, CoroutineDelegate before, CoroutineDelegate after) { CBase.Assert(gameObjectToAttach != null && modules != null); CCosmosEngine engine = gameObjectToAttach.AddComponent <CCosmosEngine>(); engine.GameModules = modules; engine.BeforeInitModules = before; engine.AfterInitModules = after; return(engine); }
public object GetUIComponent(string comName) { if (comName == "Camera") { return(UiCamera); } CBase.Assert(false); return(null); }
void OnAssetLoaded(UnityEngine.Object obj, object[] args) { Texture tex = obj as Texture; CBase.Assert(tex); if (Callback != null) { Callback(tex, CallbackArgs); } Asset = tex; IsFinished = true; }
public static void MoveAllCollidersToGameObject(GameObject srcGameObject, GameObject targetGameObject) { CBase.Assert(srcGameObject != targetGameObject); foreach (Collider collider2d in srcGameObject.GetComponentsInChildren <Collider>()) { CopyColliderToGameObject(collider2d, targetGameObject); GameObject.Destroy(collider2d); } foreach (Collider2D collider2d in srcGameObject.GetComponentsInChildren <Collider2D>()) { CopyCollider2DToGameObject(collider2d, targetGameObject); GameObject.Destroy(collider2d); } }
void CreateUIRoot() { GameObject uiRootobj = new GameObject("UIRoot"); UiRoot = uiRootobj.AddComponent <UIRoot>(); CBase.Assert(UiRoot); UiRoot.scalingStyle = UIRoot.Scaling.ConstrainedOnMobiles; UiRoot.manualHeight = 1920; UiRoot.manualWidth = 1080; GameObject panelRootObj = new GameObject("PanelRoot"); CTool.SetChild(panelRootObj.transform, uiRootobj.transform); Transform panelTrans = panelRootObj.transform; PanelRoot = panelRootObj.AddComponent <UIPanel>(); CBase.Assert(PanelRoot); GameObject uiCamObj = new GameObject("UICamera"); CTool.SetChild(uiCamObj.transform, UiRoot.transform); UiCamera = uiCamObj.AddComponent <UICamera>(); UiCamera.cachedCamera.cullingMask = 1 << (int)CLayerDef.UI; UiCamera.cachedCamera.clearFlags = CameraClearFlags.Depth; UiCamera.cachedCamera.orthographic = true; UiCamera.cachedCamera.orthographicSize = 1; UiCamera.cachedCamera.nearClipPlane = -2; UiCamera.cachedCamera.farClipPlane = 2; //panelTrans.gameObject.isStatic = true; foreach (UIAnchor.Side side in Enum.GetValues(typeof(UIAnchor.Side))) { GameObject anchorObj = new GameObject(side.ToString()); CTool.SetChild(anchorObj.transform, panelTrans); AnchorSide[side.ToString()] = anchorObj.transform; } GameObject nullAnchor = new GameObject("Null"); CTool.SetChild(nullAnchor.transform, panelTrans); AnchorSide["Null"] = nullAnchor.transform; AnchorSide[""] = AnchorSide[UIAnchor.Side.Center.ToString()]; // default NGUITools.SetLayer(uiRootobj, (int)CLayerDef.UI); }
void Update() { UpdateCount++; int exeCount = 1; int interval = 0; CBase.Assert(TimeScale > 0); if (TimeScale > 1) { exeCount = Mathf.FloorToInt(TimeScale); } else if (TimeScale < 1) { interval = Mathf.FloorToInt(1f / TimeScale); } if (interval == 0 || UpdateCount % interval == 0) { for (int count = 0; count < exeCount; count++) { while (AddQueue.Count > 0) { var d = AddQueue.Dequeue(); Coroutines.Add(d.CoroutineId, d); } foreach (KeyValuePair <int, CCoroutineWrapper> kv in Coroutines) { if (kv.Value.Suspend) { continue; } kv.Value.UpdateMove(); } while (DeleteQueue.Count > 0) { var d = DeleteQueue.Dequeue(); Coroutines.Remove(d.CoroutineId); } } } }
public CStateMachine(OBJ obj, STATE initState, CState <STATE>[] stateMap) { Object_ = obj; LastState = initState; CurState = initState; Array statesArray = Enum.GetValues(typeof(STATE)); CBase.Assert(statesArray.Length == stateMap.Length); CBase.Assert(Object_); foreach (CState <STATE> state in stateMap) { StatesHandlers[state.ToState] = state; state.OnInit(); } }
/// <summary> /// Ensure the CEngineConfig file loaded. /// </summary> static void EnsureConfigTab() { if (ConfigMap == null) { TextAsset textAsset; textAsset = Resources.Load <TextAsset>("CEngineConfig"); CBase.Assert(textAsset); CTabFile configTab = CTabFile.LoadFromString(textAsset.text); ConfigMap = new Dictionary <string, string>(); foreach (CTabFile.CTabRow row in configTab) { string key = row.GetString("Key"); string value = row.GetString("Value"); ConfigMap[key] = value; } } }
public override void OnInit() { base.OnInit(); HomeButton = GetControl <UIButton>("Button"); // child CBase.Assert(HomeButton); HomeLabel = GetControl <UILabel>("Button/Label"); // uri.... CBase.Assert(HomeLabel); HomeButton = FindControl <UIButton>("Button"); // find by gameobject name CBase.Assert(HomeButton); HomeLabel = FindControl <UILabel>("Label"); // child name CBase.Assert(HomeLabel); HomeButton.onClick.Add(new EventDelegate(() => { CBase.LogWarning("Click Home Button!"); })); }
/// <summary> /// 等待并获取UI实例,执行callback /// 源起Loadindg UI, 在加载过程中,进度条设置方法会失效 /// </summary> /// <param name="uiName"></param> /// <param name="callback"></param> /// <param name="args"></param> public void CallUI(string uiName, Action <CUIController, object[]> callback, params object[] args) { CBase.Assert(callback); CUILoadState uiState; if (!UIWindows.TryGetValue(uiName, out uiState)) { uiState = LoadWindow(uiName, false); // 加载,这样就有UIState了 } if (uiState.IsLoading) // Loading { CUILoadState openState = UIWindows[uiName]; openState.CallbacksWhenFinish.Enqueue(callback); openState.CallbacksArgsWhenFinish.Enqueue(args); return; } callback(uiState.UIWindow, args); }
public CUILoadState LoadWindow(string name, bool openWhenFinish, params object[] args) { if (UIWindows.ContainsKey(name)) { CBase.LogError("[LoadWindow]多次重复LoadWindow: {0}", name); } CBase.Assert(!UIWindows.ContainsKey(name)); string path = string.Format("UI/{0}_UI{1}", name, CCosmosEngine.GetConfig("AssetBundleExt")); CUILoadState openState = new CUILoadState(name); openState.IsStaticUI = true; openState.OpenArgs = args; openState.OpenWhenFinish = openWhenFinish; CResourceManager.Instance.StartCoroutine(LoadUIAssetBundle(path, name, openState)); UIWindows.Add(name, openState); return(openState); }
/// <summary> /// Initialize the path of AssetBundles store place ( Maybe in PersitentDataPath or StreamingAssetsPath ) /// </summary> /// <returns></returns> public static void InitResourcePath() { string productPath = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("ProductRelPath")); string assetBundlePath = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("AssetBundleRelPath")); string resourceDirName = Path.GetFileName(CCosmosEngine.GetConfig("AssetBundleRelPath")); BuildPlatformName = GetBuildPlatformName(); string fileProtocol = GetFileProtocol(); DocumentResourcesPathWithOutFileStart = string.Format("{0}/{1}/{2}/", GetAppDataPath(), resourceDirName, GetBuildPlatformName()); // 各平台通用 DocumentResourcesPath = fileProtocol + DocumentResourcesPathWithOutFileStart; switch (Application.platform) { case RuntimePlatform.WindowsEditor: case RuntimePlatform.OSXEditor: { ApplicationPath = string.Format("{0}{1}/", fileProtocol, productPath); ResourcesPath = fileProtocol + assetBundlePath + "/" + BuildPlatformName + "/"; ResourcesPathWithOutFileProtocol = assetBundlePath + "/" + BuildPlatformName + "/"; } break; case RuntimePlatform.WindowsPlayer: case RuntimePlatform.OSXPlayer: { string path = Application.dataPath.Replace('\\', '/'); path = path.Substring(0, path.LastIndexOf('/') + 1); ApplicationPath = string.Format("{0}{1}/", fileProtocol, path); ResourcesPath = string.Format("{0}{1}{2}/{3}", fileProtocol, path, resourceDirName, GetBuildPlatformName()); ResourcesPathWithOutFileProtocol = string.Format("{0}{1}/{2}/", path, resourceDirName, GetBuildPlatformName()); } break; case RuntimePlatform.Android: { ApplicationPath = string.Concat("jar:", fileProtocol, Application.dataPath, "!/assets/"); ResourcesPath = string.Concat(ApplicationPath, GetBuildPlatformName(), "/"); ResourcesPathWithOutFileProtocol = string.Concat(Application.dataPath, "!/assets/", GetBuildPlatformName() + "/"); // 注意,StramingAsset在Android平台中,是在壓縮的apk里,不做文件檢查 } break; case RuntimePlatform.IPhonePlayer: { ApplicationPath = System.Uri.EscapeUriString(fileProtocol + Application.streamingAssetsPath + "/"); // MacOSX下,带空格的文件夹,空格字符需要转义成%20 ResourcesPath = string.Format("{0}{1}/", ApplicationPath, GetBuildPlatformName()); // only iPhone need to Escape the f*****g Url!!! other platform works without it!!! Keng Die! ResourcesPathWithOutFileProtocol = Application.streamingAssetsPath + "/" + GetBuildPlatformName() + "/"; } break; default: { CBase.Assert(false); } break; } if (Debug.isDebugBuild) { CBase.Log("ResourceManager ApplicationPath: {0}", ApplicationPath); CBase.Log("ResourceManager ResourcesPath: {0}", ResourcesPath); CBase.Log("ResourceManager DocumentResourcesPath: {0}", DocumentResourcesPath); CBase.Log("================================================================================"); } }
public static void LoadFromTab(Type type, ref CBaseInfo newT, ICTabReadble tabFile, int row) { CBase.Assert(typeof(CBaseInfo).IsAssignableFrom(type)); FieldInfo[] fields = type.GetFields(); foreach (FieldInfo field in fields) { if (!tabFile.HasColumn(field.Name)) { CBase.LogError("表{0} 找不到表头{1}", type.Name, field.Name); continue; } object value; if (field.FieldType == typeof(int)) { value = tabFile.GetInteger(row, field.Name); } else if (field.FieldType == typeof(long)) { value = (long)tabFile.GetInteger(row, field.Name); } else if (field.FieldType == typeof(string)) { value = tabFile.GetString(row, field.Name); } else if (field.FieldType == typeof(float)) { value = tabFile.GetFloat(row, field.Name); } else if (field.FieldType == typeof(bool)) { value = tabFile.GetBool(row, field.Name); } else if (field.FieldType == typeof(double)) { value = tabFile.GetDouble(row, field.Name); } else if (field.FieldType == typeof(uint)) { value = tabFile.GetUInteger(row, field.Name); } else if (field.FieldType == typeof(List <string>)) { string sz = tabFile.GetString(row, field.Name); value = CTool.Split <string>(sz, '|'); } else if (field.FieldType == typeof(List <int>)) { List <int> retInt = new List <int>(); string szArr = tabFile.GetString(row, field.Name); if (!string.IsNullOrEmpty(szArr)) { string[] szIntArr = szArr.Split('|'); foreach (string szInt in szIntArr) { float parseFloat; float.TryParse(szInt, out parseFloat); int parseInt_ = (int)parseFloat; retInt.Add(parseInt_); } value = retInt; } else { value = new List <int>(); } } else if (field.FieldType == typeof(List <List <string> >)) { string sz = tabFile.GetString(row, field.Name); if (!string.IsNullOrEmpty(sz)) { var szOneList = new List <List <string> >(); string[] szArr = sz.Split('|'); foreach (string szOne in szArr) { string[] szOneArr = szOne.Split('-'); szOneList.Add(new List <string>(szOneArr)); } value = szOneList; } else { value = new List <List <string> >(); } } else if (field.FieldType == typeof(List <List <int> >)) { string sz = tabFile.GetString(row, field.Name); if (!string.IsNullOrEmpty(sz)) { var zsOneIntList = new List <List <int> >(); string[] szArr = sz.Split('|'); foreach (string szOne in szArr) { List <int> retInts = new List <int>(); string[] szOneArr = szOne.Split('-'); foreach (string szOneInt in szOneArr) { float parseFloat; float.TryParse(szOneInt, out parseFloat); int parseInt_ = (int)parseFloat; retInts.Add(parseInt_); } zsOneIntList.Add(retInts); } value = zsOneIntList; } else { value = new List <List <int> >(); } } else { CBase.LogWarning("未知类型: {0}", field.Name); value = null; } if (field.Name == "Id") // 如果是Id主键,确保数字成整数!不是浮点数 因为excel转tab可能转成浮点 { float fValue; if (float.TryParse((string)value, out fValue)) { try { value = ((int)fValue).ToString(); } catch { CBase.LogError("转型错误...{0}", value.ToString()); } } } field.SetValue(newT, value); } }
// 将字符串转成指定类型的数组 , 单元测试在Test_StrBytesToArray public static T[] StrBytesToArray <T>(string str, int arraySize) { int typeSize = Marshal.SizeOf(typeof(T)); byte[] strBytes = Encoding.Unicode.GetBytes(str); byte[] bytes = new byte[typeSize * arraySize]; // 强制数组大小 for (int k = 0; k < strBytes.Length; k++) { bytes[k] = strBytes[k]; // copy } T[] tArray = new T[bytes.Length / typeSize]; // 总字节 除以 类型长度 = 有多少个类型对象 int offset = 0; for (int i = 0; i < tArray.Length; i++) { object convertedObj = null; TypeCode typeCode = Type.GetTypeCode(typeof(T)); switch (typeCode) { case TypeCode.Byte: convertedObj = bytes[offset]; break; case TypeCode.Int16: convertedObj = BitConverter.ToInt16(bytes, offset); break; case TypeCode.Int32: convertedObj = BitConverter.ToInt32(bytes, offset); break; case TypeCode.Int64: convertedObj = BitConverter.ToInt64(bytes, offset); break; case TypeCode.UInt16: convertedObj = BitConverter.ToUInt16(bytes, offset); break; case TypeCode.UInt32: convertedObj = BitConverter.ToUInt32(bytes, offset); break; case TypeCode.UInt64: convertedObj = BitConverter.ToUInt64(bytes, offset); break; default: CBase.LogError("Unsupport Type {0} in StrBytesToArray(), You can custom this.", typeCode); CBase.Assert(false); break; } tArray[i] = (T)(convertedObj); offset += typeSize; } return(tArray); }