//修正跳跃产生的形变 void correctJumpScale() { if (currentState != state.jump && lastState == state.jump) { transform.localScale = Dir == dir.right ? originScale : GameFunction.getVector3(-originScale.x, originScale.y, originScale.z); } }
// Use this for initialization void Start() { instance = this; GameOverTitle.SetActive(false); RestartButton.SetActive(false); }
public override void onStart() { base.onStart(); CollHeight = colliderID[0].bounds.extents.y * 2; leftPoint.transform.position = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "Gravity").GetComponent <BoxCollider2D>().bounds.min + new Vector3(Dir == dir.left ? -0.05f : 0.05f, 0.01f, 0); }
/// <summary> /// 冲刺攻击 /// </summary> /// <param name="_targetPos"></param> /// <returns></returns> IEnumerator IE_dash(Vector3 _targetPos) { float duration = ((Vector2)(_targetPos - transform.position)).magnitude / dashSpeed; float timer = 0; Vector3 t_Pos_start = transform.position; _targetPos.z = t_Pos_start.z; //准备 const float time_ready = 0.5f; while (timer < time_ready) { timer += Time.deltaTime; float t = timer / time_ready; transform.localScale = Vector3.Lerp(originScale, originScale * 1.4f, GameFunction.smoothLerp(t)); yield return(null); } timer = 0; while (timer < duration) { timer += Time.deltaTime; float t = timer / duration; transform.localScale = Vector3.Lerp(originScale * 1.4f, originScale, GameFunction.smoothLerp(t)); transform.position = Vector3.Lerp(t_Pos_start, _targetPos, t); yield return(null); } isAttackFinish = true; }
public void OnCameraChanged() { if (GameBase != null && Target != null) { SetPos(GameFunction.WorldToLocalPointInRectangle(Target.transform, GameBase.CurCam, GameBase.m_GameCanvas, GameBase.UICam)); } }
/// <summary> /// 生成纹理 /// </summary> void GenTexture() { if (Size == 0 || gridSize == 0) { return; } Perlin perlin = new Perlin(gridSize); Texture2D texture = new Texture2D(Size, Size); float a = Size / gridSize; for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { float t = noise(GameFunction.getVector2(i / a, j / a), perlin); t = 0.5f * t + 0.5f; texture.SetPixel(i, j, GameFunction.getColor(t, t, t, 1)); } } texture.Apply(); FileStream fs = new FileStream(Application.dataPath + "/" + textureName + ".jpg", FileMode.Create); byte[] data = texture.EncodeToJPG(); fs.Write(data, 0, data.Length); fs.Flush(); fs.Close(); Debug.Log("生成成功"); }
protected void AddChips(Transform parent, long chips) { for (int i = parent.childCount - 1; i >= 0; i--) { GameObject.DestroyImmediate(parent.GetChild(i).gameObject); } BetData bd = BlackJack_Data.GetInstance().m_BetData[m_BjGameBase.m_RoomInfo.m_nRoomLevel - 1]; int[] grades = bd.m_nGrades; for (int i = grades.Length - 1; i >= 0; i--) { if (chips >= grades[i] || i == 0) { int index = i + (chips > grades[i] ? 2 : 1); UnityEngine.Object obj = (GameObject)m_BjGameBase.m_AssetBundle.LoadAsset("Model_chouma" + index); GameObject gameObj = GameMain.instantiate(obj) as GameObject; gameObj.transform.SetParent(parent, false); gameObj.GetComponentInChildren <TextMesh>().text = GameFunction.FormatCoinText(chips); break; } } CustomAudioDataManager.GetInstance().PlayAudio(1003); }
override protected IEnumerator die() //死亡 { //销毁光晕 try { Destroy(GameFunction.GetGameObjectInChildrenByName(this.gameObject, "Bloom")); } catch { } this.GetComponent <BoxCollider2D>().enabled = false; deadParticle.SetActive(true); GetComponent <SpriteRenderer>().enabled = false; this.enabled = false; Time.timeScale = 0; CameraFollow.instance.shakeCamera(0.25f, 0.04f, 0.2f); //镜头抖动 yield return(new WaitForSecondsRealtime(0.1f)); //卡屏 Time.timeScale = 1; yield return(new WaitForSeconds(deadParticle.GetComponent <ParticleSystem>().startLifetime)); Destroy(this.gameObject); }
///<summary> ///if an object doesn't unsubscribe from an event on destroy, the event manager will still hold a pointer to said object, meaning said object will not be garbage collected ///</summary> ///<param name="givenEventType"> Tag on which the function was be called.</param> ///<param name="givenFunction"> Function which the calling object was subscribing with.</param> public static void UnsubscribeToEvent(string givenEventType, GameFunction givenFunction) { if (subscriptionList.ContainsKey(givenEventType)) { subscriptionList[givenEventType] -= givenFunction; } }
public bool IsPlaying = false; // 宣告IsPlaying 的布林資料,並設定初始值false // Use this for initialization void Start() { Instance = this; GameOverTitle.SetActive(false); //設定GameOverTitle不顯示(打勾取消) RestartButton.SetActive(false); //RestartButton設定成不顯示 QuitButton.SetActive(false); //QuitButton設定成不顯示 }
public override void onStart() { base.onStart(); animator.SetTrigger(currentState.ToString()); Gravity = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "Gravity").GetComponent <BoxCollider2D>(); dashParticle = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "DashDustParticle").GetComponent <ParticleSystem>().emission; originParticleRate = dashParticle.rate.constant; dashParticle.rate = 0; if (transform.localScale.x < 0) //向右 { offset_Right = Gravity.bounds.min + Gravity.bounds.size.x * Vector3.right - transform.position + Vector3.one * 0.3f; GameFunction.t_Vector3.Set(-transform.localScale.x, transform.localScale.y, transform.localScale.z); transform.localScale = GameFunction.t_Vector3; offset_Left = Gravity.bounds.min - transform.position + new Vector3(-0.3f, 0.3f, 0); GameFunction.t_Vector3.Set(-transform.localScale.x, transform.localScale.y, transform.localScale.z); transform.localScale = GameFunction.t_Vector3; } else { offset_Left = Gravity.bounds.min - transform.position + new Vector3(-0.3f, 0.3f, 0); GameFunction.t_Vector3.Set(-transform.localScale.x, transform.localScale.y, transform.localScale.z); transform.localScale = GameFunction.t_Vector3; offset_Right = Gravity.bounds.min + Gravity.bounds.size.x * Vector3.right - transform.position + Vector3.one * 0.3f; GameFunction.t_Vector3.Set(-transform.localScale.x, transform.localScale.y, transform.localScale.z); transform.localScale = GameFunction.t_Vector3; } Dir = (transform.localScale.x < 0 ? dir.right : dir.left); }
IEnumerator IE_unlock() { Transform trans_shadow = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "Shadow").transform; Vector3 originScale_shadow = trans_shadow.localScale; const float duration = 1.8f; float timer = 0; while (timer < duration) { timer += Time.deltaTime; float t = timer / duration; trans_shadow.localScale = Vector3.Lerp(originScale_shadow, GameFunction.getVector3(1, 0, 1), t); SR_Stone_crack.color = Color.Lerp(SR_Stone_crack.color, Color.black, t); yield return(null); } Stone_trans.GetComponent <Rigidbody2D>().isKinematic = false; this.enabled = false; this.GetComponent <BoxCollider2D>().enabled = false; //Destroy(this.gameObject); }
// Update is called once per frame void Update() { if (((Vector2)(originPos - CharacterControl.instance._collider.bounds.center)).sqrMagnitude < Mathf.Pow(nearRange, 2) && !Rest) //是否在靠近的范围内 { transform.position = Vector2.MoveTowards(transform.position, CharacterControl.instance._collider.bounds.center, maxDistanceDelta); } else { transform.position = Vector2.MoveTowards(transform.position, new Vector2(scale * Mathf.Sin(speed * Time.time + randomTime1) + originPos.x, scale * Mathf.Sin(speed * Time.time + randomTime2) + originPos.y), maxDistanceDelta * 0.6f); } if (isCharacterIn) { if (!Rest) { if (MyInput.instance.isGetJumpDown()) { CharacterControl.instance.isPlatJump = true; Rest = true; particle.gameObject.SetActive(true); Invoke("reset", restTime); SR.color = disableColor; _light.range = light_rest_range; } } } transform.position = GameFunction.getVector3(transform.position.x, transform.position.y, originPos.z); //纠正Z值 }
void Update() { SR.color = GameFunction.getColor(SR.color.r, SR.color.g, SR.color.b, Weather.instance.SmoothLerp_LightAlpha(Day_Alpha, Night_Alpha) - deltaMinus); //随时间变化透明度 if (WeatherData.getIntance().currentWeather != lastWeather && WeatherData.getIntance().currentWeather != weather.Sunny && lastWeather == weather.Sunny) //当天气不为晴天的一刻 { deltaMinus = 0; _time0 = 0; } if (WeatherData.getIntance().currentWeather != lastWeather && WeatherData.getIntance().currentWeather == weather.Sunny) //当天气为晴天的一刻 { deltaMinus = 1; _time0 = 0; } if (WeatherData.getIntance().currentWeather != weather.Sunny) { _time0 += Time.deltaTime; deltaMinus = Mathf.Lerp(0, 1, _time0 / (WeatherData.getIntance().Weather_duration * 0.1f)); } if (WeatherData.getIntance().currentWeather == weather.Sunny) { _time0 += Time.deltaTime; deltaMinus = Mathf.Lerp(1, 0, _time0 / (WeatherData.getIntance().Weather_duration * 0.1f)); } GameFunction.m_Color = SR.color; GameFunction.m_Color.a *= (1 + Mathf.Lerp(-0.8f, 0.1f, noiseTex.GetPixel(2, ((int)(Time.time * flashSpeed) + random) % noiseTex.width).r * 0.5f + 0.25f)); SR.color = GameFunction.m_Color; lastWeather = WeatherData.getIntance().currentWeather; }
void setElementBoxTrigger() { BoxCollider2D t = GetComponent <BoxCollider2D>(); BoxCollider2D t2 = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "Element").GetComponent <BoxCollider2D>(); t2.offset = t.offset; t2.size = t.size; }
// Use this for initialization void Start() { Instance = this; //指定Instance這個程式 GameOverTitle.SetActive(false); RestartButton.SetActive(false); //RestartButton設定成不顯示 QuitButton.SetActive(false); //QuitButton設定成不顯示 }
static EngineFunctions() { VEngine = new GameFunction <DVEngine>(0x40ADA0); GetCurrentLevelName = new GameFunction <DGetCurrentLevelName>(0x404DA0); AskToChangeLevel = new GameFunction <DAskToChangeLevel>(0x4054D0); Code4PersoLePlusProche = new GameFunction <DCode4PersoLePlusProche>(0x476960); MiscFunction = new GameFunction <DMiscFunction>(0x47CC30); }
void Start() { Manual.SetActive(false); GameOverTitle.SetActive(false); RestartButton.SetActive(false); Instance = this; VictoryTitle.SetActive(false); }
IEnumerator IE_getEnergy() { isNone = true; Halo.SetActive(true); Halo.transform.parent = null; Halo.GetComponent <TrailRenderer>().enabled = true; //第一段动画 { float _time0 = 0; Vector3 _dir = Halo.transform.position - CharacterControl.instance.transform.position; Vector3 _dir_2 = Vector3.Cross(_dir, Vector3.back); _dir.z = 0; Vector3 p1, p2; p1 = Halo.transform.position + _dir * 0.9f; p2 = (CharacterControl.instance.transform.position + Halo.transform.position) / 2.0f + _dir_2 * 0.8f; p1.z = 0; p2.z = 0; while (_time0 < first_animation_duration) { _time0 += Time.deltaTime; float t = _time0 / first_animation_duration; Halo.transform.position = GameFunction.BezierLine(Halo.transform.position, CharacterControl.instance.transform.position + Vector3.up * 1, p1, p2, t); yield return(null); } } //第二段动画 { Energy.SetActive(false); float _time0 = 0; Vector3 originScale_Halo = Halo.transform.localScale; SpriteRenderer SR_BG = BG.GetComponent <SpriteRenderer>(); Color originColor_BG = SR_BG.color; SpriteRenderer SR_Stone = Stone.GetComponent <SpriteRenderer>(); Color originColor_Stone = SR_Stone.color; SpriteRenderer SR_Halo = Halo.GetComponent <SpriteRenderer>(); while (_time0 < second_animation_duration) { _time0 += Time.deltaTime; float t = _time0 / second_animation_duration; Halo.transform.localScale = Vector3.Lerp(originScale_Halo, Vector3.one * 10f, t); SR_Halo.color = Color.Lerp(SR_Halo.color, new Color(1, 1, 1, 0), t); SR_BG.color = Color.Lerp(originColor_BG, Color.black, t); SR_Stone.color = Color.Lerp(originColor_Stone, Color.black, t); yield return(null); } SR_BG.sortingOrder = 0; Stone.SetActive(false); Halo.SetActive(false); Particle.SetActive(false); } Bag.getInstance().AddArmsFragment(1); }
public override void onStart() { base.onStart(); currentState = monster_2_state.walk; CollHeight = colliderID[0].bounds.extents.y * 2; eye.transform.position = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "Gravity").GetComponent <BoxCollider2D>().bounds.min + new Vector3(Dir == dir.left ? -0.05f : 0.05f, 0.01f, 0); viewDistance_player *= Random.Range(0.6f, 1.4f); //每个单体看见玩家的距离不同 }
public Vector3 GetCoinPos() { //Vector3 pos = m_InfoUI.FindChild("left/Image_coinframe/Image_Coin").position; Vector3 pos = m_InfoUI.position; Canvas cv = GameBase.GameCanvas; Vector3 uiPos = GameFunction.WorldToLocalPointInRectangle(pos, cv.worldCamera, cv, cv.worldCamera); return(uiPos); }
private void FixedUpdate() { //夜晚不活动 if (!isNight) { Line.transform.localScale = Mathf.Sin(Time.time / cycle) * scale * GameFunction.getVector3(0, originScale.y, 0) + originScale; Spider.transform.position = SR_Line.bounds.min + GameFunction.getVector3(0, 0, 0.001f); } }
//修正冲刺产生的形变 void correntDashScale() { if (lastState == state.dash) { if (currentState != state.dash) { transform.localScale = Dir == dir.right?originScale:GameFunction.getVector3(-originScale.x, originScale.y, originScale.z); } } }
//Starts the GameStarter public static void Start(GameFunction start, GameFunction stop, GameFunction update) { GameStarter.start = start; GameStarter.stop = stop; GameStarter.update = update; Time = new Stopwatch(); _gameLogicThread.Start(); }
public bool CreateHook<T>(GameFunction<T> function, T hook) where T : Delegate { if (hook == null) return false; Hooks[hook] = LocalHook.Create(function.Pointer, hook, function); Hooks[hook].ThreadACL.SetExclusiveACL(new[] { 0 }); return true; }
public bool RemoveHook<T>(GameFunction<T> function, T hook) where T : Delegate { if (!Hooks.ContainsKey(hook)) return false; Hooks[hook].Dispose(); Hooks.Remove(hook); return true; }
///<summary> /// Adds givenFunction to the delegate called on givenEventType /// - you MUST use UnsubscribeToEvent on destroy of your object, otherwise you WILL face memory leaks ///</summary> ///<param name="givenTag"> Tag on which the function will be called.</param> ///<param name="givenFunction"> Function taking an object as parameter which will be called on BroadcastEvent.</param> public static void SubscribeToEvent(string givenTag, GameFunction givenFunction) { if (!subscriptionList.ContainsKey(givenTag)) { subscriptionList[givenTag] = givenFunction; } else { subscriptionList[givenTag] += givenFunction; } }
public void Encounter(int i) { switch (i) { case 0: Console.WriteLine("You have been attacked by" + Enemies[i]); GameFunction.AttackFunction(); itemDrop(); coinCount(); Console.WriteLine("Total Coins: "); Coin.coinCount(); Console.WriteLine("Please choose what items to take: "); lists.RunList(); start.Play(); break; case 1: Console.WriteLine("You have been attacked by" + Enemies[i]); GameFunction.AttackFunction(); itemDrop(); coinCount(); Console.WriteLine("Total Coins: "); Coin.coinCount(); Console.WriteLine("Please choose what items to take: "); lists.RunList(); start.Play(); break; case 2: Console.WriteLine("You have been attacked by" + Enemies[i]); GameFunction.AttackFunction(); itemDrop(); coinCount(); Console.WriteLine("Total Coins: "); Coin.coinCount(); Console.WriteLine("Please choose what items to take: "); lists.RunList(); start.Play(); break; case 3: Console.WriteLine("You have been attacked by" + Enemies[i]); if (Enemies[i] == "a Land Shark") { } GameStart.canPlay = false; break; default: Console.WriteLine("You have encountered no enemy."); start.Play(); break; } }
void Start() { bl_SR = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "bl").GetComponent <SpriteRenderer>(); coin_SR = GetComponent <SpriteRenderer>(); bloom_SR = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "bloom").GetComponent <SpriteRenderer>(); Effect = GameFunction.GetGameObjectInChildrenByName(this.gameObject, "Effect"); Effect.SetActive(false); randomOffset.z = -0.1f; originScale_bl = bl_SR.transform.localScale; }
private void FixedUpdate() //Update 背景会抖动 { // 背景z轴不可超过10 Vector3 tVector = nowPosition - this.transform.position; tVector.z = 0; for (int i = 0; i < maps.Length; i++) { maps[i].transform.localPosition = GameFunction.getVector3((maps[i].transform.localPosition - tVector * (maps[i].transform.localPosition.z * 0.1f)).x, (maps[i].transform.localPosition - 0.2f * tVector * (maps[i].transform.localPosition.z * 0.1f)).y, maps[i].transform.localPosition.z); } nowPosition = this.transform.position; }
Vector3 getRayPos(Vector2 startPos, float angle) { int mask = 1 << LayerMask.NameToLayer("terrain"); Vector2 dir = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)); RaycastHit2D hitPoint = Physics2D.Raycast(startPos, dir, 9999, mask); if (hitPoint.transform.Equals(null)) { return(startPos + dir * 999); } return(GameFunction.getVector3(hitPoint.point.x, hitPoint.point.y, point[0].position.z)); }