Inheritance: EnviroGear
Ejemplo n.º 1
0
 public static float AverageMoveablePulleyPositionX()
 {
     if (pulleys != null)
     {
         Vector3 pos = new Vector3();
         //the number of moveable pulleys
         int count = 0;;
         foreach (GameObject pulley in pulleys)
         {
             Pulley p = pulley.GetComponent <Pulley>();
             if (!p.fixedPulley)
             {
                 pos += pulley.transform.position;
                 count++;
             }
         }
         if (count > 0)
         {
             Vector3 average_pos = pos / count;
             return(average_pos.x);
         }
         else
         {
             return(0f);
         }
     }
     else
     {
         return(1f);
     }
 }
Ejemplo n.º 2
0
 private void AddMovementComponents(VRLocomotionRig a_vrLR)
 {
     a_vrLR.s_head.gameObject.AddComponent <SteamVR_UpdatePoses>();
     m_headBob  = a_vrLR.s_head.gameObject.AddComponent <HeadBob>();  // Adds the HeadBob movement logic component
     m_armSwing = a_vrLR.s_head.gameObject.AddComponent <ArmSwing>(); // Adds the ArmSwing movement logic component
     m_pulley   = a_vrLR.s_head.gameObject.AddComponent <Pulley>();   // Adds the Pulley movement logic component
     m_tPad     = a_vrLR.s_head.gameObject.AddComponent <Touchpad>();
     // DEVELOPER: ADD YOUR OWN CUSTOM VR MOVEMENT COMPONENT HERE!
 }
Ejemplo n.º 3
0
        // DEVELOPER: add a string for your zone tag name! dont forget to create the tag in unity and apply it
        //private const string DevCollisionTag      = "DeveloperZone";

        #endregion

        #region Unity Methods

        void Awake()
        {
            m_locoRig = GetComponent <VRLocomotionRig>();

            source = GetComponent <AudioSource>();

            try {
                m_hbMovement = m_locoRig.s_head.GetComponent <HeadBob>();
                m_asMovement = m_locoRig.s_head.GetComponent <ArmSwing>();
                m_pMovement  = m_locoRig.s_head.GetComponent <Pulley>();
            } catch {
                Debug.LogError("there are no movement components attached to your VR rig! please ensure you did the setup correctly!");
            }
            AutoDetectCurrentMovement();
        }
