美文网首页
D动画切换

D动画切换

作者: Moment__格调 | 来源:发表于2017-03-21 14:15 被阅读29次
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;
    using VRStandardAssets.Utils;
    
    public class TriggerManager : MonoBehaviour {
        //public float fadeSpeed = 1.5f;
        //private bool sceneStarting = true;
        //private bool FadeToBlackOk = false;
        //private RawImage rawImage = null;
        //public GameObject RawImage;
        public GameObject CameraPath;
        private AudioSource Scene02Aud;
    
        public VRCameraFade vrcf;
        private AsyncOperation asop;
        void Awake()
        {
            //CameraPath.SetActive(false);
            //rawImage = RawImage.GetComponent<RawImage>(); //获得RawImage组件对象
            //rawImage.color = new Color(0, 0, 0, 1);
        }
        void Start()
        {
            Scene02Aud = GetComponent<AudioSource>();
            Scene02Aud.Stop();
        }
        //void FadeToClear()
        //{
        //    rawImage.color = Color.Lerp(rawImage.color, Color.clear, fadeSpeed * Time.deltaTime);
        //}
    
        //void FadeToBlack()
        //{
        //    rawImage.color = Color.Lerp(rawImage.color, Color.black, fadeSpeed * Time.deltaTime);
        //}
    
        void OnTriggerEnter(Collider other)
        {
            Debug.Log(1111);
            if (other.name.Contains("Fade"))
            {
                Debug.Log(222);
                //StartCoroutine(FadeOutToScene_03());
                if (vrcf != null)
                {
                    vrcf.FadeOut(true);
                    StartCoroutine(ChangeScene());
                }
            }
            if (other.name.Contains("Video_01"))
            {
                EventManager.Instance.OpenAud_01();
            }
            else if (other.name.Contains("Video_02"))
            {
                EventManager.Instance.OpenAud_02();
            }
            else if (other.name.Contains("Swim"))
            {
                Debug.Log(2222);
                EventManager.Instance.whaleSwim();
            }
            else if (other.name.Contains("Take"))
            {
                Debug.Log(2222);
                EventManager.Instance.whaleTake();
            }
            else if (other .name .Contains("Idel"))
            {
                EventManager.Instance.whaleTakeToIdel();
            }
            else if (other.name.Contains("Blink"))
            {
                EventManager.Instance.whaleIdelToBlink();
            }
            else if (other.name.Contains("BK"))
            {
                EventManager.Instance.whaleBlinkToBlink_02();
            }
            else if (other.name.Contains("KK"))
            {
                EventManager.Instance.whaleBlink_02ToBlink();
            }
            else if (other.name.Contains("SSS"))
            {
                Debug.Log(6666);
                EventManager.Instance.whaleBlinkToTake();
            }
            else if (other.name.Contains("Tail"))
            {
                EventManager.Instance.OpenAud_03();
    
    
            }
            else if (other.name.Contains("Intro"))
            {
                EventManager.Instance.OpenAud_04();
    
    
            }
        }
        IEnumerator ChangeScene()
        {
            asop = SceneManager.LoadSceneAsync(Application.loadedLevel+1);
            asop.allowSceneActivation = false;
            yield return new WaitForSeconds(2f);
            asop.allowSceneActivation = true;
            
        }
    
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.O))
            {
                if (vrcf != null)
                {
                    vrcf.FadeOut(true);
                    StartCoroutine(ChangeScene());
                }
            }
        }
        //IEnumerator FadeOutToScene_03()
        //{
        //    Debug.Log(333);
        //    yield return new WaitForSeconds(3f);
        //    Debug.Log(444);
        //    //EndScene();
        //}
    
        //褪色的方法
        //void StartScene()
        //{
        //    FadeToClear();
        //    if (rawImage.color.a <= 0.05f)
        //    {
        //        rawImage.color = Color.clear;
        //        rawImage.enabled = false;
        //        CameraPath.SetActive(true);
        //        Scene02Aud.Play();
        //        sceneStarting = false;
        //    }
        //}
        //从透明变白的方法
        //public void EndScene()
        //{
        //    rawImage.enabled = true;
        //    FadeToBlackOk = true;
        //}
    
        //void Update()
        //{
        //    //如果sceneStarting = true,开始褪色;
        //    if (sceneStarting)
        //    {
        //        StartScene();
        //    }
    
        //    //如果FadeToBlackOk = true,
        //    else if (FadeToBlackOk)
        //    {
        //        //开始执行从透明变为白色的方法
        //        FadeToBlack();
        //        Debug.Log("aaaaa");
        //        //如果透明度 >= 0.95f, 开始跳转场景
        //        if (rawImage.color.a >= 0.95f)
        //        {
        //            Debug.Log("bbbbbb");
        //            SceneManager.LoadScene("02_ScenesShow");
        //        }
    
        //    }
    
        //}
    
    }
    、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
    using UnityEngine;
    using System.Collections;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;
    using VRStandardAssets.Utils;
    public class SharkManager : Singleton<SharkManager>
    {
        private AsyncOperation asop;
        public GameObject Shark;
        AnimatorStateInfo animatorInfo;
        public Animator SharkAnim;
        public GameObject Path_01;
        public GameObject Path_02;
        public GameObject RockPath_01;
        public GameObject RockPath_02;
        public GameObject SubMarinePath;
        public GameObject LanternsPath;
        public GameObject Lanterns;
        public AudioClip nervousClip;
        public  AudioSource audSou;
        private bool PlayClip_01;
        //public MeshRenderer mesh;
        private  Material[] mat;
        //public GameObject RAW;
        //private  RawImage rawImage;
        public float fadeSpeed = 1.5f;
        private bool sceneStarting = true;
        private bool FadeToBlackOk = false;
        public VRCameraFade vrcf;
      
        // Use this for initialization
    
        void Awake()
        {
            //rawImage = RAW.GetComponent<RawImage>();
            //rawImage.color = new Color(0, 0, 0, 1);
            Lanterns.SetActive(true);
            //mesh =  GetComponent<MeshRenderer>();
            audSou = GetComponent<AudioSource>();
            
            audSou.Stop();
        }
        void Start() {
            //Material mat = mesh.material;
            
             PlayClip_01 = false;
            
            //audSou.Play();
            SharkAnim = Shark.GetComponent<Animator>();
            Path_01.SetActive(true);
            Path_02.SetActive(false);
            RockPath_01.SetActive(false);
            RockPath_02.SetActive(false);
            SubMarinePath.SetActive(false);
            LanternsPath.SetActive(false);
        }
    
        // Update is called once per frame
        
        //void FadeToClear()
        //{
        //    rawImage.color = Color.Lerp(rawImage.color, Color.clear, fadeSpeed * Time.deltaTime);
        //}
    
        //void FadeToBlack()
        //{
        //    rawImage.color = Color.Lerp(rawImage.color, Color.black, fadeSpeed * Time.deltaTime);
        //}
    
        public void SharkSwim()
        {
            animatorInfo = SharkAnim.GetCurrentAnimatorStateInfo(0);
            if (animatorInfo.IsName("swim"))//注意这里指的不是动画的名字而是动画状态的名字
            {
                Debug.Log(333);
                // SharkAnim.speed = 0.7f;
                SharkAnim.SetTrigger("SwimToOpen");
            }
        }
        public void SharkClose()
        {
            animatorInfo = SharkAnim.GetCurrentAnimatorStateInfo(0);
            if (animatorInfo.IsName("open"))//注意这里指的不是动画的名字而是动画状态的名字
            {
                Debug.Log(333);
                // SharkAnim.speed = 0.7f;
                SharkAnim.SetTrigger("OpenToSwim");
            }
        }
        public void SharkWorry()
        {
            animatorInfo = SharkAnim.GetCurrentAnimatorStateInfo(0);
            if (animatorInfo.IsName("swim"))//注意这里指的不是动画的名字而是动画状态的名字
            {
                Debug.Log(333);
                // SharkAnim.speed = 0.7f;
                SharkAnim.SetTrigger("SwimToWarry");
            }
        }
        public void SharkWorryToSwim()
        {
            animatorInfo = SharkAnim.GetCurrentAnimatorStateInfo(0);
            if (animatorInfo.IsName("worry"))//注意这里指的不是动画的名字而是动画状态的名字
            {
                Debug.Log(333);
                // SharkAnim.speed = 0.7f;
                SharkAnim.SetTrigger("WorryToSwim");
            }
        }
        public void SharkSwimToAttack()
        {
            animatorInfo = SharkAnim.GetCurrentAnimatorStateInfo(0);
            if (animatorInfo.IsName("swim"))//注意这里指的不是动画的名字而是动画状态的名字
            {
                Debug.Log(333);
                // SharkAnim.speed = 0.7f;
                SharkAnim.SetTrigger("SwimToAttack");
            }
    
        }
        public void SharkAttackToSwim()
        {
            Debug.Log("PPP");
            animatorInfo = SharkAnim.GetCurrentAnimatorStateInfo(0);
    
            if (animatorInfo.IsName("attack"))//注意这里指的不是动画的名字而是动画状态的名字
            {
                Debug.Log(333);
                // SharkAnim.speed = 0.7f;
                SharkAnim.SetTrigger("AttackToSwim");
            }
    
        }
        public void PathTwo()
        {
            Debug.Log("PPP");
            animatorInfo = SharkAnim.GetCurrentAnimatorStateInfo(0);
    
            if (animatorInfo.IsName("attack"))//注意这里指的不是动画的名字而是动画状态的名字
            {
                Debug.Log(333);
                // SharkAnim.speed = 0.7f;
                SharkAnim.SetTrigger("AttackToSwim");
            }
    
        }
        public void ShowRockPath()
        {
            RockPath_01.SetActive(true);
        }
        public void HideRockPath()
        {
            RockPath_01.SetActive(false );
        }
        public void ShowRock_02()
        {
            RockPath_02.SetActive(true );
        }
        public void ShowAndHide()
        {
            Path_02.SetActive(true);
            Path_01.SetActive(false);
    
        }
        public void ShowSubMarinePath()
        {
            SubMarinePath.SetActive(true );
        }
        public void NervousAudio()
        {
            audSou.Play();
        }
        public void QuitScene()
        {
            if (vrcf != null)
            {
                vrcf.FadeOut(true);
                StartCoroutine(FadeOutToScene_03());
            }
        }
        public void ShowLanternsPath()
        {
            LanternsPath.SetActive(true);
        }
        public void HideLanternsPath()
        {
            LanternsPath.SetActive(false );
            Lanterns.SetActive(false );
        }
       
        IEnumerator FadeOutToScene_03()
        {
            // Debug.Log(333);
            // yield return new WaitForSeconds(2f);
            // Debug.Log(444);
            //// EndScene();
            asop = SceneManager.LoadSceneAsync(Application.loadedLevel + 1);
            asop.allowSceneActivation = false;
            yield return new WaitForSeconds(2f);
            asop.allowSceneActivation = true;
        }
    
    
        //褪色的方法
        //void StartScene()
        //{
        //    FadeToClear();
        //    if (rawImage.color.a <= 0.05f)
        //    {
        //        rawImage.color = Color.clear;
        //        rawImage.enabled = false;
        //        //CameraPath.SetActive(true);
        //        //Scene02Aud.Play();
        //        sceneStarting = false;
        //    }
        //}
        //从透明变白的方法
        //public void EndScene()
        //{
        //    rawImage.enabled = true;
        //    FadeToBlackOk = true;
        //}
    
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.O))
            {
                if (vrcf != null)
                {
                    vrcf.FadeOut(true);
                    StartCoroutine(FadeOutToScene_03());
                }
            }
            //    //如果sceneStarting = true,开始褪色;
            //    if (sceneStarting)
            //    {
            //        StartScene();
            //    }
    
            //    //如果FadeToBlackOk = true,
            //    else if (FadeToBlackOk)
            //    {
            //        //开始执行从透明变为白色的方法
            //        FadeToBlack();
            //        Debug.Log("aaaaa");
            //        //如果透明度 >= 0.95f, 开始跳转场景
            //        if (rawImage.color.a >= 0.95f)
            //        {
            //            Debug.Log("bbbbbb");
            //            SceneManager.LoadScene("04_End");
            //           // Application.Quit();
            //        }
    
            //    }
    
        }
    }
    

    相关文章

      网友评论

          本文标题:D动画切换

          本文链接:https://www.haomeiwen.com/subject/pncgnttx.html