Example #1
0
    //public Transform Spawn(string name, Vector3 pos, Quaternion rot, Transform parent, float timeToDistroy)
    //{
    //    var clone = FXPool.GetInstance().Spawn(name, pos, rot, parent);
    //    FXPool.GetInstance().Despawn(clone, timeToDistroy);
    //    return clone;
    //}

    public Transform Spawn(string name, Transform parent, float timeToDistroy)
    {
        var clone = FXPool.GetInstance().Spawn(name, parent.position, parent.rotation, parent);

        FXPool.GetInstance().Despawn(clone, timeToDistroy);
        return(clone);
    }
Example #2
0
    public int PlayFXOfUI(int templateId, Transform host, int time = 0, int depthValue = 2001, Action finishCallback = null)
    {
        if (!SystemConfig.IsFXOn)
        {
            return(0);
        }
        if (templateId <= 0)
        {
            return(0);
        }
        if (host == null)
        {
            return(0);
        }
        Fx fx = DataReader <Fx> .Get(templateId);

        if (fx == null || string.IsNullOrEmpty(fx.path))
        {
            return(0);
        }
        int uid = ++this.m_fxOfcounter;

        this.m_fxs.set_Item(uid, null);
        AssetManager.LoadAssetWithPool(FXPool.GetPathWithLOD(fx.path, false), delegate(bool isSuccess)
        {
            if (this.m_fxs.ContainsKey(uid))
            {
                this.JustPlayfxOnUI(uid, templateId, host, time, depthValue, finishCallback);
            }
        });
        return(uid);
    }
Example #3
0
    public void HitPointSpawn(Vector3 pos, Quaternion rot, Transform parent, int effectNum)
    {
        var hitPointClone = FXPool.GetInstance().Spawn(hitPoint, pos, rot, parent);

        hitPointClone.GetChild(effectNum).gameObject.SetActive(true);
        FXPool.GetInstance().Despawn(hitPointClone, 1.6f);
    }
Example #4
0
    public Transform Spawn(string name, Vector3 position, Quaternion rotation, float timeToDistroy)
    {
        var clone = FXPool.GetInstance().Spawn(name, position, rotation, null);

        FXPool.GetInstance().Despawn(clone, timeToDistroy);
        return(clone);
    }
Example #5
0
    void PlayFXFromPool(FXPool pool, Vector3 position)
    {
        FX playedFX = pool.Depool();

        playedFX.transform.position = position;
        playedFX.Play();
    }
Example #6
0
    public float Raise(Vector3 position, Quaternion rotation, Vector3 scale, Transform parent = null)
    {
        float fxTime = 0;

        if (sfx != null)
        {
            AudioInstance.PlayClipAtPoint(sfx, position, outputMixer, pitchRange);
            fxTime = sfx.length;
        }

        foreach (GameObject visualFX in visualFX)
        {
            GameObject instance = FXPool.getFXObject(visualFX, poolSize);
            instance.transform.position = position;
            instance.transform.rotation = rotation;
            instance.transform.SetParent(parent);
            instance.transform.localScale = scale;
            instance.SetActive(true);
            VisualFX vFX = instance.GetComponent <VisualFX>();
            if (vFX != null)
            {
                if (fxTime < vFX.displayTime)
                {
                    fxTime = vFX.displayTime;
                }
                vFX.Play();
            }
        }
        return(fxTime);
    }
Example #7
0
    public int PlayFXOfFollow(int templateId, Vector3 position, Transform targetFollow, float speed, float lessDistance, float offset = 0f, Action finishCallback = null, FXClassification fxClassification = FXClassification.Normal)
    {
        if (!SystemConfig.IsFXOn)
        {
            return(0);
        }
        if (templateId <= 0)
        {
            return(0);
        }
        Fx fx = DataReader <Fx> .Get(templateId);

        if (fx == null || string.IsNullOrEmpty(fx.path))
        {
            return(0);
        }
        int uid = ++this.m_fxOfcounter;

        this.m_fxs.set_Item(uid, null);
        AssetManager.LoadAssetWithPool(FXPool.GetPathWithLOD(fx.path, fxClassification == FXClassification.LowLod), delegate(bool isSuccess)
        {
            if (this.m_fxs.ContainsKey(uid))
            {
                this.JustPlayFXOfFollow(uid, templateId, position, targetFollow, speed, lessDistance, offset, finishCallback, fxClassification);
            }
        });
        return(uid);
    }
