播放特效 附带dotween路径用法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;


public class PlayFxLogin : MonoBehaviour
{
public GameObject coinFlyP; //金币飞行的特效 ParticleSystem
public GameObject expFlyP; //经验飞行的特效
public GameObject AppGreenP; //绿色
public GameObject AppBlueP; //蓝色 鉴定时候的特效 Appraisal==》鉴定的意思
public GameObject AppPurpleP; //紫色
public GameObject AppGlodenP; //金色
public GameObject expFollowP; //经验跟随移动特效
private GameObject tempExpFollowP; //临时加载的
public GameObject scanningPointP; //扫描点
public GameObject scanningLineP; //扫描线
public GameObject AppingP; //鉴定中特效
public GameObject XXLvP;
public GameObject XXLv01P;
public GameObject XXLv02P;
public GameObject XXLv03P;
public GameObject XXLv04P;
public GameObject SkillUpP; //升级特效
public GameObject SkillDownP; //降级特效
public GameObject SkillFlyP; //升级左飘特效
public GameObject EquipP; //提示装备操作的特效

public GameObject xxxxp; //

/////
///// 通用方法播放特效
/////
/////
/////
//public void PlayFxOnLoginScene(Transform father,GameObject t)
//{
// StartCoroutine(Play(father,t));
//}
//public IEnumerator Play(Transform father, GameObject t)
//{
// KFxUI fx = t.GetComponent();
// if (fx.startTime<=0.01)
// yield return new WaitForSeconds(fx.startTime);

// GameObject go = Instantiate(t);

// go.transform.parent = father;
// go.transform.localScale = Vector3.one;
// go.transform.localPosition = fx.posOffset;// ; //; new Vector3(0, Screen.height / 2);//
// if(fx.lifeTime!=0)
// Destroy(go, fx.lifeTime);
//}


//public void HideFxOnLoginScene(Transform father, GameObject t)
//{

// StartCoroutine(Play(father, t));

//}




[ HideInInspector]
public List< GameObject> AllFindGameP = new List< GameObject>(); //寻找比赛时候的粒子特效
[ HideInInspector]
public List< GameObject> AllEquipP = new List< GameObject>(); //寻找比赛时候的粒子特效

[ HideInInspector]
GameObject root;

public static PlayFxLogin I;
private RectTransform coin;
private RectTransform exp;


private RectTransform expBar;
private RectTransform findGame;
private RectTransform bottom;

///GameObject expFollowP;
[ HideInInspector]
GameObject point;
[ HideInInspector]
GameObject line;
public void PlayEquipP( Transform t, int type= 0)
{
xuqi.Log( "播放这个。。。。。。。。。。。特效");
GameObject go = Instantiate(EquipP);
go.transform.parent = t;
go.transform.localScale = Vector3.one;
if(type== 0)
go.transform.localPosition = new Vector3( 30,- 7);
else
go.transform.localPosition = new Vector3( 72, 0);
AllEquipP.Add(go);
}

public void HideEquipP()
{
for ( int i = 0; i < AllEquipP.Count; i++)
{
Destroy(AllEquipP[i]);
}
AllEquipP.Clear();
}
public void PlaySkillUpP()
{
GameObject go = Instantiate(SkillUpP);
go.transform.parent = KUISkillUp.I.skillUpFather;
go.transform.localScale = Vector3.one;
go.transform.localPosition = Vector3.zero; //; new Vector3(0, Screen.height / 2);//
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 20f);
}



public void PlaySkillDownP()
{
GameObject go = Instantiate(SkillDownP);
go.transform.parent = KUISkillUp.I.consumeFather;
go.transform.localScale = Vector3.one;
go.transform.localPosition = Vector3.zero; //; new Vector3(0, Screen.height / 2);//
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 20f);
}
public void PlaySkillFlyP()
{
GameObject go = Instantiate(SkillFlyP);
go.transform.parent = KUISkillUp.I.consumeFather.parent;
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector3( 156, 68, 0); //; new Vector3(0, Screen.height / 2);//

// go.transform.DOBlendableLocalMoveBy(KUISkillUp.I.consumeFather.parent.localPosition- new Vector3(156, 0, 0), 3f);// coinPos.localPosition new Vector3(500f, 330f, -200f)
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 20f);
}




