public Edge(Node start, Node end, LinkType type) { this.start = start; this.end = end; this.type = type; this.jump = new JumpInfo(); }
public Edge(Node start, Node end, JumpInfo jump) { this.start = start; this.end = end; this.type = LinkType.Jump; this.jump = jump; }
public JumpInfo GetJumpInfo(int cargo, double mass, double currentfuel, double avgfuel) { JumpInfo jid = new JumpInfo(); jid.avgsinglejump = MaxJump(cargo, mass, avgfuel); jid.avgsinglejumpnocargo = MaxJump(0, mass, avgfuel); jid.maxjumprange = CalculateMaxJumpDistance(cargo, mass, currentfuel, out jid.maxjumps); return(jid); }
public void ClearJumpStartFrom(int startIndex) { for (int i = 0; i < jumps.Count; i++) { JumpInfo curJump = jumps[i]; if (curJump.index == startIndex) { jumps.RemoveAt(i); i--; } } }
public void CheckJump() { for (int i = 0; i < jumps.Count; i++) { JumpInfo cur = jumps[i]; if (cur.index == index) { index = cur.target; jumps.RemoveAt(i); index--; return; } } }
private void Reset() { Movement = new MovementInfo() { Gravity = -9.81f, MaxSpeed = 9, //Friction = 6, //Acceleration = 6, MinimalVelocityThreshold = 0.1f, MinimalForceThreshold = 0.01f }; Jump = new JumpInfo() { JumpHeight = 2, JumpSpeed = 9 }; Animation = new AnimationInfo() { MovementBlend = "Forward", AirBoolean = "InAir" }; }
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath) { aniInfoPath.Clear(); if (CheckEventModified(importedAssets) || CheckEventModified(movedAssets)) { string[] ap = aniInfoPath.ToArray(); foreach (string child in ap) { //FCAnimationInfo sd = AssetDatabase.LoadAssetAtPath("assets/data/camera/newSkillCameraList.asset", typeof(SkillCameraList)) as SkillCameraList; string elem = child; elem = elem.Replace(".controller", ".asset"); string path = elem; FCAnimationInfo ei = AssetDatabase.LoadAssetAtPath(elem, typeof(FCAnimationInfo)) as FCAnimationInfo; FCAnimationInfo eim = null; //AssetDatabase.DeleteAsset(elem); //ei = null; if (ei == null) { ei = ScriptableObject.CreateInstance <FCAnimationInfo>(); //need not create new folder now /*string[] folders = elem.Split('/'); * string[] parentfolders = elem.Split('/'); * for(int i = 1;i< folders.Length-2;i++) * { * parentfolders[i] = parentfolders[i-1]+"/"+folders[i]; * } * for(int i = 0;i< parentfolders.Length-2;i++) * { * if(!Directory.Exists(parentfolders[i]+"/"+folders[i+1])) * { * AssetDatabase.CreateFolder(parentfolders[i],folders[i+1]); * } * }*/ path = AssetDatabase.GenerateUniqueAssetPath(elem); //ei= AssetDatabase.LoadAssetAtPath(path, typeof(FCAnimationInfo)) as FCAnimationInfo; } else { eim = ei; ei = ScriptableObject.CreateInstance <FCAnimationInfo>(); } Debug.Log("Model event changed = " + elem); bool flag = false; ei._animationInfo = new List <FCAnimationInfoDetails>(); List <JumpInfo> jumpInfos = new List <JumpInfo>(); using (System.IO.StreamReader reader = new System.IO.StreamReader(child)) { string line = reader.ReadLine(); while (line != null) { if (!flag && line == "State:") { flag = true; } if (flag) { if (line == "StateMachine:") { break; } string uid = ""; if (line.Contains("--- !u!")) { string[] ass = line.Split('&'); uid = ass[1]; } if (line.Contains("m_SrcState: {fileID: 0}")) { line = reader.ReadLine(); if (line.Contains("m_DstState")) { line = line.Replace(" m_DstState: {fileID: ", ""); line = line.Replace("}", ""); if (line != "0") { JumpInfo ji = new JumpInfo(); ji._targetID = line; line = reader.ReadLine(); while (!line.Contains("m_ConditionEvent")) { line = reader.ReadLine(); } if (line.Contains("state")) { line = reader.ReadLine(); if (line.Contains("m_EventTreshold")) { line = line.Replace(" m_EventTreshold: ", ""); } if (int.TryParse(line, out ji._jumpCondition)) { jumpInfos.Add(ji); } } else { ji = null; } } } } if (line.Contains(" m_Name: ") && line.Length > 11) { FCAnimationInfoDetails eds = new FCAnimationInfoDetails(); string nameS = line.Remove(0, 10); nameS = "Base." + nameS; eds._animationName = nameS; eds._nameHashCode = Animator.StringToHash(nameS); if (uid != "") { eds._uidString = uid; } line = reader.ReadLine(); if (line.Contains("m_Speed")) { string speed = line.Remove(0, 11); eds._speed = float.Parse(speed); } ei._animationInfo.Add(eds); } } line = reader.ReadLine(); } } ei.RefreshList(); //true means need not refresh asset bool ret = true; if (eim == null) { ret = false; } else if (eim != null && ei._animationInfo.Count == eim._animationInfo.Count) { for (int i = 0; i < ei._animationInfo.Count; i++) { if (ei._animationInfo[i]._speed != eim._animationInfo[i]._speed || ei._animationInfo[i]._nameHashCode != eim._animationInfo[i]._nameHashCode) { ret = false; break; } } } else if (eim != null && ei._animationInfo.Count != eim._animationInfo.Count) { ret = false; } if (!ret) { //AssetDatabase.DeleteAsset(elem); AssetDatabase.CreateAsset(ei, path); ei = AssetDatabase.LoadAssetAtPath(path, typeof(FCAnimationInfo)) as FCAnimationInfo; elem = elem.Replace(".asset", ".prefab"); GameObject goOld = AssetDatabase.LoadAssetAtPath(elem, typeof(GameObject)) as GameObject; GameObject goNew = PrefabUtility.InstantiatePrefab(goOld) as GameObject; if (goNew != null) { AvatarController avc = goNew.GetComponent <AvatarController>(); if (avc != null) { avc._animationInfos = ei; PrefabUtility.ReplacePrefab(goNew, goOld); PrefabUtility.DisconnectPrefabInstance(goNew); GameObject.DestroyImmediate(goNew); //AssetDatabase.CreateAsset(elem,goOld); } } } else { eim = null; ei = null; } } ap = null; } }
public MonsterMovePacket(string guid, float orientation, TimeSpan time, List <Waypoint> waypoints, uint moveTime, Position pos, JumpInfo jump) { creatureGuid = guid; creatureOrientation = orientation; packetSendTime = time; this.waypoints = waypoints; this.moveTime = moveTime; startPos = pos; jumpInfo = jump; }
/** * */ void CreatePlatformAt(Vector3 position, Vector2 size) { GameObject platformGO = GetPlatform(); JumpInfo jumpInfo; int i; Platform platform = platformGO.GetComponent<Platform>(); platform._transform.localPosition = position; platformGO.SetActive(true); platform.SetSize(size); // Create coins if (Time.timeSinceLevelLoad > mNextCoinTime) { int maxCoin = (int)(size.x / (mCoinWidth + DistanceBetweenCoins)); if (maxCoin >= 3) { GameObject coin; Vector3 coinPos = new Vector3(); int numCoin = Random.Range(3, maxCoin); float totalWidth = numCoin * (mCoinWidth + DistanceBetweenCoins) - DistanceBetweenCoins; float offsetX = (size.x - totalWidth) * 0.5f; // Place coins at center of platform coinPos.Set( position.x + offsetX + mCoinHWidth, position.y + CoinHeightFromGround + mCoinHWidth, 0 ); for(i=0; i<numCoin; ++i) { // Create/recycle coin coin = GetCoin(); // Set coin position coin.transform.localPosition = coinPos; coinPos.x += mCoinWidth + DistanceBetweenCoins; } mNextCoinTime = Time.timeSinceLevelLoad + 3 + Random.value * 3; } } // Spawn obstacle else if (Time.timeSinceLevelLoad > mNextObstacleTime && position.x >= ObstacleStartX) { int type = (int)(Random.value * ObstaclePrefabs.Count); GameObject prefab = ObstaclePrefabs[type]; // If obstacle fits in platform float obstacleHWidth = prefab.renderer.bounds.extents.x; if (ObstacleMinOffsetX + obstacleHWidth + obstacleHWidth < size.x) { Vector3 obstaclePos = new Vector3( position.x + obstacleHWidth + Random.Range(ObstacleMinOffsetX, size.x - obstacleHWidth - obstacleHWidth), position.y - 0.05f, 0 ); GameObject obstacle = GetObstacle(type); obstacle.transform.localPosition = obstaclePos; // Compute jump over obstacle jumpInfo = GetJumpInfoFromPool(); jumpInfo.type = JumpType.Obstacle; ComputeJumpOverObstacle(ref jumpInfo, platform._transform, obstacle.GetComponent<BoxCollider2D>(), obstacle.transform); platform.SetObstacleJumpInfo(jumpInfo); #if UNITY_EDITOR Debug.DrawLine(jumpInfo.jumpStart, jumpInfo.jumpPeak, Color.white, 10); Debug.DrawLine(jumpInfo.jumpPeak, jumpInfo.jumpEnd, Color.white, 10); #endif mNextObstacleTime = Time.timeSinceLevelLoad + 6 * Random.value * 3; } } else if (Time.time > mNextBubbleSpawnTime) { if (!mPlayerController.isShieldOn && Random.value <= mBubbleSpawnChance) { if (mBubblePowerup == null) { mBubblePowerup = Instantiate(BubblePowerupPrefab) as GameObject; } else { mBubblePowerup.SetActive(true); } mBubblePowerup.transform.localPosition = position + new Vector3(size.x * 0.5f, 0.8f, 0); } mNextBubbleSpawnTime = Time.time + BubbleSpawnInterval; } float foliageCount = Random.value * 7 - 2; float count; FoliageController foliage; // // Create grass // count = Random.value * foliageCount; // if (count > 0) // { // for(i=0; i<count; ++i) // { // foliage = GetFreeGrass(); // foliage._transform.localPosition = new Vector3( // position.x + PlatformEdgeJaggedness + foliage.width + Random.value * (size.x - foliage.width - 2*PlatformEdgeJaggedness), // position.y - 0.05f, 0 // ); // foliage._transform.localScale = new Vector3(Random.value < 0.5f ? -1 : 1, 1, 1); // } // // foliageCount -= count; // } // // // Create weeds // count = Random.value * foliageCount; // if (count > 0) // { // for(i=0; i<count; ++i) // { // foliage = GetFreeWeed(); // foliage._transform.localPosition = new Vector3( // position.x + PlatformEdgeJaggedness + foliage.width + Random.value * (size.x - foliage.width - 2*PlatformEdgeJaggedness), // position.y - 0.05f, 0 // ); // foliage._transform.localScale = new Vector3(Random.value < 0.5f ? -1 : 1, 1, 1); // } // // foliageCount -= count; // } // // // Create trees // count = Random.value * foliageCount; // if (count > 0) // { // float viewTop = mCameraTransform.localPosition.y + mCamera.orthographicSize; // float viewRight = mCameraTransform.localPosition.x - mCamera.orthographicSize * mCamera.aspect; // int numHangingRoots = 0; // // foliageCount -= count; // // for(i=0; i<count; ++i) // { // foliage = GetFreeTree(); // foliage._transform.localPosition = new Vector3( // position.x + PlatformEdgeJaggedness + foliage.width + Random.value * (size.x - foliage.width - 2*PlatformEdgeJaggedness), // position.y - 0.05f, 0 // ); // foliage._transform.localScale = new Vector3( // Random.value < 0.5f ? -1 : 1, // Mathf.Max(0.8f, (viewTop - foliage._transform.localPosition.y) / foliage.height + Random.value * 0.2f), // 1 // ); // // if (foliageCount > 0 && numHangingRoots < 2 && Random.value < 0.3f) // { // TryCreateHangingRoot(mTrees.Count - 1, viewRight, viewTop); // } // } // } // Move the level generator marker to end of last created platform position.x += size.x; mTransform.localPosition = position; // Create jumping information if (mPlatforms.Count - 2 >= mJumpInfos.Count) { jumpInfo = new JumpInfo(); mJumpInfos.Add (jumpInfo); } else { jumpInfo = mJumpInfos[mPlatforms.Count - 2]; } jumpInfo.type = JumpType.Platform; ComputeJump(ref jumpInfo, mPlatforms[mPlatforms.Count - 2], platformGO); #if UNITY_EDITOR // Start to peak Debug.DrawLine(jumpInfo.jumpStart, jumpInfo.jumpStart + new Vector2(0, 1f), Color.green, 10); Debug.DrawLine(jumpInfo.jumpStart, jumpInfo.jumpPeak, Color.white, 10); // Peak to end Debug.DrawLine(jumpInfo.jumpEnd, jumpInfo.jumpEnd + new Vector2(0, 1f), Color.red, 10); Debug.DrawLine(jumpInfo.jumpPeak, jumpInfo.jumpEnd, Color.white, 10); #endif }
/** * */ void ComputeJumpOverObstacle(ref JumpInfo result, Transform platformTransform, BoxCollider2D obstacleCollider, Transform obstacleTransform) { // Obstacle's left top corner Vector2 obstacleSize = obstacleCollider.size; Vector2 rayStart1 = obstacleTransform.localPosition; rayStart1.x -= obstacleSize.x * 0.5f; rayStart1.y += obstacleSize.y * 0.5f; Vector2 riseRayDir = new Vector2(-Speed, -GhostController.JumpSpeed); // A point far left from platform Vector2 rayStart2 = platformTransform.localPosition; rayStart2.x -= obstacleSize.x * 10; // Find intersection point Utils.RayRayIntersection rayIntResult; Utils.RayRayIntersect(out rayIntResult, rayStart1, riseRayDir, rayStart2, PlatformSurfaceVector); #if UNITY_EDITOR if (!rayIntResult.intersect) Debug.LogError("No intersection"); #endif // Jump's starting point result.jumpStart.Set(rayStart2.x + rayIntResult.t2 * PlatformSurfaceVector.x - CharacterHalfWidth, rayStart2.y + rayIntResult.t2 * PlatformSurfaceVector.y + CharacterHalfHeight); // Obstacle's right top corner rayStart1.x += obstacleSize.x; // Landing point Vector2 descendRayDir = new Vector2(Speed, Physics2D.gravity.y); descendRayDir.Normalize (); float t = (rayStart2.y - rayStart1.y) / descendRayDir.y; result.jumpEnd.Set(rayStart1.x + descendRayDir.x * t + CharacterHalfWidth, rayStart2.y + CharacterHalfHeight); // Find jump's peak point riseRayDir = -riseRayDir; descendRayDir = -descendRayDir; Utils.RayRayIntersect(out rayIntResult, result.jumpStart, riseRayDir, result.jumpEnd, descendRayDir); #if UNITY_EDITOR if (!rayIntResult.intersect) Debug.LogError("No intersection"); #endif result.jumpPeak.Set(result.jumpStart.x + riseRayDir.x * rayIntResult.t1, result.jumpStart.y + riseRayDir.y * rayIntResult.t1); }
/** * */ void ComputeJumpToLowerPlatform(ref JumpInfo result, Vector2 platStart1, Vector2 platEnd1, Vector2 platStart2) { // Check intersection with starting platform Utils.RayRayIntersection rayRayResult; Vector2 descendRay = new Vector2(-Speed, -GhostController.Gravity); Utils.RayRayIntersect(out rayRayResult, platStart2, descendRay, platEnd1, InvPlatformSurfaceVector); Vector2 jumpEnd = new Vector2(0, platStart2.y); if (rayRayResult.intersect) { // Push the landing point further jumpEnd.x = platStart2.x + rayRayResult.t2 + 0.01f; } else { jumpEnd.x = platStart2.x; } // Find jump's peak point Vector2 riseRay = new Vector2(Speed, GhostController.JumpSpeed); Utils.RayRayIntersect(out rayRayResult, platEnd1, riseRay, jumpEnd, descendRay); #if UNITY_EDITOR if (!rayRayResult.intersect) { Debug.LogError("no intersection"); Debug.Break(); } #endif Vector2 offset = new Vector2(CharacterHalfWidth, CharacterHalfHeight); result.jumpStart = platEnd1 + offset; result.jumpEnd = jumpEnd + offset; result.jumpPeak = platEnd1 + (riseRay * rayRayResult.t1) + offset; }
/** * */ void ComputeJumpToHigherPlatform(ref JumpInfo result, Vector2 platStart1, Vector2 platEnd1, Vector2 platStart2) { // Ray intersection Utils.RayRayIntersection rayRayResult; Vector2 jumpRiseRay = new Vector2(Speed, GhostController.JumpSpeed); Utils.RayRayIntersect(out rayRayResult, platEnd1, jumpRiseRay, platStart2, PlatformSurfaceVector); // Jump start x coordinate float jumpStartX; if (rayRayResult.intersect) { jumpStartX = platEnd1.x - rayRayResult.t2 - 0.01f; } else { jumpStartX = platEnd1.x; } // Find jump's peak point Vector2 jumpStart = new Vector2(jumpStartX, platEnd1.y); Vector2 jumpDescentRay = new Vector2(-Speed, -GhostController.Gravity); Utils.RayRayIntersect(out rayRayResult, jumpStart, jumpRiseRay, platStart2, jumpDescentRay); #if UNITY_EDITOR if (!rayRayResult.intersect) { Debug.LogError("no intersection"); Debug.Break(); } #endif Vector2 offset = new Vector2(-CharacterHalfWidth, CharacterHalfHeight); result.jumpStart = jumpStart + offset; result.jumpEnd = platStart2 + offset; result.jumpPeak = jumpStart + (jumpRiseRay * rayRayResult.t1) + offset; }
/** * */ void ComputeJump(ref JumpInfo result, GameObject platform1, GameObject platform2) { Vector3 platStart1 = platform1.transform.localPosition; Vector3 platStart2 = platform2.transform.localPosition; Vector2 platEnd1 = new Vector2(platStart1.x + platform1.GetComponent<BoxCollider2D>().size.x, platStart1.y); if (platStart1.y <= platStart2.y) { ComputeJumpToHigherPlatform(ref result, platStart1, platEnd1, platStart2); } else { ComputeJumpToLowerPlatform(ref result, platStart1, platEnd1, platStart2); } }
/** * */ void ReleaseJumpInfo(JumpInfo jump) { #if UNITY_EDITOR if (jump == null) Debug.LogError("null"); #endif mJumpInfoPool.Add(jump); }