Beispiel #1
0
        //!
        //! Use this for initialization
        //!
        void Start()
        {
            try
            {
                //cache reference to main Controller
                mainController = GameObject.Find("MainController").GetComponent <MainController>();


                //cache reference to animation Controller
                animationController = GameObject.Find("AnimationController").GetComponent <AnimationController>();

#if USE_TANGO
                //cache reference to tango Controller
                tangoController = GameObject.Find("Tango").GetComponent <TangoController>();
#endif
            }
            catch
            {
                print("Fix Me");
            }


            // get range slider
            rangeSlider = canvas.GetComponentInChildren <RangeSlider>(true);
            if (rangeSlider == null)
            {
                Debug.LogError(string.Format("{0}: Cant Find Component in Canvas: RangeSlider.", this.GetType()));
            }
            rangeSlider.OnValueChanged.AddListener(onRangeSliderChanged);

            // get light settings widget
            lightSettingsWidget = canvas.GetComponentInChildren <LightSettingsWidget>(true);
            if (lightSettingsWidget == null)
            {
                Debug.LogError(string.Format("{0}: Cant Find Component in Canvas: LightSettingsWidget.", this.GetType()));
            }


            //initalize main Menu
            GameObject mainMenuObject = new GameObject("mainMenuObject");
            mainMenuObject.transform.SetParent(this.transform.parent, false);
            mainMenu = mainMenuObject.AddComponent <MainMenu>();

            //initalize secondary Menu
            GameObject secondaryMenuObj = new GameObject("secondaryMenuObject");
            secondaryMenuObj.transform.SetParent(this.transform, false);
            secondaryMenu = secondaryMenuObj.AddComponent <SecondaryMenu>();

            //initalize center Menu
            GameObject centerMenuObj = new GameObject("centerMenuObject");
            centerMenuObj.transform.SetParent(this.transform, false);
            centerMenu = centerMenuObj.AddComponent <CenterMenu>();

            //initalize paramter Menu
            GameObject paramterMenuObj = new GameObject("paramterMenuObj");
            paramterMenuObj.transform.SetParent(this.transform, false);
            parameterMenu = paramterMenuObj.AddComponent <SubMenu>();

            // initalize ConfigWidget
            GameObject refObject = GameObject.Find("GUI/Canvas/ConfigWidget");
            if (refObject == null)
            {
                Debug.LogWarning(string.Format("{0}: No GUI/Canvas/ConfigWidget Object found. Load From Resource.", this.GetType()));
                GameObject refObjectPrefab = Resources.Load <GameObject>("VPET/Prefabs/ConfigWidget");
                refObject      = Instantiate(refObjectPrefab);
                refObject.name = refObjectPrefab.name;
                GameObject refParent = GameObject.Find("GUI/Canvas");
                refObject.transform.SetParent(refParent.transform, false);
            }
            configWidget = refObject.GetComponent <ConfigWidget>();
            if (configWidget == null)
            {
                Debug.LogWarning(string.Format("{0}: No ConfigWidget Component found. Create", this.GetType()));
                configWidget = refObject.AddComponent <ConfigWidget>();
            }
            // Submit listener
            configWidget.SubmitEvent.AddListener(mainController.configWidgetSubmit);
            // Ambient light listener
            configWidget.AmbientChangedEvent.AddListener(mainController.setAmbientIntensity);

#if USE_TANGO
            // Show Tango Scale UI objects
            GameObject tangoScaleSliderUI = GameObject.Find("GUI/Canvas/ConfigWidget/TangoScale_slider");
            // tangoScaleSliderUI.transform.localPosition = new Vector3(31.0f, -560.0f, 0.0f);
            GameObject tangoScaleLabelUI = GameObject.Find("GUI/Canvas/ConfigWidget/TangoScale_label");
            //tangoScaleLabelUI.transform.localPosition = new Vector3(-105.0f, 530.0f, 0.0f);
            GameObject startButton     = GameObject.Find("GUI/Canvas/ConfigWidget/Start_button");
            GameObject sliderValueText = GameObject.Find("GUI/Canvas/ConfigWidget/TangoScale_Value");
            sliderValueText.gameObject.SetActive(true);
            tangoScaleLabelUI.gameObject.SetActive(true);
            tangoScaleSliderUI.gameObject.SetActive(true);
            // Tango Scale Listener
            configWidget.TangoScaleChangedEvent.AddListener(tangoController.setTangoScaleIntensity);
            configWidget.OnSceneScaleChanged.AddListener(tangoController.scaleMovement);
#endif


            /*
             *  //initalize undo buttons
             *  undoButton = Instantiate(GameObject.Find("ButtonTemplate"));
             *  undoButton.transform.SetParent(this.transform,false);
             *  //undoButton.GetComponent<RectTransform>().sizeDelta = SpriteSize;
             *  undoButton.GetComponent<RectTransform>().position = new Vector2(Screen.height / 16 + 10, ((Screen.height / 3) * 2) - (Screen.height / 8 + 10));
             *  undoButton.GetComponent<Image>().sprite =   GeneralMenu_Undo_nrm;
             *  SpriteState undoSprites = new SpriteState();
             *  undoSprites.disabledSprite = GeneralMenu_Undo_nrm;
             *  undoSprites.highlightedSprite = GeneralMenu_Undo_nrm;
             *  undoSprites.pressedSprite = GeneralMenu_Undo_sel;
             *  undoButton.GetComponent<Button>().spriteState = undoSprites;
             *  undoButton.GetComponent<Button>().interactable = false;
             *  undoButton.GetComponent<Button>().onClick.AddListener(() => undoButtonClicked());
             *  // temp hide it
             *  undoButton.GetComponent<Image>().enabled = false;
             *
             *  //initalize redo buttons
             *  redoButton = Instantiate(GameObject.Find("ButtonTemplate"));
             *  redoButton.transform.SetParent(this.transform, false);
             *  //redoButton.GetComponent<RectTransform>().sizeDelta = SpriteSize;
             *  redoButton.GetComponent<RectTransform>().position = new Vector2(Screen.width - (Screen.height / 16 + 10), ((Screen.height / 3) * 2) - (Screen.height / 8 + 10));
             *  redoButton.GetComponent<Image>().sprite = GeneralMenu_Redo_nrm;
             *  SpriteState redoSprites = new SpriteState();
             *  redoSprites.disabledSprite = GeneralMenu_Redo_nrm;
             *  redoSprites.highlightedSprite = GeneralMenu_Redo_nrm;
             *  redoSprites.pressedSprite = GeneralMenu_Redo_sel;
             *  redoButton.GetComponent<Button>().spriteState = redoSprites;
             *  redoButton.GetComponent<Button>().interactable = false;
             *  redoButton.GetComponent<Button>().onClick.AddListener(() => redoButtonClicked());
             *  // temp hide it
             *  redoButton.GetComponent<Image>().enabled = false;
             */

            //initalise mainMenu button
            IMenuButton iMainMenuButton = Elements.MenuButtonToggle();
            mainMenuButton      = ((Button)iMainMenuButton).gameObject;
            mainMenuButton.name = "MainMenuButton";
            mainMenuButton.transform.SetParent(this.transform.parent, false);
            mainMenuButton.GetComponent <RectTransform>().localPosition = new Vector2(VPETSettings.Instance.canvasHalfWidth - UI.ButtonOffset, (VPETSettings.Instance.canvasHalfHeight - UI.ButtonOffset) * VPETSettings.Instance.canvasAspectScaleFactor);
            iMainMenuButton.AddAction(GeneralMenu_Main_sel, GeneralMenu_Main_nrm, () => mainMenuToggle());
            mainMenuButton.SetActive(false);
            iMainMenuButton.Menu = mainMenu;

            //call setup function for all available menues
            setupMainMenu();
            setupSecondaryMenu();
            setupCenterMenu();
            setupParameterMenu();
        }