public void CreateTrail(SaberTrailRenderer rendererPrefab)
 {
     TrailHandler = new TrailHandler(GameObject);
     TrailHandler.SetPrefab(rendererPrefab);
     TrailHandler.SetTrailData(GetTrailData());
     TrailHandler.CreateTrail();
 }
    private void OnTriggerEnter2D(Collider2D collision)
    {  //check collision with walls and trails.
        if (collision.gameObject.tag == "Trail" && Alive == true || collision.gameObject.tag == "Walls" && Alive == true)
        {
            TrailHandler handler = TrailManager.Instance.activeTrails[index].Handler;
            handler.Renderer.emitting = false;
            if (collision.gameObject.tag == "Trail")
            {
                TrailData tempdata = collision.gameObject.GetComponent <TrailCollision>().TrailData;
                if (tempdata.beforeSplitTrail == null)
                {
                    tempdata.TrailCollider.SplitPoint(transform, tempdata.Handler.transform);
                }
                else
                {
                    tempdata.TrailCollider.SubSplit(tempdata.beforeSplitTrail, transform);
                }

                collision.gameObject.SetActive(false);
            }
            else
            {
                handler.NewAtColl();
            }
            Death();
        }
    }
Exemple #3
0
        public void SetColor(Color color)
        {
            foreach (BasePieceInstance piece in PieceCollection)
            {
                piece.SetColor(color);
            }

            TrailHandler?.SetColor(color);

            if (_secondaryTrails is { })
        public void LoadBundle(string bundlePath, Transform parent)
        {
            AssetBundle bundle = AssetBundle.LoadFromFile(bundlePath);

            if (bundle == null)
            {
                return;
            }
            var prefab = bundle.LoadAsset <GameObject>("_customsaber");

            var saber = Instantiate(prefab, parent);

            if (saber.GetComponentInChildren <CustomTrail>(true) != null)
            {
                CustomTrail tlm;
                foreach (Transform child in saber.transform)
                {
                    if (child.GetComponent <CustomTrail>())
                    {
                        tlm = child.GetComponent <CustomTrail>();

                        GameObject trail = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        trail.transform.SetParent(child);
                        Destroy(trail.GetComponent <BoxCollider>());
                        trail.transform.position         = tlm.PointStart.position;
                        trail.transform.localEulerAngles = new Vector3(90, 0, 0);
                        TrailHandler newTrail = trail.AddComponent <TrailHandler>();
                        newTrail.pointEnd   = tlm.PointEnd.gameObject;
                        newTrail.pointStart = tlm.PointStart.gameObject;
                        newTrail.mat        = tlm.TrailMaterial;
                        newTrail.Onload();
                    }
                }
            }

            foreach (Transform child in saber.transform)
            {
                if (child.name == "RightSaber" || child.name == "LeftSaber")
                {
                    GameObject _Tip = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    _Tip.name = "Tip";
                    _Tip.transform.SetParent(child);
                    _Tip.transform.localScale    = new Vector3(0, 0, 0);
                    _Tip.transform.localPosition = new Vector3(0, 0, child.localScale.z);
                    GameObject _base = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    _base.name = "Base";
                    _base.transform.SetParent(child);
                    _base.transform.localScale    = new Vector3(0, 0, 0);
                    _base.transform.localPosition = new Vector3(0, 0, 0);
                }
            }
        }
Exemple #5
0
    public void SplitPoint(Transform collidingPlayer, Transform trailOwner)
    {   //we gonna find the closest collision point, find the closest position on the trailCollider, then split at that index.
        int          breakIndex    = FindBreakPoint(collidingPlayer.position, collider2D);
        TrailHandler originalTrail = trailOwner.GetComponent <TrailHandler>();

        SplitCollider(originalTrail, breakIndex);

        if (transform.parent.name != "StaticTrails")
        {
            originalTrail.NewAtColl();
        }
        collidingPlayer.GetComponent <TrailHandler>().NewAtColl();
    }
Exemple #6
0
        void CreateTrail(GameObject saber, bool leftSaber = true)
        {
            CustomTrail tlm;

            if (saber.GetComponent <CustomTrail>())
            {
                tlm = saber.GetComponent <CustomTrail>();

                GameObject trail = GameObject.CreatePrimitive(PrimitiveType.Cube);
                trail.transform.SetParent(saber.transform);
                Destroy(trail.GetComponent <BoxCollider>());
                trail.transform.position         = tlm.PointStart.position;
                trail.transform.localEulerAngles = new Vector3(90, 0, 0);
                TrailHandler newTrail = trail.AddComponent <TrailHandler>();
                newTrail.pointEnd   = tlm.PointEnd.gameObject;
                newTrail.pointStart = tlm.PointStart.gameObject;

                newTrail.mat = new Material(trailShader);
                if (tlm.TrailMaterial.HasProperty("_AlphaTex"))
                {
                    newTrail.mat.SetTexture("_AlphaTex", tlm.TrailMaterial.GetTexture("_AlphaTex"));
                }
                else
                {
                    newTrail.mat.SetTexture("_AlphaTex", tlm.TrailMaterial.GetTexture("_MainTex"));
                }

                newTrail.mat.SetColor("_Color", leftSaber ? LeftSaberMaterial.color : RightSaberMaterial.color);

                if (leftSaber)
                {
                    newTrail.startColor = LeftSaberMaterial.color;
                    newTrail.endColor   = LeftSaberMaterial.color;
                }
                else
                {
                    newTrail.startColor = RightSaberMaterial.color;
                    newTrail.endColor   = RightSaberMaterial.color;
                }

                newTrail.endColor.a = 0;
                newTrail.Onload();
            }
        }
Exemple #7
0
 private void SplitCollider(TrailHandler originalTrailHandler, int i)
 {                                                                                     //for the hole to be symetrical we need an uneven array and remove equal amount of index at both sides of collision.
     if (i < 6)                                                                        //if we collide with the first x.
     {
         Vector2[] firstNewCollider = new Vector2[collider2D.points.Length - (i + 5)]; //if its the first node we just make the new list one index shorter and offset with x.
         for (int j = 0; j < firstNewCollider.Length; j++)
         {
             firstNewCollider[j] = collider2D.points[j + 5 + i];
         }
         originalTrailHandler.NewTrailFromArr(firstNewCollider, originalTrailHandler.trailData);
         SplitGardientTrail(firstNewCollider.Length, collider2D.points.Length, true);
         return;
     }
     else if (i > collider2D.points.Length - 6)                                                                     //if we colide with the last x
     {
         Vector2[] firstNewCollider = new Vector2[collider2D.points.Length - (collider2D.points.Length - (i - 5))]; // if its the last one we copy all but last aka, x.
         for (int j = 0; j < firstNewCollider.Length; j++)
         {
             firstNewCollider[j] = collider2D.points[j];
         }
         originalTrailHandler.NewTrailFromArr(firstNewCollider, originalTrailHandler.trailData);
         SplitGardientTrail(firstNewCollider.Length, collider2D.points.Length, false);
         return;
     }
     else
     {   //if its somewhere else we cut it at the point of collision, skipping x.
         Vector2[] firstNewCollider  = new Vector2[i - 5];
         Vector2[] secondNewCollider = new Vector2[collider2D.points.Length - (i + 5)];
         for (int j = 0; j < firstNewCollider.Length; j++)
         {
             firstNewCollider[j] = collider2D.points[j];
         }
         for (int k = 0; k < secondNewCollider.Length; k++)
         {
             secondNewCollider[k] = collider2D.points[i + k + 5];
         }
         originalTrailHandler.NewTrailFromArr(firstNewCollider, originalTrailHandler.trailData);
         originalTrailHandler.NewTrailFromArr(secondNewCollider, originalTrailHandler.trailData);
         SplitGardientTrail(firstNewCollider.Length, collider2D.points.Length - secondNewCollider.Length, collider2D.points.Length);
         return;
     }
 }
 public TrailData(TrailHandler handler, TrailCollision collider, TrailRenderer renderer)
 {
     Handler       = handler;
     TrailCollider = collider;
     VisualTrail   = renderer;
 }
 public void DestroyTrail()
 {
     TrailHandler?.DestroyTrail();
 }