Ejemplo n.º 1
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.º 2
0
        //!
        //! Use this for pre initialization
        //!
        void Awake()
        {
            QualitySettings.vSyncCount  = 0;
            Application.targetFrameRate = 30;
            //Screen.SetResolution(1112, 834, 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>();
            }
        }
Ejemplo n.º 3
0
 public static void RegisterNodeBuilder()
 {
     SceneLoader.RegisterDelegate(NodeBuilderBasic.BuildNode);
 }