Beispiel #1
0
    public void UpdateTargetsList()
    {
        //update bolts for each target list, fill up for missing
        int boltsMissing = targets.Count - allBolts.Count;

        if (boltsMissing > 0)
        {
            for (int j = 0; j < boltsMissing; j++)
            {
                GameObject newBolt = (GameObject)Instantiate(boltPrefab, transform.position, transform.rotation);
                newBolt.name             = "BoltPart" + j;
                newBolt.transform.parent = transform;
                allBolts.Add(newBolt.GetComponent <X_LB_Bolt> ());
                newBolt.GetComponent <X_LB_Bolt>().Initialize(this);
            }
        }
        //clear segments from redundant bolts
        if (boltsMissing < 0)
        {
            for (int e = allBolts.Count - 1; e > targets.Count - 1; e--)
            {
                X_LB_Bolt current = (X_LB_Bolt)allBolts[e];
                current.ClearSegments();
            }
        }
    }
Beispiel #2
0
 public void Disappear(X_LB_Bolt currentBolt, bool fadeEffect)
 {
     fadeTime = 0;
     if (fadeEffect == true)
     {
         fadeTime = lightningSource.impactTimeForOne * fadeLengthMultiplier;
     }
     StartCoroutine(Fade(currentBolt, fadeTime));
 }
Beispiel #3
0
 public void FromBoltInPool(X_LB_Bolt currentBolt)
 {
     transform.parent = lightningSource.pool;
     if (currentBolt.allSegmentsInBolt.Contains(this))
     {
         currentBolt.allSegmentsInBolt.Remove(this);
     }
     lightningSource.allSegmentsInPool.Add(this);
     gameObject.SetActive(false);
 }
Beispiel #4
0
 public void FromPoolInBolt(X_LB_Bolt currentBolt)
 {
     transform.parent = currentBolt.transform;
     if (lightningSource.allSegmentsInPool.Contains(this))
     {
         lightningSource.allSegmentsInPool.Remove(this);
     }
     currentBolt.allSegmentsInBolt.Add(this);
     gameObject.SetActive(true);
     Prepare();
 }
Beispiel #5
0
 IEnumerator Fade(X_LB_Bolt currentBolt, float fadeTime)
 {
     if (fadeTime > 0)
     {
         GoFading();
         while (fadeTime > 0)
         {
             fadeTime      -= Time.deltaTime;
             material.color = new Color(material.color.r, material.color.g, material.color.b, fadeTime / (lightningSource.impactTimeForOne * fadeLengthMultiplier));
             yield return(0);
         }
         EndFading();
     }
     FromBoltInPool(currentBolt);
 }
Beispiel #6
0
    IEnumerator EndStrike(float after)
    {
        yield return(new WaitForSeconds(after));

        striking   = false;
        strike     = false;
        strikeBool = false;
        sounds.StopStreamSound();
        mainLight.enabled = false;
        flickeringOffsets = new Vector3[0];
        for (int i = 0; i < allBolts.Count; i++)
        {
            X_LB_Bolt      currentBolt     = (X_LB_Bolt)allBolts[i];
            X_LB_Segment[] segmentsToClean = currentBolt.transform.GetComponentsInChildren <X_LB_Segment>();
            for (int j = 0; j < segmentsToClean.Length; j++)
            {
                segmentsToClean[j].Disappear(currentBolt, fadeEffect);
            }
        }
    }
