//Setting public static bool SetEffect(string name, HeightRender.Effect effect, CSScript script = null) { if (name != null) { if (script == null) { script = new CSScript(); } EffectScript es; if (!effects.TryGetValue(name, out es)) { es = new EffectScript() { effect = effect, script = script } } ; else { es.effect = effect; } effects[name] = es; if (effectSet != null) { effectSet(name, es.effect); } return(true); } else { return(false); } }
public void Initialize(Fish.FishInfo info) { renderer.sprite = info.icon; switch (info.rank) { case Fish.FishInfo.Rank.R: currentEffect = Instantiate(Effect_R, effectParent).GetComponent <EffectScript>(); break; case Fish.FishInfo.Rank.SR: currentEffect = Instantiate(Effect_SR, effectParent).GetComponent <EffectScript>(); break; case Fish.FishInfo.Rank.SSR: currentEffect = Instantiate(Effect_SSR, effectParent).GetComponent <EffectScript>(); break; default: break; } var obj = Instantiate(Effect_Text, effectCanvas); obj.transform.GetChild(1).GetComponent <TextMeshProUGUI>().text = info.fishName; currentEffect.SetOnDead(() => { renderer.DOFade(0f, 0.5f).OnComplete(() => { renderer.sprite = null; renderer.color = Color.white; Destroy(obj); }); }); }
//Setting public static bool SetEffect(string name, HeightRender.Effect effect, CSScript script = null) { if (name != null && name.Length > 0) { if (script == null) { script = new CSScript(); script.Source = "Photon Apply(int x, int y, Photon color, HeightField heightField)\r\n{\r\n\t//Your code goes here\r\n}"; } EffectScript es; if (!effects.TryGetValue(name, out es)) { es = new EffectScript() { effect = effect, script = script } } ; else { es.effect = effect; } effects[name] = es; if (effectSet != null) { effectSet(name, es.effect); } return(true); } else { return(false); } }
public void Damage(int input) { if (input <= 0) { return; } if (null != myDamageEffects) { input = (int)EffectScript.AffectsList( myDamageEffects, null == myUnit ? new Message(new Message.Term(), new Message.Term()) : myUnit.ToMessage(), (float)input); } if (input <= 0) { return; } /*myOwningPlayer.myFrameData.myDamages++; * myOwningPlayer.myTurnData.myFrameData.myDamages++; * myOwningPlayer.myMatchData.myTurnData.myFrameData.myDamages++; * * GlobalScript.ourPlayerFrameData.myDamages++; * GlobalScript.ourPlayerTurnData.myFrameData.myDamages++; * GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myDamages++;*/ myDamage += input; Checkup(); }
public PlayerScript Draw(bool destroyOnFailure = true) // If no space in hand, // trigger removal effect // destroy card if specified { CardScript drawCardScript = myDeckScript.RemoveCard(); if (null != drawCardScript) { /*myFrameData.myDraws++; * myTurnData.myFrameData.myDraws++; * myMatchData.myTurnData.myFrameData.myDraws++; * * GlobalScript.ourPlayerFrameData.myDraws++; * GlobalScript.ourPlayerTurnData.myFrameData.myDraws++; * GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myDraws++;*/ // If false, then hand was over capacity, // But the removal effect for the card should go off if (false == myHandScript.InsertCard(drawCardScript)) { EffectScript.AffectsList(drawCardScript.myRemoveEffects, ToMessage()); //failed to draw card so destroy if specified if (destroyOnFailure) { Destroy(drawCardScript.gameObject); } } } return(this); }
// Inserts a card into the hand, // returns false if not successful public bool InsertCard(CardScript input, bool discard = true) { if (null != input) { if (myOwningPlayer) { EffectScript.AffectsList(input.myInsertEffects, myOwningPlayer.ToMessage()); } int cardCount = CountCards(); if (cardCount < myCardCapacity) { input.myHandScript = this; Reanimate(); return(true); } else if (discard) { if (myOwningPlayer) { EffectScript.AffectsList(input.myRemoveEffects, myOwningPlayer.ToMessage()); } } } return(false); }
public static void CheckEffectInResource() { //获取所有资源路径 mEffectResources.Clear(); //Resource资源路径 string resourcePath = Application.dataPath + "/Resources/effect"; string[] files = Directory.GetFiles(resourcePath, "*.*", SearchOption.AllDirectories); foreach (string file in files) { string suffix = BuildCommon.getFileSuffix(file); if (suffix == "meta") { continue; } //查找预制件件 if (suffix == "prefab") { string realFile = file.Replace("\\", "/"); realFile = realFile.Replace(Application.dataPath, "Assets"); mEffectResources.Add(realFile); } } List <ParticleSystem> pss = new List <ParticleSystem>(); //查找是否缺少EffectScript foreach (string assetPath in mEffectResources) { GameObject asset = AssetDatabase.LoadMainAssetAtPath(assetPath) as GameObject; //检测是否缺少EffectScript脚本 EffectScript effectScript = asset.GetComponent <EffectScript>(); if (effectScript == null) { Debug.Log("the effect " + assetPath + " miss EffectScript!"); } SL_DestroyByTime destTimeScript = asset.GetComponent <SL_DestroyByTime>(); if (destTimeScript != null) { Debug.Log("do not use the SL_DestoryByTime script now!"); } pss.Clear(); //检测ParticleSystem RecusionParticleSystemObject(asset, ref pss); foreach (ParticleSystem ps in pss) { if (ps.GetComponent <Renderer>().castShadows || ps.GetComponent <Renderer>().receiveShadows) { Debug.Log(asset.name + " " + ps.name + "is cast shadow or receive shadow"); } } } Debug.Log("Check finised!"); }
private static EffectScript LoadEffect(Stream stream) { EffectScript es = new EffectScript() { effect = null, script = new CSScript() }; es.script.Source = LoadText(stream); return(es); }
public int Cost(Message message) { if (null == myEffects) { return((int)myBase); } else { return((int)EffectScript.AffectsList(myEffects, message, myBase)); } }
/// <summary> /// 차지 효과 개체의 색상표를 업데이트합니다. /// </summary> /// <param name="chargeEffect">차지 효과 개체입니다.</param> /// <param name="colorPalette">차지 효과 개체의 새 색상표입니다.</param> void UpdateChargeEffectColor(GameObject chargeEffect, Color[] colorPalette) { // 차지 효과 개체를 획득합니다. EffectScript effect = chargeEffect.GetComponent <EffectScript>(); // 색상표를 획득합니다. Color[] palette = (_chargeTime < CHARGE_LEVEL[2]) ? XColorPalette.XNormalChargeEffectColorPalette1 : XColorPalette.XNormalChargeEffectColorPalette2; // 텍스쳐를 업데이트합니다. effect.RequestUpdateTexture(XColorPalette.XDefaultChargeEffectColorPalette, palette); }
//特效创建接口 public void Create() { //创建的时候检查特效projectId,服务器没有设置生成本地id CheckProjectId(); //获取特效模板名称 templateName = ResourceCommon.getResourceName(resPath); //使用特效缓存机制 obj = ObjectPool.Instance.GetGO(resPath); if (null == obj) { Debugger.LogError("load effect object failed in IEffect::Create" + resPath); return; } //创建完成,修改特效名称,便于调试 obj.name = templateName + "_" + projectID.ToString(); OnLoadComplete(); //获取美术特效脚本信息 effectScript = obj.GetComponent <EffectScript>(); if (effectScript == null) { Debugger.LogError("cant not find the effect script in " + resPath); return; } artTime = effectScript.lifeTime; //美术配置时间为0,使用策划时间 if (effectScript.lifeTime == 0) { lifeTime = cehuaTime; } //否则使用美术时间 else { lifeTime = artTime; } //特效等级不同,重新设置 EffectLodLevel effectLevel = effectScript.lodLevel; EffectLodLevel curLevel = EffectManager.Instance.mLodLevel; if (effectLevel != curLevel) { //调整特效显示等级 AdjustEffectLodLevel(curLevel); } }
void OnEffectShake(EffectScript firedEffect) { ShakeDuration = firedEffect.lifeTime; if (ShakeAmplitude < maxShakeAmp) { ShakeAmplitude += firedEffect.shakeAmp; } if (ShakeFrequency < maxShakeFreq) { ShakeFrequency += firedEffect.shakeFreq; } ShakeElapsedTime = ShakeDuration; }
// Activates a card public void ActivateCard(CardScript cardScript, Message message) { EffectScript.AffectsList(cardScript.myPlayEffects, message); /*myFrameData.myCardsPlayed++; * myTurnData.myFrameData.myCardsPlayed++; * myMatchData.myTurnData.myFrameData.myCardsPlayed++; * * GlobalScript.ourPlayerFrameData.myCardsPlayed++; * GlobalScript.ourPlayerTurnData.myFrameData.myCardsPlayed++; * GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myCardsPlayed++;*/ switch (cardScript.myType) { case CardScript.Type.Spell: /*myFrameData.mySpellsCast++; * myTurnData.myFrameData.mySpellsCast++; * myMatchData.myTurnData.myFrameData.mySpellsCast++; * * GlobalScript.ourPlayerFrameData.mySpellsCast++; * GlobalScript.ourPlayerTurnData.myFrameData.mySpellsCast++; * GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.mySpellsCast++;*/ break; case CardScript.Type.Item: /*myFrameData.myItemsUsed++; * myTurnData.myFrameData.myItemsUsed++; * myMatchData.myTurnData.myFrameData.myItemsUsed++; * * GlobalScript.ourPlayerFrameData.myItemsUsed++; * GlobalScript.ourPlayerTurnData.myFrameData.myItemsUsed++; * GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myItemsUsed++;*/ break; case CardScript.Type.Unit: /*myFrameData.myUnitsMade++; * myTurnData.myFrameData.myUnitsMade++; * myMatchData.myTurnData.myFrameData.myUnitsMade++; * * GlobalScript.ourPlayerFrameData.myUnitsMade++; * GlobalScript.ourPlayerTurnData.myFrameData.myUnitsMade++; * GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myUnitsMade++;*/ break; } }
private static EffectScript LoadEffect(Stream stream) { CSScript script = new CSScript(); script.Source = LoadText(stream); HeightRender.Effect effect; string errors; HeightRender.CompileEffect(script, out effect, out errors); EffectScript es = new EffectScript() { effect = effect, script = script }; return(es); }
public CardScript RemoveCard(CardScript input, bool discard = false) { if (input.transform.IsChildOf(transform)) { input.myHandScript = null; Reanimate(); if (discard) { EffectScript.AffectsList(input.myRemoveEffects, myOwningPlayer.ToMessage()); } return(input); } return(null); }
public void Death() { /*myOwningPlayer.myFrameData.myDeaths++; * myOwningPlayer.myTurnData.myFrameData.myDeaths++; * myOwningPlayer.myMatchData.myTurnData.myFrameData.myDeaths++; * * GlobalScript.ourPlayerFrameData.myDeaths++; * GlobalScript.ourPlayerTurnData.myFrameData.myDeaths++; * GlobalScript.ourPlayerMatchData.myTurnData.myFrameData.myDeaths++;*/ EffectScript.AffectsList(myDeathEffects, ToMessage()); myDeathMessenger.Publish(); myNavMeshAgent.speed = 0f; Destroy(gameObject, 10f); }
public static float AffectsList(EffectScript[] list, Message message, float input = 0f) { if(null == list) { return input; } for(int i = 0; i < list.Length; i ++) { if(null == list[i]) { continue; } input = list[i].Affect(message, input); } return input; }
public static EffectScript[] Append(EffectScript[] list, EffectScript input, int inch = 2) { // Handle idiots inching wrong inch = inch < 1 ? 1 : inch; // Handle null list, i.e. // "Make me a new list and put this on it" if (null == list) { list = new EffectScript[2]; list[0] = input; return list; } else { // Find a null indeces to recycle for (int i = 0; i < list.Length; i++) { if (null == list[i]) { list[i] = input; return list; } } // No vacancies, so make a new list EffectScript[] newList = new EffectScript[list.Length + 2]; // Put old values into new list for (int i = 0; i < list.Length; i++) { newList[i] = list[i]; } // Put input on new list newList[list.Length] = input; //return new list return newList; } }
public static EffectScript[] Append(EffectScript[] list, EffectScript input, int inch = 2) { // Handle idiots inching wrong inch = inch < 1 ? 1 : inch; // Handle null list, i.e. // "Make me a new list and put this on it" if (null == list) { list = new EffectScript[2]; list[0] = input; return(list); } else { // Find a null indeces to recycle for (int i = 0; i < list.Length; i++) { if (null == list[i]) { list[i] = input; return(list); } } // No vacancies, so make a new list EffectScript[] newList = new EffectScript[list.Length + 2]; // Put old values into new list for (int i = 0; i < list.Length; i++) { newList[i] = list[i]; } // Put input on new list newList[list.Length] = input; //return new list return(newList); } }
protected override void afterUpdateObject() { base.afterUpdateObject(); setProjectorEffectSize(mProjSize); if (mGameObject != null) { Projector theProj = (Projector)mGameObject.GetComponent(typeof(Projector)); if (theProj) { theProj.ignoreLayers = ~LayerManager.GroundMask; } //查看是否有EffectScript脚本 EffectScript lifeScript = (EffectScript)mGameObject.GetComponent("EffectScript"); if (lifeScript) { mHasLife = lifeScript.UseLifeTime; mLifeTime = lifeScript.LifeTime; } } }
/// <summary> /// 피격 효과 객체를 생성합니다. /// </summary> /// <returns>피격 효과 객체입니다.</returns> protected GameObject MakeHitParticle_dep() { GameObject hitParticle = Instantiate (effects[0], transform.position, transform.rotation) as GameObject; // 버스터 속도의 반대쪽으로 적절히 x 반전합니다. if (_rigidbody.velocity.x < 0) { Vector3 newScale = hitParticle.transform.localScale; newScale.x *= -1; hitParticle.transform.localScale = newScale; } // 효과음을 재생합니다. EffectScript hitEffect = hitParticle.GetComponent <EffectScript>(); hitEffect.PlayEffectSound(SoundEffects[0].clip); // 생성한 효과 객체를 반환합니다. return(hitParticle); }
/// <summary> /// 피격 효과 객체를 생성합니다. /// </summary> /// <returns>피격 효과 객체입니다.</returns> protected virtual GameObject MakeHitParticle(bool right, Transform transform) { GameObject hitParticle = Instantiate (_HitParticle, transform.position, transform.rotation) as GameObject; // 버스터 속도의 반대쪽으로 적절히 x 반전합니다. if (right) { Vector3 newScale = hitParticle.transform.localScale; newScale.x *= -1; hitParticle.transform.localScale = newScale; } // 효과음을 재생합니다. EffectScript hitEffect = hitParticle.GetComponent <EffectScript>(); hitEffect.PlayEffectSound(SoundEffects[1].clip); // 생성한 효과 객체를 반환합니다. return(hitParticle); }
/// <summary> /// 피격 효과 객체를 생성합니다. /// </summary> /// <returns>피격 효과 객체입니다.</returns> protected GameObject MakeReflectedParticle(bool right, Vector3 position) { GameObject particle = Instantiate (_ReflectedParticle, position, transform.rotation) as GameObject; // 버스터 속도의 반대쪽으로 적절히 x 반전합니다. if (right) { Vector3 newScale = particle.transform.localScale; newScale.x *= -1; particle.transform.localScale = newScale; } // 효과음을 재생합니다. EffectScript hitEffect = particle.GetComponent <EffectScript>(); hitEffect.PlayEffectSound(SoundEffects[0].clip); // 생성한 효과 객체를 반환합니다. return(particle); }
//hits something void OnCollisionEnter(Collision collision) { UnitScript unitScript = collision.gameObject.GetComponent <UnitScript>(); if (null == unitScript) { return; } bool deleting = false; if (null == myMessage.mySubject) { } else if (false == mySelfTrigger && unitScript == myMessage.mySubject.myUnitScript) { return; } if (false == myAllyTrigger && unitScript.myOwner == myMessage.mySubject.myPlayerScript) { return; } myMessage.myObject = unitScript.ToTerm(); EffectScript.AffectsList(myHitUnit, myMessage); if (myDeleteOnUnit) { deleting = true; } if (deleting) { Destroy(gameObject); } }
/// <summary> /// 폭발 효과 개체를 생성합니다. /// </summary> /// <param name="position">폭발 효과 개체를 생성할 위치입니다.</param> void CreateExplosion(Vector3 position) { EffectScript effect = DataBase.Instance.Explosion1Effect; switch (UnityEngine.Random.Range(0, 3)) { case 0: effect = DataBase.Instance.Explosion1Effect; break; case 1: effect = DataBase.Instance.Explosion2Effect; break; case 2: effect = DataBase.Instance.Explosion3Effect; break; default: effect = DataBase.Instance.Explosion4Effect; break; } Instantiate(effect, position, transform.rotation); }
/// <summary> /// 폭발 효과 개체를 생성합니다. /// </summary> /// <param name="position">폭발 효과 개체를 생성할 위치입니다.</param> void CreateExplosion(Vector3 position) { EffectScript effect = DataBase.Instance.Explosion1Effect; Instantiate(effect, position, transform.rotation); }
//特效创建接口 public void Create() { //创建的时候检查特效projectId,服务器没有设置生成本地id CheckProjectId(); //获取特效模板名称 templateName = ResourceCommon.getResourceName(resPath); //使用特效缓存机制 obj = GameObjectPool.Instance.GetGO(resPath); ////使用特效缓存机制但是无缓存特效或者 不使用缓存特效 //if ((EffectManager.Instance.CachEffect && obj == null) ||(!EffectManager.Instance.CachEffect)) //{ // //每次重新创建 // ResourceUnit unit = ResourcesManager.Instance.loadImmediate(resPath, ResourceType.PREFAB); // if (null == unit.Asset) // { // Debug.LogError("load PREFAB failed in IEffect::Create" + resPath); // return; // } // obj = GameObject.Instantiate(unit.Asset) as GameObject; //} if (null == obj) { Debugger.LogError("load effect object failed in IEffect::Create" + resPath); return; } //创建完成,修改特效名称,便于调试 obj.name = templateName + "_" + projectID.ToString(); OnLoadComplete(); //获取美术特效脚本信息 effectScript = obj.GetComponent <EffectScript>(); if (effectScript == null) { Debugger.LogError("cant not find the effect script in " + resPath); return; } artTime = effectScript.lifeTime; //美术配置时间为0,使用策划时间 if (effectScript.lifeTime == 0) { lifeTime = cehuaTime; } //否则使用美术时间 else { lifeTime = artTime; } //特效等级不同,重新设置 EffectLodLevel effectLevel = effectScript.lodLevel; EffectLodLevel curLevel = EffectManager.Instance.mLodLevel; if (effectLevel != curLevel) { //调整特效显示等级 AdjustEffectLodLevel(curLevel); } }
//Loading public static bool Load(string path) { Clear(); if (File.Exists(path)) { FileStream stream = new FileStream(path, FileMode.Open); try { byte[] countBuf = new byte[4]; int count; //Load Renders stream.Read(countBuf, 0, sizeof(int)); count = BitConverter.ToInt32(countBuf, 0); for (int i = 0; i < count; i++) { string name = LoadText(stream); HeightRender render = LoadRender(stream); SetRender(name, render); } //Load Gradients stream.Read(countBuf, 0, sizeof(int)); count = BitConverter.ToInt32(countBuf, 0); for (int i = 0; i < count; i++) { string name = LoadText(stream); PhotonGradient gradient = LoadGradient(stream); SetGradient(name, gradient); } //Load Effects stream.Read(countBuf, 0, sizeof(int)); count = BitConverter.ToInt32(countBuf, 0); for (int i = 0; i < count; i++) { string name = LoadText(stream); EffectScript es = LoadEffect(stream); SetEffect(name, es.effect, es.script); } //Load Brushes stream.Read(countBuf, 0, sizeof(int)); count = BitConverter.ToInt32(countBuf, 0); for (int i = 0; i < count; i++) { string name = LoadText(stream); BrushScript bs = LoadBrush(stream); SetBrush(name, bs.brush, bs.script); } //Path and Callback associatedPath = path; if (loaded != null) { loaded(path); } return(true); } catch { associatedPath = null; return(false); } finally { stream.Close(); } } else { associatedPath = path; return(false); } }
private static void SaveEffect(Stream stream, EffectScript effect) { SaveText(stream, effect.script.Source); }
private void HandleHeroInit(HeroRecord record) { //Preload resources List<HeroData> dataList = heroProxy.GetAllHeroDataList(); for (int i = 0; i < dataList.Count; ++i) { HeroData heroData = dataList[i]; ResourceManager.Instance.PreloadAsset(ObjectType.GameObject, heroData.GetResPath()); } ResourceManager.Instance.PreloadAsset(ObjectType.GameObject, "Effects/ConversionEffect"); //Init if(record == null) { int heroKid = IDManager.Instance.GetID(IDType.Hero, 1); hero = Hero.Create(heroKid, null); MazeData mazeData = MazeDataManager.Instance.CurrentMazeData; Vector3 startPosition = MazeUtil.GetWorldPosition(mazeData.StartCol, mazeData.StartRow, mazeData.BlockSize); hero.SetPosition(startPosition); } else { hero = Hero.Create(record); hero.SetPosition(record.WorldPosition.ToVector3()); hero.SetRotation(record.WorldAngle); hero.Info.IsInHall = record.IsInHall; hero.IsVisible = record.IsVisible; } hero.CallbackDie = OnHeroDie; //Battle BattleProxy battleProxy = ApplicationFacade.Instance.RetrieveProxy<BattleProxy>(); battleProxy.SetHero(hero); //Conversion convertEffect = ResourceManager.Instance.LoadAsset<EffectScript>(ObjectType.GameObject, "Effects/ConversionEffect"); convertEffect.Deactive(); //Input // InputManager.Instance.SetKeyboardAction(KeyboardActionType.Attack, OnHeroAttack); // InputManager.Instance.SetKeyboardAction(KeyboardActionType.Function, OnHeroFunction); hero.Info.AddHP(999999); }
//Loading public static IOEvaluation Load(string path) { Clear(); if (File.Exists(path)) { FileStream stream = null; try { stream = new FileStream(path, FileMode.Open); } catch { return(IOEvaluation.CannotOpenStream); } try { IOBlockIdentifier block; string blockName; byte[] blockBuff = new byte[sizeof(int)]; stream.Read(blockBuff, 0, sizeof(int)); block = (IOBlockIdentifier)BitConverter.ToInt32(blockBuff, 0); if (block == IOBlockIdentifier.FileBegin) { do { if (stream.Position < stream.Length) { stream.Read(blockBuff, 0, sizeof(int)); block = (IOBlockIdentifier)BitConverter.ToInt32(blockBuff, 0); switch (block) { case IOBlockIdentifier.FileEnd: break; case IOBlockIdentifier.Brush: blockName = LoadText(stream); BrushScript bs = LoadBrush(stream); SetBrush(blockName, bs.brush, bs.script); break; case IOBlockIdentifier.Effect: blockName = LoadText(stream); EffectScript es = LoadEffect(stream); SetEffect(blockName, es.effect, es.script); break; case IOBlockIdentifier.Gradient: blockName = LoadText(stream); PhotonGradient gradient = LoadGradient(stream); SetGradient(blockName, gradient); break; case IOBlockIdentifier.Render: blockName = LoadText(stream); HeightRender render = LoadRender(stream); SetRender(blockName, render); break; case IOBlockIdentifier.Generator: blockName = LoadText(stream); GeneratorScript gs = LoadGenerator(stream); SetGenerator(blockName, gs.generator, gs.script); break; default: throw new Exception("Encountered a block that couldn't be identified."); } } else { throw new Exception("The end of the file was reached before the appropriate 'End of File' flag was found."); } }while (block != IOBlockIdentifier.FileEnd); //Path and Callback associatedPath = path; if (loaded != null) { loaded(path); } return(IOEvaluation.Success); } else { return(IOEvaluation.ConversionError); } } catch { Clear(); return(IOEvaluation.ConversionError); } finally { stream.Close(); } } else { associatedPath = path; return(IOEvaluation.FileDoesNotExist); } }
public void destroyAllAroundRegular(int side, int row) { int leftSide = 0; int rightSide = 0; if (side == 0) { leftSide = 5; } else { leftSide = side - 1; } if (side == 5) { rightSide = 0; } else { rightSide = side + 1; } //Top left if (grid [leftSide, row + 1] != null) { connectedGameObjectsRow.Add(row + 1); connectedGameObjectsSide.Add(leftSide); } //Top Right if (grid [rightSide, row + 1] != null) { connectedGameObjectsRow.Add(row + 1); connectedGameObjectsSide.Add(rightSide); } //Left if (grid [leftSide, row] != null) { connectedGameObjectsRow.Add(row); connectedGameObjectsSide.Add(leftSide); } //Right if (grid [rightSide, row] != null) { connectedGameObjectsRow.Add(row); connectedGameObjectsSide.Add(rightSide); } //Bottom Left if (grid [leftSide, row - 1] != null) { connectedGameObjectsRow.Add(row - 1); connectedGameObjectsSide.Add(leftSide); } //Bottom Middle if (grid [side, row - 1] != null) { connectedGameObjectsRow.Add(row - 1); connectedGameObjectsSide.Add(side); } //Bottom Right if (grid [rightSide, row - 1] != null) { connectedGameObjectsRow.Add(row - 1); connectedGameObjectsSide.Add(rightSide); } score += Mathf.CeilToInt(connectedGameObjectsRow.Count * 10f * Time.timeSinceLevelLoad); PauseManager.text.text = "" + score; for (int i = 0; i < connectedGameObjectsRow.Count; i++) { if (grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.childCount > 3) { grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.GetChild(3). SetParent(PauseManager.canvas.transform); } Destroy(grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]]); EffectScript.playDestroy(); grid [(int)connectedGameObjectsSide [i], (int)connectedGameObjectsRow [i]] = null; } connectedGameObjectsRow = new ArrayList(); connectedGameObjectsSide = new ArrayList(); ContinueFlowOfGame(); }
/** * @brief This function is a recursive algorithm that destroys blocks that are within * a connection of three or greater. After all checks are completed, the game objects are destroyed. * */ void floodfill(int side, int row, string rootObjectType) { //adds the trapezoid game object to the connectedGameObjectsRow.Add(row); connectedGameObjectsSide.Add(side); visited[side, row] = true; //Right Side if (side == 5) { int wrapAround = 0; if (grid [wrapAround, row] != null && grid [wrapAround, row].name == rootObjectType && visited [wrapAround, row] == false) { floodfill(wrapAround, row, rootObjectType); } } else { if (grid [side + 1, row] != null && grid [side + 1, row].name == rootObjectType && visited [side + 1, row] == false) { floodfill(side + 1, row, rootObjectType); } } //left side if (side == 0) { int leftWrapAround = 5; if (grid [leftWrapAround, row] != null && grid [leftWrapAround, row].name == rootObjectType && visited [leftWrapAround, row] == false) { floodfill(leftWrapAround, row, rootObjectType); } } else { if (grid [side - 1, row] != null && grid [side - 1, row].name == rootObjectType && visited [side - 1, row] == false) { floodfill(side - 1, row, rootObjectType); } } //down if (row > 0) { if (grid [side, row - 1] != null && grid [side, row - 1].name == rootObjectType && visited [side, row - 1] == false) { floodfill(side, row - 1, rootObjectType); } } //up if (row < 7) { if (grid [side, row + 1] != null && grid [side, row + 1].name == rootObjectType && visited [side, row + 1] == false) { floodfill(side, row + 1, rootObjectType); } } //Ending and checking if (side == enteringSide && row == enteringRow) { if (connectedGameObjectsRow.Count >= 3) { score += Mathf.CeilToInt(connectedGameObjectsRow.Count * 10f * Time.timeSinceLevelLoad); PauseManager.text.text = "" + score; for (int i = 0; i < connectedGameObjectsRow.Count; i++) { if (grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.childCount > 3) { grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.GetChild(3). SetParent(PauseManager.canvas.transform); } Destroy(grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]]); EffectScript.playDestroy(); grid [(int)connectedGameObjectsSide [i], (int)connectedGameObjectsRow [i]] = null; } } //Resets the visited array and connected game objects array visited = new bool[6, 8]; connectedGameObjectsRow = new ArrayList(); connectedGameObjectsSide = new ArrayList(); } }