public void PlayLvP()
{
GameObject go = Instantiate(XXLvP);
go.transform.parent = KUIMain.I.Head.transform;
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector3(- 42,- 9); //; new Vector3(0, Screen.height / 2);//
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 1f);
}

public void PlayLv01P()
{
GameObject go = Instantiate(XXLv01P);
go.transform.parent = KUIMain.I.RankInfo.transform;
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector3( 70, 0); // ; //; new Vector3(0, Screen.height / 2);//
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 1f);
}
public void PlayLv03P()
{
GameObject go = Instantiate(XXLv03P);
go.transform.parent = KUIMain.I.StateAll.transform;
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector3(- 115, 202); //; new Vector3(0, Screen.height / 2);//
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 1f);
}

public void PlayLv04P( Transform trans)
{
xuqi.Log( "播放了 04特效");
GameObject go = Instantiate(XXLv04P);
go.transform.parent = trans; // KUIMain.I.StateAll.transform;
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector3( 0, 0,- 200f); //; new Vector3(0, Screen.height / 2);//
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 1f);
}


public void PlayLv02P()
{
GameObject go = Instantiate(XXLv02P);
GameObject go1 = Instantiate(XXLv02P);
go.transform.parent = KUIMain.I.guideEquip.transform.Find( "Left");
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector3( 0, 0); //; new Vector3(0, Screen.height / 2);//
go1.transform.parent = KUIMain.I.guideEquip.transform.Find( "Right");
go1.transform.localScale = Vector3.one;
go1.transform.localPosition = new Vector3( 0, 0);
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(go, 1f);
Destroy(go1, 1f);
}




void Awake()
{
I = this;
bottom = GameObject.Find( "FX/Bottom").GetComponent< RectTransform>();
root = GameObject.Find( "Canvas/FX");
coin= GameObject.Find( "FX/Coin").GetComponent< RectTransform>();
exp = GameObject.Find( "FX/Bottom/Exp").GetComponent< RectTransform>();
expBar = GameObject.Find( "Head/ExpBar").GetComponent< RectTransform>();
findGame = GameObject.Find( "FX/FindGame").GetComponent< RectTransform>();
}
void Update()
{

}
public void FindGameP()
{
// xuqi.Log("产生扫描特效");
if (line == null)
{
line = Instantiate(scanningLineP);
AllFindGameP.Add(line);
}
else
{
// line = Instantiate(scanningLineP);
}
// GameObject a= Instantiate(scanningLineP);


line.transform.parent = transform.Find( "FindGame");
// xuqi.Log(" line.transform.parent :" + line.transform.parent.name + " line.transform pos :" + line.transform.position+" line name"+line.name);
line.transform.localScale = Vector3.one;
line.transform.localPosition = Vector3.zero;

// float time = ParticleSystemLength(scanningPointP.transform) ;
//xuqi.Log("time ::::特效时长:::::::::"+time);

StartCoroutine( ControlPoint());
// StartCoroutine( ControlPoint());
// 注意 销毁的方式
}

public IEnumerator ControlPoint()
{

// ParticleSystem ps = line.GetComponent();

int MatchNumber1 = KUIGame.I.MatchNumber; //匹配次数
while (KUIGame.I.isMatching && MatchNumber1== KUIGame.I.MatchNumber)
{

// yield return new WaitForSeconds(0.3f);

// line.GetComponent().Play();
// ps.gameObject.SetActive(true);
// ps.Stop();
// ps.Play();
if (line)
line.SetActive( true);
yield return PlayPointP(Random.Range(- 250, - 200), Random.Range( 60, 150));
yield return new WaitForSeconds( 0.2f);
if (MatchNumber1 != KUIGame.I.MatchNumber) { xuqi.Log( "(*^_^*)"); break; }
yield return PlayPointP(Random.Range(- 200, - 150), Random.Range( 150, 200));
yield return new WaitForSeconds( 0.2f);
if (MatchNumber1 != KUIGame.I.MatchNumber) { xuqi.Log( "(*^_^*)"); break; }
yield return PlayPointP( Random.Range(- 80, 0),Random.Range( 100, 160));
yield return new WaitForSeconds( 0.2f);
if (MatchNumber1 != KUIGame.I.MatchNumber) { xuqi.Log( "(*^_^*)"); break; }
yield return PlayPointP(Random.Range(- 100, 0), Random.Range( 273, 245));
// line.GetComponent().Stop();
yield return new WaitForSeconds( 1.5f);
if (MatchNumber1 != KUIGame.I.MatchNumber) { xuqi.Log( "(*^_^*)"); break; }
// ps.gameObject.SetActive(false);
if (line)
line.SetActive( false);
yield return new WaitForSeconds( 0.4f);

}
// if (line)
// Destroy(line);

}

