/// <summary> /// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab. /// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it /// will be used for the Prefab. /// </summary> /// <param name="obj">The object to inject as Prefab root object.</param> public void Inject(GameObject obj) { // Dispose old content if (obj == null) { if (this.objTree != null) { this.objTree.Dispose(); this.objTree = null; } } // Inject new content else { obj.OnSaving(true); if (this.objTree != null) obj.CopyTo(this.objTree); else this.objTree = obj.Clone(); obj.OnSaved(true); this.objTree.BreakPrefabLink(); // Prevent recursion foreach (GameObject child in this.objTree.ChildrenDeep) { if (child.PrefabLink != null && child.PrefabLink.Prefab == this) { child.BreakPrefabLink(); } } } }
/// <summary> /// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab. /// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it /// will be used for the Prefab. /// </summary> /// <param name="obj">The object to inject as Prefab root object.</param> public void Inject(GameObject obj) { if (obj == null) { if (this.objTree != null) { this.objTree.Dispose(); this.objTree = null; } } else { obj.OnSaving(true); this.objTree = obj.Clone(); obj.OnSaved(true); this.objTree.Parent = null; this.objTree.prefabLink = null; // Prevent recursion foreach (GameObject child in this.objTree.ChildrenDeep) if (child.PrefabLink != null && child.PrefabLink.Prefab == this) child.BreakPrefabLink(); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { helpers = new HonzCore.Helpers.IHelper[] { HonzCore.Helpers.ApplicationHelper.instance, HonzCore.Helpers.InputHelper.instance, HonzCore.Helpers.BlueprintHelper.instance, HonzCore.Helpers.TimeHelper.instance }; foreach (var h in helpers) { h.Initialize(); } scene = new Scene(); gm1 = new GameObject(); gm1.SetParent(scene.root); HonzCore.ECS.Component.TestComponent comp = new HonzCore.ECS.Component.TestComponent(); gm1.AddComponent(comp); GameObject gm2 = gm1.Clone("Hannes"); gm2.SetParent(gm1); HonzCore.Helpers.ApplicationHelper.instance.LoadScene(scene); System.Console.WriteLine(scene.root.FindChildren("Hannes", recursive: true, requireEnabled: true)); HonzCore.Helpers.BlueprintHelper.instance.RegisterBlueprint(gm2, "TestBlueprint"); HonzCore.Helpers.BlueprintHelper.instance.CreateBlueprint("TestBlueprint", gm2); base.Initialize(); }
public void Duplicate(GameObject gameObject) { var clone = (GameObject)gameObject.Clone(); _editorScene.AddGameObject(clone); SelectGameObject(clone); }
public static GameObject AddPrefabChildTo( this GameObject parent, GameObject prefab, string childName) { return(parent.AddChildToParent(prefab.Clone((string)null), childName, false, true)); }
public static T Clone <T>(this GameObject self, Transform parent, bool worldPositionStays = false, bool copyTransform = true) where T : Component { var res = self.Clone(false, copyTransform); res.transform.SetParent(parent, worldPositionStays); return(res.GetComponent <T>()); }
void CloneNewObjects() { List <GameObject> rootObjects = new List <GameObject>(); Scene scene = SceneManager.GetActiveScene(); scene.GetRootGameObjects(rootObjects); foreach (GameObject obj in rootObjects) { Queue <GameObject> Q = new Queue <GameObject>(); Q.Enqueue(obj); while (Q.Count > 0) { GameObject objToClone = Q.Dequeue(); if (!clones.ContainsKey(objToClone) && objToClone.tag != "Portal" && objToClone.tag != "Clone" && objToClone.tag != "Inside Portal" && objToClone.tag != "Clip Collider") { GameObject clone = objToClone.Clone("Clone (" + name + ")", CloneLayer, new System.Type[] { typeof(MeshFilter), typeof(MeshRenderer) }, true); MeshRenderer MR = clone.GetComponent <MeshRenderer>(); if (MR) { cloneRenderers.Add(MR); } clone.transform.parent = objToClone.transform; clones.Add(objToClone, clone); } foreach (Transform child in objToClone.transform) { if (child.tag != "Clone") { Q.Enqueue(child.gameObject); } } } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { prefabToClone.Clone("Clone of " + prefabToClone.name, parentOfNewClone); } }
/// <summary> /// Create the particle type. /// </summary> /// <param name="particle">Particle object prototype.</param> /// <param name="frequency">Spawn frequency.</param> /// <param name="minCountPerSpawn">How many min particles to spawn every time.</param> /// <param name="maxCountPerSpawn">How many max particles to spawn every time.</param> /// <param name="frequencyChange">Change frequency over time.</param> public ParticleType(GameObject particle, float frequency = 0.01f, uint minCountPerSpawn = 1, uint maxCountPerSpawn = 1, float frequencyChange = 0f) { ParticlePrototype = particle.Clone(); Frequency = frequency; MinParticlesPerSpawn = minCountPerSpawn; MaxParticlesPerSpawn = maxCountPerSpawn; FrequencyChange = frequencyChange; }
/// <inheritdoc /> void HandleDeath() { const float range = 0.5f; var offset = new Vector3(Random.Range(-range, range), Random.Range(-range, range), Random.Range(-range, range)); var cloned = ItemToDropOnDeath.Clone(transform.position + offset, transform.rotation); cloned.SetParent(GameObject.Find("Dropped Items")); }
public static GameObject AddPrefab( this GameObject parent, GameObject prefab, bool worldPositionStays, string childName) { return(parent.AddChild(prefab.Clone((string)null), worldPositionStays, childName)); }
public void RegisterBlueprint(GameObject gm, string name = null) { if (gm == null) { throw new ArgumentException("The GameObject cannot be null"); } blueprints.Add(name ?? gm.name, gm.Clone()); }
private void Awake() { var clone = _prefabSrc.Clone(); clone.name = _prefabSrc.name; clone.transform.SetParent(transform.parent); clone.transform.localPosition = transform.localPosition; clone.transform.localRotation = transform.localRotation; clone.transform.localScale = transform.localScale; Destroy(gameObject); }
/// <summary> /// Creates a new instance of the Game Object /// </summary> /// <param name="original">Original object to clone from.</param> /// <param name="copyName">Does the new instance will have the same name from the original?</param> /// <returns></returns> public static GameObject Clone(this GameObject original, bool copyName = true) { if (copyName) { return(original.Clone(original.name)); } else { return(GameObject.Instantiate(original) as GameObject); } }
/// <summary> /// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab. /// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it /// will be used for the Prefab. /// </summary> /// <param name="obj">The object to inject as Prefab root object.</param> public void Inject(GameObject obj) { // Dispose old content if (obj == null) { if (this.objTree != null) { this.objTree.Dispose(); this.objTree = null; } } // Inject new content else { // Compose a list of all initializable Components in the new // content, and sort them by type ICmpSerializeListener[] initSchedule = obj.GetComponentsDeep <ICmpSerializeListener>().ToArray(); Component.ExecOrder.SortTypedItems(initSchedule, item => item.GetType(), false); // Prepare components for saving for (int i = initSchedule.Length - 1; i >= 0; i--) { initSchedule[i].OnSaving(); } // Copy the new content into the Prefabs internal object if (this.objTree != null) { obj.CopyTo(this.objTree); } else { this.objTree = obj.Clone(); } // Execute re-init code after saving for (int i = 0; i < initSchedule.Length; i++) { initSchedule[i].OnSaved(); } // Cleanup any leftover prefab links that might have been copied this.objTree.BreakPrefabLink(); // Prevent recursion foreach (GameObject child in this.objTree.GetChildrenDeep()) { if (child.PrefabLink != null && child.PrefabLink.Prefab == this) { child.BreakPrefabLink(); } } } }
/// <summary> Creates a new instance of the given prefab. </summary> /// <param name="prefab"> The prefab to create an instance of. </param> /// <param name="position"> The location at which the new instance should be placed. </param> /// <param name="euler"> The rotation at which the new instance should be placed. </param> /// <returns> A GameObject representing the newly created instance. </returns> protected GameObject Create(GameObject prefab, Vector3 position, Quaternion euler) { var cloned = prefab.Clone(position, euler); cloned.SetParent(Parent); var prefabBased = cloned.AddComponent <LifetimeManagementBehavior>(); prefabBased.Manager = this; return(cloned); }
/// <summary> /// Set the tile GameObject at a given index (will replace previous tile if exists). /// </summary> /// <param name="index">Tile index to set.</param> /// <param name="tile">GameObject to set as tile (note: will be cloned).</param> public void SetTile(Point index, GameObject tile) { // calc batch index and relative index CalcBatchIndexAndRelativeIndex(index); // get batch TilesBatch batch = GetBatch(batchIndex, true); // set tile tile = tile.Clone(); SetTileProperties(batch, tile, index); batch.Tiles[relativeIndex.X, relativeIndex.Y] = tile; }
/// <summary> Create a copy of an object. </summary> /// <param name="instance"> The object to clone. </param> /// <param name="parent"> The object that should be set to the parent of the given object. </param> /// <param name="locationAndRotation"> The location and rotation of the clone. </param> /// <returns> The new copy of the object. </returns> public static GameObject Clone(this GameObject instance, GameObject parent, LocationAndRotation locationAndRotation) { var clone = instance.Clone(parent); var transform = clone.transform; transform.localPosition = locationAndRotation.Location; transform.localRotation = locationAndRotation.Rotation; return(clone); }
IInventoryInstance IInventoryItemBlueprint.CreateInstance(IWorld world, IPlayer player) { // TODO remove - this currently gives them 10 projectiles player.Inventory.Add(m_Projectile, 10); var locationAndRotation = player.AttachmentPoints[AttachmentPoint.Weapon]; // TODO should we allow left/right placement var clonedWeapon = WeaponObject.Clone(player.Owner, locationAndRotation); var weapon = clonedWeapon.GetComponent <WeaponBehavior>(); weapon.Initialize(this, player); return(weapon); }
void CreatePortalCamera() { portalCamera = MainCamera.Clone(); portalCamera.name = name + " Camera"; Camera cam = portalCamera.AddComponent <Camera>(); cam.CopyFrom(MainCamera.GetComponent <Camera>()); RenderTexture rt = new RenderTexture(cam.pixelWidth, cam.pixelHeight, 16); //rt.antiAliasing = QualitySettings.antiAliasing; rt.filterMode = FilterMode.Point; GetComponent <MeshRenderer>().material.SetTexture("_MainTex", rt); cam.targetTexture = rt; cam.cullingMask = 1 << (int)CloneLayer; }
/// <summary> Process a single row of tiles. </summary> /// <param name="chunk"> The chunk that is being processed. </param> /// <param name="chunkObject"> The game object that represents the tile. </param> /// <param name="chunkOffset"> The world offset of the chunk to add to the tiles local location. </param> /// <param name="x"> The x coordinates of the tile row to process. </param> private void ProcessRow(Chunk chunk, GameObject chunkObject, Vector3 chunkOffset, int x) { for (int z = 0; z < Chunk.Length; z++) { var coordinate = new TileCoordinate(x, z); var tile = chunk[coordinate]; if (tile.Type > 0) { var position = chunkOffset + new Vector3(x, _wall.transform.position.y, z); var newWall = _wall.Clone(position); newWall.transform.parent = chunkObject.transform; } } }
private void CreateCloneHirearchy(GameObject original, GameObject clone, int CloneLayer) { foreach (Transform child in original.transform) { if (child.tag != "Clone" && child.tag != "Clip Collider") { GameObject childClone = child.gameObject.Clone("in-clone", child.gameObject.layer, new System.Type[] { typeof(MeshFilter), typeof(MeshRenderer), typeof(Collider), typeof(CollisionTest) }, true); childClone.tag = "Inside Portal"; childClone.transform.parent = clone.transform; childClone.transform.localPosition = child.localPosition; childClone.transform.localRotation = child.localRotation; childClone.transform.localScale = child.localScale; MeshRenderer objMR = child.gameObject.GetComponent <MeshRenderer>(); if (objMR != null) { oldMaterials.Add(objMR, objMR.materials); objMR.SetToClipMaterial(); objMRs.Add(objMR); } MeshRenderer cloneMR = childClone.GetComponent <MeshRenderer>(); if (cloneMR != null) { cloneMRs.Add(cloneMR); } Collider[] cols = childClone.GetComponents <Collider>(); cloneCols.Add(cols); GameObject cloneCameraClone = childClone.Clone("in-camera-clone", CloneLayer, new System.Type[] { typeof(MeshFilter), typeof(MeshRenderer) }, true); cloneCameraClones.Add(childClone, cloneCameraClone); PlaneClipCollider objClipCol = child.gameObject.GetComponent <PlaneClipCollider>(); if (objClipCol == null) { objClipCol = child.gameObject.AddComponent <PlaneClipCollider>(); } objClipCol.enabled = true; objClipCols.Add(objClipCol); PlaneClipCollider cloneClipCol = childClone.AddComponent <PlaneClipCollider>(); cloneClipCol.enabled = true; cloneClipCols.Add(cloneClipCol); CreateCloneHirearchy(child.gameObject, childClone, CloneLayer); clonedChildren.Add(child.gameObject, childClone); } } }
// Called only when placing an object from the PickerWheel public void CreateNewGameObject(GameObject newObject) { GameObject obj = GameObject.Clone(newObject); if (newObject is Door) { (obj as Door).LockedLight = GameObject.Clone((newObject as Door).LockedLight) as PlatformBackground; (obj as Door).UnlockedLight = GameObject.Clone((newObject as Door).UnlockedLight) as PlatformBackground; } if (newObject is Platform) { (obj as Platform).Background = GameObject.Clone((newObject as Platform).Background) as PlatformBackground; } CurrentObjects = new List <GameObject>(); CurrentObjects.Add(obj); CurrentIsNewObject = true; MovingStartPosition = Vector2.Zero; }
/// <summary> /// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab. /// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it /// will be used for the Prefab. /// </summary> /// <param name="obj">The object to inject as Prefab root object.</param> public void Inject(GameObject obj) { // Dispose old content if (obj == null) { if (this.objTree != null) { this.objTree.Dispose(); this.objTree = null; } } // Inject new content else { obj.OnSaving(true); if (this.objTree != null) { obj.CopyTo(this.objTree); } else { this.objTree = obj.Clone(); } obj.OnSaved(true); this.objTree.Parent = null; this.objTree.BreakPrefabLink(); // Prevent recursion foreach (GameObject child in this.objTree.ChildrenDeep) { if (child.PrefabLink != null && child.PrefabLink.Prefab == this) { child.BreakPrefabLink(); } } } }
public GameObject getNextFittingRoom(Coordinate baseTile) { RoomDataHolder checkRoom = mansionDataHandler.getRoomDataOnCoordinate(new Coordinate(0, 0, 1)); //List<UnityEngine.Object> roomPrefabs = getAllRoomPrefabs(); GameObject[] checkableSpawnableRooms = spawnableRooms; while (checkableSpawnableRooms.Length > 0) { GameObject roomObject = CommonOperations.getRandomItemFromList <GameObject>(checkableSpawnableRooms); RoomDataHolder roomData = roomObject.GetComponent(typeof(RoomDataHolder)) as RoomDataHolder; if (roomData != null) { RoomFitTransform roomFitTransform = checkIfRoomFits(baseTile, roomData); if (roomFitTransform != null) { roomData.setWorldPosition(baseTile + roomFitTransform.baseLocation); roomData.setOrientation(roomFitTransform.orientation); RoomDataHolder roomData2 = roomObject.GetComponent(typeof(RoomDataHolder)) as RoomDataHolder; return(roomObject); } } // Remove checked GameObject from list GameObject[] newCheckableSpawnableRooms = new GameObject[checkableSpawnableRooms.Length - 1]; int index = 0; for (int i = 0; i < checkableSpawnableRooms.Length && index < newCheckableSpawnableRooms.Length; ++i) { if (checkableSpawnableRooms[i] != roomObject) { newCheckableSpawnableRooms[index++] = checkableSpawnableRooms[i]; } } checkableSpawnableRooms = newCheckableSpawnableRooms.Clone() as GameObject[]; } return(null); }
public void DuplicateObjectUnderCursor() { List <GameObject> collisions = _engine.CollisionDetector.FindCollisions (new AxisAllignedBoundingBox(CursorPosition, CursorPosition + CursorSize), _engine.GameState.GetAll()); if (collisions.Count > 0) { CurrentObjects = new List <GameObject>(); CursorPosition = new Vector2(float.MaxValue); GameObject obj; foreach (GameObject newObject in collisions) { obj = GameObject.Clone(newObject); if (obj is Door) { (obj as Door).LockedLight = GameObject.Clone((newObject as Door).LockedLight) as PlatformBackground; (obj as Door).UnlockedLight = GameObject.Clone((newObject as Door).UnlockedLight) as PlatformBackground; } if (!(obj is Miner)) { CurrentObjects.Add(GameObject.Clone(obj)); } CursorPosition = Vector2.Min(CursorPosition, obj.Position); } if (CurrentObjects.Count == 0) { CurrentIsNewObject = false; CurrentObjects = null; } else { MovingStartPosition = CursorPosition; CurrentIsNewObject = true; } } }
public static T Clone <T>(this GameObject self, bool copyParent = true, bool copyTransform = true) where T : Component { return(self.Clone(copyParent, copyTransform).GetComponent <T>()); }
/// <summary> /// alan kazanildiginda kazanilan alaninin taranmasi ve tekrar sahaya girilebilir hale getirilmesi ayrica win check /// </summary> void reDraw(int xPos, int yPos) { checking = true; GameObject[] line1 = new GameObject[(int)Mathf.Pow((float)TextureBorder, 2)]; //sinir listesi 1 GameObject[] line2 = new GameObject[(int)Mathf.Pow((float)TextureBorder, 2)]; //sinir listesi 2 bool line1Done = false; int xL1 = xPos; int xL2 = xPos; int yL1 = yPos; int yL2 = yPos; bool line2Done = false; int increament1 = 0; int increament2 = 0; #region walkable while (!line1Done) // sinir cizgileri grupluyoruz 1 { GameObject nextObject = NextOne(Node._nodeState.walkable, xL1, yL1, out xL1, out yL1); if (nextObject == null) { line1Done = true; goto line1result; } line1[increament1] = nextObject; increament1++; } line1result: while (!line2Done) // sinir cizgileri grupluyoruz 2 { GameObject nextObject = NextOne(Node._nodeState.walkable, xL2, yL2, out xL2, out yL2); if (nextObject == null) { line2Done = true; goto result2; } line2[increament2] = nextObject; increament2++; } result2: #endregion #region deadHunt GameObject[] line1Save = (GameObject[])line1.Clone(); //sinir listesi 1 i yedekledik GameObject[] line2Save = (GameObject[])line2.Clone(); //sinir listesi 2 i yedekledik //dead hunt GameObject[] basket1 = new GameObject[(int)Mathf.Pow((float)TextureBorder, 2)]; GameObject[] basket2 = new GameObject[(int)Mathf.Pow((float)TextureBorder, 2)]; bool enemyDetected1 = false; bool enemyDetected2 = false; int inc1 = -1; int inc2 = -1; bool firstDone = false; bool secondDone = false; List <GameObject> list1 = new List <GameObject>(line1); List <GameObject> list2 = new List <GameObject>(line2); foreach (GameObject dot in line1) { if (dot != null) { Node node = dot.GetComponent <Node>(); int xxx = node.xx; int yyy = node.yy; while (!firstDone) { GameObject nextOne = NextOne(Node._nodeState.dead, xxx, yyy, out xxx, out yyy, out enemyDetected1); if (nextOne == null) { firstDone = true; continue; } nextOne.GetComponent <Node>().lineIndex = 1; inc1++; basket1[inc1] = nextOne; if (!list1.Contains(nextOne)) { line1[inc1] = nextOne; } } firstDone = false; } } foreach (GameObject dot in line2) { if (dot != null) { Node node = dot.GetComponent <Node>(); int xxx = node.xx; int yyy = node.yy; while (!secondDone) { GameObject nextOne = NextOne(Node._nodeState.dead, xxx, yyy, out xxx, out yyy, out enemyDetected2); if (nextOne == null) { secondDone = true; continue; } nextOne.GetComponent <Node>().lineIndex = 2; inc2++; basket2[inc2] = nextOne; if (list2.Contains(nextOne)) { line2[inc2] = nextOne; } } secondDone = false; } } List <GameObject> listUnchecked = new List <GameObject>(); foreach (GameObject item in dotObjects) { if (item.GetComponent <Node>().lineIndex == 0 && item.GetComponent <Node>().state == Node._nodeState.dead) { int xa = item.GetComponent <Node>().xx; int ya = item.GetComponent <Node>().yy; xa++; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } xa -= 2; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } ya++; xa++; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } ya -= 2; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } listUnchecked.Add(item); } } int count = listUnchecked.Count; int nom = 0; while (nom != count) { try { foreach (GameObject item in listUnchecked) { if (item.GetComponent <Node>().lineIndex == 0 && item.GetComponent <Node>().state == Node._nodeState.dead) { int xa = item.GetComponent <Node>().xx; int ya = item.GetComponent <Node>().yy; xa++; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } xa -= 2; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } ya++; xa++; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } ya -= 2; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } } } } catch { } } foreach (GameObject item in dotObjects) { Node node = item.GetComponent <Node>(); if (node.state == Node._nodeState.permanent) { int xa = item.GetComponent <Node>().xx; int ya = item.GetComponent <Node>().yy; xa++; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } ya++; xa--; if (dotObjects[xa, ya].GetComponent <Node>().state == Node._nodeState.dead && (dotObjects[xa, ya].GetComponent <Node>().lineIndex != 0)) { item.GetComponent <Node>().lineIndex = dotObjects[xa, ya].GetComponent <Node>().lineIndex; if (item.GetComponent <Node>().lineIndex == 1) { inc1++; basket1[inc1] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected1 = true; } continue; } else if (item.GetComponent <Node>().lineIndex == 2) { inc2++; basket2[inc2] = item; listUnchecked.Remove(item); nom++; if (dotObjects[xa, ya].GetComponent <Node>().enemyOnIt == true) { enemyDetected2 = true; } continue; } } } } foreach (GameObject dot in basket1) { if (dot != null) { if (dot.GetComponent <Node>().enemyOnIt) { enemyDetected1 = true; } } } foreach (GameObject dot in basket2) { if (dot != null) { if (dot.GetComponent <Node>().enemyOnIt) { enemyDetected2 = true; } } } Debug.Log(enemyDetected1); Debug.Log(enemyDetected2); foreach (GameObject dot in basket1) { if (dot != null) { if (!enemyDetected1) { GameObject mesh = dot.GetComponent <Node>().mesh; mesh.GetComponent <MeshRenderer>().material = deadZone; } } } foreach (GameObject dot in line1Save) { if (dot != null) { if (!enemyDetected1) { if (dot.GetComponent <Node>().mesh) { Debug.Log(dot.name); GameObject mesh = dot.GetComponent <Node>().mesh; mesh.GetComponent <MeshRenderer>().material = deadZone; } } } } foreach (GameObject dot in basket2) { if (dot != null) { if (!enemyDetected2) { GameObject mesh = dot.GetComponent <Node>().mesh; mesh.GetComponent <MeshRenderer>().material = deadZone; } } } foreach (GameObject dot in line2Save) { if (dot != null) { if (!enemyDetected2) { Debug.Log(dot.name); if (dot.GetComponent <Node>().mesh) { GameObject mesh = dot.GetComponent <Node>().mesh; mesh.GetComponent <MeshRenderer>().material = deadZone; } } } } foreach (GameObject dot in dotObjects) { dot.GetComponent <Node>().refresh = true; } #endregion checking = false; }
/// <summary> /// Creates a new instance of the Game Object /// </summary> /// <param name="original">Original object to clone from.</param> /// <param name="position">Position of the new instance.</param> /// <param name="rotation">Rotation of the new instance.</param> /// <returns>A clone of the Game Object</returns> public static GameObject Clone(this GameObject original, Vector3 position, Quaternion rotation) { return(original.Clone(position, rotation, original.name, original.transform.parent)); }
/// <summary> /// Creates a new instance of the Game Object /// </summary> /// <param name="original">Original object to clone from.</param> /// <param name="position">Position of the new instance.</param> /// <param name="name">Name of the new instance.</param> /// <param name="customParent">Parent of the new instance (use 'null' to put the new instance at the root)</param> /// <param name="worldPositionStays">If true, the parent-relative position, scale and rotation is modified such that the object keeps the same world space position, rotation and scale as before.</param> /// <returns>A clone of the Game Object</returns> public static GameObject Clone(this GameObject original, Vector3 position, string name, Transform parent, bool worldPositionStays = false) { return(original.Clone(position, original.transform.rotation, name, parent, worldPositionStays)); }
/// <summary> /// Creates a new instance of the Game Object /// </summary> /// <param name="original">Original object to clone from.</param> /// <param name="name">Name of the new instance.</param> /// <returns>A clone of the Game Object</returns> public static GameObject Clone(this GameObject original, string name) { return(original.Clone(original.transform.position, original.transform.rotation, name, original.transform.parent)); }
public override void Init() { Environment.AmbientLight.Color.Set(0.4f, 0.25f, 0.1f, 1.0f); Environment.FogColor.Set(0.2f, 0.3f, 0.45f, 1.0f); Environment.DirectionalLight.Direction.Set(0.6f, 1, 0.6f).NormalizeStore(); Environment.DirectionalLight.Color.Set(1.0f, 0.85f, 0.65f, 1.0f); ((PerspectiveCamera)Camera).FieldOfView = 75; Camera.Far = 330; ShadowMappingComponent smc; RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment, new int[] { 2048, 1024 })); smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward; RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter()); const float curb_scale_y = 0.4f; road = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road.jpg"); roadnrm = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_nrm.jpg"); roadCorner = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner.jpg"); roadCornernrm = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner_nrm.jpg"); curbModel = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb.obj"); curbCorner = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb_corner.obj"); curbCorner.SetLocalScale(new Vector3f(1, curb_scale_y, 1)); Random rand = new Random(); int xAmt = rand.Next(2, 7), zAmt = rand.Next(2, 7), scaleX = rand.Next(10, 30), scaleZ = rand.Next(10, 30); int offset = 3; AddRoadCorner(new Line(new Vector3f(0, 0, -2), new Vector3f(0, 0, 0))); for (int x = 0; x <= xAmt; x++) { for (int i = 0; i < zAmt; i++) { AddRoad(new Line(new Vector3f(x * scaleX, 0, i * scaleZ), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2))); AddRoadCorner(new Line(new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ))); if (x == 0) { // long bar Node curb2 = (Node)curbModel.Clone(); tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - 1); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180)); curb2.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ)); curbNode.AddChild(curb2); } else if (x == (xAmt - 1)) { Node curb2 = (Node)curbModel.Clone(); tmpVec.Set((x + 1) * scaleX + 1, 0, (i) * scaleZ - 1); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ)); curbNode.AddChild(curb2); } Node curb0 = (Node)curbModel.Clone(); tmpVec.Set(x * scaleX + 1, 0, i * scaleZ + 1); tmpVec.y = HeightRoad(tmpVec); curb0.SetLocalTranslation(tmpVec); curb0.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ - offset - 1)); curbNode.AddChild(curb0); Node curb1 = (Node)curbModel.Clone(); tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - offset); tmpVec.y = HeightRoad(tmpVec); curb1.SetLocalTranslation(tmpVec); curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180)); curb1.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ - offset - 1)); curbNode.AddChild(curb1); if (x != 0) { Node curbCorner1 = (Node)curbCorner.Clone(); tmpVec.Set((x) * scaleX - 2, 0, (i + 1) * scaleZ - offset + 1); tmpVec.y = HeightRoad(tmpVec); curbCorner1.SetLocalTranslation(tmpVec); curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90)); curbNode.AddChild(curbCorner1); } if (x != xAmt) { Node curbCorner0 = (Node)curbCorner.Clone(); tmpVec.Set(x * scaleX + 2, 0, i * scaleZ); tmpVec.y = HeightRoad(tmpVec); curbCorner0.SetLocalTranslation(tmpVec); curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90)); curbNode.AddChild(curbCorner0); } } } for (int z = 0; z <= zAmt; z++) { for (int i = 0; i < xAmt; i++) { AddRoad(new Line(new Vector3f(i * scaleX + 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1))); AddRoadCorner(new Line(new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX + 1, 0, z * scaleZ - 1))); // long pieces if (z == 0) { // long bar Node curb2 = (Node)curbModel.Clone(); tmpVec.Set(i * scaleX, 0, z * scaleZ - 2); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90)); curb2.SetLocalScale(new Vector3f(scaleX, curb_scale_y, 1)); curbNode.AddChild(curb2); } else if (z == (zAmt - 1)) { Node curb2 = (Node)curbModel.Clone(); tmpVec.Set((i + 1) * scaleX, 0, (z + 1) * scaleZ); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90 + 180)); curb2.SetLocalScale(new Vector3f(scaleX, curb_scale_y, 1)); curbNode.AddChild(curb2); } Node curb0 = (Node)curbModel.Clone(); tmpVec.Set((i + 1) * scaleX - 2, 0, z * scaleZ); tmpVec.y = HeightRoad(tmpVec); curb0.SetLocalTranslation(tmpVec); curb0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90)); curb0.SetLocalScale(new Vector3f(scaleX - offset - 1, curb_scale_y, 1)); curbNode.AddChild(curb0); Node curb1 = (Node)curbModel.Clone(); tmpVec.Set((i) * scaleX + offset - 1, 0, z * scaleZ - 2); tmpVec.y = HeightRoad(tmpVec); curb1.SetLocalTranslation(tmpVec); curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90)); curb1.SetLocalScale(new Vector3f(scaleX - offset - 1, curb_scale_y, 1)); curbNode.AddChild(curb1); if (z != zAmt) { Node curbCorner0 = (Node)curbCorner.Clone(); Vector3f curbVec1 = new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ + 1); curbVec1.y = HeightRoad(curbVec1); curbCorner0.SetLocalTranslation(curbVec1); curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180)); curbNode.AddChild(curbCorner0); } if (z != 0) { Node curbCorner1 = (Node)curbCorner.Clone(); Vector3f curbVec1 = new Vector3f((i) * scaleX + offset - 2, 0, z * scaleZ - 3); curbVec1.y = HeightRoad(curbVec1); curbCorner1.SetLocalTranslation(curbVec1); curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 360)); curbNode.AddChild(curbCorner1); } } } Geometry roadMerged = new Geometry(MeshUtil.MergeMeshes(roadNode)); Geometry curbMerged = new Geometry(MeshUtil.MergeMeshes(curbNode)); rootNode.AddChild(curbMerged); roadMerged.Material.SetValue(Material.MATERIAL_CULLENABLED, false); roadMerged.Material.SetValue(Material.TEXTURE_DIFFUSE, road); roadMerged.Material.SetValue(Material.TEXTURE_NORMAL, roadnrm); roadMerged.Material.SetValue(Material.SHININESS, 0.3f); roadMerged.Material.SetValue(Material.ROUGHNESS, 0.3f); Geometry roadCornerMerged = new Geometry(MeshUtil.MergeMeshes(roadCornerNode)); roadCornerMerged.Material.SetValue(Material.MATERIAL_CULLENABLED, false); roadCornerMerged.Material.SetValue(Material.TEXTURE_DIFFUSE, roadCorner); roadCornerMerged.Material.SetValue(Material.TEXTURE_NORMAL, roadCornernrm); roadCornerMerged.Material.SetValue(Material.SHININESS, 0.3f); roadCornerMerged.Material.SetValue(Material.ROUGHNESS, 0.3f); rootNode.AddChild(roadCornerMerged); rootNode.AddChild(roadMerged); /* addroad(new line(new vector3f(0, 0, 0), new vector3f(0, 0, 10))); AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(1, 0, 12))); AddRoad(new Line(new Vector3f(1, 0, 12), new Vector3f(5, 0, 12)));*/ /* for (int x = 0; x < 16; x ++) { AddRoad(new Line(new Vector3f((float)System.Math.Sin(x)*13, 0, (float)System.Math.Cos(x) * 13), new Vector3f((float)System.Math.Sin(x+1) * 13, 0, (float)System.Math.Cos(x+1) * 13))); } */ /* AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(-3, 0, 11))); AddRoad(new Line(new Vector3f(-3, 0, 11), new Vector3f(-4, 0, 12))); AddRoad(new Line(new Vector3f(-4, 0, 12), new Vector3f(-5, 0, 13))); AddRoad(new Line(new Vector3f(-5, 0, 13), new Vector3f(-6, 0, 14)));*/ // AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(10, 0, 10))); /* for (int i = 0; i < 4; i++) { Line myline = new Line(lastLine.To, lastLine.To.Add(new Vector3f(rand.Next(-15, 15),0, rand.Next(-15, 15)))); Geometry quad = new Geometry(QuadFromLine(myline)); quad.Material.SetValue(Material.MATERIAL_CULLENABLED, false); quad.Material.SetValue(Material.TEXTURE_DIFFUSE, road); quad.Material.SetValue(Material.SHININESS, 0.0f); lastLine = myline; rootNode.AddChild(quad); } */ }
/// <summary> /// Initialize to implement per main type. /// </summary> override public void Initialize() { // set default scene node type GameObject.DefaultSceneNodeType = SceneNodeType.Simple; // create the scene GameScene scene = new GameScene(); // add instructions GeonBit.UI.Entities.Paragraph instructions = new GeonBit.UI.Entities.Paragraph("Press number keys (1-9) to change particle types."); scene.UserInterface.AddEntity(instructions); // add diagnostic data paragraph to scene var diagnosticData = new GeonBit.UI.Entities.Paragraph("", GeonBit.UI.Entities.Anchor.BottomLeft, offset: Vector2.One * 10f, scale: 0.7f); diagnosticData.BeforeDraw = (GeonBit.UI.Entities.Entity entity) => { diagnosticData.Text = Managers.Diagnostic.GetReportString(); }; scene.UserInterface.AddEntity(diagnosticData); // create camera camera = new GameObject(); Camera cameraComponent = new Camera(); cameraComponent.LookAt = Vector3.Zero; camera.AddComponent(cameraComponent); camera.SceneNode.PositionZ = 50; camera.SceneNode.PositionY = 50; camera.AddComponent(new CameraEditorController()); camera.Parent = scene.Root; // add skybox Managers.GraphicsManager.CreateSkybox(null, scene.Root); // particle system: red fountain { // define the particle GameObject particle = new GameObject("particle", SceneNodeType.ParticlesNode); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle.AddComponent(new TimeToLive(3f)); particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1f, 0f, 2.5f, 0.5f)); particle.AddComponent(new MotionAnimator(BaseAnimatorProperties.Defaults, Vector3.Up * 25f, acceleration: Vector3.Down * 15f, velocityDirectionJitter: Vector3.One * 5)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 1.5f, 4f, 0.5f, 0.5f, 0.5f)); particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Red, Color.Orange, 3f)); // create particles system GameObject systemObject = new GameObject("system1", SceneNodeType.Simple); ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.85f)); systemObject.Parent = scene.Root; _systems.Add(systemObject); } // particle system: gas cloud { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle.AddComponent(new TimeToLive(3f)); particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2f)); particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.75f, 0f, 2.5f, 0.5f)); particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 1.5f), Vector3.One, velocityDirectionJitter: Vector3.One)); particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 1f)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 1.5f, 4f, 0.5f, 0.5f, 0.5f)); particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Green, Color.Black, 3f, startColorJitter: Color.Blue)); // create particles system GameObject systemObject = new GameObject("system2"); ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.35f)); systemObject.Parent = scene.Root; _systems.Add(systemObject); } // particle system: balls madness { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Solid; particle.AddComponent(new TimeToLive(3f)); particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 25f), Vector3.One, velocityDirectionJitter: Vector3.One)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 1.5f, 4f, 0.5f, 0.5f, 0.5f)); particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 20f, 4f)); particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Black, Color.Black, 1f, startColorJitter: Color.White, endColorJitter: Color.White)); // create particles system GameObject systemObject = new GameObject("system3"); ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.85f)); systemObject.Parent = scene.Root; _systems.Add(systemObject); } // particle system: rain { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Solid; particle.SceneNode.PositionY = 50; particle.AddComponent(new TimeToLive(3f)); particle.AddComponent(new SpawnRandomizer(positionJitter: new Vector3(100, 0, 40))); particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 25f), Vector3.Down)); // create particles system GameObject systemObject = new GameObject("system4"); ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.85f)); systemObject.Parent = scene.Root; _systems.Add(systemObject); } // particle system: explosions { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle.AddComponent(new TimeToLive(1f)); particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2f, minColor: new Color(200, 75, 0), maxColor: new Color(255, 225, 50))); particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1.0f, 0f, 1.0f, 0.25f)); particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 1f)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 2.5f, 1f, 0.15f, 0.25f, 0.25f)); particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 2f), Vector3.Zero, velocityDirectionJitter: Vector3.One)); GameObject particle2 = particle.Clone(); particle.GetComponent <ShapeRenderer>().BlendingState = GeonBit.Core.Graphics.BlendStates.Additive; // create particles system GameObject systemObject = new GameObject("system5"); ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.85f)); system.AddParticleType(new ParticleType(particle2, frequency: 0.85f)); systemObject.Parent = scene.Root; _systems.Add(systemObject); } // particle system: backfire { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle.AddComponent(new TimeToLive(1f)); particle.AddComponent(new SpawnRandomizer(minColor: new Color(200, 75, 0), maxColor: new Color(255, 225, 50))); particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1.0f, 0f, 0.8f)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 1.5f, 0.1f, 1f, 0.15f, 0.15f, 0.15f)); particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 25f), Vector3.Down)); // create an object that's rotating the particles system position around center GameObject rotator = new GameObject(); rotator.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 2f)); rotator.Parent = scene.Root; // create particles system GameObject systemObject = new GameObject("system6"); systemObject.SceneNode.PositionY = 10f; ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 1.0f)); system.Interval = 0.015f; system.AddParticlesToRoot = true; systemObject.Parent = rotator; _systems.Add(systemObject); } // particle system: magic { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.BlendingState = GeonBit.Core.Graphics.BlendStates.Additive; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle.AddComponent(new TimeToLive(3f)); particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2.5f, minColor: Color.Red * 0.25f, maxColor: Color.White * 0.25f)); particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.75f, 0f, 2.5f, 0.5f)); particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 1.5f), Vector3.One, velocityDirectionJitter: Vector3.One)); particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 1f)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 2.5f, 4f, 0.5f, 0.5f, 0.5f)); // create particles system GameObject systemObject = new GameObject("system7"); ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.3f)); systemObject.Parent = scene.Root; _systems.Add(systemObject); } // particle system: magic missile { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.BlendingState = GeonBit.Core.Graphics.BlendStates.Additive; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle.AddComponent(new TimeToLive(3f)); particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2.5f, minColor: Color.Red * 0.25f, maxColor: Color.White * 0.25f)); particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.75f, 0f, 2.5f, 0.5f)); particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 1.5f), Vector3.One, velocityDirectionJitter: Vector3.One)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 2.5f, 4f, 0.5f, 0.5f, 0.5f)); // define another type of particle GameObject particle2 = new GameObject("particle2"); ShapeRenderer shape2 = particle2.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape2.BlendingState = GeonBit.Core.Graphics.BlendStates.Additive; shape2.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle2.AddComponent(new TimeToLive(2f)); particle2.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 1.5f, 0.1f, 1.5f, 0.15f, 0.15f, 0.15f)); particle2.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.5f, 0f, 1.5f, 0.5f)); // create an object that's rotating the particles system position around center GameObject rotator = new GameObject(); rotator.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 2f)); rotator.Parent = scene.Root; // create particles system GameObject systemObject = new GameObject("system8"); systemObject.SceneNode.PositionY = 10f; ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.3f)); system.AddParticleType(new ParticleType(particle2, frequency: 0.5f)); system.AddParticlesToRoot = true; systemObject.Parent = rotator; _systems.Add(systemObject); } // particle system: smoke { // define the particle GameObject particle = new GameObject("particle"); ShapeRenderer shape = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer; shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects; particle.AddComponent(new TimeToLive(3f)); particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1f, 0f, 2.5f, 0.5f)); particle.AddComponent(new MotionAnimator(BaseAnimatorProperties.Defaults, Vector3.Up * 10f, velocityDirectionJitter: Vector3.One * 0.75f)); particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.25f, 3.5f, 4f, 0.5f, 0.5f, 0.5f)); particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Purple, Color.Black, 3f)); // create particles system GameObject systemObject = new GameObject("system9"); ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem; system.AddParticleType(new ParticleType(particle, frequency: 0.35f)); systemObject.Parent = scene.Root; _systems.Add(systemObject); } // select default system SelectParticleSystem(0); // set scene GeonBitMain.Instance.Application.LoadScene(scene); }
public override void Init() { road = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road.jpg"); roadCorner = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner.jpg"); curbModel = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb.obj"); curbCorner = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb_corner.obj"); Random rand = new Random(); int xAmt = rand.Next(2, 7), zAmt = rand.Next(2, 7), scaleX = rand.Next(10, 30), scaleZ = rand.Next(10, 30); int offset = 3; AddRoadCorner(new Line(new Vector3f(0, 0, -2), new Vector3f(0, 0, 0))); for (int x = 0; x <= xAmt; x++) { for (int i = 0; i < zAmt; i++) { AddRoad(new Line(new Vector3f(x * scaleX, 0, i * scaleZ), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2))); AddRoadCorner(new Line(new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ))); if (x == 0) { // long bar Node curb2 = (Node)curbModel.Clone(); tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - 1); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180)); curb2.SetLocalScale(new Vector3f(1, 1, scaleZ)); curbNode.AddChild(curb2); } else if (x == (xAmt - 1)) { Node curb2 = (Node)curbModel.Clone(); tmpVec.Set((x + 1) * scaleX + 1, 0, (i) * scaleZ - 1); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalScale(new Vector3f(1, 1, scaleZ)); curbNode.AddChild(curb2); } Node curb0 = (Node)curbModel.Clone(); tmpVec.Set(x * scaleX + 1, 0, i * scaleZ + 1); tmpVec.y = HeightRoad(tmpVec); curb0.SetLocalTranslation(tmpVec); curb0.SetLocalScale(new Vector3f(1, 1, scaleZ - offset - 1)); curbNode.AddChild(curb0); Node curb1 = (Node)curbModel.Clone(); tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - offset); tmpVec.y = HeightRoad(tmpVec); curb1.SetLocalTranslation(tmpVec); curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180)); curb1.SetLocalScale(new Vector3f(1, 1, scaleZ - offset - 1)); curbNode.AddChild(curb1); if (x != 0) { Node curbCorner1 = (Node)curbCorner.Clone(); tmpVec.Set((x) * scaleX - 2, 0, (i + 1) * scaleZ - offset + 1); tmpVec.y = HeightRoad(tmpVec); curbCorner1.SetLocalTranslation(tmpVec); curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90)); curbNode.AddChild(curbCorner1); } if (x != xAmt) { Node curbCorner0 = (Node)curbCorner.Clone(); tmpVec.Set(x * scaleX + 2, 0, i * scaleZ); tmpVec.y = HeightRoad(tmpVec); curbCorner0.SetLocalTranslation(tmpVec); curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90)); curbNode.AddChild(curbCorner0); } } } for (int z = 0; z <= zAmt; z++) { for (int i = 0; i < xAmt; i++) { AddRoad(new Line(new Vector3f(i * scaleX + 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1))); AddRoadCorner(new Line(new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX + 1, 0, z * scaleZ - 1))); // long pieces if (z == 0) { // long bar Node curb2 = (Node)curbModel.Clone(); tmpVec.Set(i * scaleX, 0, z * scaleZ - 2); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90)); curb2.SetLocalScale(new Vector3f(scaleX, 1, 1)); curbNode.AddChild(curb2); } else if (z == (zAmt - 1)) { Node curb2 = (Node)curbModel.Clone(); tmpVec.Set((i + 1) * scaleX, 0, (z + 1) * scaleZ); tmpVec.y = HeightRoad(tmpVec); curb2.SetLocalTranslation(tmpVec); curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90 + 180)); curb2.SetLocalScale(new Vector3f(scaleX, 1, 1)); curbNode.AddChild(curb2); } Node curb0 = (Node)curbModel.Clone(); tmpVec.Set((i + 1) * scaleX - 2, 0, z * scaleZ); tmpVec.y = HeightRoad(tmpVec); curb0.SetLocalTranslation(tmpVec); curb0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90)); curb0.SetLocalScale(new Vector3f(scaleX - offset - 1, 1, 1)); curbNode.AddChild(curb0); Node curb1 = (Node)curbModel.Clone(); tmpVec.Set((i) * scaleX + offset - 1, 0, z * scaleZ - 2); tmpVec.y = HeightRoad(tmpVec); curb1.SetLocalTranslation(tmpVec); curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90)); curb1.SetLocalScale(new Vector3f(scaleX - offset - 1, 1, 1)); curbNode.AddChild(curb1); if (z != zAmt) { Node curbCorner0 = (Node)curbCorner.Clone(); Vector3f curbVec1 = new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ + 1); curbVec1.y = HeightRoad(curbVec1); curbCorner0.SetLocalTranslation(curbVec1); curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180)); curbNode.AddChild(curbCorner0); } if (z != 0) { Node curbCorner1 = (Node)curbCorner.Clone(); Vector3f curbVec1 = new Vector3f((i) * scaleX + offset - 2, 0, z * scaleZ - 3); curbVec1.y = HeightRoad(curbVec1); curbCorner1.SetLocalTranslation(curbVec1); curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 360)); curbNode.AddChild(curbCorner1); } } } Geometry roadMerged = new Geometry(MeshUtil.MergeMeshes(roadNode)); Geometry curbMerged = new Geometry(MeshUtil.MergeMeshes(curbNode)); rootNode.AddChild(curbMerged); roadMerged.Material.SetValue(Material.MATERIAL_CULLENABLED, false); roadMerged.Material.SetValue(Material.TEXTURE_DIFFUSE, road); roadMerged.Material.SetValue(Material.SHININESS, 0.0f); Geometry roadCornerMerged = new Geometry(MeshUtil.MergeMeshes(roadCornerNode)); roadCornerMerged.Material.SetValue(Material.MATERIAL_CULLENABLED, false); roadCornerMerged.Material.SetValue(Material.TEXTURE_DIFFUSE, roadCorner); roadCornerMerged.Material.SetValue(Material.SHININESS, 0.0f); rootNode.AddChild(roadCornerMerged); rootNode.AddChild(roadMerged); /* addroad(new line(new vector3f(0, 0, 0), new vector3f(0, 0, 10))); AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(1, 0, 12))); AddRoad(new Line(new Vector3f(1, 0, 12), new Vector3f(5, 0, 12)));*/ /* for (int x = 0; x < 16; x ++) { AddRoad(new Line(new Vector3f((float)System.Math.Sin(x)*13, 0, (float)System.Math.Cos(x) * 13), new Vector3f((float)System.Math.Sin(x+1) * 13, 0, (float)System.Math.Cos(x+1) * 13))); } */ /* AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(-3, 0, 11))); AddRoad(new Line(new Vector3f(-3, 0, 11), new Vector3f(-4, 0, 12))); AddRoad(new Line(new Vector3f(-4, 0, 12), new Vector3f(-5, 0, 13))); AddRoad(new Line(new Vector3f(-5, 0, 13), new Vector3f(-6, 0, 14)));*/ // AddRoad(new Line(new Vector3f(0, 0, 10), new Vector3f(10, 0, 10))); /* for (int i = 0; i < 4; i++) { Line myline = new Line(lastLine.To, lastLine.To.Add(new Vector3f(rand.Next(-15, 15),0, rand.Next(-15, 15)))); Geometry quad = new Geometry(QuadFromLine(myline)); quad.Material.SetValue(Material.MATERIAL_CULLENABLED, false); quad.Material.SetValue(Material.TEXTURE_DIFFUSE, road); quad.Material.SetValue(Material.SHININESS, 0.0f); lastLine = myline; rootNode.AddChild(quad); } */ }