Exemple #1
0
        //one time function that fills the line renderers width list; the start particle system list and adds to the psList;
        //the middle particle system list and adds to the psList; the end particle system list and adds to the psList; creates 1st trail and adds to the trails list
        void FillLists()
        {
            if (!psListFilled)
            {
                psListFilled = true;

                //adds the width of the lasers to a list and sets the width to 0
                if (lineRenderers.Count > 0)
                {
                    if (lrWidth.Count == 0)
                    {
                        for (int i = 0; i < lineRenderers.Count; i++)
                        {
                            lrWidth.Add(lineRenderers[i].widthMultiplier * size);
                            lineRenderers [i].widthMultiplier = 0;
                            lineRenderers [i].enabled         = false;
                            if (layerOrderTo != 0)
                            {
                                lineRenderers [i].sortingOrder += layerOrderTo;
                            }
                        }
                    }
                }
                else
                {
                    Debug.Log("Line Renderers list is empty.");
                }

                if (startVFX != null)
                {
                    startPSList._parent = startVFX;
                    startPSList._psType = PSList.PSLIST_TYPE.start;
                    startPSList.AddPSToList(startVFX, true);
                    startPSList.DisablePS(true);
                    if (layerOrderTo != 0)
                    {
                        startPSList.LayerOrder(layerOrderTo);
                    }
                    psList.Add(startPSList);
                }

                if (middleVFX != null)
                {
                    middlePSList._parent = middleVFX;
                    middlePSList._psType = PSList.PSLIST_TYPE.middle;
                    middlePSList.AddPSToList(middleVFX, true);
                    middlePSList.DisablePS(true);
                    if (layerOrderTo != 0)
                    {
                        middlePSList.LayerOrder(layerOrderTo);
                    }
                    psList.Add(middlePSList);
                }

                if (endVFX != null)
                {
                    endPSList._parent = endVFX;
                    endPSList._psType = PSList.PSLIST_TYPE.end;
                    endPSList.AddPSToList(endVFX, true);
                    endPSList.DisablePS(true);
                    if (layerOrderTo != 0)
                    {
                        endPSList.LayerOrder(layerOrderTo);
                    }
                    psList.Add(endPSList);
                }

                if (trailVFX != null && useTrail)
                {
                    psTrailVFX = trailVFX.GetComponent <ParticleSystem> ();
                    if (layerName != "Default" || layerOrderTo != 0)
                    {
                        var trailRenderer = psTrailVFX.GetComponent <Renderer>();
                        trailRenderer.sortingOrder += layerOrderTo;
                    }
                    Trail newTrail = new Trail()
                    {
                        _ps = psTrailVFX, _trailInterval = trailInterval
                    };
                    trails.Add(newTrail);
                }
            }
        }
