Example #1
0
    void OnTriggerStay(Collider collider)
    {
        // check type of collision object

        if (state != SnapBaseState.Open)
        {
            return;
        }

        SnapTarget target = collider.gameObject.GetComponent <SnapTarget> ();

        if (target == null || target.targetType != targetType)
        {
            return;
        }

        if (!target.isFree())
        {
            return;
        }

        if (checkDependency())
        {
            targetObj = collider.gameObject;
            target.snapTo(position);
            state = SnapBaseState.Closed;
        }
    }
Example #2
0
    void OnTriggerExit(Collider collider)
    {
        if (state != SnapBaseState.Closed || targetObj == null || (targetObj != null && targetObj.GetComponent <SnapTarget>().state == SnapTargetState.Locked))
        {
            return;
        }

        if (collider.gameObject != targetObj)
        {
            return;
        }

        SnapTarget target = targetObj.GetComponent <SnapTarget> ();

        if (target == null || target.targetType != targetType)
        {
            return;
        }

        target.disconnect();

        targetObj = null;

        state = SnapBaseState.Open;
    }
Example #3
0
    // Use this for initialization
    void Start()
    {
        if (GetComponent <SnapTarget> () != null)
        {
            snap = GetComponent <SnapTarget> ();
        }

        if (GetComponent <HighlighterHelper> () != null)
        {
            hl = GetComponent <HighlighterHelper> ();
        }

        audioSource              = GetComponent <AudioSource> ();
        audioSource.loop         = false;
        audioSource.volume       = volume;
        audioSource.spatialBlend = 0.0f;
    }
Example #4
0
        public void MoveTo(Point position)
        {
            if (SnapTarget != null)
            {
                double angle;
                SnapTarget.SnapPoint(ref position, out angle);

                setAngle(angle);
            }

            _inMoveTo = true;
            try
            {
                Left = position.X;
                Top  = position.Y;
            }
            finally
            {
                _inMoveTo = false;
            }
        }
    private void DropInRoom(Worker worker, SnapTarget snapTarget)
    {
        SnapTarget openSnapTarget = GameController.FindOpenSnapTargetOfType( snapTarget.GetType() );

        dragObject.EndDrag(openSnapTarget);
    }
 void Start()
 {
     if(snapTarget == null) snapTarget = GameController.AddSnapTarget(gameObject);	// TODO: This will change.
 }
Example #7
0
    /////////////////////////// DRAG //////////////////////////////
    public void StartDrag()
    {
        gameObject.layer = 2;													// Ignore Raycasting
        lastSnapTarget = currentSnapTarget;										// Set lastSnapTarget to currentSnapTarget for later reference
        if(currentSnapTarget != null) currentSnapTarget.SetWorker(null);		// Empty currentSnapTarget
        currentSnapTarget = null;

        anim.SetBool(currentAnimation, false);
        currentAnimation = "MouseDrag";
        anim.SetBool(currentAnimation, true);
    }