Example #8
0
    private void Start()
    {
        instance = this;

        audioSourcePrefab = Resources.Load("Prefabs/Audio Source") as Transform;

        var particles = Resources.LoadAll("Prefabs/Particle");

        foreach (var p in particles)
        {
            poolItems.Add(((GameObject)p).transform);
            poolLength.Add(10);
        }

        // Initialize effects pool
        if (poolItems.Count > 0)
        {
            pool = new Dictionary <Transform, Transform[]>();

            for (int i = 0; i < poolItems.Count; i++)
            {
                Transform[] itemArray = new Transform[poolLength[i]];

                for (int x = 0; x < poolLength[i]; x++)
                {
                    Transform newItem = (Transform)Instantiate(poolItems[i], Vector3.zero, Quaternion.identity);
                    newItem.gameObject.SetActive(false);
                    newItem.parent = transform;

                    itemArray[x] = newItem;
                }
                pool.Add(poolItems[i], itemArray);
            }
        }

        // Initialize audio pool
        if (audioPoolItems.Length > 0)
        {
            audioPool = new Dictionary <AudioClip, AudioSource[]>();

            for (int i = 0; i < audioPoolItems.Length; i++)
            {
                AudioSource[] audioArray = new AudioSource[audioPoolLength[i]];

                for (int x = 0; x < audioPoolLength[i]; x++)
                {
                    AudioSource newAudio = ((Transform)Instantiate(audioSourcePrefab, Vector3.zero, Quaternion.identity)).GetComponent <AudioSource>();
                    newAudio.clip = audioPoolItems[i];

                    newAudio.gameObject.SetActive(false);
                    newAudio.transform.parent = transform;

                    audioArray[x] = newAudio;
                }

                audioPool.Add(audioPoolItems[i], audioArray);
            }
        }
    }
Example #9
0
    public static GameObject InstanceFromPool(this GameObject prefab, int poolSize, Transform parent)
    {
        GameObject instance = FXPool.getFXObject(prefab, poolSize);

        instance.transform.SetParent(parent);
        instance.SetActive(true);
        return(instance);
    }
Example #10
0
    void PlayFXFromPool(FXPool pool, Vector3 _position, Transform _parent)
    {
        FX playedFX = pool.Depool();

        playedFX.transform.position = _position;
        playedFX.Play();
        playedFX.transform.parent = _parent;
    }
Example #11
0
 public void Initialize()
 {
     fxPools = new FXPool[config.fxs.Length];
     for (int i = 0; i < config.fxs.Length; i++)
     {
         GameObject newPoolGO = new GameObject("FXPool_" + config.fxs[i].fxName);
         newPoolGO.transform.parent = transform;
         FXPool newPool = newPoolGO.AddComponent <FXPool>();
         newPool.Initialize(config.fxs[i]);
         fxPools[i] = newPool;
     }
 }
Example #12
0
    public static GameObject InstanceFromPool(this GameObject[] prefabArray, int maxIndex, int poolSize, Transform parent)
    {
        GameObject prefab = prefabArray[
            Random.Range(
                0,
                Mathf.Clamp(maxIndex, 0, prefabArray.Length)
                )];
        GameObject instance = FXPool.getFXObject(prefab, poolSize);

        instance.transform.SetParent(parent);
        instance.SetActive(true);
        return(instance);
    }
Example #13
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }

        SetupHitFXsQueue();
    }
Example #14
0
    void PlayFXFromPool(FXPool pool, Transform _transform, bool textMessage, Color color, string text, float height)
    {
        FX playedFX = pool.Depool();

        playedFX.transform.parent        = _transform;
        playedFX.transform.localPosition = Vector3.zero;

        if (textMessage)
        {
            TextMessage message = (TextMessage)playedFX;
            message.SetTextAndPlay(text, color, height);
        }
        else
        {
            playedFX.Play();
        }
    }
Example #15
0
    public ActorFX Get(int guid, bool isLow)
    {
        string text = this.pipeline.GetPath(guid);

        if (text == null)
        {
            return(null);
        }
        text = FXPool.GetPathWithLOD(text, isLow);
        GameObject gameObject = this.GetPool().Get(text);

        if (gameObject == null)
        {
            Debug.LogError(string.Format("马上联系左总,m_loader.Get拿到空值,路径是{0}", text));
            return(null);
        }
        return(base.SetGameObject(gameObject, guid));
    }
Example #16
0
    public void Preload(int templateId, Action callbackSuccess)
    {
        Fx fx = DataReader <Fx> .Get(templateId);

        if (fx == null || string.IsNullOrEmpty(fx.path))
        {
            if (callbackSuccess != null)
            {
                callbackSuccess.Invoke();
            }
            return;
        }
        AssetManager.LoadAssetWithPool(FXPool.GetPathWithLOD(fx.path, false), delegate(bool isSuccess)
        {
            if (callbackSuccess != null)
            {
                callbackSuccess.Invoke();
            }
        });
    }
