private void MakePartScrewable(Screws screws, Vector3[] screwsScale)
        {
            if (screws != null && screws.screwsPositionsLocal != null && screws.screwsRotationLocal != null && screws.screwsTightness != null && screwsScale != null)
            {
                for (int i = 0; i < screws.screwsPositionsLocal.Length; i++)
                {
                    GameObject screw = GameObject.Instantiate(screwModelToUse);
                    screw.name = (parentGameObject.name + "_SCREW" + (i + 1));
                    screw.transform.SetParent(parentGameObject.transform);
                    screw.transform.localPosition = screws.screwsPositionsLocal[i];
                    screw.transform.localScale    = screwsScale[i];
                    screw.transform.localRotation = new Quaternion {
                        eulerAngles = screws.screwsRotationLocal[i]
                    };
                    screw.layer = LayerMask.NameToLayer("DontCollide");
                }

                this.parentGameObjectCollider = this.parentGameObject.GetComponent <Collider>();
            }
            screwableLogic = parentGameObject.AddComponent <ScrewableLogic>();
            screwableLogic.SetSavedInformation(screws, screw_material, screw_soundClip, parentGameObject, parentGameObjectCollider, this);

            if (screws.screwsTightness.All(element => element == screwableLogic.maxTightness))
            {
                //All Screws tight. Make part fixed
                this.parentGameObjectCollider.enabled = false;
                partFixed = true;
                screwableLogic.SetPartFixed(partFixed);
            }
        }
示例#2
0
 /// <summary>
 /// This loads the current (either loaded save or empty information about the screw into the MonoBehaviour class.
 /// This is needed so that the MonoBehaviour can work independet from the main class.
 /// </summary>
 /// <param name="screws">This is the screws save where all the information for a part is stored</param>
 /// <param name="screw_material">The screw material</param>
 /// <param name="screw_soundClip">The soundclip to be played when screwing in/out</param>
 /// <param name="parentGameObject">The parent gameObject</param>
 /// <param name="parentGameObjectCollider">The parent gameObjects collider</param>
 /// <param name="screwablePart">The screwable part object</param>
 public void SetSavedInformation(Screws screws, Material screw_material, AudioClip screw_soundClip, GameObject parentGameObject, Collider parentGameObjectCollider, ScrewablePart screwablePart)
 {
     this.screwablePart            = screwablePart;
     this.screws                   = screws;
     this.screw_material           = screw_material;
     this.screw_soundClip          = screw_soundClip;
     this.parentGameObject         = parentGameObject;
     this.parentGameObjectCollider = parentGameObjectCollider;
 }
示例#3
0
        private void ScrewIn(GameObject hitScrew, Screws screws, int screwIndex)
        {
            if (screws.screwsTightness[screwIndex] >= 0 && screws.screwsTightness[screwIndex] <= maxTightness - 1)
            {
                AudioSource.PlayClipAtPoint(this.screw_soundClip, hitScrew.transform.position);
                hitScrew.transform.Rotate(0, 0, rotationStep);
                hitScrew.transform.Translate(0f, 0f, -transformStep);

                screws.screwsPositionsLocal[screwIndex] = hitScrew.transform.localPosition;
                screws.screwsRotationLocal[screwIndex]  = hitScrew.transform.localRotation.eulerAngles;
                screws.screwsTightness[screwIndex]++;
                UpdateScrewInfoTightness(hitScrew, screws.screwsTightness[screwIndex]);
            }
        }
示例#4
0
        private void ScrewOut(GameObject hitScrew, Screws screws, int screwIndex)
        {
            if (screws.screwsTightness[screwIndex] > 0 && screws.screwsTightness[screwIndex] <= maxTightness)
            {
                AudioSource.PlayClipAtPoint(this.screw_soundClip, hitScrew.transform.position);
                hitScrew.transform.Rotate(0, 0, -rotationStep);
                hitScrew.transform.Translate(0f, 0f, transformStep); //Has to be adjustable

                screws.screwsPositionsLocal[screwIndex] = hitScrew.transform.localPosition;
                screws.screwsRotationLocal[screwIndex]  = hitScrew.transform.localRotation.eulerAngles;
                screws.screwsTightness[screwIndex]--;
                UpdateScrewInfoTightness(hitScrew, screws.screwsTightness[screwIndex]);
            }
            partFixed = false;
            screwablePart.SetPartFixed(false);
        }