Ejemplo n.º 4
0
        public void LoadMisc(WzImage mapImage, Board mapBoard)
        {
            // All of the following properties are extremely esoteric features that only appear in a handful of maps.
            // They are implemented here for the sake of completeness, and being able to repack their maps without corruption.

            WzImageProperty clock    = mapImage["clock"];
            WzImageProperty ship     = mapImage["shipObj"];
            WzImageProperty area     = mapImage["area"];
            WzImageProperty healer   = mapImage["healer"];
            WzImageProperty pulley   = mapImage["pulley"];
            WzImageProperty BuffZone = mapImage["BuffZone"];
            WzImageProperty swimArea = mapImage["swimArea"];

            if (clock != null)
            {
                Clock clockInstance = new Clock(mapBoard, new Rectangle(InfoTool.GetInt(clock["x"]), InfoTool.GetInt(clock["y"]), InfoTool.GetInt(clock["width"]), InfoTool.GetInt(clock["height"])));
                mapBoard.BoardItems.Add(clockInstance, false);
            }
            if (ship != null)
            {
                string     objPath      = InfoTool.GetString(ship["shipObj"]);
                string[]   objPathParts = objPath.Split("/".ToCharArray());
                string     oS           = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0           = objPathParts[objPathParts.Length - 3];
                string     l1           = objPathParts[objPathParts.Length - 2];
                string     l2           = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo      = ObjectInfo.Get(oS, l0, l1, l2);
                ShipObject shipInstance = new ShipObject(objInfo, mapBoard,
                                                         InfoTool.GetInt(ship["x"]),
                                                         InfoTool.GetInt(ship["y"]),
                                                         InfoTool.GetOptionalInt(ship["z"]),
                                                         InfoTool.GetOptionalInt(ship["x0"]),
                                                         InfoTool.GetInt(ship["tMove"]),
                                                         InfoTool.GetInt(ship["shipKind"]),
                                                         InfoTool.GetBool(ship["f"]));
                mapBoard.BoardItems.Add(shipInstance, false);
            }
            if (area != null)
            {
                foreach (WzImageProperty prop in area.WzProperties)
                {
                    int  x1       = InfoTool.GetInt(prop["x1"]);
                    int  x2       = InfoTool.GetInt(prop["x2"]);
                    int  y1       = InfoTool.GetInt(prop["y1"]);
                    int  y2       = InfoTool.GetInt(prop["y2"]);
                    Area currArea = new Area(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name);
                    mapBoard.BoardItems.Add(currArea, false);
                }
            }
            if (healer != null)
            {
                string     objPath        = InfoTool.GetString(healer["healer"]);
                string[]   objPathParts   = objPath.Split("/".ToCharArray());
                string     oS             = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0             = objPathParts[objPathParts.Length - 3];
                string     l1             = objPathParts[objPathParts.Length - 2];
                string     l2             = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo        = ObjectInfo.Get(oS, l0, l1, l2);
                Healer     healerInstance = new Healer(objInfo, mapBoard,
                                                       InfoTool.GetInt(healer["x"]),
                                                       InfoTool.GetInt(healer["yMin"]),
                                                       InfoTool.GetInt(healer["yMax"]),
                                                       InfoTool.GetInt(healer["healMin"]),
                                                       InfoTool.GetInt(healer["healMax"]),
                                                       InfoTool.GetInt(healer["fall"]),
                                                       InfoTool.GetInt(healer["rise"]));
                mapBoard.BoardItems.Add(healerInstance, false);
            }
            if (pulley != null)
            {
                string     objPath        = InfoTool.GetString(pulley["pulley"]);
                string[]   objPathParts   = objPath.Split("/".ToCharArray());
                string     oS             = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0             = objPathParts[objPathParts.Length - 3];
                string     l1             = objPathParts[objPathParts.Length - 2];
                string     l2             = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo        = ObjectInfo.Get(oS, l0, l1, l2);
                Pulley     pulleyInstance = new Pulley(objInfo, mapBoard,
                                                       InfoTool.GetInt(pulley["x"]),
                                                       InfoTool.GetInt(pulley["y"]));
                mapBoard.BoardItems.Add(pulleyInstance, false);
            }
            if (BuffZone != null)
            {
                foreach (WzImageProperty zone in BuffZone.WzProperties)
                {
                    int      x1       = InfoTool.GetInt(zone["x1"]);
                    int      x2       = InfoTool.GetInt(zone["x2"]);
                    int      y1       = InfoTool.GetInt(zone["y1"]);
                    int      y2       = InfoTool.GetInt(zone["y2"]);
                    int      id       = InfoTool.GetInt(zone["ItemID"]);
                    int      interval = InfoTool.GetInt(zone["Interval"]);
                    int      duration = InfoTool.GetInt(zone["Duration"]);
                    BuffZone currZone = new BuffZone(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), id, interval, duration, zone.Name);
                    mapBoard.BoardItems.Add(currZone, false);
                }
            }
            if (swimArea != null)
            {
                foreach (WzImageProperty prop in swimArea.WzProperties)
                {
                    int      x1       = InfoTool.GetInt(prop["x1"]);
                    int      x2       = InfoTool.GetInt(prop["x2"]);
                    int      y1       = InfoTool.GetInt(prop["y1"]);
                    int      y2       = InfoTool.GetInt(prop["y2"]);
                    SwimArea currArea = new SwimArea(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name);
                    mapBoard.BoardItems.Add(currArea, false);
                }
            }
            // Some misc items are not implemented here; these are copied byte-to-byte from the original. See VerifyMapPropsKnown for details.
        }
Ejemplo n.º 5
0
 void Start()
 {
     cargoMass = 0;
     other     = otherPulley.GetComponent <Pulley>();
     initCoord = transform.position;
 }
