/// <summary> /// 中间处的陷阱 /// </summary> private void CreateMidTrapPlatform() { //中间处概率 生成陷阱或者空的物体 float n = (m_RegionNumberRange.y - m_RegionNumberRange.x) / 2 + m_RegionNumberRange.x; if (m_ReginNumber == n && m_ReginTotalNumber == m_RegionNumberRange.y - 1) { bool isTrap = UnityEngine.Random.Range(0, 2) == 0 ? true : false; string trapName = m_CurPlatformInfo.OtherTrapPlatfromNames[UnityEngine.Random.Range(0, m_CurPlatformInfo.OtherTrapPlatfromNames.Count)]; PlatfromType tempType = PlatfromType.HideTrap; Platform t = null; if (isTrap) { if (m_ReginLeftDir) { t = CreateRightPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } else { t = CreateLeftPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } } else { if (m_ReginLeftDir) { //生成空的 t = CreateRightPlatform("Hide", m_LastPlatform, m_CurPlatformInfo, isNoramlShow: false, platfromType: PlatfromType.Hide); //生成 t = CreateRightPlatform(trapName, t, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } else { //生成空的 t = CreateLeftPlatform("Hide", m_LastPlatform, m_CurPlatformInfo, isNoramlShow: false, platfromType: PlatfromType.Hide); //生成 t = CreateLeftPlatform(trapName, t, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } } } }
/// <summary> /// 转折处陷阱 /// </summary> private void CreateTurnTrapPlatform() { //在改变环境处不生成陷阱 if (Step % m_ChangeEnvStep != 0) { //概率在相反方向生成隐藏陷阱 int temp = UnityEngine.Random.Range(0, 100); Platform t = null; string trapName = ""; PlatfromType tempType = PlatfromType.HideTrap; if (temp < 15) { //转折处距离最小为1,避免拥挤 if (m_ReginTotalNumber >= 2) { trapName = m_CurPlatformInfo.HideTrapPlatfromName; tempType = PlatfromType.HideTrap; } } else if (temp < 50 && temp >= 15) { trapName = m_CurPlatformInfo.OtherTrapPlatfromNames[0]; tempType = PlatfromType.OtherTrap; } else if (temp < 85 && temp >= 50) { trapName = m_CurPlatformInfo.OtherTrapPlatfromNames[1]; tempType = PlatfromType.OtherTrap; } if (!string.IsNullOrEmpty(trapName)) { if (m_ReginLeftDir) { t = CreateRightPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: tempType); } else { t = CreateLeftPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: tempType); } } } }
//startFallTime 比跳跃的时间短一点 public void Init(Vector3 startPos, Vector3 endPos, float startFallTime, float standTime, PlatformStatus status, PlatformInfo platformInfo, PlatfromType platfromType = PlatfromType.Normal) { if (status == PlatformStatus.Show) { transform.position = startPos; } else { transform.position = endPos; } PlatfromType = platfromType; CurPlatformInfo = platformInfo; m_EndPos = endPos; m_StartPos = startPos; Status = status; m_Timer = 0; m_StandTime = standTime; m_StartDownTime = startFallTime; m_IsShowHide = false; }
public Platform CreateRightPlatform(string name, Platform parnet, PlatformInfo platformInfo, bool isNoramlShow = true, PlatfromType platfromType = PlatfromType.Normal) { GameObject go = Resources.Load <GameObject>("Platform/" + name); go = Instantiate(go); Platform platform = go.GetComponent <Platform>(); parnet.RNode = platform; platform.PNode = parnet; Vector3 startPos = parnet.transform.TransformPoint(new Vector3(0.65f, 3f, 0)); Vector3 endPos = parnet.transform.TransformPoint(new Vector3(0.65f, 0.65f, 0)); Platform.PlatformStatus status = Platform.PlatformStatus.Show; if (!isNoramlShow) { status = Platform.PlatformStatus.Stand; } platform.Init(startPos, endPos, 0.1f, m_StandTime, status, platformInfo, platfromType); return(platform); }
public void CreatePlatformTest() { m_ReginNumber++; //生成隐藏陷阱后续 List <Node> hideList = FindHidePlatform(GlobalInit.Instance.CurRoleCtrl.CurPlatform); if (hideList != null) { for (int i = 0; i < hideList.Count; i++) { if (((Platform)hideList[i]).HideTrapChildCount < 2) { Node node = hideList[i]; //5步之内查看玩家是否在范围内,是的话显示隐藏陷阱 for (int j = 0; j < 5; j++) { if (node == GlobalInit.Instance.CurRoleCtrl.CurPlatform) { ((Platform)hideList[i]).ShowHideTrap(); break; } node = node.PNode; } //生成下一个平台 node = null; //左边 if (hideList[i].PNode.LNode == hideList[i]) { node = FindLeftLastNode(hideList[i]); if (node == null) { CreateLeftPlatform(((Platform)hideList[i]).CurPlatformInfo.NormalPlatfromName, (Platform)hideList[i], ((Platform)hideList[i]).CurPlatformInfo, platfromType: PlatfromType.Normal); } else { CreateLeftPlatform(((Platform)hideList[i]).CurPlatformInfo.NormalPlatfromName, (Platform)node, ((Platform)hideList[i]).CurPlatformInfo, platfromType: PlatfromType.Normal); } } else//右边 { node = FindRightLastNode(hideList[i]); if (node == null) { CreateRightPlatform(((Platform)hideList[i]).CurPlatformInfo.NormalPlatfromName, (Platform)hideList[i], ((Platform)hideList[i]).CurPlatformInfo, platfromType: PlatfromType.Normal); } else { CreateRightPlatform(((Platform)hideList[i]).CurPlatformInfo.NormalPlatfromName, (Platform)node, ((Platform)hideList[i]).CurPlatformInfo, platfromType: PlatfromType.Normal); } } ((Platform)hideList[i]).HideTrapChildCount++; } } } //转折处生成陷阱 if (m_ReginNumber == 1) { //在改变环境处不生成陷阱 if (Step % m_ChangeEnvStep != 0) { //概率在相反方向生成隐藏陷阱 int temp = UnityEngine.Random.Range(0, 100); Platform t = null; string trapName = ""; PlatfromType tempType = PlatfromType.HideTrap; if (temp < 15) { //转折处距离最小为1,避免拥挤 if (m_ReginTotalNumber >= 2) { trapName = m_CurPlatformInfo.HideTrapPlatfromName; tempType = PlatfromType.HideTrap; } } else if (temp < 50 && temp >= 15) { trapName = m_CurPlatformInfo.OtherTrapPlatfromNames[0]; tempType = PlatfromType.OtherTrap; } else if (temp < 85 && temp >= 50) { trapName = m_CurPlatformInfo.OtherTrapPlatfromNames[1]; tempType = PlatfromType.OtherTrap; } if (!string.IsNullOrEmpty(trapName)) { if (m_ReginLeftDir) { t = CreateRightPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: tempType); } else { t = CreateLeftPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: tempType); } } } } else { //中间处概率 生成陷阱或者空的物体 float n = (m_RegionNumberRange.y - m_RegionNumberRange.x) / 2 + m_RegionNumberRange.x; if (m_ReginNumber == n && m_ReginTotalNumber == m_RegionNumberRange.y - 1) { bool isTrap = UnityEngine.Random.Range(0, 2) == 0 ? true : false; string trapName = m_CurPlatformInfo.OtherTrapPlatfromNames[UnityEngine.Random.Range(0, m_CurPlatformInfo.OtherTrapPlatfromNames.Count)]; PlatfromType tempType = PlatfromType.HideTrap; Platform t = null; if (isTrap) { if (m_ReginLeftDir) { t = CreateRightPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } else { t = CreateLeftPlatform(trapName, m_LastPlatform, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } } else { if (m_ReginLeftDir) { //生成空的 t = CreateRightPlatform("Hide", m_LastPlatform, m_CurPlatformInfo, isNoramlShow: false, platfromType: PlatfromType.Hide); //生成 t = CreateRightPlatform(trapName, t, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } else { //生成空的 t = CreateLeftPlatform("Hide", m_LastPlatform, m_CurPlatformInfo, isNoramlShow: false, platfromType: PlatfromType.Hide); //生成 t = CreateLeftPlatform(trapName, t, m_CurPlatformInfo, platfromType: PlatfromType.OtherTrap); } } } } //生成正常的平台 if (m_ReginLeftDir) { m_LastPlatform = CreateLeftPlatform(m_CurPlatformInfo.NormalPlatfromName, m_LastPlatform, m_CurPlatformInfo); } else { m_LastPlatform = CreateRightPlatform(m_CurPlatformInfo.NormalPlatfromName, m_LastPlatform, m_CurPlatformInfo); } }