Example #17
0
    public void Raise(Vector3 position, out AudioSource audioSource, out GameObject[] vfx)
    {
        if (sfx != null)
        {
            if (loopSFX)
            {
                audioSource = AudioInstance.LoopClipAtPoint(sfx, position, outputMixer, pitchRange);
            }
            else
            {
                AudioInstance.PlayClipAtPoint(sfx, position, outputMixer, pitchRange);
                audioSource = null;
            }
        }
        else
        {
            audioSource = null;
        }

        vfx = new GameObject[visualFX.Length];
        for (int i = 0; i < visualFX.Length; i++)
        {
            GameObject visualfx = visualFX[i];
            GameObject instance = FXPool.getFXObject(visualfx, poolSize);
            instance.transform.position = position;
            instance.transform.rotation = visualfx.transform.rotation;
            instance.transform.SetParent(null);
            instance.transform.localScale = Vector3.one;
            instance.SetActive(true);
            VisualFX vFX = instance.GetComponent <VisualFX>();
            if (vFX != null)
            {
                vFX.Play();
            }
            vfx[i] = instance;
        }
    }
Example #18
0
    private int AsyncPlayfxOnScene(int templateId, Transform host, Vector3 position, Quaternion rotation, float speed = 1f, float scale = 1f, int time = 0, bool syncNode = false, int bulletLife = 0, Action <Actor, XPoint, ActorParent> bulletCallback = null, Action finishCallback = null, Action <ActorFX> loadCallback = null, bool sound3D = true, float rate = 1f, FXClassification fxClassification = FXClassification.Normal)
    {
        if (!SystemConfig.IsFXOn)
        {
            return(0);
        }
        if (templateId == ClientGMManager.fxout_id)
        {
            return(0);
        }
        if (templateId <= 0)
        {
            return(0);
        }
        if (fxClassification == FXClassification.NoPlay)
        {
            return(0);
        }
        Fx fx = DataReader <Fx> .Get(templateId);

        if (fx == null || string.IsNullOrEmpty(fx.path))
        {
            return(0);
        }
        int uid = ++this.m_fxOfcounter;

        this.m_fxs.set_Item(uid, null);
        AssetManager.LoadAssetWithPool(FXPool.GetPathWithLOD(fx.path, fxClassification == FXClassification.LowLod), delegate(bool isSuccess)
        {
            if (this.m_fxs.ContainsKey(uid))
            {
                this.JustPlayfxOnScene(uid, templateId, host, position, rotation, speed, scale, time, syncNode, bulletLife, bulletCallback, finishCallback, loadCallback, sound3D, rate, fxClassification);
            }
        });
        return(uid);
    }
Example #19
0
    public void StubSpawn(Vector3 pos, Quaternion rot, Transform parent)
    {
        var stubClone = FXPool.GetInstance().Spawn(stub, pos, rot, parent);

        FXPool.GetInstance().Despawn(stubClone, 4f);
    }
Example #20
0
    public void DustSpawn(Vector3 pos, Quaternion rot, Transform parent)
    {
        var dustClone = FXPool.GetInstance().Spawn(dust, pos, rot, parent);

        FXPool.GetInstance().Despawn(dustClone, 3f);
    }
Example #21
0
    public void SmokeSpawn(Vector3 pos, Quaternion rot, Transform parent)
    {
        var smokeClone = FXPool.GetInstance().Spawn(smoke, pos, rot, parent);

        FXPool.GetInstance().Despawn(smokeClone, 1.6f);
    }
Example #22
0
    private void Start()
    {
        instance = this;

        audioSourcePrefab = Resources.Load("Prefabs/Audio Source") as Transform;

        //var particles = Resources.LoadAll("Prefabs/Particle");
        //var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "particle"));
        //var particles = myLoadedAssetBundle.LoadAllAssets<GameObject>();

        //foreach(var p in particles)
        //{
        //    poolItems.Add(((GameObject)p).transform);
        //    poolLength.Add(10);
        //}

        // Initialize effects pool
        if (poolItems.Length > 0)
        {
            pool = new Dictionary <string, Transform[]>();

            for (int i = 0; i < poolItems.Length; i++)
            {
                Transform[] itemArray = new Transform[poolLength[i]];

                for (int x = 0; x < poolLength[i]; x++)
                {
                    GameObject newItem = Instantiate(poolItems[i], Vector3.zero, Quaternion.identity).gameObject;
                    newItem.SetActive(false);
                    newItem.transform.parent = transform;

                    itemArray[x] = newItem.transform;
                }
                pool.Add(poolItems[i].name, itemArray);
            }
        }

        // Initialize audio pool
        if (audioPoolItems.Length > 0)
        {
            audioPool = new Dictionary <AudioClip, AudioSource[]>();

            for (int i = 0; i < audioPoolItems.Length; i++)
            {
                AudioSource[] audioArray = new AudioSource[audioPoolLength[i]];

                for (int x = 0; x < audioPoolLength[i]; x++)
                {
                    AudioSource newAudio = ((Transform)Instantiate(audioSourcePrefab, Vector3.zero, Quaternion.identity)).GetComponent <AudioSource>();
                    newAudio.clip = audioPoolItems[i];

                    newAudio.gameObject.SetActive(false);
                    newAudio.transform.parent = transform;

                    audioArray[x] = newAudio;
                }

                audioPool.Add(audioPoolItems[i], audioArray);
            }
        }
    }