internal void DestroyFindGameP()
{
int n = AllFindGameP.Count;
xuqi.Log( "删除的特效数量:"+n);
for ( int i = 0; i < n; i++)
{
// if (AllP[i])
if (AllFindGameP[i] != null)
{
AllFindGameP[i].SetActive( false);
Destroy(AllFindGameP[i]);
}
}
// AllP.Clear();
}

public IEnumerator PlayPointP( int i, int j)
{
////xuqi.Log("产生一个点特效");
// if(point==null)
GameObject go = Instantiate(scanningPointP);
go.transform.parent = transform.Find( "FindGame");
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector2(i,j);
AllFindGameP.Add(go);
// Destroy(go, 3f);
StartCoroutine(DestroyGameObject( go, 3f));
yield return null;
}

public IEnumerator DestroyGameObject( GameObject go, float time )
{
yield return new WaitForSeconds(time);
if (go)
{
go.SetActive( false);
// AllP.Remove(go);
Destroy(go);
}
// AllP.Remove(go);
// Destroy(go);
}

//计算例子特效时常
//static float ParticleSystemLength(Transform transform)
//{
// ParticleSystem[] particleSystems = transform.GetComponentsInChildren();
// float maxDuration = 0;
// foreach (ParticleSystem ps in particleSystems)
// {
// if (ps.enableEmission)
// {
// if (ps.loop)
// {
// return -1f;
// }
// float dunration = 0f;
// if (ps.emissionRate <= 0)
// {
// dunration = ps.startDelay + ps.startLifetime;
// }
// else
// {
// dunration = ps.startDelay + Mathf.Max(ps.duration, ps.startLifetime);
// }
// if (dunration > maxDuration)
// {
// maxDuration = dunration;
// }
// }
// }
// return maxDuration;
//}


public void ShowCoinFlyP()
{
GameObject go= Instantiate(coinFlyP);
go.transform.parent = transform;
go.transform.localScale = Vector3.one;
go.transform.localPosition = Vector3.zero;
go.transform.DOBlendableLocalMoveBy(coin.localPosition, 1.5f); // coinPos.localPosition new Vector3(500f, 330f, -200f)
Destroy(go, 1.6f);
//DOTween.
}

