// create and initialize SpawnPointInfo object based on given SpawnPoint SpawnPointInfo CreateSpawnPointInfo(SpawnPoint SPoint) { SpawnPointInfo SPointInfo = new SpawnPointInfo(); SPointInfo.SPoint = SPoint; SPointInfo.DistMin = float.MaxValue; // find distance to nearest existing player foreach (KeyValuePair <uLink.NetworkPlayer, ComponentPlayer> pair in Player.Players) { Vector3 deltaToPlayer = pair.Value.Owner.Position - SPoint.Transform.position; float height = deltaToPlayer.y; deltaToPlayer.y = 0.0f; float distanceToAPlayer = deltaToPlayer.magnitude; if (height > SpawnSetup.FloorToFloorHeight) { distanceToAPlayer *= SpawnSetup.AnotherFloorMultiplier; distanceToAPlayer += SpawnSetup.AnotherFloorDistanceAdded; } SPointInfo.DistMin = Mathf.Min(distanceToAPlayer, SPointInfo.DistMin); } return(SPointInfo); }
public AreaSpawnPointHelper(TerrainContext terrainContext) { this.terrainContext = terrainContext; boundingBoxHelper = new BoundingBoxHelper(); areaCollisionHelper = new AreaCollisionHelper(); info = new SpawnPointInfo(); }
public void Load(BinaryHelper helper) { m_virsion = helper.ReadInt(); m_areaName = helper.ReadString(); int normalNpcCount = helper.ReadInt(); for (int index = 0; index < normalNpcCount; index++) { FuncNPCInfo normalNpc = new FuncNPCInfo(); normalNpc.Read(helper); } int blockNpcCount = helper.ReadInt(); for (int index = 0; index < blockNpcCount; index++) { FuncNPCInfo blockNpc = new FuncNPCInfo(); blockNpc.Read(helper); } int triggerAreaCount = helper.ReadInt(); for (int index = 0; index < triggerAreaCount; index++) { TriggerAreaInfo triggerAreaInfo = new TriggerAreaInfo(); triggerAreaInfo.Read(helper); } int spawnPointCount = helper.ReadInt(); for (int index = 0; index < spawnPointCount; index++) { SpawnPointInfo spawnPointInfo = new SpawnPointInfo(); spawnPointInfo.Read(helper); } }
private void SetLEDSelected(SpawnPointInfo spawnPoint) { spawnPoint.SpawnLED.material = GreenMaterial; var otherSpawnPoints = SpawnPoints.FindAll(p => p != spawnPoint); otherSpawnPoints.ForEach(p => p.SpawnLED.material = RedMaterial); }
private IEnumerator SpawnSequence() { int totalIterations = 10; float interval = 0.1f; int currentIteration = 0; while (currentIteration < totalIterations) { SpawnPointInfo spawnPointInfo = SelectRandomSpawnPoint(); SetLEDSelected(spawnPointInfo); currentIteration++; yield return(new WaitForSeconds(interval)); } SpawnPointInfo selectedSpawnPoint = SelectRandomSpawnPoint(); SetLEDSelected(selectedSpawnPoint); yield return(new WaitForSeconds(interval)); selectedSpawnPoint.SpawnLED.material = RedMaterial; yield return(new WaitForSeconds(interval / 2)); selectedSpawnPoint.SpawnLED.material = GreenMaterial; yield return(new WaitForSeconds(interval)); selectedSpawnPoint.SpawnLED.material = RedMaterial; //... wow this is really good code ( °_ʖ °) yield return(new WaitForSeconds(interval / 2)); selectedSpawnPoint.SpawnLED.material = GreenMaterial; yield return(new WaitForSeconds(interval)); selectedSpawnPoint.SpawnLED.material = RedMaterial; yield return(new WaitForSeconds(interval / 2)); selectedSpawnPoint.SpawnLED.material = GreenMaterial; yield return(new WaitForSeconds(1f)); GameObject newAccessory = Instantiate(AccessoryPrefabs[selectedAccessoryIdx], selectedSpawnPoint.SpawnPoint.position, Quaternion.identity) as GameObject; }
public void GetSpawnPositions() { float localX, localY, localZ; int columnIndex, rowIndex; // i j for (rowIndex = 0; rowIndex < rowsNumber; rowIndex++) { for (columnIndex = 0; columnIndex < columnsNumber; columnIndex++) { localX = ((2 * columnIndex - columnsNumber * 1f + 1) / (2f * columnsNumber)); localZ = ((2 * rowIndex - rowsNumber * 1f + 1) / (2f * rowsNumber)); localY = 0.6f; allSpawnPoints[rowIndex * columnsNumber + columnIndex] = new SpawnPointInfo(); allSpawnPoints[rowIndex * columnsNumber + columnIndex].pointIndex = rowIndex * columnsNumber + columnIndex; allSpawnPoints[rowIndex * columnsNumber + columnIndex].pointPosition = new Vector3(localX, localY, localZ); } } }
public static void SaveSceneAreas(GameObject monsterNode) { if (monsterNode == null) { return; } if (monsterNode.name == "") { Debug.Log("必须给物体起名,该名字将作为保存的二进制文件的名字"); } int areaCount = monsterNode.transform.childCount; SceneAreas sceneAreas = new SceneAreas(); for (int areaIndex = 0; areaIndex < areaCount; areaIndex++) { Transform tarAreaTrans = monsterNode.transform.GetChild(areaIndex); //一个区域 SceneArea newArea = new SceneArea(); newArea.m_areaName = tarAreaTrans.name; int funcPointCount = tarAreaTrans.childCount; for (int funcPointIndex = 0; funcPointIndex < funcPointCount; funcPointIndex++) { Transform tarPoint = tarAreaTrans.GetChild(funcPointIndex); SceneFuncPoint funcPoint = tarPoint.GetComponent <SceneFuncPoint>(); if (funcPoint == null || funcPoint.m_pointType == ENScenePointType.none) { Debug.Log(tarPoint.name + " has no component 'SceneFuncPoint' or it is 'none' "); return; } switch (funcPoint.m_pointType) { case ENScenePointType.normalNPC: FuncNPCInfo normalNpc = funcPoint.m_npcInfo; normalNpc.m_pos = tarPoint.localPosition; newArea.m_normalNpcList.Add(normalNpc); break; case ENScenePointType.blockNPC: FuncNPCInfo blockNpc = funcPoint.m_npcInfo; blockNpc.m_pos = tarPoint.localPosition; newArea.m_blockNpcList.Add(blockNpc); break; case ENScenePointType.triggerArea: TriggerAreaInfo triggerAreaInfo = funcPoint.m_triggerAreaInfo; triggerAreaInfo.m_pos = tarPoint.localPosition; newArea.m_triggerAreaList.Add(triggerAreaInfo); break; case ENScenePointType.spawnPoint: SpawnPointInfo spawnPointInfo = funcPoint.m_spawnPointInfo; spawnPointInfo.m_pos = tarPoint.localPosition; spawnPointInfo.m_areaScale = tarPoint.localScale; for (int index = 0; index < funcPoint.m_spawnPointInfo.m_spawnPointsId.Count; index++) { spawnPointInfo.m_spawnPointsId.Add(funcPoint.m_spawnPointInfo.m_spawnPointsId[index]); } newArea.m_spawnPointList.Add(spawnPointInfo); break; } } sceneAreas.m_areaList.Add(newArea); } using (FileStream targetFile = new FileStream("Assets/Resources/Prefabs/ScenePrefabs/" + monsterNode.name + ".bytes", FileMode.Create)) { BinaryHelper helper = new BinaryHelper(); sceneAreas.Save(helper); byte[] saveBytes = helper.GetBytes(); targetFile.Write(saveBytes, 0, saveBytes.Length); Debug.Log(monsterNode.name + ".bytes Success Saved"); } }