示例#5
0
        /// <summary>
        /// makes part that got created using the Constructor boltable by creating child GameObjects using the bolt_model loaded
        /// </summary>
        /// <param name="screws">The screws of the single part</param>
        private void MakePartScrewable(Screws screws)
        {
            for (int i = 0; i < screws.screwsPositionsLocal.Length; i++)
            {
                GameObject bolt = GameObject.Instantiate(boltModelToUse);
                bolt.name = (parentGameObject.name + "_BOLT" + (i + 1));
                bolt.transform.SetParent(parentGameObject.transform);
                bolt.transform.localPosition = screws.screwsPositionsLocal[i];
                bolt.transform.localScale    = new Vector3(0.7f, 0.7f, 0.7f);
                bolt.transform.localRotation = new Quaternion {
                    eulerAngles = screws.screwsRotationLocal[i]
                };
                bolt.layer = LayerMask.NameToLayer("DontCollide");
            }

            this.parentGameObjectCollider = this.parentGameObject.GetComponent <Collider>();
            if (screws.screwsTightness.All(element => element == 8))
            {
                //All Screws tight. Make part fixed
                this.parentGameObjectCollider.enabled = false;
                partFixed = true;
            }
        }
示例#6
0
        /// <summary>
        /// Generates the Screws for a part and makes them detectable using the DetectBolting method
        /// <para>Dont ever change the name of the BOLT GameObject that gets created, which is always parentGameObject.name + "_BOLT + boltNumber</para>
        /// <para>example: Racing Turbocharger_BOLT1</para>
        /// <para>the constructor will auto find the correct gameObject to create the screws on (if names did not change)</para>
        /// </summary>
        /// <param name="screwsListSave">SortedList of saved information for ALL Parts!</param>
        /// <param name="parentGameObject">The "parentGameObject" GameObject on which bolts should be placed. This should always be the ModAPI part.rigidPart when using modapi!!!</param>
        /// <param name="screwsPositionsLocal">The position where each screw should be placed on the parentGameObject GameObject</param>
        /// <param name="screwsRotationLocal">The rotation the screws should have when placed on parentGameObject GameObject</param>
        /// <param name="screwsSizeForAll">The size for all screws to be used as a single value if it is set to 8 you need to use the wrench size 8 to install the parts</param>
        /// <param name="assets">The assets bundle to use. this will by default load the model as 'bolt_nut.prefab' and the material as 'bolt-texture.mat make sure those are inside your prefab</param>
        public ScrewablePart(SortedList <String, Screws> screwsListSave, GameObject parentGameObject, Vector3[] screwsPositionsLocal, Vector3[] screwsRotationLocal, int screwsSizeForAll, AssetBundle assets)
        {
            this.assets = assets;

            this.selectedItem    = GameObject.Find("PLAYER/Pivot/AnimPivot/Camera/FPSCamera/SelectItem");
            this.selectedItemFSM = selectedItem.GetComponent <PlayMakerFSM>();
            FsmHook.FsmInject(selectedItem, "Hand", new Action(ChangedToHand));
            FsmHook.FsmInject(selectedItem, "Tools", new Action(ChangedToTools));

            this._wrenchSize      = selectedItemFSM.Fsm.GetFsmFloat("OldWrench");
            this.bolt_material    = assets.LoadAsset <Material>("bolt-texture.mat");
            this.boltModelToUse   = (assets.LoadAsset("bolt_nut.prefab") as GameObject);
            this.parentGameObject = parentGameObject;

            this.screwsDefaultPositionLocal = screwsPositionsLocal;
            this.screwsDefaultRotationLocal = screwsRotationLocal;


            if (screwsListSave != null)
            {
                Screws loadedScrews;
                bool   successWhenLoading = screwsListSave.TryGetValue(parentGameObject.name, out loadedScrews);
                if (successWhenLoading)
                {
                    //Save provided and found in file
                    this.screws = loadedScrews;
                }
                else
                {
                    this.screws = new Screws();
                }
            }

            if (this.screws == null)
            {
                //No Save provided
                this.screws = new Screws();


                //Initialize boltSize
                int[] boltSize = new int[screwsPositionsLocal.Length];
                for (int i = 0; i < boltSize.Length; i++)
                {
                    boltSize[i] = screwsSizeForAll;
                }

                for (int i = 0; i < boltSize.Length; i++)
                {
                    if (boltSize[i] < 5)
                    {
                        boltSize[i] = 5;
                    }
                    else if (boltSize[i] > 15)
                    {
                        boltSize[i] = 15;
                    }
                }

                //Initialize boltTightness
                int[] boltTightness = new int[screwsPositionsLocal.Length];
                for (int i = 0; i < boltTightness.Length; i++)
                {
                    boltTightness[i] = 0;
                }

                this.screws.partName             = parentGameObject.name;
                this.screws.screwsPositionsLocal = screwsPositionsLocal;
                this.screws.screwsRotationLocal  = screwsRotationLocal;
                this.screws.screwsSize           = boltSize;
                this.screws.screwsTightness      = boltTightness;
            }
            MakePartScrewable(this.screws);
        }
        private void LoadScrewsSave(SortedList <String, Screws> screwsListSave, Vector3[] screwsPositionLocal, Vector3[] screwsRotationLocal, int[] sizes)
        {
            if (screwsListSave != null)
            {
                Screws loadedScrews;
                bool   successWhenLoading = screwsListSave.TryGetValue(parentGameObject.name, out loadedScrews);
                if (successWhenLoading)
                {
                    //Save provided and found in file
                    this.screws = loadedScrews;
                }
                else
                {
                    //Save provided but part not found inside
                    this.screws = new Screws();

                    //Initialize screwSize
                    int[] screwSize = new int[screwsPositionLocal.Length];
                    for (int i = 0; i < screwSize.Length; i++)
                    {
                        screwSize[i] = sizes[i];
                    }

                    for (int i = 0; i < screwSize.Length; i++)
                    {
                        if (screwSize[i] < 5)
                        {
                            screwSize[i] = 5;
                        }
                        else if (screwSize[i] > 15)
                        {
                            screwSize[i] = 15;
                        }
                    }

                    //Initialize screwTightness
                    int[] screwTightness = new int[screwsPositionLocal.Length];
                    for (int i = 0; i < screwTightness.Length; i++)
                    {
                        screwTightness[i] = 0;
                    }

                    this.screws.partName             = parentGameObject.name;
                    this.screws.screwsPositionsLocal = screwsPositionLocal;
                    this.screws.screwsRotationLocal  = screwsRotationLocal;
                    this.screws.screwsSize           = screwSize;
                    this.screws.screwsTightness      = screwTightness;
                }
            }

            if (this.screws == null)
            {
                //No Save provided
                this.screws = new Screws();


                //Initialize screwSize
                int[] screwSize = new int[screwsPositionLocal.Length];
                for (int i = 0; i < screwSize.Length; i++)
                {
                    screwSize[i] = sizes[i];
                }

                for (int i = 0; i < screwSize.Length; i++)
                {
                    if (screwSize[i] < 5)
                    {
                        screwSize[i] = 5;
                    }
                    else if (screwSize[i] > 15)
                    {
                        screwSize[i] = 15;
                    }
                }

                //Initialize screwTightness
                int[] screwTightness = new int[screwsPositionLocal.Length];
                for (int i = 0; i < screwTightness.Length; i++)
                {
                    screwTightness[i] = 0;
                }

                this.screws.partName             = parentGameObject.name;
                this.screws.screwsPositionsLocal = screwsPositionLocal;
                this.screws.screwsRotationLocal  = screwsRotationLocal;
                this.screws.screwsSize           = screwSize;
                this.screws.screwsTightness      = screwTightness;
            }
        }