Example #8
0
    public void EndDrag(SnapTarget snapTarget)
    {
        if(snapTarget != null)		// Set pos to snapTarget
        {
            if(currentSnapTarget != null)
            {
                lastSnapTarget = currentSnapTarget;
                //Debug.Log("setting lastSnapTarget to " + currentSnapTarget.ToString());
            }
            if(snapTarget.isEmpty()) currentSnapTarget = snapTarget; 	// If snapTarget is empty, snap to it
            else currentSnapTarget = GameController.FindOpenSnapTargetOfType( snapTarget.GetType() );	// else, find empty snapTarget of same type
        }
        else 						// Set pos to lastSnapTarget
        {
            if(lastSnapTarget == null || !lastSnapTarget.isEmpty())		// If lastSnapTarget is null or not empty, find empty snapTarget of same type
                lastSnapTarget = GameController.FindOpenSnapTargetOfType( SnapTargetType.Workstation );

            currentSnapTarget = lastSnapTarget;
        }

        //Debug.Log("currentSnapTarget " + currentSnapTarget + " , lastSnapTarget " + lastSnapTarget);
        if(currentSnapTarget != null && lastSnapTarget != null)	// Check For timeInRoom reset
        {
            //Debug.Log(""+currentSnapTarget.GetType() +", "+lastSnapTarget.GetType());
            if(currentSnapTarget.GetType() != lastSnapTarget.GetType())	timeInRoom = 0f; // If switched room type, reset timeInRoom
        }
        Debug.Log("Worker.timeInRoom = " + timeInRoom);

        if(currentSnapTarget == null) return;

        currentSnapTarget.SetWorker(this);					// Fill currentSnapTarget

        Vector3 pos = currentSnapTarget.GetPosition();
        //pos.y = 0.5f;
        pos.y = 0.0f;

        SetPosition( pos );
        gameObject.layer = 9;			// Default Layer

        // Get Animation Name from currentSnapTarget
        Debug.Log ("Play animation " + currentSnapTarget.animation +", Stop animation "+ currentAnimation);
        anim.SetBool(currentAnimation, false);
        currentAnimation = currentSnapTarget.animation;
        anim.SetBool(currentAnimation, true);
    }
    /////////////////////////// SNAPTARGET LIST //////////////////////////////
    public static SnapTarget AddSnapTarget(GameObject newSnapTarget)
    {
        SnapTarget snapTarget = null;
        SnapTargetType type = SnapTargetType.Workstation;
        bool isRoom = false;
        if(newSnapTarget)
        {
            SnapTargetScript script = newSnapTarget.GetComponent<SnapTargetScript>();
            if(script != null)
            {
                type = script.snapTargetType;
                isRoom = script.isRoom;
            }
        }

        snapTarget = new SnapTarget(newSnapTarget, type, isRoom);
        snaptargets.Add(snapTarget);

        //Debug.Log("GameController -> snaptargets.Count = " + snaptargets.Count);

        return snapTarget;
    }
    private void updateStep()
    {
        if (stepIndex < 0 || stepIndex >= steps.Length)
        {
            return;
        }
        StepInfo info = steps [stepIndex];

        GameObject[] items  = info.items;
        AudioClip[]  audios = info.audios;

        // pick up the tire iron
        if (stepIndex == 0)
        {
            if (items[0].GetComponent <SnapTarget>().state == SnapTargetState.Locked)
            {
                items[0].GetComponent <SnapTarget>().unlockTarget();
            }
            if (items[1].GetComponent <SnapBase>().state == SnapBaseState.Closed)
            {
                return;
            }
            lightOffAll(items);
        }
        // remove the lug nuts
        else if (stepIndex >= 1 && stepIndex <= 5)
        {
            TwistTarget2 lugNut = items[0].GetComponent <TwistTarget2>();
            if (lugNut.progress != 0)
            {
                return;
            }
            items[0].GetComponent <SnapTarget>().highlighter.lightOff();
            items[0].GetComponent <TwistTarget2>().SetDisable();
        }
        // put the jack to the correct position
        else if (stepIndex == 6)
        {
            if (items[0].GetComponent <SnapTarget>().state == SnapTargetState.Locked)
            {
                items[0].GetComponent <SnapTarget>().unlockTarget();
            }
            if (items[1].GetComponent <SnapBase>().state == SnapBaseState.Closed)
            {
                return;
            }
            lightOffAll(items);
        }
        // put the jack to the correct position
        else if (stepIndex == 7)
        {
            if (items [0].GetComponent <SnapTarget> ().state != SnapTargetState.Closed)
            {
                return;
            }
            lightOffAll(items);
        }
        // pick up the jack hook
        else if (stepIndex == 8)
        {
            if (items [0].GetComponent <SnapTarget> ().state == SnapTargetState.Locked)
            {
                items [0].GetComponent <SnapTarget> ().unlockTarget();
            }
            if (items [1].GetComponent <SnapBase> ().state == SnapBaseState.Closed)
            {
                return;
            }
            lightOffAll(items);
        }
        else if (stepIndex == 9)
        {
            for (int i = 2; i < items.Length; i++)
            {
                if (items [i].GetComponent <SnapTarget> ().state != SnapTargetState.Locked)
                {
                    items [i].GetComponent <SnapTarget> ().lockTarget();
                    items [i].GetComponent <SnapTarget> ().highlighter.lightOff();
                }
            }


            if (items [0].GetComponent <JackHook> ().state != JackHookState.Connecting)
            {
                items [1].GetComponent <HighlighterHelper> ().lightOn(Color.green);
                return;
            }

            // lock the jack once the jack hook is connected.
            items [0].GetComponent <JackHook> ().SetEnable();
            steps [0].items [0].GetComponent <SnapTarget> ().lockTarget();

            if (items [1].GetComponent <JackHookBase> ().getProgress() < 1.0f)
            {
                return;
            }

            items [0].GetComponent <JackHook> ().SetDisable();

            lightOffAll(items);
        }
        // remove the lug nuts
        else if (stepIndex >= 10 && stepIndex <= 14)
        {
            SnapTarget lugNut = items [0].GetComponent <SnapTarget> ();
            if (lugNut.state == SnapTargetState.Locked)
            {
                lugNut.unlockTarget();
            }
            if (lugNut.state != SnapTargetState.Open)
            {
                return;
            }
            lugNut.highlighter.lightOff();
        }
        else if (stepIndex == 15)
        {
            SnapTarget flatTire = items [0].GetComponent <SnapTarget> ();
            if (flatTire.state == SnapTargetState.Locked)
            {
                flatTire.unlockTarget();
            }

            if (flatTire.state != SnapTargetState.Open)
            {
                return;
            }
            flatTire.highlighter.lightOff();
        }
        // get the spare tire from the truck
        else if (stepIndex == 16)
        {
            // hide the tool tray over the spare tire
            items [2].SetActive(false);

            if (items [0].GetComponent <SnapTarget> ().state == SnapTargetState.Locked)
            {
                items [0].GetComponent <SnapTarget> ().unlockTarget();
            }

            if (items [1].GetComponent <SnapBase> ().state == SnapBaseState.Closed)
            {
                return;
            }

            lightOffAll(items);
        }
        // put the spare tire onto the hub
        else if (stepIndex == 17)
        {
            if (items [1].GetComponent <SnapBase> ().state != SnapBaseState.Closed)
            {
                return;
            }

            lightOffAll(items);
        }
        // put back the lug nuts and tighten them
        else if (stepIndex >= 18 && stepIndex <= 22)
        {
            SnapBase stud = items [0].GetComponent <SnapBase> ();

            if (stud.targetObj != null && curObj == null)
            {
                curObj = stud.targetObj;
                if (curObj.GetComponent <TwistTarget2> () != null)
                {
                    curObj.GetComponent <TwistTarget2> ().SetEnable();
                }
                // please put on tighten the lugNut with Tire Iron
                if (audios.Length > 1)
                {
                    playAudioEffect(audios [1]);
                }
            }

            if (stud.state == SnapBaseState.Closed)
            {
                HighlighterHelper[] hl = stud.GetComponentsInChildren <HighlighterHelper> ();
                if (hl.Length > 0)
                {
                    hl [0].lightOff();
                }
            }
            if (stud.state == SnapBaseState.Closed &&
                curObj != null &&
                curObj.GetComponent <TwistTarget2> ().progress >= curObj.GetComponent <TwistTarget2> ().max2)
            {
                curObj = null;
                // go to next Step
            }
            else
            {
                return;
            }

            lightOffAll(items);
        }
        // jack down the car
        else if (stepIndex == 23)
        {
            items [0].GetComponent <JackHook> ().SetEnable();

            if (items [1].GetComponent <JackHookBase> ().getProgress() > 0.0f)
            {
                return;
            }

            lightOffAll(items);

            if (audios.Length > 1)
            {
                playAudioEffect(audios [1]);
            }
        }
        // put the flat tire to the truck
        else if (stepIndex == 24)
        {
            items [2].SetActive(false);
            if (items [1].GetComponent <SnapBase> ().state != SnapBaseState.Closed)
            {
                return;
            }

            items [0].GetComponent <SnapTarget> ().lockTarget();
            items [2].SetActive(true);
            lightOffAll(items);
        }

        // disconnect the jack hook and put it back to the trunk
        else if (stepIndex == 25)
        {
            // disable the jaskhook base;
            items [1].SetActive(false);

            items [0].GetComponent <JackHook> ().SetState(JackHookState.Open);

            if (items [2].GetComponent <SnapBase> ().state != SnapBaseState.Closed)
            {
                return;
            }

            // unlock the jack
            steps [0].items [0].GetComponent <SnapTarget> ().unlockTarget();

            lightOffAll(items);
        }
        // remove the jack and put it back to the trunk
        else if (stepIndex == 26)
        {
            if (items [1].GetComponent <SnapBase> ().state != SnapBaseState.Closed)
            {
                return;
            }
            lightOffAll(items);
        }
        // put the tire iron to the  tooltray
        else if (stepIndex == 27)
        {
            if (items [1].GetComponent <SnapBase> ().state != SnapBaseState.Closed)
            {
                return;
            }
            lightOffAll(items);
        }
        else if (stepIndex == 28)
        {
            HighlighterHelper car = items [0].GetComponent <HighlighterHelper> ();
            car.lightOn();
            print("Completed!!!!!");
            completed   = true;
            timer.index = 3;
        }

        info.delay -= Time.deltaTime;
        if (info.delay > 0)
        {
            return;
        }
        stepIndex = info.nextStepIndex;
        enableStep();
    }
    private void MouseOver()
    {
        if(mousePos != lastMousePos)
        {
            mouseOverObject = RaycastFromMouse();
            GameController.MouseOver(mouseOverObject);

            mouseOverWorker = null;
            mouseOverSnapTarget = null;
            if(!mouseOverObject) return;

            if(mouseOverObject.CompareTag("SnapTarget") || mouseOverObject.layer == 8)
         	{
                SnapTargetScript script = mouseOverObject.GetComponent<SnapTargetScript>();
                mouseOverSnapTarget = script.GetSnapTarget();
         	}
            else if(mouseOverObject.CompareTag("Worker"))
         	{
                //mouseOverWorker = mouseOverObject;
                WorkerScript script = mouseOverObject.GetComponent<WorkerScript>();
                mouseOverWorker = script.GetWorker();
         	}
         	else
         	{

         	}
        }
    }
