private void InitializeWonButtons()
    {
        if (WonButtonsContainer == null)
        {
            return;
        }

        // find all puzzle controllers in the scene
        var puzzleControllers = ChapterManager.transform.GetComponentsInChildren <PuzzleController>(true);

        // make cheat win button for each puzzle
        foreach (var controller in puzzleControllers)
        {
            // find won fsm candidate
            PlayMakerFSM possibleWonFSM       = null;
            FieldInfo    wonEventFsmFieldInfo = controller.GetType().GetField("_wonEventFsm", BindingFlags.NonPublic | BindingFlags.Instance);
            if (wonEventFsmFieldInfo != null && wonEventFsmFieldInfo.GetValue(controller) != null)
            {
                possibleWonFSM = (PlayMakerFSM)wonEventFsmFieldInfo.GetValue(controller);
            }

            // create button (if there is no skip button for the puzzle)
            if (possibleWonFSM != null)
            {
                // do not create if skip button is present for the puzzle
                bool      hasSkipButton = false;
                FieldInfo fieldInfo     = controller.GetType().GetField("_puzzleUI", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null && fieldInfo.GetValue(controller) != null)
                {
                    PuzzleUI  controllerPuzzleUI  = (PuzzleUI)fieldInfo.GetValue(controller);
                    FieldInfo fieldInfoOfPuzzleUI = controllerPuzzleUI.GetType().GetField("_skipButton", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (fieldInfoOfPuzzleUI != null && fieldInfoOfPuzzleUI.GetValue(controllerPuzzleUI) != null)
                    {
                        hasSkipButton = true;
                    }
                }

                // create button
                if (!hasSkipButton)
                {
                    var newButton = Instantiate(WonButtonToClone, WonButtonsContainer);
                    newButton.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => { possibleWonFSM.SendEvent("won"); });
                    newButton.GetComponentInChildren <UnityEngine.UI.Text>().text = "" +
                                                                                    GetNameOfParentRoom(controller.transform) + " > " +
                                                                                    controller.gameObject.name;
                }
            }
        }
    }
Exemple #2
0
	// Use this for initialization
	void Awake () {
        p1 = GameObject.Find("P1 Camera").GetComponentInChildren<PuzzleUI>();
        p2 = GameObject.Find("P2 Camera").GetComponentInChildren<PuzzleUI>();
	}