Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
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();
            }
        }