Example #12
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (isDoubleHolding())
        {
            SnapTarget snap = left.hand.ongoingTriggers [0].gameObject.GetComponent <SnapTarget> ();
            if (snap != null && snap.state == FAFVR.SnapTargetState.Locked)
            {
                return;
            }

            Vector3 mid = (left.hand.transform.position + right.hand.transform.position) / 2.0f;

            if (dhTraget == null)
            {
                dhTraget    = left.hand.ongoingTriggers [0].gameObject;
                left.state  = VirtualHandState.Holding;
                right.state = VirtualHandState.Holding;

                if (dhTraget.GetComponent <SnapTarget> () != null)
                {
                    dhTraget.GetComponent <SnapTarget> ().setState(FAFVR.SnapTargetState.Holding);
                }

                Rigidbody rig = dhTraget.GetComponent <Rigidbody> ();
                rig.isKinematic = true;
                rig.useGravity  = false;

                dhPivotOffset = mid - dhTraget.transform.position;
            }
            dhTraget.transform.position = mid - dhPivotOffset;
        }
        else if (isTwoHandTwisting())
        {
            if (dhTraget == null)
            {
                dhTraget = left.hand.ongoingTriggers [0].gameObject;
                resetHand(left);
                resetHand(right);
                left.state  = VirtualHandState.Holding;
                right.state = VirtualHandState.Holding;
                Rigidbody rig = dhTraget.GetComponent <Rigidbody> ();
                rig.isKinematic = true;
                rig.useGravity  = false;

                dhTraget.GetComponent <TireIron> ().SetStatus(TireIronStatus.TowHandHolding);
            }
        }
        else
        {
            if (dhTraget != null)
            {
                left.state  = VirtualHandState.Open;
                right.state = VirtualHandState.Open;

                Rigidbody rig = dhTraget.GetComponent <Rigidbody> ();
                rig.isKinematic = false;
                rig.useGravity  = true;

                if (dhTraget.GetComponent <SnapTarget> () != null)
                {
                    dhTraget.GetComponent <SnapTarget> ().setState(FAFVR.SnapTargetState.Open);
                }

                if (dhTraget.GetComponent <TireIron> () != null)
                {
                    dhTraget.GetComponent <TireIron> ().SetStatus(TireIronStatus.None);
                }

                dhTraget = null;
            }

            updateHand(left);
            updateHand(right);
        }
    }