public void ShowAppP( int qua)
{
GameObject go;
//我们要去掉遮罩

if (qua == 2)
{
go = Instantiate(AppGreenP);
}
else if (qua == 3)
{
go = Instantiate(AppBlueP);
}
else if (qua == 4)
{
go = Instantiate(AppPurpleP);
}
else if (qua == 5)
{
go = Instantiate(AppGlodenP);
}
else
{
StartCoroutine(ControlEnable( false));
return;
}

StartCoroutine(ControlEnable( true));
go.transform.parent = KUIItem.I.gameObject.transform;
go.transform.localScale = Vector3.one;
go.transform.localPosition = Vector3.zero+Vector3.up* 200f;
//播放特效
//销毁特效
Destroy(go, 3f);
}
public IEnumerator ControlEnable( bool needWait)
{
if(needWait)
yield return new WaitForSeconds( 1f);
else
yield return new WaitForSeconds( 0.5f);
KUIMain.I.huiAppLevelMost.enabled = false;
}
Vector3[] waypoints1 = new[] {
// new Vector3(0, 0, 0),
new Vector3(- 1, - 1f, 0),
// new Vector3(-1, -1f, 0),
         //new Vector3(-2.5f, -2f, 0)
};
Vector3[] waypoints2 = new[] {
// new Vector3(0, 0, 0),
new Vector3(- 1, - 1f, 0),
new Vector3(- 1.4f, - 2.3f, 0)
};
public void ShowExpFlyP()
{
// GameObject go = Instantiate(expFlyP);
// go.transform.parent = bottom;
// go.transform.localScale = Vector3.one;
// go.transform.localPosition = new Vector3(0, Screen.height/2);// Vector3.zero;
// go.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2) , 1.5f);//new Vector3(-500f, 370f, -200f)
//Destroy(go, 1.6f);


StartCoroutine(PlayCoin());


//DOTween.
}
public IEnumerator PlayCoin()
{
float timeStep1 = 0.8f;
float timeStep2 = 0.6f;
int count = KUIManager.I.ReqSellEquipQuality* 5;
for ( int i = 0; i < count; i++)
{
yield return new WaitForSeconds(Random.Range( 3, 10)* 0.01f);
GameObject coin = Instantiate(Resources.Load( "Prefabs/ModelOnUI/Coin") as GameObject);
coin.transform.localScale = Vector3.one / 3f; // *30f;
coin.transform.localEulerAngles = Vector3.zero; // *30f;
coin.transform.localPosition = new Vector3( 0, 1, 0); //;// new Vector3(0, Screen.height / 2);// Vector3.zero;
int randomX = Random.Range(- 100, 100);
int randomY = Random.Range(- 100, 100);
waypoints1[ 0] = new Vector3(randomX * - 0.01f, randomY * - 0.01f, 0) + coin.transform.localPosition;
// waypoints1[1] = new Vector3(Random.Range(-200, 200) * -0.01f, Random.Range(-200, 200) * -0.01f, 0) + coin.transform.localPosition;

Tween tstep1 = coin.transform.DOPath(waypoints1, timeStep1, PathType.CatmullRom).SetEase(Ease.OutCubic);

Tween tstep2= coin.transform.DORotate( new Vector3( 0, 720f, 90f) + coin.transform.eulerAngles, timeStep1+timeStep2, RotateMode.WorldAxisAdd);

waypoints2[ 0] = new Vector3(randomX * - 0.01f, randomY * - 0.01f, 0);
/// yield return new WaitForSeconds(0.8f+ Random.Range(0, 20)*0.01f);
// tstep1.Kill();
//tstep2.Kill();
Tween t1 = coin.transform.DOPath(waypoints2, timeStep2, PathType.CatmullRom).SetDelay(timeStep1); // + Random.Range(0, 20) * 0.01f);
// coin.transform.DORotate(new Vector3(0, 180f, 0) + coin.transform.eulerAngles, timeStep1, RotateMode.WorldAxisAdd).SetDelay(timeStep1);

// t.SetEase(Ease.Linear);//.SetLoops(-1);

// coin.transform.DOBlendableLocalMoveBy(exp.localPosition - new Vector3(0, Screen.height / 2), 1.5f);//new Vector3(-500f, 370f, -200f)
Destroy(coin, timeStep1+timeStep2);

}
yield return null;
}


public void ShowExpFollowP()
{
if (tempExpFollowP== null)
tempExpFollowP = Instantiate(expFollowP);
tempExpFollowP.transform.parent = expBar;
tempExpFollowP.transform.localScale = Vector3.one;
tempExpFollowP.transform.localPosition = Vector3.zero;
// go.transform.DOBlendableLocalMoveBy(exp.localPosition, 1.5f);//new Vector3(-500f, 370f, -200f)
}
public void HideExpFollowP()
{
Destroy(tempExpFollowP);
}
public void UpdatePosExpFollowP( int i, int j )
{
float k = i* 1.0f / j;
tempExpFollowP.transform.localPosition = Vector3.right * k * 143f; // 234f;
}

/// < summary >
/// 鉴定中的特效
/// summary >
public void ShowAppingP( Transform trans)
{
GameObject go = Instantiate(AppingP);
go.transform.parent = trans;
go.transform.localScale = Vector3.one;
go.transform.localPosition = new Vector2( 0, - 77);
}
}

你可能感兴趣的:(UNTIY3D)