Ejemplo n.º 1
0
    protected virtual void InuPlayEffect(Dictionary <string, object> _data)
    {
        string effectName = (string)_data[InuParam.name];
        object tmp;
        int    effectSkip = 0;

        if (_data.TryGetValue(InuParam.effectskip, out tmp))
        {
            effectSkip = (int)tmp;
        }

        string dummyName = (string)_data[InuParam.dummy];
        bool   multiple  = false;

        if (_data.ContainsKey(InuParam.destroy))
        {
            multiple = (bool)_data[InuParam.destroy];
        }

        Transform tModel;
        bool      worldrotation = false;

        if (dummyName == "root")
        {
            tModel = transform;
        }
        else if (dummyName == "rootWorld")
        {
            tModel        = transform;
            worldrotation = true;
        }
        else
        {
            tModel = transform.Find(dummyName);
        }
        if (tModel != null)
        {
            if (!multiple)
            {
                // if effect exist in dummy position, set it active
                if (tModel.Find(effectName))
                {
                    Transform tEffect = tModel.Find(effectName);
                    tEffect.gameObject.SetActive(true);
                    return;
                }
            }

            // create an instance of effect
            GameObject effect = InuResources.GetEffectInstance(effectName, tModel.position, worldrotation ? Quaternion.identity : tModel.rotation);
            if (effect != null)
            {
                //Vector3 effectPos = effect.transform.position;
                //Quaternion rot = effect.transform.rotation;
                effect.name                    = effectName;
                effect.transform.parent        = tModel;
                effect.transform.localPosition = Vector3.zero;
                effect.transform.localRotation = Quaternion.identity;
            }
        }
    }
Ejemplo n.º 2
0
    public void Play(AudioSource _audio, string _clipName)
    {
        // check same sfx limitation
        if (!CheckSameLimit(_clipName))
        {
            return;
        }

        if (!mAudioes.Contains(_audio))
        {
            if (mSameSfxNumber.ContainsKey(_clipName))
            {
                mSameSfxNumber[_clipName]++;
                mAudioPlayTime[_clipName] = Time.time;
            }
            else
            {
                mSameSfxNumber.Add(_clipName, 1);
                mAudioPlayTime.Add(_clipName, Time.time);
            }

            _audio.Stop();

            mAudioes.Add(_audio);
            mClipNames.Add(_clipName);

            // check total sfx limitation
            CheckTotalLimit();
        }
        else
        {
            if (mSameSfxNumber.ContainsKey(_clipName))
            {
                mSameSfxNumber[_clipName]++;
                mAudioPlayTime[_clipName] = Time.time;
            }
            else
            {
                mSameSfxNumber.Add(_clipName, 1);
                mAudioPlayTime.Add(_clipName, Time.time);
            }

            _audio.Stop();

            int index = mAudioes.IndexOf(_audio);
            mAudioes.RemoveAt(index);
            mAudioes.Add(_audio);

            string prev_clipname = mClipNames[index];
            if (mSameSfxNumber.ContainsKey(prev_clipname))
            {
                mSameSfxNumber[prev_clipname]--;
            }
            mClipNames.RemoveAt(index);
            mClipNames.Add(_clipName);
        }

        // play sfx
        AudioClip clip = InuResources.GetSfx(_clipName);

        if (clip)
        {
            _audio.clip   = clip;
            _audio.volume = 1;
            _audio.Play();
        }
    }