/// <summary>
        /// Occurs on game load.
        /// </summary>
        public override void OnLoad()
        {
            // Written, 18.10.2018
            // Called once, when mod is loading after game is fully loaded

            // Creating truck engine object. NOTE Mod-API excepts the gameobject to have both a rigidbody and a collider attached before passing the reference.
            GameObject truckEngineGo = LoadAssets.LoadOBJ(this, @"truck_engine.obj", rigidbody: true);

            truckEngineGo.name = "Truck Engine";
            // Loading and assigning the texture for the object.
            Texture2D engineTexture = LoadAssets.LoadTexture(this, "Truck_Engine_Texture.png");

            truckEngineGo.GetComponent <Renderer>().material.mainTexture = engineTexture;
            GameObject parent = GameObject.Find("SATSUMA(557kg, 248)");
            // Creating trigger for truck engine. and assigning the local location and scale of the trigger related to the parent. (in this case the satsuma).
            Trigger trigger = new Trigger("TruckEngineTrigger", parent, new Vector3(0.0f, 1.3f, -0.3f), Quaternion.Euler(0, 0, 0), new Vector3(1f, 1f, 1f), false);

            // Creating a new instance of the truckengine.
            this.truckEngine = new TruckEngine(
                this.loadSaveData(),            // The save data, as this is null, default save info will always be loaded.
                truckEngineGo,                  // The instance of the part to create.
                parent,                         // The parent for the part; the gameobject the part installs to.
                trigger,                        // The trigger for the part.
                new Vector3(0.0f, 0.63f, 1.5f), // The installed-position
                new Quaternion(0, 90, 90, 0));  // The installed-rotation
            ModConsole.Print(string.Format("{0} v{1}: Loaded.", this.Name, this.Version));
        }
예제 #2
0
        private void _initShop()
        {
            // Load the lightbulb box
            GameObject original = LoadAssets.LoadOBJ(this, "model\\box.obj", false, false);

            original.name = "new_lightbulb";
            original.GetComponent <MeshRenderer>().material.mainTexture = LoadAssets.LoadTexture(this, "model\\box_d.png");
            AudioSource audio = original.AddComponent <AudioSource>();

            audio.clip             = GameObject.Find("cash_register_2").GetComponent <AudioSource>().clip;
            audio.transform.parent = original.transform;
            audio.spatialBlend     = 1.0f;
            audio.maxDistance      = 10.0f;

            GameObject fBox = GameObject.Instantiate <GameObject>(original);

            original.transform.position = _teimoPos;
            original.transform.rotation = Quaternion.Euler(0.0f, 180.0f, 0.0f);
            MeshCollider coll = original.AddComponent <MeshCollider>();

            coll.name         = "replace lightbulb (300mk)(Clone)";
            coll.convex       = true;
            coll.isTrigger    = true;
            _boxColliderTeimo = coll;

            fBox.transform.position = _fleetariPos;
            coll                 = fBox.AddComponent <MeshCollider>();
            coll.name            = "replace lightbulb (300mk)(Clone)";
            coll.convex          = true;
            coll.isTrigger       = true;
            _boxColliderFleetari = coll;
        }
        public override void OnLoad()
        {
            // Written, 23.09.2018
            // Called once, when mod is loading after game is fully loaded

            // Creating Game Object.
            this.truckEngine = LoadAssets.LoadOBJ(this, @"truck_engine.obj", true, true);
            // Loading and assigning the texture for the object.
            this.engineTexture = LoadAssets.LoadTexture(this, "Truck_Engine_Texture.png");
            this.truckEngine.GetComponent <Renderer>().material.mainTexture = this.engineTexture;
            // Naming the object. NOTE, name must follow naming convention of <ObjectName>(xxxxx) where <ObjectName> is the game objects name.
            this.truckEngine.name = "Truck Engine(xxxxx)";
            // Spawning the game object to home.
            this.truckEngine.transform.position = new Vector3(-20.7f, 10, 10.9f); // Home Location (Outside Garage)
            this.truckEngine.transform.rotation = new Quaternion(0, 90, 90, 0);   // The Rotation.
            // Allowing the object to be picked up.
            this.truckEngine.tag = "PART";
            // Sending object to it's own layer.
            this.truckEngine.layer = LayerMask.NameToLayer(this.truckEngine.name);
        }
