Ejemplo n.º 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);
#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();
        }
Ejemplo n.º 2
0
        //!
        //! Use this for initialization
        //!
        void Start()
        {
            if (transform.childCount > 0)
            {
                lightTarget = transform.GetChild(0);
                if (lightTarget != null)
                {
                    sourceLight = lightTarget.GetComponent <Light>();
                }
            }

            // if (this.transform.parent.transform.GetComponent<Light>())

            if (sourceLight)
            {
                // target = this.transform.parent;
                target = this.transform;

                initialLightColor     = sourceLight.color;
                initialLightColor.a   = 0.25f;
                initialLightIntensity = sourceLight.intensity;

                if (sourceLight.type == LightType.Directional)
                {
                    isDirectionalLight = true;
                    lightGeo           = lightTarget.Find("Arrow");
                }
                else if (sourceLight.type == LightType.Spot)
                {
                    isSpotLight       = true;
                    initialLightRange = sourceLight.range;
                    initialSpotAngle  = sourceLight.spotAngle;
                    lightGeo          = lightTarget.Find("Cone");
                }
                else if (sourceLight.type == LightType.Point)
                {
                    isPointLight      = true;
                    initialLightRange = sourceLight.range;
                    lightGeo          = lightTarget.Find("Sphere");
                }
            }
            else
            {
                target = this.transform;
            }

            //initalize cached references
            animationController = GameObject.Find("AnimationController").GetComponent <AnimationController>();
            mainController      = GameObject.Find("MainController").GetComponent <MainController>();
            serverAdapter       = GameObject.Find("ServerAdapter").GetComponent <ServerAdapter>();
            undoRedoController  = GameObject.Find("UndoRedoController").GetComponent <UndoRedoController> ();
            sceneLoader         = GameObject.Find("SceneAdapter").GetComponent <SceneLoader>();


            //cache Reference to animation data
            animData = AnimationData.Data;

            //update initial parameters
            initialPosition = target.position;
            initialRotation = target.rotation;
            initialScale    = target.localScale;

            lastPosition = initialPosition;
            lastRotation = initialRotation;


            //generate colliding volumes
            if (generateBoxCollider)
            {
                //calculate bounds
                bounds = new Bounds(Vector3.zero, Vector3.zero);


                bool       hasBounds = false;
                Renderer[] renderers = this.gameObject.GetComponentsInChildren <Renderer>();
                foreach (Renderer render in renderers)
                {
                    if (!sceneLoader.isEditable(render.gameObject) || render.gameObject == this.gameObject)
                    {
                        if (hasBounds)
                        {
                            bounds.Encapsulate(render.bounds);
                        }
                        else
                        {
                            bounds    = render.bounds;
                            hasBounds = true;
                        }
                    }
                }

                BoxCollider col = this.gameObject.AddComponent <BoxCollider>();

                // TODO: temporary
                if (transform.GetComponent <CameraObject>() != null)
                {
                    col.isTrigger = true; // not interacting
                    this.gameObject.AddComponent <Rigidbody>();
                    this.gameObject.GetComponent <Rigidbody>().mass = 100.0f;
                    this.gameObject.GetComponent <Rigidbody>().drag = 2.5f;


                    // TODO: temporary
                    this.gameObject.GetComponent <Rigidbody>().useGravity = false;
                }


                // col.isTrigger = true; // not interacting



                if (sourceLight)
                {
                    // BoxCollider col_lightquad = lightTarget.FindChild("LightQuad").GetComponent<BoxCollider>();
                    // col.size = col_lightquad.size;
                    // col.center = col_lightquad.center;
                    col.isTrigger = true; // not interacting
                    LightIcon iconScript = lightTarget.Find("LightQuad").GetComponent <LightIcon>();
                    iconScript.TargetCollider = col;
                    iconScript.TargetScale    = target.lossyScale; // target.localScale;
                }
                else
                {
                    col.center              = new Vector3((bounds.center.x - this.transform.position.x) / this.transform.lossyScale.x, (bounds.center.y - this.transform.position.y) / this.transform.lossyScale.y, (bounds.center.z - this.transform.position.z) / this.transform.lossyScale.z);
                    col.size                = new Vector3(bounds.size.x / this.transform.lossyScale.x, bounds.size.y / this.transform.lossyScale.y, bounds.size.z / this.transform.lossyScale.z);
                    col.material            = new PhysicMaterial();
                    col.material.bounciness = 1.0f;
                }
            }
            if (!isDirectionalLight && !isPointLight && !isSpotLight && this.name != "camera" && transform.GetComponent <CameraObject>() == null)
            {
                this.gameObject.AddComponent <Rigidbody>();
                this.gameObject.GetComponent <Rigidbody>().mass = 100.0f;
                this.gameObject.GetComponent <Rigidbody>().drag = 2.5f;


                // TODO: temporary
                this.gameObject.GetComponent <Rigidbody>().useGravity = true;
            }

            //Initalize animation loading if animation available
            AnimationSerializer asScript = target.gameObject.AddComponent <AnimationSerializer>();

            if (asScript.loadData())
            {
                //register the object in the animation Controller
                GameObject.Find("AnimationController").GetComponent <AnimationController>().registerAnimatedObject(gameObject.GetComponent <SceneObject>());
                gameObject.GetComponent <SceneObject>().setKinematic(true, false);
                updateAnimationCurves();
            }
        }