Ejemplo n.º 6
0
        private void ShowSettingsTab()
        {
            EditorGUILayout.Separator();
            SerializedProperty vrType            = SerializedObject.FindProperty("vrType");
            SerializedProperty movementType      = SerializedObject.FindProperty("movementType");
            SerializedProperty startMoveSpeed    = SerializedObject.FindProperty("startMoveSpeed");
            SerializedProperty rigAlreadyInScene = SerializedObject.FindProperty("haveRigPrefab");
            SerializedProperty vrRig             = SerializedObject.FindProperty("vrRig");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(vrType);
            if (EditorGUI.EndChangeCheck())
            {
                Utility.ChangeVRType((Utility.eVRType)vrType.enumValueIndex);
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(movementType);
            if (EditorGUI.EndChangeCheck())
            {
                Utility.ChangeMovementType((Utility.eMovementType)movementType.enumValueIndex);
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Start Movement Speed");
            LocomotionSettings.startMoveSpeed = (float)EditorGUILayout.Slider((float)startMoveSpeed.floatValue, 1.0f, 4.0f);
            EditorGUILayout.EndHorizontal();

            if (!Utility.RigInScene)
            {
                EditorGUILayout.PropertyField(vrRig);
                Utility.BUTTON_TEXT = "Find & Setup Locomotion";
            }
            else
            {
                Utility.BUTTON_TEXT = "Update Rig In Scene";
            }

            if (GUILayout.Button(Utility.BUTTON_TEXT))
            {
                if (Utility.BUTTON_TEXT.Equals("Find & Setup Locomotion") && !Utility.RigInScene)
                {
                    try {
                        LocomotionSettings.vrRig = PrefabUtility.GetPrefabParent(FindObjectOfType <SteamVR_ControllerManager>().gameObject) as GameObject;
                    } catch {
                        Debug.LogError("SETUP ERROR: 'missing camera rig' Please drag in the [CameraRig] prefab provided by SteamVR and try again!");
                        return;
                    }
                    VRLocomotionRig vrLR;

                    FindAndDisableRig();                                        // finds and disables the steamVR rig
                    CreateLocoRig("[Camera Rig] - LOCO");                       // Instantiating a custom rig called "[Camera Rig] - LOCO"
                    AddNavMesh(0.5f, 1.5f);                                     // Adding the nav mesh component and setting its height and radius
                    AddLocomotionRig(out vrLR);                                 // Adding the VRLocomotionRig and running the AutoSetup method to attach all the needed components
                    AddCapsuleCollider(0.5f, 1.5f, new Vector3(0, 0.68f, 0));   // Adding the capsule collider component and setting up its radius, height, and center offset
                    AddRigidbody(false, true);                                  // Adding the rigidbody component and setting gravity to false and kinimetic to true
                    AddVrCharController();                                      // Adds the VR character controller to allow for realtime switching
                    AddMovementComponents(vrLR);                                // Adds the required movement logic for HeadBob, ArmSwing and Pulley

                    vrLR.s_handLeft.gameObject.AddComponent <VRBasicController>();
                    vrLR.s_handRight.gameObject.AddComponent <VRBasicController>();

                    //-----------------------------------------------------------------------------------------------------
                    //                    Enables the appropriate movement logic, based on your settings
                    //-----------------------------------------------------------------------------------------------------
                    switch (LocomotionSettings.movementType)
                    {
                    case Utility.eMovementType.BOBBING: m_headBob.enabled = true; m_armSwing.enabled = false; m_pulley.enabled = false; break;

                    case Utility.eMovementType.ARM_SWING:  m_headBob.enabled = false; m_armSwing.enabled = true; m_pulley.enabled = false; m_armSwing.motionType = ArmSwing.eMotionType.ARM_SWING; break;

                    case Utility.eMovementType.BREAST_STROKE: m_headBob.enabled = false; m_armSwing.enabled = true; m_pulley.enabled = false; m_armSwing.motionType = ArmSwing.eMotionType.BREAST_STROKE; break;

                    case Utility.eMovementType.SKIING: m_headBob.enabled = false; m_armSwing.enabled = true; m_pulley.enabled = false; m_armSwing.motionType = ArmSwing.eMotionType.SKIING; break;

                    case Utility.eMovementType.PULLEY: m_headBob.enabled = false; m_armSwing.enabled = false; m_pulley.enabled = true; break;
                        // DEVELOPER: IF YOU ADD YOUR OWN, DONT FORGET TO ADD A CASE TO SWITCH IT ON AND OFF
                    }
                    //----------------------------------------------------------------------------------------------------

                    Utility.RigInScene = true;
                }
                else if (Utility.RigInScene)
                {
                    VRLocomotionRig vrLocoRig = null;
                    if (!m_steamVRrig.activeInHierarchy)
                    {
                        try {
                            vrLocoRig = FindObjectOfType <SteamVR_ControllerManager>().gameObject.GetComponent <VRLocomotionRig>();
                        } catch {
                            vrLocoRig = null;
                            m_steamVRrig.SetActive(true);
                        }
                    }

                    if (vrLocoRig == null)
                    {
                        Utility.RigInScene       = false;
                        LocomotionSettings.vrRig = PrefabUtility.GetPrefabParent(m_steamVRrig.gameObject) as GameObject;

                        //FIXME: add new functions to replace the old redundant code below!
                        GameObject rig = Instantiate(LocomotionSettings.vrRig) as GameObject;
                        rig.name = "[Camera Rig] - LOCO";
                        UnityEngine.AI.NavMeshAgent ag = rig.AddComponent <UnityEngine.AI.NavMeshAgent>();
                        ag.radius = 1;
                        ag.height = 1.5f;
                        VRLocomotionRig vrLR = rig.AddComponent <VRLocomotionRig>();
                        vrLR.AutoSetup();
                        HeadBob  hd = vrLR.s_head.gameObject.AddComponent <HeadBob>();
                        ArmSwing ar = vrLR.s_head.gameObject.AddComponent <ArmSwing>();
                        Pulley   pl = vrLR.s_head.gameObject.AddComponent <Pulley>();
                        vrLR.s_head.gameObject.AddComponent <SteamVR_UpdatePoses>();

                        vrLR.s_handLeft.gameObject.AddComponent <VRBasicController>();
                        vrLR.s_handRight.gameObject.AddComponent <VRBasicController>();

                        switch (LocomotionSettings.movementType)
                        {
                        case Utility.eMovementType.BOBBING: hd.enabled = true; ar.enabled = false; pl.enabled = false; break;

                        case Utility.eMovementType.ARM_SWING: hd.enabled = false; ar.enabled = true; pl.enabled = false; break;

                        case Utility.eMovementType.PULLEY: hd.enabled = false; ar.enabled = false; pl.enabled = true; break;
                        }

                        vrLocoRig = rig.GetComponent <VRLocomotionRig>();
                        m_steamVRrig.SetActive(false);
                        Utility.RigInScene = true;
                    }

                    HeadBob  h = vrLocoRig.s_head.gameObject.GetComponent <HeadBob>();
                    ArmSwing a = vrLocoRig.s_head.gameObject.GetComponent <ArmSwing>();
                    Pulley   p = vrLocoRig.s_head.gameObject.GetComponent <Pulley>();
                    switch (LocomotionSettings.movementType)
                    {
                    case Utility.eMovementType.BOBBING: h.enabled = true; a.enabled = false; p.enabled = false; break;

                    case Utility.eMovementType.ARM_SWING: h.enabled = false; a.enabled = true; p.enabled = false; break;

                    case Utility.eMovementType.PULLEY: h.enabled = false; a.enabled = false; p.enabled = true; break;
                    }

                    m_steamVRrig.SetActive(false);
                }
            }

            if (GUILayout.Button("Click to reset Settings & Scene"))
            {
                Utility.RigInScene = false;
                try {
                    m_steamVRrig.SetActive(true);
                    //try {
                    GameObject o = GameObject.Find("[Camera Rig] - LOCO");
                    DestroyImmediate(o);
                    DestroyImmediate(m_steamVRrig);
                } catch {
                    Debug.LogWarning("WARNING: can't reset! it has already been reset! drag the CameraRig provided by steam VR into your hierarchy and click the button above to get started");
                }
            }
        }