Esempio n. 1
0
    void Update()
    {
        if (_firstUpdate)
          {
         _firstUpdate = false;
         if (RevealSound != null)
            RevealSound.Play();
          }

          bool torchUnlocked = (_torchIcon != null) ? (_forceUnlock1 || _torchIcon.RequiredPropIsNear()) : false;
          bool lanternUnlocked = (_lanternIcon != null) ? (_forceUnlock2 || _lanternIcon.RequiredPropIsNear()) : false;

          int curNumUnlocked = 0;
          if (torchUnlocked)
         curNumUnlocked++;
          if (lanternUnlocked)
         curNumUnlocked++;

          //first icon unlocked
          if ((_lastNumUnlocked == 0) && (curNumUnlocked == 1))
          {
         if (UnlockSound != null)
            UnlockSound.Play();
          }

          _lastNumUnlocked = curNumUnlocked;

          if((_animator != null) && (TorchLockedBool.Length > 0))
          {
         _animator.SetBool(TorchLockedBool, !torchUnlocked);
          }

          if ((_animator != null) && (LanternLockedBool.Length > 0))
          {
         _animator.SetBool(LanternLockedBool, !lanternUnlocked);
          }

          bool wasUnlocked = _isUnlocked;
          _isUnlocked = _forceOpen || (torchUnlocked && lanternUnlocked);

          if (!wasUnlocked && _isUnlocked && (_animator != null))
          {
         if (CompletedSound != null)
            CompletedSound.Play();

         _animator.SetTrigger(UnlockedMagicTrigger);

         //trigger fx on the physical lights
         Nights2Mgr.Instance.FXTurnOnInSequence(new Nights2Mgr.TurnOnInSequenceParams(LightSeqHoldTime, LightSeqFadeTime, LightSeqInterval, Nights2Mgr.Instance.ClockwiseCandleOrder));

         //transition lantern + torch icons out
         if (_lanternIcon != null)
             _lanternIcon.Destroy();
         if (_torchIcon != null)
             _torchIcon.Destroy();

         //show magic and begin waiting for anim to complete
         MagicTrans.gameObject.SetActive(true);
         _magicState = MagicPhase.Waiting;
         _magicTimer = Time.time;
          }

          if (_destroyTimerStart > 0.0f)
          {
         float elapsed = Time.time - _destroyTimerStart;
         if (elapsed >= DelayToDestroy)
         {
            if (_torchIcon != null)
               DestroyObject(_torchIcon.gameObject);
            if (_lanternIcon != null)
               DestroyObject(_lanternIcon.gameObject);
            if (_collectIcon != null)
               DestroyObject(_collectIcon.gameObject);
            DestroyObject(this.gameObject);
         }
          }

          if (_magicTimer > 0.0f)
          {
         float elapsed = Time.time - _magicTimer;
         switch (_magicState)
         {
            case MagicPhase.Waiting:
               if (elapsed >= MagicInitialWaitTime)
               {
                  _magicState = MagicPhase.WaitForCollect;
                  _magicTimer = Time.time;

                  //spawn torch icon
                  if (TorchIconPrefab != null)
                  {
                     GameObject spawned = Instantiate(TorchIconPrefab) as GameObject;
                     if (spawned != null)
                     {
                        _collectIcon = spawned.GetComponent<Nights2Icon>();
                        spawned.transform.parent = CollectIconSpot;
                        spawned.transform.localPosition = Vector3.zero;
                        spawned.transform.localRotation = Quaternion.identity;
                     }
                  }
               }
               break;
            case MagicPhase.WaitForCollect:
               if (_collectIcon.RequiredPropIsNear() || _forceCollect)
               {
                  if (CollectedSound != null)
                     CollectedSound.Play();
                  //imbue torch with magic
                  Nights2Mgr.Instance.SetTorchHasMagic(true);
                  //hide magic
                  //MagicTrans.gameObject.SetActive(false);
                  //advance to next state
                  _magicState = MagicPhase.Hidden;
                  //transition icon out
                  _collectIcon.Destroy();
                  //animate magic out
                  _animator.SetTrigger(MagicCollectTrigger);
                  //start destroy timer
                  _destroyTimerStart = Time.time;
                  _isCollected = true;

                  //light FX
                  Nights2Mgr.Instance.FXTurnOnAll(new Nights2Mgr.TurnAllOnParams(LightCollectTime, LightCollectFadeTime, true, Nights2Mgr.Instance.NextBeacon().CandleColor));
               }
               break;
            /*case MagicPhase.Rising:
               if (elapsed >= MagicRiseTime)
               {
                  _magicState = MagicPhase.ToTorch;
                  _magicTimer = Time.time;
                  _magicTracker.SetOverrideTargetPos(Nights2CamMgr.Instance.GetTorchParent().position);
               }
               break;
            case MagicPhase.ToTorch:
               _magicTracker.SetOverrideTargetPos(Nights2CamMgr.Instance.GetTorchParent().position);
               float distToTorch = (Nights2CamMgr.Instance.GetTorchParent().position - MagicTrans.transform.position).magnitude;
               //imbue torch when magic gets close
               if (distToTorch <= HasMagicDistThresh)
                  Nights2Mgr.Instance.SetTorchHasMagic(true);
               if (elapsed >= MagicToTorchTime)
               {
                  Nights2Mgr.Instance.SetTorchHasMagic(true); //just in case...
                  _magicState = MagicPhase.Hidden;
                  _magicTracker.gameObject.SetActive(false);
               }
               break;*/
            default: break;
         }
          }
    }
Esempio n. 2
0
    void Start()
    {
        _firstUpdate = true;
          _lastNumUnlocked = 0;

          _animator = gameObject.GetComponent<Animator>();
          _isUnlocked = false;

          //setup magic obj with physics tracker
          if(MagicTrans != null)
          {
         MagicTrans.gameObject.SetActive(false);

         _magicState = MagicPhase.Initial;
          }

          //spawn torch icon
          if ((TorchIconPrefab != null) && (TorchIconSpot != null))
          {
         GameObject spawned = Instantiate(TorchIconPrefab) as GameObject;
         if (spawned != null)
         {
            _torchIcon = spawned.GetComponent<Nights2Icon>();
            spawned.transform.parent = TorchIconSpot;
            spawned.transform.localPosition = Vector3.zero;
            spawned.transform.localRotation = Quaternion.identity;
         }
          }

          //spawn lantern icon
          if ((LanternIconPrefab != null) && (LanternIconSpot != null))
          {
         GameObject spawned = Instantiate(LanternIconPrefab) as GameObject;
         if (spawned != null)
         {
            _lanternIcon = spawned.GetComponent<Nights2Icon>();
            spawned.transform.parent = LanternIconSpot;
            spawned.transform.localPosition = Vector3.zero;
            spawned.transform.localRotation = Quaternion.identity;
         }
          }

          //turn off old physics tracker state, just in case its still there
          PhysicsTracker tracker = MagicTrans.GetComponent<PhysicsTracker>();
          if (tracker != null)
          {
         tracker.gameObject.GetComponent<Rigidbody>().isKinematic = true;
         tracker.enabled = false;
          }
    }