Esempio n. 1
0
    public void SetPlayMode()
    {
        if (htree == null)
        {
            return;
        }
        List <SceneNode> cannonList = htree.FindByNameList("Cannon");

        if (cannonList != null && cannonList.Count > 0)
        {
            foreach (SceneNode s in cannonList)
            {
                s.gameObject.GetComponent <Cannon>().active = !s.gameObject.GetComponent <Cannon>().active;
                s.gameObject.GetComponent <Cannon>().world  = this;
            }
        }

        if (htree.GetSize() < 3)
        {
            warning.text = "Must have at least 3 objects in the Hierarchy before playing.";
            return;
        }

        warning.text = "";
        isPlayTime   = !isPlayTime;

        if (isPlayTime)
        {
            oldPos = TheRoot.transform.localPosition;
            oldRot = TheRoot.transform.localRotation;
            bound.DestroyCube();
            gameMode.SetActive(true);
            editorMode.SetActive(false);
            mainCamera.gameObject.SetActive(true);
            Vector3[] sz = bound.GetBounds();
            mainCamera.transform.localPosition = TheRoot.transform.localPosition + new Vector3(0, -5 - sz[1].y / 2, 0);
            mainCamera.transform.LookAt(TheRoot.transform);
            mainCamera.transform.SetParent(TheRoot.transform, true);
            secondaryCamera.gameObject.SetActive(true);
            secondaryCamera.transform.localPosition = TheRoot.transform.localPosition + new Vector3(0, 5 + sz[1].y / 2, 0);
            secondaryCamera.transform.LookAt(TheRoot.transform);
            secondaryCamera.transform.localRotation *= Quaternion.AngleAxis(180f, TheRoot.transform.forward);
            secondaryCamera.transform.SetParent(TheRoot.transform, true);
            ForceDeselect();
        }
        else
        {
            mainCamera.transform.SetParent(null, true);
            secondaryCamera.transform.SetParent(null, true);
            gameMode.SetActive(false);
            editorMode.SetActive(true);
            mainCamera.gameObject.SetActive(false);
            secondaryCamera.gameObject.SetActive(false);
            ResetHierarchy();
        }
    }