Example #13
0
    void updateHand(VirtualHandInfo hi)
    {
        VirtualHandState state  = hi.state;
        Affect           hand   = hi.hand;
        CommonButton     button = hi.button;
        GameObject       target = hi.target;

        if (state == VirtualHandState.Open)
        {
            if (hand.triggerOngoing)
            {
                state = VirtualHandState.Touching;
            }
            else
            {
            }
        }
        else if (hi.state == VirtualHandState.Touching)
        {
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state  = VirtualHandState.Open;
                target = null;
            }
            else
            {
                if (button.GetPress() && target == null && !hand.ongoingTriggers [0].GetComponent <Interactive>().isHeavy)
                {
                    target = hand.ongoingTriggers [0].gameObject;

                    JackHook jackHook = target.GetComponent <JackHook> ();
                    if (jackHook == null)
                    {
                        SnapTarget snap = target.GetComponent <SnapTarget> ();

                        if (snap != null && snap.state == FAFVR.SnapTargetState.Locked)
                        {
                            state  = VirtualHandState.Open;
                            target = null;
                        }
                        else
                        {
                            if (snap != null)
                            {
                                snap.setState(FAFVR.SnapTargetState.Holding);
                            }

                            TireIron ti = target.GetComponent <TireIron> ();
                            if (ti != null)
                            {
                                ti.SetStatus(TireIronStatus.OneHandHolding);
                            }
                            Rigidbody rig = target.GetComponent <Rigidbody> ();
                            rig.isKinematic         = true;
                            rig.useGravity          = false;
                            target.transform.parent = hand.gameObject.transform;
                            state = VirtualHandState.Holding;
                        }
                    }
                    else
                    {
                        if (jackHook.state == JackHookState.Open)
                        {
                            Rigidbody rig = target.GetComponent <Rigidbody> ();
                            rig.isKinematic         = true;
                            rig.useGravity          = false;
                            target.transform.parent = hand.gameObject.transform;
                            state = VirtualHandState.Holding;
                            jackHook.SetState(JackHookState.Holding);
                            jackHook.isRotating = false;
                        }
                        else if (jackHook.state == JackHookState.Connecting)
                        {
                            jackHook.isRotating = true;
                        }
                        else
                        {
                            jackHook.isRotating = false;
                        }
                    }
                }
            }
        }
        else if (hi.state == VirtualHandState.Holding)
        {
            if (target == null)
            {
                state = VirtualHandState.Open;
            }
            else
            {
                SnapTarget snap = target.GetComponent <SnapTarget> ();
                if (snap != null && snap.state == FAFVR.SnapTargetState.Locked)
                {
                    target.transform.parent = world;
                    target = null;
                    state  = VirtualHandState.Open;
                }
                else if (!button.GetPress() && target != null)
                {
                    Rigidbody rig = target.GetComponent <Rigidbody> ();
                    rig.isKinematic         = false;
                    rig.useGravity          = true;
                    target.transform.parent = world;

                    state = VirtualHandState.Open;

                    snap = target.GetComponent <SnapTarget> ();

                    if (snap != null)
                    {
                        snap.setState(FAFVR.SnapTargetState.Open);
                    }

                    if (target.GetComponent <JackHook> () != null)
                    {
                        target.GetComponent <JackHook> ().state = JackHookState.Open;
                    }
                    target = null;
                }
            }
        }

        hi.state  = state;
        hi.target = target;
    }