public static void PlayEnvironmentMusic(string resource, bool loop = true, float volume = 1f, float fade = 1f) { Create2DAudioSource(resource, volume, sourceObject => { AudioSource source = sourceObject as AudioSource; if (source) { source.volume = volume * _globalMusicVolume; if (_environment == null) { _environment = new MusicAudioSource(); } if (_environment.AudioSource != null) { Object.Destroy(_environment.AudioSource.gameObject); } _environment.Resources = resource; _environment.AudioSource = source; _environmentVolume = volume; _environment.AudioSource.loop = loop; _environment.AudioSource.name = "EnvironmentAudio"; _environment.AudioSource.Play(); GameObjectTools.DontDestroyOnSceneChanged(_environment.AudioSource.gameObject); } else if (_environment != null && _environment.AudioSource != null) { Object.Destroy(_environment.AudioSource.gameObject); _environment.AudioSource = null; } }); }
public static bool beginCollisionWithKoopaTroopa(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); KoopaTroopa koopa1 = shape1.GetComponent <KoopaTroopa>(); KoopaTroopa koopa2 = shape2.GetComponent <KoopaTroopa>(); bool hidden1 = koopa1._hide.isHidden(); bool hidden2 = koopa2._hide.isHidden(); bool bouncing1 = koopa1.bounce.isBouncing(); bool bouncing2 = koopa2.bounce.isBouncing(); // avoid koopa1 pushes hidden koopa2 Chase chase = shape1.GetComponent <Chase>(); if (chase != null && chase.isChasing()) { chase.stopChasing(); chase.enableOperateWhenOutOfSensor(); } // avoid koopa2 pushes hidden koopa1 chase = shape2.GetComponent <Chase>(); if (chase != null && chase.isChasing()) { chase.stopChasing(); chase.enableOperateWhenOutOfSensor(); } // is koopa above the other koopa? if (GameObjectTools.isGrounded(arbiter)) { if (!hidden1) { koopa1.jump.forceJump(koopa1.jumpSpeed); } else { koopa2.jump.forceJump(koopa1.jumpSpeed); } // NOTE: I assume here the isGrounded() works as expected return(false); // avoid the collision to continue since this frame } // kills koopa 2 else if (bouncing1 && !hidden2 && !bouncing2) { //koopa2.die(); koopa2.hide(); } // kills koopa 1 else if (bouncing2 && !hidden1 && !bouncing1) { //koopa1.die(); koopa1.hide(); } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next frame. return(true); }
void OnWizardCreate() { if (obj == null) { EditorUtility.DisplayDialog("错误警告", "必须拖入物体", "OK"); return; } Mesh resultMesh; GameObject resultObj; Material resultMaterial; GameObjectTools.MeshAddOutline(obj, lightningTexture, outline, out resultMesh, out resultObj, out resultMaterial, fixNormals); string path = EditorUtility.SaveFilePanelInProject("保存文件", "", "prefab", "aaaa"); int start = path.LastIndexOf("/"); int end = path.LastIndexOf("."); string saveName = path.Substring(start + 1, end - start - 1); string qian = path.Substring(0, start + 1); AssetDatabase.CreateAsset(resultMesh, qian + saveName + "_mesh.asset"); AssetDatabase.CreateAsset(resultMaterial, qian + saveName + "_mat.mat"); PrefabUtility.CreatePrefab(qian + saveName + ".prefab", resultObj); AssetBundleTools.SetAssetBundleName(qian + saveName + ".prefab", saveName); GameObject.DestroyImmediate(resultObj); }
public static bool beginCollisionWithScenery(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; // The order of the arguments matches the order in the function name. arbiter.GetShapes(out shape1, out shape2); Jump jump = shape1.GetComponent <Jump>(); // if is jumping and hits a wall then continue the collision /*if (jump != null && jump.isJumping && GameObjectTools.isWallHit(arbiter)) * return true;*/ if (jump != null && GameObjectTools.isGrounded(arbiter)) { if (jump.foreverJump) { jump.forceJump(jump.foreverJumpVel); } // if it was jumping then reset jump behavior else if (jump.isJumping) { jump.stop(); } } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next frame. return(true); }
public Body CreateSnakeTail(Body target) { var snakeTail = GameObjectTools.CreateGameObject(Constants.Resources.Prefabs.SNAKE_TAIL); var bodyView = GameObjectTools.GetComponent <BodyView>(snakeTail); return(new Body(bodyView, target)); }
public void onReloadLevel(Vector3 spawnPos) { GameObjectTools.setActive(gameObject, true); if (bounce.isBouncing()) { bounce.stop(); } patrol.enablePatrol(); patrol.setDir(1f); // initialize patrol direction patrol.setMoveSpeed(initialPatrolSpeed); if (_hide.isHidden()) { _hide.unHide(); } chase.stop(); chase.setOperable(true); if (jump != null) { jump.setForeverJump(jumpInLoop); } transform.position = spawnPos; shape.body._UpdatedTransform(); // update the body position }
/// <summary> /// This invoked from StartLevel script which gives the curretn level index. /// It enables the player's game object if playerEnabled is true, load the spawn positions, set the player's position. /// Warm ups some managers, etc. /// </summary> /// <param name='level'> /// Index of scene according Unity's indexing. /// </param> /// <param name='playerEnabled'> /// True if player starts being enabled. False if not. /// </param> /// <param name='levelExtent'> /// Level dimensions in world coordinates. /// </param> public void startLevel(int level, bool playerEnabled, Rect levelExtent) { if (level == 0) { Camera.main.cullingMask = 0; // avoid render anything warmUp(); loadLevel(getNextLevel()); return; } activeLevel = level; // activate/deactivate entire Player game object hierarchy GameObjectTools.setActive(player.gameObject, playerEnabled); // setup the scene components for the current scene setupSceneActors(); #if DEBUG if (LevelManager.getGUIContainerSceneOnly() == null) { Debug.LogError("Missing " + GUI_CONTAINER_SO_NAME + " game object. Please create it."); } #endif // if GUI_container_nd doesn't exist then create it and add minimum required game objects setupGUIContainerNonDestroyable(); // configure the parallax properties for a correct scrolling of background and foreground images setParallaxProperties(spawnPosArray[activeLevel].position, levelExtent); // warmUp some managers warmUp(); // find IFadeable component since main camera instance changes during scenes OptionQuit.Instance.setFaderFromMainCamera(); }
public Body CreateSnakeHead() { var snakeHead = GameObjectTools.CreateGameObject(Constants.Resources.Prefabs.SNAKE_HEAD); var bodyView = GameObjectTools.GetComponent <BodyView>(snakeHead); return(new Body(bodyView, new Vector2(0, 0), DirectionSnake.RIGHT)); }
public static bool presolveCollisionWithOneway(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; // The order of the arguments matches the order in the function name. arbiter.GetShapes(out shape1, out shape2); // if collision was from below then continue with oneway platform logic if (GameObjectTools.isHitFromBelow(arbiter)) { arbiter.Ignore(); return(false); } Player player = shape1.getOwnComponent <Player>(); // if player wants to climb down (once it is over the platform) then disable the collision to start free fall if (player.GetComponent <ClimbDownFromPlatform>().isClimbingDown()) { player.jump.reset(); // set state as if were jumping arbiter.Ignore(); return(false); } // let the collision happens return(true); }
public static bool beginCollisionWithAny(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; // The order of the arguments matches the order in the function name. arbiter.GetShapes(out shape1, out shape2); // change direction of movement whenever hit something like a wall if (GameObjectTools.isWallHit(arbiter)) { Patrol p1 = shape1.GetComponent <Patrol>(); if (p1 != null && p1.enabled) { p1.toogleDir(); } Patrol p2 = shape2.GetComponent <Patrol>(); if (p2 != null && p2.enabled) { p2.toogleDir(); } } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next fixed step. return(true); }
public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); Goomba goomba = shape1.GetComponent <Goomba>(); Player player = shape2.GetComponent <Player>(); if (goomba.dieAnim.isDying() || player.isDying()) { arbiter.Ignore(); // avoid the collision to continue since this frame return(false); // avoid the collision to continue since this frame } goomba.idle.setIdle(true); // if collides from top then kill the goomba if (GameObjectTools.isHitFromAbove(goomba.transform.position.y, shape2.body, arbiter)) { goomba.die(); // makes the player jumps a little upwards player.forceJump(); } // kills Player else { arbiter.Ignore(); // avoid the collision to continue since this frame LevelManager.Instance.loseGame(true); // force die animation } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next frame. return(true); }
void OnGUI() { if (debugZones && EventType.Repaint == Event.current.type) { // NOTE: use this with no aspect ratio modification. Set it as false in LevelManager for (int i = 0; i < arrowRects.Length; ++i) { Rect r = arrowRects[i]; Rect rTarget = new Rect(r.x, Screen.height - r.y - r.height, r.width, r.height); GUI.Box(rTarget, GUIContent.none); } } // since this game object has a GUICustomElement script attached to it, for strange a reason no mouse event // is caught, so we need to manually check for the event and fire it here Event e = Event.current; if (e != null && e.isMouse && e.button == 0 && e.type == EventType.MouseDown) { if (GameObjectTools.testHitFromMousePos(transform, e.mousePosition)) { Vector2 mousePosInverted; mousePosInverted.x = e.mousePosition.x; // mouse position is in GUI space which has inverted Y axis mousePosInverted.y = Screen.height - e.mousePosition.y; optionSelected(mousePosInverted); } } }
private static void ReleasePool(int removeCount) { HolderList.Clear(); var e = CachePool.GetEnumerator(); using (e) { while (e.MoveNext()) { HolderList.Add(e.Current.Value); } } HolderList.Sort(HolderComparison); if (removeCount > HolderList.Count) { removeCount = HolderList.Count; } for (int i = 0; i < removeCount; i++) { var queue = HolderList[i].Queue.GetEnumerator(); using (queue) { while (queue.MoveNext()) { var effect = queue.Current; GameObjectTools.DestroyGameObject(effect); } } HolderList[i].Queue.Clear(); CachePool.Remove(HolderList[i].EffectName); } }
public static bool beginCollisionWithKoopaTroopa(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); KoopaTroopa koopa1 = shape1.getOwnComponent <KoopaTroopa>(); KoopaTroopa koopa2 = shape2.getOwnComponent <KoopaTroopa>(); bool hidden1 = koopa1._hide.isHidden(); bool hidden2 = koopa2._hide.isHidden(); bool bouncing1 = koopa1.bounce.isBouncing(); bool bouncing2 = koopa2.bounce.isBouncing(); // avoid koopa1 pushes hidden koopa2 Chase chase1 = shape1.GetComponent <Chase>(); if (chase1 != null && chase1.isChasing()) { chase1.stop(); chase1.enableOperateWhenOutOfSensor(); } // avoid koopa2 pushes hidden koopa1 Chase chase2 = shape2.GetComponent <Chase>(); if (chase2 != null && chase2.isChasing()) { chase2.stop(); chase2.enableOperateWhenOutOfSensor(); } // is koopa1 above the koopa2? if (GameObjectTools.isGrounded(arbiter)) { if (!hidden1 && koopa1.jump.isJumping()) { koopa1.jump.forceJump(koopa1.jumpSpeed); } else if (hidden1 && koopa2.jump.isJumping()) { koopa2.jump.forceJump(koopa1.jumpSpeed); } return(false); // avoid the collision since this frame } // hide koopa 2 else if (bouncing1 && !hidden2 && !bouncing2) { koopa2.hide(); } // hide koopa 1 else if (bouncing2 && !hidden1 && !bouncing1) { //koopa1.die(); koopa1.hide(); } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next fixed step. return(true); }
public Wall CreateWall(Vector2 pos) { var wallGo = GameObjectTools.CreateGameObject(Constants.Resources.Prefabs.WALL); var wallView = GameObjectTools.GetComponent <WallView>(wallGo); wallGo.transform.position = new Vector3(pos.x, 0, pos.y); return(new Wall(wallView, pos)); }
public Stone CreateStone(Vector2 pos) { var go = GameObjectTools.CreateGameObject(_prefabs[Random.Range(0, _prefabs.Count)]); var view = GameObjectTools.GetComponent <StoneView>(go); go.transform.position = new Vector3(pos.x, 0, pos.y); return(new Stone(view, pos)); }
public void restorePlayerProps() { dying = false; // set back original shader setBackOrigShader(); // set back player's original layer GameObjectTools.setLayerForShapes(gameObject, layersCP); }
public void CreateFood(Vector2 pos) { var food = GameObjectTools.CreateGameObject(Constants.Resources.Prefabs.FOOD); var foodView = GameObjectTools.GetComponent <FoodView>(food); food.transform.position = new Vector3(pos.x, 0, pos.y); GameData.GetInstance.SetFood(pos, foodView); }
public void onReloadLevel(Vector3 spawnPos) { GameObjectTools.setActive(gameObject, true); chase.stop(); transform.position = spawnPos; body._UpdatedTransform(); // update the body position }
private GameObject spawnPosition; //The position of the randomly selected Spawn Point. void Start() { //-----------------------------------ORIGINAL----------------------------------- //spawnPoints = GameObject.FindGameObjectsWithTag("Spawn"); //This finds all the objects tagged as "Spawn"; usually the Spawn Points. InvokeRepeating("SpawnBox", 0.0f, 0.7f); //Every 0.7 "seconds", the function "Spawn Box" will trigger. //------------------------------------------------------------------------------ spawnPoints = GameObjectTools.GetAllChildren(m_spawnPointsParent); Debug.Log(spawnPoints.Count); }
public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); KoopaTroopa koopa = shape1.getOwnComponent <KoopaTroopa>(); Player player = shape2.getOwnComponent <Player>(); if (player.isDying()) { arbiter.Ignore(); // avoid the collision to continue since this frame return(false); // avoid the collision to continue since this frame } bool collisionFromAbove = GameObjectTools.isHitFromAbove(koopa.transform.position.y, shape2.body, arbiter); if (collisionFromAbove) { // if koopa was jumping then stop forever jumping if (koopa.jump.isJumping()) { koopa.stopJumping(); } // hide the koopa troopa or stop the bouncing of the hidden koopa else if (!koopa._hide.isHidden() || koopa.bounce.isBouncing()) { koopa.hide(); } // kills the koopa else { koopa.die(); } // makes the player jumps a little upwards player.forceJump(); } // koopa starts bouncing else if (koopa._hide.isHidden() && !koopa.bounce.isBouncing()) { koopa.stop(); koopa.bounce.bounce(Mathf.Sign(koopa.transform.position.x - player.transform.position.x)); } // kills Player else { koopa.stop(); arbiter.Ignore(); // avoid the collision to continue since this frame LevelManager.Instance.loseGame(true); // force die animation } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next fixed step. return(true); }
/** * Self implementation for destroy since using GamObject.Destroy() has a performance hit in android. */ private void destroy() { shape.enabled = false; // makes the shape to be removed from the space GameObjectTools.ChipmunkBodyDestroy(body); #if UNITY_4_AND_LATER gameObject.SetActive(false); #else gameObject.SetActiveRecursively(false); #endif PauseGameManager.Instance.remove(this); }
public void onReloadLevel(Vector3 spawnPos) { GameObjectTools.setActive(gameObject, true); patrol.enablePatrol(); patrol.setDir(1f); // initialize patrol direction idle.setIdle(false); transform.position = spawnPos; body._UpdatedTransform(); // update the body position }
void OnDestroy() { GameObjectTools.ChipmunkBodyDestroy(body, GetComponent <ChipmunkShape>()); // this is to avoid nullifying or destroying static variables. Intance variables can be destroyed before this check if (duplicated) { duplicated = false; // reset the flag for next time return; } PauseGameManager.Instance.remove(this as IPausable); instance = null; }
public static GameObject AddInstantiateObj(GameObject obj, Transform p) { GameObject o = GameObjectTools.InstantiateGO(obj); o.SetActive(true); if (p) { o.transform.SetParent(p); } o.transform.localScale = Vector3.one; o.transform.localPosition = Vector3.zero; o.transform.localRotation = Quaternion.identity; return(o); }
void OnGUI() { // since this game object has a GUICustomElement script attached to it, for strange a reason no mouse event // is caught, so we need to manually check for the event and fire it here Event e = Event.current; if (e != null && e.isMouse && e.button == 0 && e.type == EventType.mouseDown) { if (GameObjectTools.testHitFromMousePos(transform, e.mousePosition)) { optionSelected(); } } }
public static void Init() { if (!soundListenter) { soundListenter = GameObjectTools.CreateGameObject("soundListenter", typeof(AudioListener)); soundListenter.AddComponent <SoundListenter>(); reverbZone = soundListenter.AddComponent <AudioReverbZone>(); GameObjectTools.DontDestroyOnSceneChanged(soundListenter); EnabledReverbZone(false); } Sound.GlobalMusicVolume = GameSetting.MusicVolume; Sound.GlobalAudioVolume = GameSetting.AudioVolume; }
private void destroyBrickGracefully() { gameObject.GetComponent <Renderer>().enabled = false; // if no power up attached then destroy it if (GetComponent <PowerUp>() == null) { Destroy(this.gameObject, 0.1f); } // don't destroy the object to avoid killing the PowerUp instance else { gameObject.GetComponent <Collider>().enabled = false; // disable the child ("top" game object) GameObjectTools.setActive(transform.FindChild("BrickTop").gameObject, false); } }
void Init() { mainPanel = GameObjectTools.GetComponentInChildren <MainPanel> (gameObject); playPanel = GameObjectTools.GetComponentInChildren <PlayPanel> (gameObject); pausePanel = GameObjectTools.GetComponentInChildren <PausePanel> (gameObject); gameOverPanel = GameObjectTools.GetComponentInChildren <GameOverPanel> (gameObject); mainPanel.gameObject.SetActive(true); playPanel.gameObject.SetActive(false); pausePanel.gameObject.SetActive(false); gameOverPanel.gameObject.SetActive(false); mainPanel.Init(); playPanel.Init(); pausePanel.Init(); gameOverPanel.Init(); }
public void loadLevel(int level) { // fix level index if invalid if (level < SCENE_MAIN_INDEX || level >= Application.levelCount) { activeLevel = SCENE_MAIN_INDEX; // splash scree } else { activeLevel = level; // update current level index } GameObjectTools.setActive(player.gameObject, false); // deactivate to avoid falling in empty scene OptionQuit.Instance.reset(); // remove option buttons if on screen guiContainer_so = null; // reset the references of scene only GUI elements container Application.LoadLevel(activeLevel); // load scene }