Example #1
0
    public static void PlaySoundClip(string preMake)
    {
#if IN_GAME
        ISoundMan soundMan = EntryPoint.Instance.SoundMan;
        if (soundMan != null)
        {
            soundMan.Play2DAudio(preMake);
        }
#else
        /*
         * if (Application.isPlaying)
         * {
         *  GameObject g = GameObject.Find("AudioSources");
         *  if (g == null) g = new GameObject("AudioSources");
         *
         *  AudioSource audioSource = g.GetComponent<AudioSource>();
         *  if (audioSource == null)
         *  {
         *      audioSource = g.AddComponent<AudioSource>();
         *  }
         *
         *  AudioClip clip = AssetDatabase.LoadAssetAtPath(preMake, typeof(AudioClip)) as AudioClip;
         *  audioSource.clip = clip;
         *  audioSource.volume = 1f;
         *  audioSource.spatialBlend = 0f;
         *  audioSource.Play();
         * }
         */
#endif
    }
Example #2
0
        //        private void _PlayFx(Transform hook, Transform anchor, string fx_path, float life_time, bool is_ui)
        //        {
        //            if (!is_ui)
        //            {
        //                if (hook == null) hook = _CachedT;
        //#if ART_USE && UNITY_EDITOR
        //                GameObject obj = UnityEditor.AssetDatabase.LoadAssetAtPath(fx_path, typeof(GameObject)) as GameObject;
        //                if (obj != null)
        //                {
        //                    obj = Instantiate<GameObject>(obj);
        //                    Transform t = obj.transform;
        //                    t.SetParent(hook, false);
        //                    obj.SetActive(true);
        //                    Util.SetLayerRecursively(obj, LayerMask.NameToLayer("UIScene"));

        //                    //re-position
        //                    if (anchor != null && anchor != hook)
        //                    {
        //                        t.position = anchor.position;
        //                    }

        //                    if (life_time < 0.0001f)
        //                    {
        //                        FxDuration fxd = obj.GetComponent<FxDuration>();
        //                        if (fxd != null) life_time = fxd.duration;
        //                    }

        //                    Destroy(obj, life_time > 0.0001f ? life_time : 5);

        //                    Debug.Log("PlayFx " + hook.name + ", " + fx_path + ", " + life_time);
        //                }

        //#else
        //                //Debug.Log("TODO: PlayFx");
        //#if IN_Game
        //                 int fxId = 0;
        //                 CFxOne fx_one = CFxCacheMan.Instance.RequestFxOne(fx_path, -1, ref fxId);
        //                 if (fx_one != null)
        //                 {
        //                     Transform t_fx=fx_one.transform;
        //                     GameObject g_fx = fx_one.gameObject;
        //                     t_fx.SetParent(hook, false);

        //                     //re-position
        //                    if (anchor != null && anchor != hook)
        //                     {
        //                         t_fx.position = anchor.position;
        //                     }

        //                     //g_fx.SetActive(true);
        //                     Util.SetLayerRecursively(g_fx, LayerMask.NameToLayer("UIScene"));

        //                     fx_one.Play(life_time > 0.0001f ? life_time : 5);
        //                 }
        //#endif
        //#endif
        //            }
        //            else
        //            {
        //                UISfxBehaviour.Play(fx_path, anchor.gameObject, hook.gameObject, null, life_time > 0.0001f ? life_time : 5);
        //            }
        //        }

        private void _PlaySound(GameObject go, string snd_path, float life_time, bool is_2D)
        {
            if (go == null)
            {
                return;
            }
#if ART_USE && UNITY_EDITOR
            AudioClip clip = UnityEditor.AssetDatabase.LoadAssetAtPath(snd_path, typeof(AudioClip)) as AudioClip;
            if (clip != null)
            {
                AudioSource source = go.AddComponent <AudioSource>();
                source.clip         = clip;
                source.spatialBlend = is_2D ? 0 : 1;
                source.Play();

                Destroy(source, life_time > 0.0001f ? life_time : clip.length);
            }

            Debug.Log("PlaySound " + go.name + ", " + snd_path);
#elif IN_GAME
            //Debug.Log("TODO: PlaySound");

            ISoundMan soundMan = EntryPoint.Instance.SoundMan;
            if (soundMan != null)
            {
                if (is_2D)
                {
                    soundMan.Play2DAudio(snd_path);
                }
                else
                {
                    soundMan.PlayAttached3DAudio(snd_path, go.transform);
                }
            }
#endif
        }
Example #3
0
        public void ExcEvent(TLEvent evt)
        {
            if (evt.EvtType == UEEventType.PlayAnim)
            {
                UEvtAnim block = evt as UEvtAnim;
                if (block != null && block.Anim != null)
                {
                    block.Anim.Play(block.Path);
                }
            }
            else if (evt.EvtType == UEEventType.PlayDotween)
            {
                UEvtDot block = evt as UEvtDot;
                if (block != null && block.DotPlayer != null)
                {
                    block.DotPlayer.Restart(block.Id);
                }
            }
            else if (evt.EvtType == UEEventType.UIFx)
            {
                UEvtUIFx block = evt as UEvtUIFx;
                if (block != null)
                {
                    GNewUITools.PlayFx(block.Holder, block.Target, block.Clipper, block.Path, block.LifeTime, true, block.OrderOffset);
                }
            }
            else if (evt.EvtType == UEEventType.SetActive)
            {
                UEvtActive block = evt as UEvtActive;
                if (block != null && block.Go != null)
                {
                    block.Go.SetActive(block.ActiveState);
                }
            }
            else if (evt.EvtType == UEEventType.ShakeScreen)
            {
                UEvtShake block = evt as UEvtShake;
                if (block != null)
                {
                    CameraShaker cs = Main.PanelRoot.GetComponent <CameraShaker>();
                    if (cs != null)
                    {
                        cs.ShakeOnce(block.Mag, 10, 0.15f, 0.15f, block.LifeTime, "ui");
                    }
                }
            }
            else if (evt.EvtType == UEEventType.Lua)
            {
                UEvtLua block = evt as UEvtLua;
                if (block != null && block.LuaFunc != null)
                {
                    block.LuaFunc.Call();
                }
            }
            else if (evt.EvtType == UEEventType.UISound)
            {
                UEvtUISound block = evt as UEvtUISound;
                if (block != null)
                {
#if IN_GAME
                    ISoundMan soundMan = EntryPoint.Instance.SoundMan;
                    if (soundMan != null)
                    {
                        soundMan.Play2DAudio(block.Path);
                    }
#endif
                }
            }
        }