Beispiel #7
0
    public void StrikeAction()
    {
        //first: update targets
        //it's a realtime parameter!
        UpdateTargetsList();

        //The action
        striking = true;

        if (lightSize > 0)
        {
            mainLight.enabled = true;
            mainLight.color   = color;
            mainLight.range   = lightSize;
        }
        else
        {
            mainLight.enabled = false;
        }

        if (targets.Count == 0)
        {
            return;
        }

        startingPoint = transform;

        for (int h = 0; h < targets.Count; h++)
        {
            //create one bolt with several segments from one target	to another
            currentTarget = targets[h];
            currentBolt   = (X_LB_Bolt)allBolts[h];

            if (currentTarget == null)
            {
                currentBolt.ClearSegments();
                continue;
            }

            //Call method on impact, that's what a lightning is for
            if (callMethodOnImpactBool[h] == true)
            {
                targets[h].gameObject.SendMessage(callMethodOnImpact[h], SendMessageOptions.DontRequireReceiver);
            }

            //get number of segments for bolt part
            distanceToTarget = Calculator.X_LB_Math.Sqrt2((startingPoint.position - currentTarget.position).sqrMagnitude);

            numberOfSegmentsFloat = distanceToTarget / segmentSize;
            //catch no segment case
            if (numberOfSegmentsFloat < minNumberOfSegments)
            {
                numberOfSegmentsFloat = minNumberOfSegments;
            }
            numberOfSegments = (int)Mathf.Round(numberOfSegmentsFloat);

            numberOfSegmentsActive  = currentBolt.allSegmentsInBolt.Count;
            numberOfSegmentsMissing = numberOfSegments - numberOfSegmentsActive;

            if (numberOfSegmentsMissing > 0)
            {
                for (int i = 0; i < numberOfSegmentsMissing; i++)
                {
                    //too little segments active, put some into the bolt
                    if (allSegmentsInPool.Count > 0)
                    {
                        currentSegmentOutOfPool = (X_LB_Segment)allSegmentsInPool [0];
                        currentSegmentOutOfPool.FromPoolInBolt(currentBolt);
                    }
                }
            }
            if (numberOfSegmentsMissing < 0)
            {
                for (int j = 0; j < -numberOfSegmentsMissing; j++)
                {
                    //too many segments active, put them back in pool
                    currentSegmentOutOfBolt = (X_LB_Segment)currentBolt.allSegmentsInBolt [0];
                    currentSegmentOutOfBolt.FromBoltInPool(currentBolt);
                }
            }

            //before positioning the segments: set an array of chain points for this bolt and flickering offsets
            chainPoints = new Vector3[currentBolt.allSegmentsInBolt.Count + 1];           // +1 because is has 5 chain points per bolt with 4 segments
            for (int e = 0; e < chainPoints.Length; e++)
            {
                segmentCount   = currentBolt.allSegmentsInBolt.Count;
                chainSpace     = (currentTarget.position - startingPoint.position) / segmentCount;
                chainPoint     = startingPoint.position + e * chainSpace;
                chainPoints[e] = chainPoint;
            }
            if ((flickeringOffsets.Length == 0 && freezeShape == true) || freezeShape == false)
            {
                flickeringOffsets = new Vector3[currentBolt.allSegmentsInBolt.Count + 1];
                for (int f = 0; f < flickeringOffsets.Length; f++)
                {
                    flickerOffset = GetFlickerOffset();
                    if (f == 0 || f == chainPoints.Length - 1)
                    {
                        flickerOffset = Vector3.zero;
                    }
                    flickeringOffsets[f] = flickerOffset;
                }
            }
            //now positioning all segments of one bolt regarding the chain points
            for (int k = 0; k < currentBolt.allSegmentsInBolt.Count; k++)
            {
                currentSegment = (X_LB_Segment)currentBolt.allSegmentsInBolt [k];
                //position start
                currentSegment.SetChainPositioner(chainPoints[k] + flickeringOffsets[k]);
                //position end
                currentSegment.SetEndingPoint(chainPoints[k + 1] + flickeringOffsets[k + 1]);
                currentSegment.target            = currentTarget;
                currentSegment.point2.localScale = Vector3.one;
            }
            //end point is starting point for next bolt/target
            startingPoint = currentTarget;
        }

        //end cap of the whole lightning
        if (allBolts.Count > 0)
        {
            lastBoltForEndCap = (X_LB_Bolt)allBolts [allBolts.Count - 1];
            if (lastBoltForEndCap.allSegmentsInBolt.Count > 0)
            {
                lastSegmentForEndCap = (X_LB_Segment)lastBoltForEndCap.allSegmentsInBolt [lastBoltForEndCap.allSegmentsInBolt.Count - 1];
                lastSegmentForEndCap.point2.transform.localScale = new Vector3(.5f, .5f, .5f);
            }
        }
    }