//! //! Use this for initialization //! protected void Start() { target = this.transform; isPhysicsActive = false; serverAdapter = GameObject.Find("ServerAdapter").GetComponent <ServerAdapter>(); #if !SCENE_HOST animationController = GameObject.Find("AnimationController").GetComponent <AnimationController>(); mainController = GameObject.Find("MainController").GetComponent <MainController>(); sceneLoader = GameObject.Find("SceneAdapter").GetComponent <SceneLoader>(); //cache Reference to animation data animData = AnimationData.Data; #endif //update initial parameters initialPosition = target.localPosition; initialRotation = target.localRotation; initialScale = target.localScale; lastPosition = initialPosition; lastRotation = initialRotation; InvokeRepeating("checkUpdate", 0.0f, updateIntervall); if (gameObject.GetComponent <Animator>()) { isAnimatedCharacter = true; } //generate colliding volumes if (generateBoxCollider) { //calculate bounds bounds = new Bounds(Vector3.zero, Vector3.zero); bool isSkinned = false; bool hasBounds = false; Renderer[] renderers = this.gameObject.GetComponentsInChildren <Renderer>(true); foreach (Renderer renderer in renderers) { if (!sceneLoader.isEditable(renderer.gameObject) || renderer.gameObject == this.gameObject) { if (hasBounds) { if (typeof(SkinnedMeshRenderer) == renderer.GetType()) { bounds.Encapsulate(((SkinnedMeshRenderer)renderer).localBounds); isSkinned = true; } else { bounds.Encapsulate(renderer.bounds); } } else { if (typeof(SkinnedMeshRenderer) == renderer.GetType()) { bounds = ((SkinnedMeshRenderer)renderer).localBounds; isSkinned = true; } else { bounds = renderer.bounds; } hasBounds = true; } } } boxCollider = this.gameObject.AddComponent <BoxCollider>(); #if !SCENE_HOST if (this is SceneObjectCamera) { boxCollider.enabled = mainController.showCam; } #endif // col.isTrigger = true; // not interacting if ((this is SceneObject) && !(this is SceneObjectLight)) { if (isSkinned) { boxCollider.center = bounds.center; boxCollider.size = bounds.size; } else { boxCollider.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); boxCollider.size = new Vector3(bounds.size.x / this.transform.lossyScale.x, bounds.size.y / this.transform.lossyScale.y, bounds.size.z / this.transform.lossyScale.z); } boxCollider.material = new PhysicMaterial(); boxCollider.material.bounciness = 1.0f; } } if (this is SceneObject) { rigidbody = this.gameObject.AddComponent <Rigidbody>(); rigidbody.mass = 100f; rigidbody.drag = 2.5f; // TODO: temporary rigidbody.useGravity = true; rigidbody.isKinematic = true; globalKinematic = true; } #if !SCENE_HOST //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(); } isPlayingAnimation = false; #endif }
//! //! Use this for pre initialization //! void Awake() { // read settings from inspector values VPETSettings.mapValuesFromObject(this); // read settings from config file if wanted if (!ignoreConfig) { string filePath = Application.dataPath + "/VPET/editing_tool.cfg"; if (!File.Exists(filePath)) { filePath = Application.persistentDataPath + "/editing_tool.cfg"; } VPETSettings.mapValuesFromConfigFile(filePath); } // read settings from user preferences VPETSettings.mapValuesFromPreferences(); // check if scene dump file available if (Directory.Exists(Application.dataPath + "/Resources/VPET/SceneDumps")) { VPETSettings.Instance.sceneDumpFolderEmpty = (Directory.GetFiles(Application.dataPath + "/Resources/VPET/SceneDumps", "*.bytes").Length == 0); // print("PETSettings.Instance.sceneDumpFolderEmpty " + VPETSettings.Instance.sceneDumpFolderEmpty); } VPETSettings.Instance.sceneDumpFolderEmpty = false; // get all adapters and add them if missing // // get scene adapter GameObject refObject = GameObject.Find("SceneAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No SceneAdapter Object found. Create.", this.GetType())); refObject = new GameObject("SceneAdapter"); } sceneAdapter = refObject.GetComponent <SceneLoader>(); if (sceneAdapter == null) { Debug.LogWarning(string.Format("{0}: No SceneAdapter Component found. Create", this.GetType())); sceneAdapter = refObject.AddComponent <SceneLoader>(); } // get server adapter refObject = GameObject.Find("ServerAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No ServerAdapter Object found. Create.", this.GetType())); refObject = new GameObject("ServerAdapter"); } serverAdapter = refObject.GetComponent <ServerAdapter>(); if (serverAdapter == null) { Debug.LogWarning(string.Format("{0}: No ServerAdapter Component found. Create", this.GetType())); serverAdapter = refObject.AddComponent <ServerAdapter>(); } // set properties serverAdapter.SceneLoader = sceneAdapter; // get animation adapter refObject = GameObject.Find("AnimationController"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No AnimationController Object found. Create.", this.GetType())); refObject = new GameObject("AnimationAdapter"); } animationController = refObject.GetComponent <AnimationController>(); if (animationController == null) { Debug.LogWarning(string.Format("{0}: No AnimationController Component found. Create", this.GetType())); animationController = refObject.AddComponent <AnimationController>(); } // get JoystickAdapter adapter refObject = GameObject.Find("JoystickAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No JoystickAdapter Object found. Create.", this.GetType())); refObject = new GameObject("JoystickAdapter"); } joystickAdapter = refObject.GetComponent <JoystickInput>(); if (joystickAdapter == null) { Debug.LogWarning(string.Format("{0}: No JoystickAdapter Component found. Create", this.GetType())); joystickAdapter = refObject.AddComponent <JoystickInput>(); } // get InputAdapter adapter refObject = GameObject.Find("InputAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No InputAdapter Object found. Create.", this.GetType())); refObject = new GameObject("InputAdapter"); } inputAdapter = refObject.GetComponent <InputAdapter>(); if (inputAdapter == null) { Debug.LogWarning(string.Format("{0}: No InputAdapter Component found. Create", this.GetType())); inputAdapter = refObject.AddComponent <InputAdapter>(); } // inputAdapter.MainController = this; // get ui adapter refObject = GameObject.Find("GUI/Canvas/UI"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No GUI/Canvas/UI Object found. Create.", this.GetType())); refObject = new GameObject("UI"); GameObject refParent = GameObject.Find("GUI/Canvas"); refObject.transform.SetParent(refParent.transform, false); } ui = refObject.GetComponent <UI>(); if (ui == null) { Debug.LogWarning(string.Format("{0}: No UI Component found. Create", this.GetType())); ui = refObject.AddComponent <UI>(); } // get move camera component camera Adapter cameraAdapter = Camera.main.GetComponent <MoveCamera>(); if (cameraAdapter == null) { Debug.LogWarning(string.Format("{0}: No CameraAdapter Component found. Create", this.GetType())); cameraAdapter = Camera.main.gameObject.AddComponent <MoveCamera>(); } #if USE_TANGO GameObject tangoObject = GameObject.Find("Tango Manager"); if (tangoObject) { tangoApplication = tangoObject.GetComponent <Tango.TangoApplication>(); } #endif }
//! //! Use this for initialization //! void Start() { arKeyVideoPlane = GameObject.Find("GUI/Canvas/ARVideoPlane"); try { //cache reference to main Controller mainController = GameObject.Find("MainController").GetComponent <MainController>(); //cache reference to animation Controller animationController = GameObject.Find("AnimationController").GetComponent <AnimationController>(); } 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>(); helpContext = GameObject.Find("GUI/Canvas/HelpScreen"); //initalize paramter Menu GameObject paramterMenuObj = new GameObject("paramterMenuObj"); paramterMenuObj.transform.SetParent(this.transform, false); parameterMenu = paramterMenuObj.AddComponent <SubMenu>(); //store scene scale lable reference scaleLable = GameObject.Find("GUI/Canvas/ARConfigWidget/scale_value").GetComponent <Text>(); // 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_AR configWidget.ToggleAREvent.AddListener(mainController.ToggleArMode); // ar key connects configWidget.KeyDepthChangedEvent.AddListener(mainController.setARKeyDepth); configWidget.KeyColorChangedEvent.AddListener(mainController.setARKeyColor); configWidget.KeyRadiusChangedEvent.AddListener(mainController.setARKeyRadius); configWidget.KeyThresholdChangedEvent.AddListener(mainController.setARKeyThreshold); configWidget.ToggleARMatteEvent.AddListener(mainController.ToggleARMatteMode); configWidget.ToggleARKeyEvent.AddListener(mainController.ToggleARKeyMode); // add other ar managers here or change a global variable like VPET.Settings.sceneScale! #endif //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(); }
//! //! 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>(); sceneLoader = GameObject.Find("SceneAdapter").GetComponent <SceneLoader>(); //cache Reference to animation data animData = AnimationData.Data; //update initial parameters initialPosition = target.localPosition; initialRotation = target.localRotation; 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) { Rigidbody rigidbody = this.gameObject.AddComponent <Rigidbody>(); rigidbody.mass = 100f; rigidbody.drag = 2.5f; // TODO: temporary rigidbody.useGravity = true; rigidbody.isKinematic = true; this.GetComponent <SceneObject> ().lockKinematic = 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(); } isPlayingAnimation = false; }
//! //! 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"); } // initialize light settings widget GameObject ciLightSettingsObject = new GameObject("ciLightSettingsObject"); ciLightSettingsObject.AddComponent <RectTransform>(); ciLightSettingsObject.transform.SetParent(canvas, false); // ciLightSettingsObject.transform.localPosition = new Vector3(0, -canvasHeight/2+UI.ButtonOffset, 0); lightSettingsWidget = ciLightSettingsObject.AddComponent <LightSettingsWidget>(); //initalize main Menu GameObject mainMenuObject = new GameObject("mainMenuObject"); mainMenuObject.transform.SetParent(this.transform, 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 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"); startButton.transform.localPosition = new Vector3(0f, -670f, 0.0f); 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, 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(); // initialize camera slider widget setupCameraSlider(); }
//! //! Use this for pre initialization //! void Awake() { QualitySettings.vSyncCount = 0; Application.targetFrameRate = 30; Resolution res = Screen.currentResolution; //Screen.SetResolution(res.width/2, res.height/2, true); // read settings from inspector values VPETSettings.mapValuesFromObject(this); // read settings from config file if wanted if (!ignoreConfig) { string filePath = Application.dataPath + "/VPET/editing_tool.cfg"; if (!File.Exists(filePath)) { filePath = Application.persistentDataPath + "/editing_tool.cfg"; } VPETSettings.mapValuesFromConfigFile(filePath); } // read settings from user preferences VPETSettings.mapValuesFromPreferences(); // check if scene dump file available if (Directory.Exists(Application.dataPath + "/Resources/VPET/SceneDumps")) { VPETSettings.Instance.sceneDumpFolderEmpty = (Directory.GetFiles(Application.dataPath + "/Resources/VPET/SceneDumps", "*.bytes").Length == 0); // print("PETSettings.Instance.sceneDumpFolderEmpty " + VPETSettings.Instance.sceneDumpFolderEmpty); } VPETSettings.Instance.sceneDumpFolderEmpty = false; // Register plugins VPETRegister.RegisterNodeParser(); VPETRegister.RegisterNodeBuilder(); VPETRegister.RegisterObjectSender(); // get all adapters and add them if missing // // get scene adapter GameObject refObject = GameObject.Find("SceneAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No SceneAdapter Object found. Create.", this.GetType())); refObject = new GameObject("SceneAdapter"); } sceneAdapter = refObject.GetComponent <SceneLoader>(); if (sceneAdapter == null) { Debug.LogWarning(string.Format("{0}: No SceneAdapter Component found. Create", this.GetType())); sceneAdapter = refObject.AddComponent <SceneLoader>(); } // get server adapter refObject = GameObject.Find("ServerAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No ServerAdapter Object found. Create.", this.GetType())); refObject = new GameObject("ServerAdapter"); } serverAdapter = refObject.GetComponent <ServerAdapter>(); if (serverAdapter == null) { Debug.LogWarning(string.Format("{0}: No ServerAdapter Component found. Create", this.GetType())); serverAdapter = refObject.AddComponent <ServerAdapter>(); } // copy cache name to settings VPETSettings.Instance.sceneFileName = serverAdapter.sceneFileName; // set properties serverAdapter.SceneLoader = sceneAdapter; // get animation adapter refObject = GameObject.Find("AnimationController"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No AnimationController Object found. Create.", this.GetType())); refObject = new GameObject("AnimationAdapter"); } animationController = refObject.GetComponent <AnimationController>(); if (animationController == null) { Debug.LogWarning(string.Format("{0}: No AnimationController Component found. Create", this.GetType())); animationController = refObject.AddComponent <AnimationController>(); } // get JoystickAdapter adapter refObject = GameObject.Find("JoystickAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No JoystickAdapter Object found. Create.", this.GetType())); refObject = new GameObject("JoystickAdapter"); } #if !SCENE_HOST joystickAdapter = refObject.GetComponent <JoystickInput>(); if (joystickAdapter == null) { Debug.LogWarning(string.Format("{0}: No JoystickAdapter Component found. Create", this.GetType())); joystickAdapter = refObject.AddComponent <JoystickInput>(); } #endif // get InputAdapter adapter refObject = GameObject.Find("InputAdapter"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No InputAdapter Object found. Create.", this.GetType())); refObject = new GameObject("InputAdapter"); } inputAdapter = refObject.GetComponent <InputAdapter>(); if (inputAdapter == null) { Debug.LogWarning(string.Format("{0}: No InputAdapter Component found. Create", this.GetType())); inputAdapter = refObject.AddComponent <InputAdapter>(); } // inputAdapter.MainController = this; // get ui adapter refObject = GameObject.Find("GUI/Canvas/UI"); if (refObject == null) { Debug.LogWarning(string.Format("{0}: No GUI/Canvas/UI Object found. Create.", this.GetType())); refObject = new GameObject("UI"); GameObject refParent = GameObject.Find("GUI/Canvas"); refObject.transform.SetParent(refParent.transform, false); } ui = refObject.GetComponent <UI>(); if (ui == null) { Debug.LogWarning(string.Format("{0}: No UI Component found. Create", this.GetType())); ui = refObject.AddComponent <UI>(); } // get move camera component camera Adapter cameraAdapter = Camera.main.GetComponent <MoveCamera>(); if (cameraAdapter == null) { Debug.LogWarning(string.Format("{0}: No CameraAdapter Component found. Create", this.GetType())); cameraAdapter = Camera.main.gameObject.AddComponent <MoveCamera>(); } }
//! //! 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.FindChild("Arrow"); } else if (sourceLight.type == LightType.Spot) { isSpotLight = true; initialLightRange = sourceLight.range; initialSpotAngle = sourceLight.spotAngle; lightGeo = lightTarget.FindChild("Cone"); } else if (sourceLight.type == LightType.Point) { isPointLight = true; initialLightRange = sourceLight.range; lightGeo = lightTarget.FindChild("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> (); //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 //target.position = new Vector3(-3000,-3000,-3000); //target.localScale = new Vector3(1, 1, 1); bounds = new Bounds(Vector3.zero, Vector3.zero); //set rotation to 0 // this.transform.rotation = Quaternion.Euler(Vector3.zero); bool hasBounds = false; Renderer[] renderers = this.gameObject.GetComponentsInChildren <Renderer>(); foreach (Renderer render in renderers) { if (hasBounds) { bounds.Encapsulate(render.bounds); } else { bounds = render.bounds; hasBounds = true; } } BoxCollider col = this.gameObject.AddComponent <BoxCollider>(); if (sourceLight) { // BoxCollider col_lightquad = lightTarget.FindChild("LightQuad").GetComponent<BoxCollider>(); // col.size = col_lightquad.size; // col.center = col_lightquad.center; LightIcon iconScript = lightTarget.FindChild("LightQuad").GetComponent <LightIcon>(); iconScript.TargetCollider = col; iconScript.TargetScale = 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; } //target.position = initialPosition; // target.localScale = initialScale; // target.rotation = initialRotation; } if (!isDirectionalLight && !isPointLight && !isSpotLight && this.name != "camera") { this.gameObject.AddComponent <Rigidbody>(); this.gameObject.GetComponent <Rigidbody>().mass = 100.0f; this.gameObject.GetComponent <Rigidbody>().drag = 2.5f; // this.gameObject.GetComponent<Rigidbody>().useGravity = false; } //Initalize animation loading if animation available AnimationSerializer asScript = target.gameObject.AddComponent <AnimationSerializer>(); asScript.loadData(); animationController.setStartEndTimeline(asScript.timeStart, asScript.timeEnd); updateAnimationCurves(); }