Exemple #2
0
        void RecursiveBounces(LineRenderer lr, Vector3 position, Vector3 direction, int bouncesRemaining, float lengthRemaining)
        {
            if (bouncesRemaining == 0)
            {
                return;
            }
            if (lengthRemaining <= 0.1f)
            {
                return;
            }

            int index = bounces - bouncesRemaining;

            if (lr.positionCount == index + 2)
            {
                lr.positionCount++;
            }

            Ray        ray = new Ray(position, direction);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, lengthRemaining))
            {
                direction = Vector3.Reflect(direction, hit.normal);
                lr.SetPosition(index + 2, hit.point);

                if (startVFX != null && useStart && reflectStart)
                {
                    if (GetByType(PSList.PSLIST_TYPE.start).Count == index + 1)
                    {
                        CreateNewPSList(PSList.PSLIST_TYPE.start);
                    }

                    List <PSList> startListPS = GetByType(PSList.PSLIST_TYPE.start);
                    if (startListPS.Count > index)
                    {
                        startListPS[index + 1]._parent.transform.position = position;
                        RotateToMouse(startListPS[index + 1]._parent, hit.point);
                    }
                }

                if (middleVFX != null && useMiddle && reflectMiddle)
                {
                    if (GetByType(PSList.PSLIST_TYPE.middle).Count == index + 1)
                    {
                        CreateNewPSList(PSList.PSLIST_TYPE.middle);
                    }

                    List <PSList> middleListPS = GetByType(PSList.PSLIST_TYPE.middle);
                    if (middleListPS.Count > index)
                    {
                        middleListPS[index + 1]._parent.transform.position = position;
                        RotateToMouse(middleListPS[index + 1]._parent, hit.point);
                    }
                }

                if (endVFX != null && useEnd)
                {
                    if (reflectEnd)
                    {
                        if (GetByType(PSList.PSLIST_TYPE.end).Count == index + 1)
                        {
                            CreateNewPSList(PSList.PSLIST_TYPE.end);
                        }

                        List <PSList> endListPS = GetByType(PSList.PSLIST_TYPE.end);
                        if (endListPS.Count > index)
                        {
                            endListPS [index + 1]._parent.transform.position = hit.point;
                            endListPS [index + 1]._parent.transform.forward  = -hit.normal;
                        }
                    }
                    else
                    {
                        endVFX.transform.position = hit.point;
                        endVFX.transform.forward  = -hit.normal;
                    }
                }

                if (trailVFX != null && useTrail && reflectTrail)
                {
                    if (trails.Count == index + 1)
                    {
                        Trail newTrail = new Trail()
                        {
                            _ps = psTrailVFX, _trailInterval = trailInterval
                        };
                        trails.Add(newTrail);
                    }

                    if (trails [index + 1]._emittingTrail == false)
                    {
                        trails [index + 1]._trailPosition    = hit.point;
                        trails [index + 1]._trailEulerAngles = Quaternion.LookRotation(-hit.normal).eulerAngles;
                        StartCoroutine(trails [index + 1].EmitTrail());
                    }
                }

                if (!useEnd || !reflectEnd && generateColliders)
                {
                    if (collidersList.Count == index + 1)
                    {
                        Debug.Log("NewColliderAdded");
                        GameObject gObj = new GameObject("NewCollider");
                        gObj.transform.SetParent(transform);
                        gObj.transform.position = hit.point;
                        gObj.transform.forward  = -hit.normal;
                        GenerateCollider(gObj);
                    }

                    if (collidersList.Count > index)
                    {
                        var coObj = collidersList [index + 1].gameObject;
                        coObj.transform.position = hit.point;
                        coObj.transform.forward  = -hit.normal;
                    }
                }
            }
            else
            {
                if (lr.positionCount > index + 3)
                {
                    lr.positionCount--;
                }
                if (lengthRemaining > 0.1f)
                {
                    var pos = ray.GetPoint(lengthRemaining);

                    lr.SetPosition(index + 2, pos);

                    if (startVFX != null && useStart && reflectStart)
                    {
                        if (GetByType(PSList.PSLIST_TYPE.start).Count == index + 1)
                        {
                            CreateNewPSList(PSList.PSLIST_TYPE.start);
                        }

                        List <PSList> startListPS = GetByType(PSList.PSLIST_TYPE.start);
                        if (startListPS.Count > index)
                        {
                            startListPS[index + 1]._parent.transform.position = position;
                            RotateToMouse(startListPS[index + 1]._parent, pos);
                        }

                        if (startListPS.Count > index + 2)
                        {
                            RemoveLastByType(PSList.PSLIST_TYPE.start);
                        }
                    }

                    if (middleVFX != null && useMiddle && reflectMiddle)
                    {
                        if (GetByType(PSList.PSLIST_TYPE.middle).Count == index + 1)
                        {
                            CreateNewPSList(PSList.PSLIST_TYPE.middle);
                        }

                        List <PSList> middleListPS = GetByType(PSList.PSLIST_TYPE.middle);
                        if (middleListPS.Count > index)
                        {
                            middleListPS[index + 1]._parent.transform.position = position;
                            RotateToMouse(middleListPS[index + 1]._parent, pos);
                        }

                        if (middleListPS.Count > index + 2)
                        {
                            RemoveLastByType(PSList.PSLIST_TYPE.middle);
                        }
                    }

                    if (endVFX != null && useEnd)
                    {
                        if (reflectEnd)
                        {
                            if (useEndAlways)
                            {
                                if (GetByType(PSList.PSLIST_TYPE.end).Count == index + 1)
                                {
                                    CreateNewPSList(PSList.PSLIST_TYPE.end);
                                }

                                List <PSList> endListPS = GetByType(PSList.PSLIST_TYPE.end);
                                if (endListPS.Count > index)
                                {
                                    endListPS [index + 1]._parent.transform.position = pos;
                                    RotateToMouse(endListPS [index + 1]._parent, ray.origin);
                                }

                                if (endListPS.Count > index + 2)
                                {
                                    RemoveLastByType(PSList.PSLIST_TYPE.end);
                                }
                            }
                            else
                            {
                                List <PSList> endListPS = GetByType(PSList.PSLIST_TYPE.end);
                                if (endListPS.Count > index + 1)
                                {
                                    endListPS [index + 1].DisablePS(false);
                                }
                            }
                        }
                        else
                        {
                            endVFX.transform.position = pos;
                            RotateToMouse(endVFX, ray.origin);
                        }
                    }

                    if (trailVFX != null && useTrail)
                    {
                        for (int i = index + 1; i < trails.Count; i++)
                        {
                            trails [i]._emittingTrail = false;
                            trails [i]._ps.Stop();
                        }
                    }

                    if (!useEnd || !reflectEnd && generateColliders)
                    {
                        if (collidersList.Count == index + 1)
                        {
                            Debug.Log("NewColliderAdded");
                            GameObject gObj = new GameObject("NewCollider");
                            gObj.transform.SetParent(transform);
                            gObj.transform.position = pos;
                            RotateToMouse(gObj, ray.origin);
                            GenerateCollider(gObj);
                        }

                        if (collidersList.Count > index)
                        {
                            var coObj = collidersList [index + 1].gameObject;
                            coObj.transform.position = pos;
                            RotateToMouse(coObj, ray.origin);
                        }

                        if (collidersList.Count > index + 2)
                        {
                            Debug.Log("Removing Collider from List. Left: " + collidersList.Count);
                            RemoveLastCollider(true);
                        }
                    }
                }
            }

            bouncesRemaining--;
            lengthRemaining -= Vector3.Distance(lr.GetPosition(index + 1), lr.GetPosition(index + 2));
            RecursiveBounces(lr, hit.point, Vector3.Reflect(ray.direction, hit.normal), bouncesRemaining, lengthRemaining);
        }