예제 #4
0
        private void _initLight(SaveData saveData)
        {
            MeshCollider coll;
            MeshRenderer renderer;
            Texture2D    tex_diff = LoadAssets.LoadTexture(this, "model\\floodlight_d.png");

            // Floodlight base
            _base       = LoadAssets.LoadOBJ(this, "model\\floodlight_base.obj", false, false);
            _base.name  = "floodlight(Clone)";
            _base.layer = LayerMask.NameToLayer("Parts");
            _base.tag   = "PART";
            _base.transform.position = saveData.Pos;
            _base.transform.rotation = saveData.Rot;
            coll        = _base.AddComponent <MeshCollider>();
            coll.convex = true;
            coll.name   = "floodlight(Clone)";
            Rigidbody rb = _base.AddComponent <Rigidbody>();

            rb.mass                       = 5.0f;
            rb.detectCollisions           = true;
            rb.collisionDetectionMode     = CollisionDetectionMode.Continuous;
            rb.isKinematic                = false;
            renderer                      = _base.GetComponent <MeshRenderer>();
            renderer.material.mainTexture = tex_diff;

            // Lamp cover
            _lamp                            = LoadAssets.LoadOBJ(this, "model\\floodlight_cover.obj", false, false);
            _lamp.name                       = "floodlight cover(Clone)";
            _lamp.transform.parent           = _base.transform;
            _lamp.transform.localPosition    = new Vector3(0.0f, 0.22f, 0.0f);
            _lamp.transform.localEulerAngles = new Vector3(_pitch, 0.0f, 0.0f);
            _lampCollider                    = _lamp.AddComponent <MeshCollider>();
            _lampCollider.convex             = true;
            _lampCollider.isTrigger          = true;
            renderer                         = _lamp.GetComponent <MeshRenderer>();
            renderer.material.mainTexture    = tex_diff;

            // Glass
            _glass                         = LoadAssets.LoadOBJ(this, "model\\floodlight_glass.obj", false, false);
            _glass.name                    = "floodlight glass(Clone)";
            _glass.transform.parent        = _lamp.transform;
            _glass.transform.localPosition = new Vector3();
            _glass.transform.localRotation = new Quaternion();
            _glassMaterial                 = _glass.GetComponent <MeshRenderer>().material;
            _glassMaterial.mainTexture     = tex_diff;
            _glassMaterial.shader          = Shader.Find("Standard");

            // Switch
            _switch                         = GameObject.CreatePrimitive(PrimitiveType.Cube);
            _switch.name                    = "floodlight indicator(Clone)";
            _switch.transform.parent        = _lamp.transform;
            _switch.transform.localScale    = new Vector3(0.03f, 0.01f, 0.01f);
            _switch.transform.localPosition = new Vector3(0.0f, 0.09f, 0.04f);
            _switch.transform.localRotation = new Quaternion();
            _switch.AddComponent <Renderer>();
            _switchMaterial       = _switch.GetComponent <Renderer>().material;
            _switchMaterial.color = Color.red * 0.3f;
            GameObject.Destroy(_switch.GetComponent <Rigidbody>());
            GameObject.Destroy(_switch.GetComponent <Collider>());

            // Light
            _light           = _lamp.AddComponent <Light>();
            _light.type      = LightType.Spot;
            _light.color     = _lightColor;
            _light.intensity = _baseIntensity;
            _light.range     = 20.0f;
            _light.spotAngle = 80.0f;
            _light.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
            _light.renderMode = LightRenderMode.ForceVertex;
            _light.enabled    = false;
        }
예제 #5
0
        public void LoadRecorder()
        {
            // Create GameObject, load mesh and set Collider and Rigidbody for recorder.
            GameObject _nokkahuilu = LoadAssets.LoadOBJ(this, Path.Combine(ModLoader.GetModAssetsFolder(this), "nokkahuilu.obj"), true, true);

            _nokkahuilu.name = "Nokkahuilu";
            _nokkahuilu.GetComponent <Rigidbody>().interpolation          = RigidbodyInterpolation.None;
            _nokkahuilu.GetComponent <Rigidbody>().collisionDetectionMode = CollisionDetectionMode.Continuous;

            // Set flute to table.
            _nokkahuilu.transform.position      = new Vector3(-10.03136f, 0.23f, 14.44618f);
            _nokkahuilu.transform.localRotation = Quaternion.Euler(358.67f, 89.36f, 321.8837f);

            // Create Material
            Material mat = new Material(Shader.Find("Specular"));

            mat.name  = "RecorderMaterial";
            mat.color = new Color(0.640f, 0.494f, 0.181f, 1);
            _nokkahuilu.GetComponent <Renderer>().material = mat;

            // Make pivot object for recorder and add the actual recorder logic to it (Recorder.cs)
            GameObject RecorderPivot = new GameObject();

            RecorderPivot.name                    = "RecorderPivot";
            RecorderPivot.transform.parent        = GameObject.Find("FPSCamera").transform;
            RecorderPivot.transform.localPosition = Vector3.zero;
            RecorderPivot.transform.localRotation = Quaternion.Euler(0, 0, 0);
            _nokkahuilu.AddComponent <RecorderCollision>().recorder = RecorderPivot.AddComponent <Recorder>();

            // Instantiate copy of recorder to be used in FPS mode
            GameObject _nokkahuiluFPS = GameObject.Instantiate(_nokkahuilu);

            GameObject.Destroy(_nokkahuiluFPS.GetComponent <MeshCollider>());
            GameObject.Destroy(_nokkahuiluFPS.GetComponent <Rigidbody>());
            _nokkahuiluFPS.transform.parent        = GameObject.Find("FPSCamera").transform;
            _nokkahuiluFPS.transform.localPosition = new Vector3(0.0291f, -0.0919f, 0.301f);
            _nokkahuiluFPS.transform.localRotation = Quaternion.Euler(0, 180, 0);

            // Add and setup AudioSource component for recorder.
            RecorderPivot.gameObject.AddComponent <AudioSource>();
            RecorderPivot.GetComponent <AudioSource>().loop         = true;
            RecorderPivot.GetComponent <AudioSource>().spatialBlend = 0;
            RecorderPivot.GetComponent <AudioSource>().volume       = 1;

            // Set variables to RecorderPivot
            RecorderPivot.GetComponent <Recorder>().audio       = RecorderPivot.GetComponent <AudioSource>();
            RecorderPivot.GetComponent <Recorder>().recorder    = _nokkahuilu.transform;
            RecorderPivot.GetComponent <Recorder>().recorderFPS = _nokkahuiluFPS.transform;
            _nokkahuiluFPS.transform.parent = RecorderPivot.transform;
            _nokkahuiluFPS.gameObject.SetActive(false);

            // Load .wav file using WWW -class.
            WWW RecorderSound = new WWW("file:///" + @Path.Combine(ModLoader.GetModAssetsFolder(this), "g5.wav"));

            while (!RecorderSound.isDone)
            {
            }
            ;                                  // Wait sound to be loaded.

            // Add clip to recorder flute.
            RecorderPivot.GetComponent <AudioSource>().clip = RecorderSound.GetAudioClip(false);

            // Stop the loading loop.
            HasLoaded = true;
        }