private IEnumerator Sleep(float duration) { yield return(CTool.Wait(duration)); StartCoroutine(nameof(ControlledUpdate)); StartCoroutine(nameof(Idle)); }
public static void GenerateCoinPoint(Vector3 pos, int num = 1) { for (int i = 0; i < num; i++) { GenerateFromAsset("coinpoint", pos + CTool.RandomVector3(), CTool.s_ZeroQuaternion).SetActive(true); } }
private void CreateAgentObserverObj() { GameObject obj = CTool.CreateEmptyGameObject("AgentObserver"); _angetObserver = obj.AddComponent <AgentObserver>(); _angetObserver.SetEnvironment(_env); }
protected override IEnumerator Idle() { m_Rigidbody.velocity = Vector3.zero; yield return(CTool.Wait(T_IDLE)); StartCoroutine(nameof(Attack)); //Ö»Óй¥»÷¡¢¾²Ö¹Á½¸ö½×¶Î }
private static bool DoCheckNeedBuild(string filePath, bool log = false) { BuildRecord assetMd5; if (!File.Exists(filePath)) { if (log) { CDebug.LogError("[DoCheckNeedBuild]Not Found 无法找到文件 {0}", filePath); } if (filePath.Contains("unity_builtin_extra")) { CDebug.LogError("[DoCheckNeedBuild]Find unity_builtin_extra resource to build!! Please check it! current scene: {0}", EditorApplication.currentScene); } return(false); } if (!BuildVersion.TryGetValue(filePath, out assetMd5)) { return(true); } if (CTool.MD5_File(filePath) != assetMd5.MD5) { return(true); // different } return(false); }
protected virtual IEnumerator Wander() { m_Direction = CTool.RandomVector3().normalized; m_Rigidbody.velocity = m_Direction * Speed; yield return(CTool.Wait(T_MOVE)); StartCoroutine(Idle()); }
private void InitEnvironmentObjs() { _planeObj = CTool.FindGameObject(gameObject, "Plane"); _eastWallObj = CTool.FindGameObject(gameObject, "East"); _westWallObj = CTool.FindGameObject(gameObject, "West"); _northWallObj = CTool.FindGameObject(gameObject, "North"); _southWallObj = CTool.FindGameObject(gameObject, "South"); }
protected virtual IEnumerator Chase() { m_Direction = v_Player.normalized; m_Rigidbody.velocity = m_Direction.normalized * UpSpeed; yield return(CTool.Wait(T_CHASE)); StartCoroutine(Attack()); }
protected virtual void Follow() { transform.position = Player.transform.position + new Vector3(m_Offset.x * Player.transform.localScale.x, m_Offset.y, 0); m_Direction = (MousePos - transform.position).normalized; m_Angle = CTool.Direction2Angle(m_Direction); m_Rotation = Quaternion.Euler(0f, 0f, 90f - m_Angle); transform.localRotation = m_Rotation; transform.localScale = new Vector3(transform.localScale.x, m_Angle < 0f ? -1f : 1f, transform.localScale.z); }
protected override void GenerateBullet() { extraOffset = CTool.Angle2Direction(m_Angle + 90f) * 0.5f; base.GenerateBullet(); base.GenerateBullet(); TempBullet.transform.position += extraOffset; base.GenerateBullet(); TempBullet.transform.position -= extraOffset; }
private void LoadObstacleObjs() { _obstacleObjs = new List <GameObject>(); for (int i = 0; i < numObstacles; i++) { GameObject obj = ResourceManager.Instance.InstantiateGameObjectFromPath(OBSTACLE_PREFAB_PATH, "Obstacle" + i, transform); CTool.ResetGameObjectTransform(obj); _obstacleObjs.Add(obj); } }
//如果是单发射击,不用重写此函数 protected virtual void GenerateBullet() { m_Angle += Random.Range(-m_DeflectLevel, m_DeflectLevel); Vector3 direction = CTool.Angle2Direction(m_Angle); //修改angle来控制角度 m_BulletOffset = new Vector3(direction.x, direction.y, 0) * m_BulletOffsetDistance; TempBullet = GameObject.Instantiate(Bullet, transform.position + m_BulletOffset, transform.localRotation); TempRb = TempBullet.GetComponent <Rigidbody2D>(); TempRb.velocity = m_Direction * SHOOT_SPEED; }
private void LoadGoalObjs() { _goalObjs = new List <GameObject>(); for (int i = 0; i < numGoals; i++) { GameObject obj = ResourceManager.Instance.InstantiateGameObjectFromPath(GOAL_PREFAB_PATH, "Goal" + i, transform); CTool.ResetGameObjectTransform(obj); _goalObjs.Add(obj); } }
protected virtual void GenerateDanmaku() //不能发射弹幕的敌人禁止使用 { GameObject TempBullet; Rigidbody2D TempRb; m_Direction = CTool.Angle2Direction(m_Angle); //每次调用此函数前改变m_Angle以改变射击方向 TempBullet = GameObject.Instantiate(Danmaku, transform.position, Quaternion.Euler(0, 0, 90f - m_Angle)); TempRb = TempBullet.GetComponent <Rigidbody2D>(); TempRb.velocity = m_Direction * SHOOT_SPEED; }
public IEnumerator Die() { m_Rigidbody.velocity = Vector2.zero; GetComponent <BoxCollider2D>().enabled = false; m_Animator.SetBool("dead", true); GenerateEnergyPoint(m_Pos, m_Energypoint); GenerateCoinPoint(m_Pos, m_Coin); yield return(CTool.Wait(2f)); Destroy(this.gameObject); }
public bool Contains(string str) { var findStr = str; if (_isMD5) { findStr = CTool.MD5_16bit(str); } return(_hashSet.Contains(findStr)); }
public static CVersionNumber Parse(string verStr) { var verArgs = CTool.Split <string>(verStr, '.'); return(new CVersionNumber { Major = verArgs.Count >= 1 ? verArgs[0].ToInt32() : 0, Minor = verArgs.Count >= 2 ? verArgs[1].ToInt32() : 0, Build = verArgs.Count >= 3 ? verArgs[2].ToInt32() : 0, Flag = verArgs.Count >= 4 ? verArgs[3] : "" }); }
protected virtual IEnumerator Attack() { m_Rigidbody.velocity = Vector2.zero; m_Direction = v_Player.normalized; m_Angle = CTool.Direction2Angle(m_Direction); if (Danmaku != null) { GenerateDanmaku(); } yield return(CTool.Wait(T_ATTACK)); StartCoroutine(Idle()); }
public static void MarkBuildVersion(params string[] sourceFiles) { if (!IsCheckMd5) { return; } if (sourceFiles == null || sourceFiles.Length == 0) { return; } foreach (string file in sourceFiles) { //BuildVersion[file] = GetAssetVersion(file); BuildRecord theRecord; var nowMd5 = CTool.MD5_File(file); if (!BuildVersion.TryGetValue(file, out theRecord)) { theRecord = BuildVersion[file] = new BuildRecord(); theRecord.Mark(nowMd5); } else { if (nowMd5 != theRecord.MD5) { theRecord.Mark(nowMd5); } } string metaFile = file + ".meta"; if (File.Exists(metaFile)) { BuildRecord theMetaRecord; var nowMetaMd5 = CTool.MD5_File(metaFile); if (!BuildVersion.TryGetValue(metaFile, out theMetaRecord)) { theMetaRecord = BuildVersion[metaFile] = new BuildRecord(); theMetaRecord.Mark(nowMetaMd5); } else { if (nowMetaMd5 != theMetaRecord.MD5) { theMetaRecord.Mark(nowMetaMd5); } } } } }
protected virtual IEnumerator Idle() { m_Rigidbody.velocity = Vector3.zero; yield return(CTool.Wait(T_IDLE)); if (b_Battling) { StartCoroutine(Chase()); } else { StartCoroutine(Wander()); } }
protected void Button7_Click(object sender, EventArgs e) { int Tp_Ret = 0; string Tp_ExMsg = string.Empty; //try //{ Tp_Ret = CTool.Test_Split_String_To_Array("A,B"); //} //catch (Exception ex) //{ // Tp_ExMsg = ex.Message; //} TextBox2.Text = Tp_Ret.ToString() + "\r\n" + Tp_ExMsg; }
/// <summary> /// 获取波浪随机数的最大最小 /// </summary> /// <param name="str"></param> /// <returns></returns> public static FromToNumber ParseMinMaxNumber(string str) { var rangeArr = CTool.Split <float>(str, '~', '-'); var number = new FromToNumber(); if (rangeArr.Count > 0) { number.From = rangeArr[0]; } if (rangeArr.Count > 1) { number.To = rangeArr[1]; } return(number); }
protected static Transform GetParent(string bigType, string smallType) { var uri = GetUri(bigType, smallType); Transform theParent; if (!Parents.TryGetValue(uri, out theParent)) { var bigTypeObjName = string.Format("__{0}__", bigType); var bigTypeObj = GameObject.Find(bigTypeObjName) ?? new GameObject(bigTypeObjName); theParent = new GameObject(smallType).transform; CTool.SetChild(theParent, bigTypeObj.transform); Parents[uri] = theParent; } return(theParent); }
public bool Add(string str) { var setStr = str.Trim(); if (_isMD5) { setStr = CTool.MD5_16bit(str); } if (_hashSet.Add(setStr)) { _writer.WriteLine(setStr); return(true); } return(false); }
public static void SetParent(string bigType, string smallType, GameObject obj) { var uri = GetUri(bigType, smallType); Transform theParent = GetParent(bigType, smallType); int typeCount; if (!Counts.TryGetValue(uri, out typeCount)) { Counts[uri] = 0; } typeCount = ++Counts[uri]; CTool.SetChild(obj, theParent.gameObject); theParent.gameObject.name = GetNameWithCount(smallType, typeCount); }
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); }
private static bool DoCheckNeedBuild(string filePath, bool log = false) { BuildRecord assetMd5; if (!File.Exists(filePath)) { if (log) { CDebug.LogError("[DoCheckNeedBuild]无法找到文件 {0}", filePath); } return(false); } if (!BuildVersion.TryGetValue(filePath, out assetMd5)) { return(true); } if (CTool.MD5_File(filePath) != assetMd5.MD5) { return(true); // different } return(false); }
private void Init() { IsRootUser = CTool.HasWriteAccessToFolder(Application.dataPath); // Root User运行时,能穿越沙盒写DataPath, 以此为依据 if (Debug.isDebugBuild) { RenderWatcher = new CFpsWatcher(0.95f); } if (Debug.isDebugBuild) { CBase.Log("===================================================================================="); CBase.Log("Application.platform = {0}", Application.platform); CBase.Log("Application.dataPath = {0} , WritePermission: {1}", Application.dataPath, IsRootUser); CBase.Log("Application.streamingAssetsPath = {0} , WritePermission: {1}", Application.streamingAssetsPath, CTool.HasWriteAccessToFolder(Application.streamingAssetsPath)); CBase.Log("Application.persistentDataPath = {0} , WritePermission: {1}", Application.persistentDataPath, CTool.HasWriteAccessToFolder(Application.persistentDataPath)); CBase.Log("Application.temporaryCachePath = {0} , WritePermission: {1}", Application.temporaryCachePath, CTool.HasWriteAccessToFolder(Application.temporaryCachePath)); CBase.Log("Application.unityVersion = {0}", Application.unityVersion); CBase.Log("SystemInfo.deviceModel = {0}", SystemInfo.deviceModel); CBase.Log("SystemInfo.deviceUniqueIdentifier = {0}", SystemInfo.deviceUniqueIdentifier); CBase.Log("===================================================================================="); } StartCoroutine(DoInit()); }
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); } }
private void LoadAgentObj() { _agentObj = ResourceManager.Instance.InstantiateGameObjectFromPath(AGENT_PREFAB_PATH, "Agent", transform); CTool.ResetGameObjectTransform(_agentObj); _agent = CTool.GetOrAddComponent <Agent>(_agentObj); }