Ejemplo n.º 3
0
        //!
        //! Use this for initialization
        //!
        void Awake()
        {
            updateAppearance = true;

            //cache reference to main Controller
            mainController = GameObject.Find("MainController").GetComponent <MainController>();

            //cache reference to animation timeline
            timeLineObject = GameObject.Find("GUI/Canvas/UI/TimeLine");
            if (timeLineObject == null)
            {
                Debug.LogError(string.Format("{0}: Cant Find TimeLine (GUI/Canvas/UI/TimeLine).", this.GetType()));
            }

            timeLine = timeLineObject.GetComponent <TimeLineWidget>();
            if (timeLine == null)
            {
                Debug.LogError(string.Format("{0}: No TimeLine script attached.", this.GetType()));
            }
            // assign callback for frame changes on timeline (on user drag)
            timeLine.Callback = this.setTime;

            //cache reference to keyframe Sphere container
            if (!frameSphereContainer)
            {
                frameSphereContainer = new GameObject("FrameSphereContainer");
                frameSphereContainer.transform.parent        = GameObject.Find("Scene").transform;
                frameSphereContainer.transform.localPosition = Vector3.zero;
                frameSphereContainer.transform.localRotation = Quaternion.identity;
                frameSphereContainer.transform.localScale    = Vector3.one;
            }

            // cache key prefab
            keySpherePrefab = Resources.Load <GameObject>("VPET/Prefabs/KeySphere");
            if (keySpherePrefab == null)
            {
                Debug.LogError(string.Format("{0}: Cant find Resources: KeySphere.", this.GetType()));
            }

            //cache reference to dragArea and deactivate it
            //dragArea = timeline.transform.GetChild(7).gameObject;
            //dragArea.SetActive(false);

            //cache Reference to animation data
            animData = AnimationData.Data;

            //initalize keyframe list
            keyframeSpheres = new List <GameObject>();

            //initalize animated scene objects list
            if (animatedObjects == null)
            {
                animatedObjects = new List <SceneObject>();
            }

            //initialize animation layers
            for (int i = 0; i < animationLayers.Length; ++i)
            {
                animationLayers[i] = new AnimationLayer();
            }

            //initalize lineRenderer
            lineRenderer               = gameObject.AddComponent <LineRenderer>();
            lineRenderer.material      = Resources.Load <Material>("VPET/Materials/LineRendererMaterial");
            lineRenderer.useWorldSpace = true;
            lineRenderer.positionCount = 0;
        }
Ejemplo n.º 4
0
        //!
        //! Use this for initialization
        //!
        void Start()
        {
            timeleft = updateInterval;
            //initialize the sensor reading for the current platform
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
            initalizeSensorReading();
#elif (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            // SensorHelper.ActivateRotation();
#endif

            supervisedObjects = new List <GameObject>(0);
            mainCamera        = this.GetComponent <Camera>();
            //sync renderInFront camera to mainCamera
            Camera frontCamera = this.transform.GetChild(0).GetComponent <Camera>();
            if (frontCamera)
            {
                frontCamera.fieldOfView   = mainCamera.fieldOfView;
                frontCamera.farClipPlane  = mainCamera.farClipPlane;
                frontCamera.nearClipPlane = mainCamera.nearClipPlane;
            }

            //sync Outline camera to mainCamera
            if (frontCamera.transform.childCount > 0)
            {
                Camera outlineCamera = frontCamera.transform.GetChild(0).GetComponent <Camera>();
                outlineCamera.fieldOfView   = mainCamera.fieldOfView;
                outlineCamera.farClipPlane  = mainCamera.farClipPlane;
                outlineCamera.nearClipPlane = mainCamera.nearClipPlane;
            }

            scene = GameObject.Find("Scene").transform;

            // get server adapter
            GameObject refObject = GameObject.Find("ServerAdapter");
            if (refObject != null)
            {
                serverAdapter = refObject.GetComponent <ServerAdapter>();
            }
            if (serverAdapter == null)
            {
                Debug.LogError(string.Format("{0}: No ServerAdapter found.", this.GetType()));
            }

#if !SCENE_HOST
            // get joystick adapter
            refObject = GameObject.Find("JoystickAdapter");
            if (refObject != null)
            {
                joystickAdapter = refObject.GetComponent <JoystickInput>();
            }
            if (joystickAdapter == null)
            {
                Debug.LogError(string.Format("{0}: No JoystickInput found.", this.GetType()));
            }
#endif

            // get mainController
            refObject = GameObject.Find("MainController");
            if (refObject != null)
            {
                mainController = refObject.GetComponent <MainController>();
            }
            if (mainController == null)
            {
                Debug.LogError(string.Format("{0}: No MainController found.", this.GetType()));
            }

#if USE_AR
            trackingTransform = GameObject.Find("Cameras").transform;
#else
            Camera.main.transform.parent.transform.Rotate(Vector3.right, 90);
#endif
        }