//Recursive script destroyer private void destroyScript(Transform go, bool refund = false) { //refund blocActionLimit if (refund && go.gameObject.GetComponent <UIActionType>() != null) { ActionManipulator.updateActionBlocLimit(gameData, go.gameObject.GetComponent <UIActionType>().type, 1); } else if (go.gameObject.GetComponent <UIActionType>() != null) { gameData.totalActionBloc++; } if (go.gameObject.GetComponent <UITypeContainer>() != null) { for (int i = 0; i < go.childCount; i++) { destroyScript(go.GetChild(i)); } } for (int i = 0; i < go.transform.childCount; i++) { Object.Destroy(go.transform.GetChild(i).gameObject); } go.transform.DetachChildren(); GameObjectManager.unbind(go.gameObject); Object.Destroy(go.gameObject); }
private GameObject createEntity(int i, int j, Direction.Dir direction, int type, List <Action> script = null, bool repeat = false) { GameObject entity = null; switch (type) { case 0: entity = Object.Instantiate <GameObject>(Resources.Load("Prefabs/Robot Kyle") as GameObject, gameData.Level.transform.position + new Vector3(i * 3, 1.5f, j * 3), Quaternion.Euler(0, 0, 0), gameData.Level.transform); break; case 1: entity = Object.Instantiate <GameObject>(Resources.Load("Prefabs/Ennemy") as GameObject, gameData.Level.transform.position + new Vector3(i * 3, 3, j * 3), Quaternion.Euler(0, 0, 0), gameData.Level.transform); break; case 2: entity = Object.Instantiate <GameObject>(Resources.Load("Prefabs/Drone") as GameObject, gameData.Level.transform.position + new Vector3(i * 3, 5f, j * 3), Quaternion.Euler(0, 0, 0), gameData.Level.transform); break; } entity.GetComponent <Position>().x = i; entity.GetComponent <Position>().z = j; entity.GetComponent <Direction>().direction = direction; ActionManipulator.resetScript(entity.GetComponent <Script>()); if (script != null) { entity.GetComponent <Script>().actions = script; } entity.GetComponent <Script>().repeat = repeat; GameObjectManager.bind(entity); return(entity); }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { if (gameData.step) { foreach (GameObject go in controllableGO) { if (!ActionManipulator.endOfScript(go)) { Action action = ActionManipulator.getCurrentAction(go); switch (action.actionType) { case Action.ActionType.Forward: ApplyForward(go); break; case Action.ActionType.TurnLeft: ApplyTurnLeft(go); break; case Action.ActionType.TurnRight: ApplyTurnRight(go); break; case Action.ActionType.Wait: break; case Action.ActionType.Activate: foreach (GameObject actGo in activableGO) { if (actGo.GetComponent <Position>().x == go.GetComponent <Position>().x&& actGo.GetComponent <Position>().z == go.GetComponent <Position>().z) { actGo.GetComponent <AudioSource>().Play(); actGo.GetComponent <Activable>().isActivated = true; } } break; } ActionManipulator.incrementActionScript(go.GetComponent <Script>()); } } /*foreach( GameObject go in playerGO){ * if(ActionManipulator.endOfScript(go)){ * ActionManipulator.restartScript(go.GetComponent<Script>()); * } * }*/ } }
private void generateLevel4() { eraseMap(); map = new List <List <int> > { new List <int> { 1, 1, 1, 1, 1 }, new List <int> { 1, 0, 0, 3, 1 }, new List <int> { 1, 0, 1, 1, 1 }, new List <int> { 1, 2, 1, 1, 1 }, new List <int> { 1, 1, 1, 1, 1 } }; generateMap(); createEntity(3, 1, Direction.Dir.West, 0); List <Action> script = new List <Action>(); script.Add(ActionManipulator.createAction(Action.ActionType.Wait)); script.Add(ActionManipulator.createAction(Action.ActionType.Wait)); script.Add(ActionManipulator.createAction(Action.ActionType.TurnLeft)); script.Add(ActionManipulator.createAction(Action.ActionType.Wait)); script.Add(ActionManipulator.createAction(Action.ActionType.Wait)); script.Add(ActionManipulator.createAction(Action.ActionType.TurnRight)); GameObject camera = createEntity(1, 1, Direction.Dir.East, 2, script, true); camera.GetComponent <DetectRange>().range = 1; gameData.dialogMessage.Add("Attention il y a une caméra devant toi ! Par chance son champ de détection est très petit, mais elle te bloque tout de même le passage."); gameData.dialogMessage.Add("Il semblerait que cette caméra a une IA, clique dessus pour analyser son comportement pour y trouver une faille et passer. De plus ce modèle de caméra ne semble pas voir en dessous d'elle même."); gameData.actionBlocLimit = new List <int>() { -1, -1, -1, -1, -1, -1 }; }
public static bool ContainerToActionList(Action act, GameObject obj) { bool nonEmpty = false; for (int i = 1; i < obj.transform.childCount; i++) { GameObject child = obj.transform.GetChild(i).gameObject; if (child.GetComponent <UIActionType>().type == Action.ActionType.For) { Action forAct = ActionManipulator.createAction(child.GetComponent <UIActionType>().type); forAct.nbFor = int.Parse(child.transform.GetChild(0).transform.GetChild(1).GetComponent <InputField>().text); if (forAct.nbFor > 0 && child.transform.childCount > 1 && ContainerToActionList(forAct, child)) { ActionManipulator.addAction(act, forAct); nonEmpty = true; } } else if (child.GetComponent <UIActionType>().type == Action.ActionType.If) { Action IfAct = ActionManipulator.createAction(child.GetComponent <UIActionType>().type); IfAct.ifEntityType = child.transform.GetChild(0).GetChild(1).GetChild(1).GetComponent <Dropdown>().value; IfAct.ifDirection = child.transform.GetChild(0).GetChild(1).GetChild(2).GetComponent <Dropdown>().value; IfAct.range = int.Parse(child.transform.GetChild(0).GetChild(1).GetChild(3).GetComponent <InputField>().text); IfAct.ifNot = (child.transform.GetChild(0).GetChild(2).GetComponent <Dropdown>().value == 1); IfAct.ifValid = false; if (child.transform.childCount > 1 && ContainerToActionList(IfAct, child)) { ActionManipulator.addAction(act, IfAct); nonEmpty = true; } } else { ActionManipulator.addAction(act, ActionManipulator.createAction(child.GetComponent <UIActionType>().type)); nonEmpty = true; } } return(nonEmpty); }
//Convert the UI script in a usable script public static List <Action> ScriptContainerToActionList(GameObject scriptComposer) { List <Action> l = new List <Action>(); for (int i = 0; i < scriptComposer.transform.childCount; i++) { GameObject child = scriptComposer.transform.GetChild(i).gameObject; if (child.GetComponent <UIActionType>().type == Action.ActionType.For) { Action forAct = ActionManipulator.createAction(child.GetComponent <UIActionType>().type); forAct.nbFor = int.Parse(child.transform.GetChild(0).transform.GetChild(1).GetComponent <InputField>().text); if (forAct.nbFor > 0 && child.transform.childCount > 1 && ContainerToActionList(forAct, child)) { l.Add(forAct); } } else if (child.GetComponent <UIActionType>().type == Action.ActionType.If) { Action IfAct = ActionManipulator.createAction(child.GetComponent <UIActionType>().type); IfAct.ifEntityType = child.transform.GetChild(0).GetChild(1).GetChild(1).GetComponent <Dropdown>().value; IfAct.ifDirection = child.transform.GetChild(0).GetChild(1).GetChild(2).GetComponent <Dropdown>().value; IfAct.range = int.Parse(child.transform.GetChild(0).GetChild(1).GetChild(3).GetComponent <InputField>().text); IfAct.ifValid = false; IfAct.ifNot = (child.transform.GetChild(0).GetChild(2).GetComponent <Dropdown>().value == 1); if (child.transform.childCount > 1 && ContainerToActionList(IfAct, child)) { l.Add(IfAct); } } else { l.Add(ActionManipulator.createAction(child.GetComponent <UIActionType>().type)); } } return(l); }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { //Change the higlighted action every step if (gameData.checkStep && scriptInWindow) { foreach (Transform child in EnemyScriptContainer.transform) { GameObject.Destroy(child.gameObject); } ActionManipulator.ScriptToContainer(scriptInWindow.GetComponent <Script>(), EnemyScriptContainer); } //If click on highlighted item and item has a script, then show script in the 2nd script window if (highLightedItem && Input.GetMouseButtonDown(0) && highLightedItem.GetComponent <Script>()) { foreach (Transform child in EnemyScriptContainer.transform) { GameObject.Destroy(child.gameObject); } scriptInWindow = highLightedItem; GameObject.Find("EnemyScript").GetComponent <AudioSource>().Play(); ActionManipulator.ScriptToContainer(highLightedItem.GetComponent <Script>(), EnemyScriptContainer); } }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { //Activate EndPanel if (gameData.endLevel != 0 && !endPanel.activeSelf) { endPanel.SetActive(true); switch (gameData.endLevel) { case 1: endPanel.transform.GetChild(0).GetComponent <Text>().text = "Vous avez été repéré !"; endPanel.transform.GetChild(3).gameObject.SetActive(false); endPanel.GetComponent <AudioSource>().clip = Resources.Load("Sound/LoseSound") as AudioClip; endPanel.GetComponent <AudioSource>().loop = true; endPanel.GetComponent <AudioSource>().Play(); break; case 2: //endPanel.transform.GetChild(0).GetComponent<Text>().text = "Bravo vous avez gagné !\n Nombre d'instructions: "+ //gameData.totalActionBloc + "\nNombre d'étape: " + gameData.totalStep +"\nPièces récoltées:" + gameData.totalCoin; endPanel.transform.GetChild(0).GetComponent <Text>().text = "Bravo vous avez gagné !\nScore: " + (10000 / (gameData.totalActionBloc + 1) + 5000 / (gameData.totalStep + 1) + 6000 / (gameData.totalExecute + 1) + 5000 * gameData.totalCoin); endPanel.GetComponent <AudioSource>().clip = Resources.Load("Sound/VictorySound") as AudioClip; endPanel.GetComponent <AudioSource>().loop = false; endPanel.GetComponent <AudioSource>().Play(); //End if (gameData.levelToLoad >= gameData.levelList.Count - 1) { endPanel.transform.GetChild(3).gameObject.SetActive(false); } break; } } //Activate DialogPanel if there is a message if (gameData.dialogMessage.Count > 0 && !dialogPanel.activeSelf) { showDialogPanel(); } //Desactivate Execute & ResetButton if there is a script running if (gameData.nbStep > 0) { gameData.ButtonExec.GetComponent <Button>().interactable = false; gameData.ButtonReset.GetComponent <Button>().interactable = false; } else { gameData.ButtonExec.GetComponent <Button>().interactable = true; gameData.ButtonReset.GetComponent <Button>().interactable = true; } //Update LimitText for (int i = 0; i < limitTexts.Count; i++) { if (gameData.actionBlocLimit[i] >= 0) { limitTexts[i].GetComponent <Text>().text = "Reste\n" + gameData.actionBlocLimit[i].ToString(); //desactivate actionBlocs if (gameData.actionBlocLimit[i] == 0) { limitTexts[i].transform.parent.GetComponent <Image>().raycastTarget = false; } else { limitTexts[i].transform.parent.GetComponent <Image>().raycastTarget = true; } } } //Drag foreach (GameObject go in PointedGO) { if (Input.GetMouseButtonDown(0)) { itemDragged = Object.Instantiate <GameObject>(go.GetComponent <ElementToDrag>().actionPrefab, go.transform); GameObjectManager.bind(itemDragged); itemDragged.GetComponent <Image>().raycastTarget = false; break; } } if (itemDragged != null) { itemDragged.transform.position = Input.mousePosition; } //Find the container with the last layer GameObject priority = null; foreach (GameObject go in ContainersGO) { if (priority == null || priority.GetComponent <UITypeContainer>().layer < go.GetComponent <UITypeContainer>().layer) { priority = go; } } //PositionBar positioning if (priority && itemDragged) { int start = 0; if (priority.GetComponent <UITypeContainer>().type != UITypeContainer.Type.Script) { start++; } positionBar.SetActive(true); positionBar.transform.SetParent(priority.transform); positionBar.transform.SetSiblingIndex(priority.transform.childCount - 1); for (int i = start; i < priority.transform.childCount; i++) { if (priority.transform.GetChild(i).gameObject != positionBar && Input.mousePosition.y > priority.transform.GetChild(i).position.y) { positionBar.transform.SetSiblingIndex(i); break; } } } else { positionBar.transform.SetParent(GameObject.Find("PlayerScript").transform); positionBar.SetActive(false); } //Delete if (!itemDragged && Input.GetMouseButtonUp(1)) { priority = null; foreach (GameObject go in UIScriptPointedGO) { if (!priority || !go.GetComponent <UITypeContainer>() || priority.GetComponent <UITypeContainer>().layer < go.GetComponent <UITypeContainer>().layer) { priority = go; } } if (priority) { destroyScript(priority.transform, true); } priority = null; } //Drop if (Input.GetMouseButtonUp(0)) { //Drop in script if (priority != null && itemDragged != null) { itemDragged.transform.SetParent(priority.transform); itemDragged.transform.SetSiblingIndex(positionBar.transform.GetSiblingIndex()); itemDragged.GetComponent <Image>().raycastTarget = true; //update limit bloc ActionManipulator.updateActionBlocLimit(gameData, itemDragged.GetComponent <UIActionType>().type, -1); if (itemDragged.GetComponent <UITypeContainer>() != null) { itemDragged.GetComponent <Image>().raycastTarget = true; itemDragged.GetComponent <UITypeContainer>().layer = priority.GetComponent <UITypeContainer>().layer + 1; } GameObject.Find("PlayerScript").GetComponent <AudioSource>().Play(); refreshUI(); } else if (itemDragged != null) { for (int i = 0; i < itemDragged.transform.childCount; i++) { Object.Destroy(itemDragged.transform.GetChild(i).gameObject); } itemDragged.transform.DetachChildren(); GameObjectManager.unbind(itemDragged); Object.Destroy(itemDragged); } itemDragged = null; } }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { if (gameData.checkStep) { //Check if the player is on the end of the level int nbEnd = 0; foreach (GameObject player in playerGO) { foreach (GameObject exit in exitGO) { if (gameData.nbStep == 1 && player.GetComponent <Position>().x == exit.GetComponent <Position>().x&& player.GetComponent <Position>().z == exit.GetComponent <Position>().z) { nbEnd++; //end level if (nbEnd >= playerGO.Count) { Debug.Log("Fin du niveau"); gameData.endLevel = 2; } } } } //Check Activations foreach (GameObject activable in activableGO) { if (activable.GetComponent <Activable>().isActivated&& !activable.GetComponent <Activable>().isFullyActivated) { activate(activable); } } //Check if If actions are valid int nbStepToAdd = 0; foreach (GameObject scripted in scriptedGO) { int nbStepPlayer = 0; ActionManipulator.invalidAllIf(scripted.GetComponent <Script>()); Action nextIf = ActionManipulator.getCurrentIf(scripted); while (nextIf != null && !ActionManipulator.endOfScript(scripted)) { //Check if ok bool ifok = nextIf.ifNot; Vector2 vec = new Vector2(); switch (ActionManipulator.getDirection(scripted.GetComponent <Direction>().direction, nextIf.ifDirection)) { case Direction.Dir.North: vec = new Vector2(0, 1); break; case Direction.Dir.South: vec = new Vector2(0, -1); break; case Direction.Dir.East: vec = new Vector2(1, 0); break; case Direction.Dir.West: vec = new Vector2(-1, 0); break; } switch (nextIf.ifEntityType) { case 0: for (int i = 1; i <= nextIf.range; i++) { foreach (GameObject go in wallGO) { if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i) { ifok = !nextIf.ifNot; } } } break; case 1: for (int i = 1; i <= nextIf.range; i++) { foreach (GameObject go in scriptedGO) { if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i && go.tag == "Ennemy") { ifok = !nextIf.ifNot; } } } break; case 2: for (int i = 1; i <= nextIf.range; i++) { foreach (GameObject go in scriptedGO) { if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i && go.tag == "Player") { ifok = !nextIf.ifNot; } } } break; } if (ifok) { nextIf.ifValid = true; if (scripted.tag == "Player") { nbStepPlayer += ActionManipulator.getNbStep(nextIf, true); } } else { nextIf.currentAction = nextIf.actions.Count - 1; ActionManipulator.incrementActionScript(scripted.GetComponent <Script>()); } nextIf = ActionManipulator.getCurrentIf(scripted); } if (nbStepPlayer > nbStepToAdd) { nbStepToAdd = nbStepPlayer; } } gameData.nbStep += nbStepToAdd; foreach (GameObject player in playerGO) { //Check if the player collide with a non-player /*foreach( GameObject noPlayer in noPlayerGO){ * if(player.GetComponent<Position>().x == noPlayer.GetComponent<Position>().x && player.GetComponent<Position>().z == noPlayer.GetComponent<Position>().z){ * //end level * Debug.Log("Repéré !"); * gameData.endLevel = 1; * } * }*/ //Check if the player collide with a detection cell foreach (GameObject detector in detectorGO) { if (player.GetComponent <Position>().x == detector.GetComponent <Position>().x&& player.GetComponent <Position>().z == detector.GetComponent <Position>().z) { //end level Debug.Log("Repéré !"); gameData.endLevel = 1; } } } } }
public void applyScriptToPlayer() { foreach (GameObject go in playerGO) { ActionManipulator.resetScript(go.GetComponent <Script>()); go.GetComponent <Script>().actions = ActionManipulator.ScriptContainerToActionList(scriptComposer); gameData.nbStep = ActionManipulator.getNbStep(go.GetComponent <Script>()); } //Check if If actions are valid int nbStepToAdd = 0; foreach (GameObject scripted in controllableGO) { int nbStepPlayer = 0; ActionManipulator.invalidAllIf(scripted.GetComponent <Script>()); Action nextIf = ActionManipulator.getCurrentIf(scripted); while (nextIf != null && !ActionManipulator.endOfScript(scripted)) { //Check if ok bool ifok = nextIf.ifNot; Vector2 vec = new Vector2(); switch (ActionManipulator.getDirection(scripted.GetComponent <Direction>().direction, nextIf.ifDirection)) { case Direction.Dir.North: vec = new Vector2(0, 1); break; case Direction.Dir.South: vec = new Vector2(0, -1); break; case Direction.Dir.East: vec = new Vector2(1, 0); break; case Direction.Dir.West: vec = new Vector2(-1, 0); break; } switch (nextIf.ifEntityType) { case 0: for (int i = 1; i <= nextIf.range; i++) { foreach (GameObject go in wallGO) { if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i) { ifok = !nextIf.ifNot; } } } break; case 1: for (int i = 1; i <= nextIf.range; i++) { foreach (GameObject go in controllableGO) { if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i && go.tag == "Ennemy") { ifok = !nextIf.ifNot; } } } break; case 2: for (int i = 1; i <= nextIf.range; i++) { foreach (GameObject go in controllableGO) { if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i && go.tag == "Player") { ifok = !nextIf.ifNot; } } } break; } if (ifok) { nextIf.ifValid = true; if (scripted.tag == "Player") { nbStepPlayer += ActionManipulator.getNbStep(nextIf, true); } } else { nextIf.currentAction = nextIf.actions.Count - 1; ActionManipulator.incrementActionScript(scripted.GetComponent <Script>()); } nextIf = ActionManipulator.getCurrentIf(scripted); } if (nbStepPlayer > nbStepToAdd) { nbStepToAdd = nbStepPlayer; } } gameData.nbStep += nbStepToAdd; if (gameData.nbStep > 0) { gameData.totalExecute++; } }