|
@@ -108,7 +108,7 @@ namespace GFGGame
|
|
|
if (!string.IsNullOrEmpty(itemCfg.resLayer1))
|
|
|
{
|
|
|
spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, 1);
|
|
|
- TryClearSpriteObj(parentObj, spritObjName);
|
|
|
+ TryRemoveObj(parentObj, spritObjName);
|
|
|
aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, 1);
|
|
|
TryRemoveObj(parentObj, aniObjName);
|
|
|
aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType, 1);
|
|
@@ -118,7 +118,7 @@ namespace GFGGame
|
|
|
if (!string.IsNullOrEmpty(itemCfg.resLayer2))
|
|
|
{
|
|
|
spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, 2);
|
|
|
- TryClearSpriteObj(parentObj, spritObjName);
|
|
|
+ TryRemoveObj(parentObj, spritObjName);
|
|
|
aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, 2);
|
|
|
TryRemoveObj(parentObj, aniObjName);
|
|
|
aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType, 2);
|
|
@@ -128,7 +128,7 @@ namespace GFGGame
|
|
|
if (!string.IsNullOrEmpty(itemCfg.resLayer3))
|
|
|
{
|
|
|
spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, 3);
|
|
|
- TryClearSpriteObj(parentObj, spritObjName);
|
|
|
+ TryRemoveObj(parentObj, spritObjName);
|
|
|
aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, 3);
|
|
|
TryRemoveObj(parentObj, aniObjName);
|
|
|
aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType, 3);
|
|
@@ -137,57 +137,73 @@ namespace GFGGame
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void InitHead(GameObject sceneObj, bool needSetMask = false, GameObject parentObj = null)
|
|
|
+ public static void UpdateHead(bool show, GameObject sceneObj, bool needSetMask = false, GameObject parentObj = null)
|
|
|
{
|
|
|
var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
|
|
|
parentObj = parentObj == null ? roleTf.gameObject : parentObj;
|
|
|
string res = HEAD_DEFAULT_RES_NAME;
|
|
|
+
|
|
|
Transform transform_t = parentObj.transform.Find(HEAD_SPRITE_NAME);
|
|
|
- if (transform_t != null)
|
|
|
+ if (show)
|
|
|
{
|
|
|
- return;
|
|
|
+ if (transform_t != null)
|
|
|
+ {
|
|
|
+ transform_t.gameObject.SetActive(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AddSpriteObj(res, "png", HEAD_SPRITE_NAME, parentObj, 1, needSetMask);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(transform_t == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ transform_t.gameObject.SetActive(false);
|
|
|
}
|
|
|
- AddSpriteObj(res, "png", HEAD_SPRITE_NAME, parentObj, 1, needSetMask);
|
|
|
- }
|
|
|
-
|
|
|
- public static void UpdateWholeBody(string res, GameObject sceneObj, bool isAni = false, string effRes = null, bool needSetMask = false, GameObject parentObj = null)
|
|
|
- {
|
|
|
- InitHead(sceneObj, needSetMask, parentObj);
|
|
|
- UpdateBodyOnly(res, sceneObj, isAni, effRes, needSetMask, parentObj);
|
|
|
}
|
|
|
|
|
|
- public static void UpdateBodyOnly(string res, GameObject sceneObj, bool isAni = false, string effRes = null, bool needSetMask = false, GameObject parentObj = null)
|
|
|
+ public static void UpdateBody(string actionRes, GameObject sceneObj, bool needSetMask = false, GameObject parentObj = null)
|
|
|
{
|
|
|
//角色
|
|
|
var roleTf = sceneObj.transform.Find(ROLE_OBJ_NAME);
|
|
|
parentObj = parentObj == null ? roleTf.gameObject : parentObj;
|
|
|
- if (res == null)
|
|
|
+
|
|
|
+ var extPng = "png";
|
|
|
+ if (!string.IsNullOrEmpty(actionRes))
|
|
|
{
|
|
|
- res = BODY_DEFAULT_RES_NAME;
|
|
|
+ string resPath = ResPathUtil.GetDressUpAnimationPath(actionRes);
|
|
|
+ if (CheckGameObjExisted(parentObj, BODY_ANIMATION_NAME, resPath))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string resPath = ResPathUtil.GetDressUpPath(BODY_DEFAULT_RES_NAME, extPng);
|
|
|
+ if (CheckGameObjExisted(parentObj, BODY_SPRITE_NAME, resPath))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //清理旧的
|
|
|
- TryClearSpriteObj(parentObj, BODY_SPRITE_NAME);
|
|
|
var removeBodyAni = TryRemoveObj(parentObj, BODY_ANIMATION_NAME);
|
|
|
TryRemoveObj(parentObj, BODY_EFFECT_OBJ_NAME);
|
|
|
-
|
|
|
- if (isAni)
|
|
|
+ TryRemoveObj(parentObj, BODY_SPRITE_NAME);
|
|
|
+ if (!string.IsNullOrEmpty(actionRes))
|
|
|
{
|
|
|
- AddAnimationObj(res, BODY_ANIMATION_NAME, parentObj, 0);
|
|
|
+ AddAnimationObj(actionRes, BODY_ANIMATION_NAME, parentObj, 0);
|
|
|
+ //特效
|
|
|
+ TryAddEffectObj(actionRes, BODY_EFFECT_OBJ_NAME, parentObj, 0, false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- AddSpriteObj(res, "png", BODY_SPRITE_NAME, parentObj, 0, needSetMask);
|
|
|
+ AddSpriteObj(BODY_DEFAULT_RES_NAME, extPng, BODY_SPRITE_NAME, parentObj, 0, needSetMask);
|
|
|
if (removeBodyAni)
|
|
|
{
|
|
|
parentObj.transform.SetPositionAndRotation(new Vector3(), new Quaternion());
|
|
|
}
|
|
|
}
|
|
|
- //特效
|
|
|
- if (!string.IsNullOrEmpty(effRes))
|
|
|
- {
|
|
|
- TryAddEffectObj(effRes, BODY_EFFECT_OBJ_NAME, parentObj, 0, false);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
public static void AddAssetReleaser(GameObject gameObj, string resPath)
|
|
@@ -242,18 +258,18 @@ namespace GFGGame
|
|
|
|
|
|
//清理旧的
|
|
|
var spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, layerId);
|
|
|
- TryClearSpriteObj(parentObj, spritObjName);
|
|
|
- var aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, layerId);
|
|
|
- TryRemoveObj(parentObj, aniObjName);
|
|
|
+ TryRemoveObj(parentObj, spritObjName);
|
|
|
+ var objName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, layerId);
|
|
|
+ TryRemoveObj(parentObj, objName);
|
|
|
string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
|
|
|
//这里需要先添加静态图,防止加载动画有延迟,出现光头
|
|
|
GameObject spriteObj = AddSpriteObj(res, ext, spritObjName, parentObj, sortingOrder, needSetMask);
|
|
|
|
|
|
- GameObject aniObj = null;
|
|
|
+ GameObject addAniObj = null;
|
|
|
if (showAni)
|
|
|
{
|
|
|
- aniObj = AddAnimationObj(res, aniObjName, parentObj, sortingOrder);
|
|
|
- if (aniObj != null && spriteObj != null)
|
|
|
+ addAniObj = AddAnimationObj(res, objName, parentObj, sortingOrder);
|
|
|
+ if (addAniObj != null && spriteObj != null)
|
|
|
{
|
|
|
Timers.inst.Add(0.03f, 1, (obj) =>
|
|
|
{
|
|
@@ -270,7 +286,7 @@ namespace GFGGame
|
|
|
string resPath = ResPathUtil.GetDressUpPath(res, ext);
|
|
|
if (assetDisposer.resPath == resPath)
|
|
|
{
|
|
|
- TryClearSpriteObj(parentObj, spritObjName);
|
|
|
+ TryRemoveObj(parentObj, spritObjName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -280,9 +296,9 @@ namespace GFGGame
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- aniObjName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType, layerId);
|
|
|
- TryRemoveObj(parentObj, aniObjName);
|
|
|
- TryAddEffectObj(res, aniObjName, parentObj, sortingOrder, aniObj != null);
|
|
|
+ objName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType, layerId);
|
|
|
+ TryRemoveObj(parentObj, objName);
|
|
|
+ TryAddEffectObj(res, objName, parentObj, sortingOrder, addAniObj != null);
|
|
|
}
|
|
|
|
|
|
private static GameObject AddSpriteObj(string res, string ext, string objName, GameObject parentObj, int sortingOrder, bool needSetMask)
|
|
@@ -292,6 +308,10 @@ namespace GFGGame
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
+ if (CheckGameObjExisted(parentObj, objName, resPath))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
SpriteRenderer spr = null;
|
|
|
var gameObj = parentObj.transform.Find(objName)?.gameObject;
|
|
|
if (gameObj == null)
|
|
@@ -331,44 +351,6 @@ namespace GFGGame
|
|
|
return gameObj;
|
|
|
}
|
|
|
|
|
|
- public static void TryClearSpriteObj(GameObject parentObj, string spritObjName)
|
|
|
- {
|
|
|
- if (parentObj == null)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- Transform transform_t = parentObj.transform.Find(spritObjName);
|
|
|
- if (transform_t != null)
|
|
|
- {
|
|
|
- GameObject gameObj_t = transform_t.gameObject;
|
|
|
- if (gameObj_t != null)
|
|
|
- {
|
|
|
- //SpriteRenderer spr = null;
|
|
|
- //spr = gameObj_t.GetComponent<SpriteRenderer>();
|
|
|
- //if(spr != null)
|
|
|
- //{
|
|
|
- // spr.sprite = null;
|
|
|
- //}
|
|
|
- // var assetDisposer = gameObj_t.GetComponent<AssetReleaser>();
|
|
|
- // if (assetDisposer != null)
|
|
|
- // {
|
|
|
- // if (!string.IsNullOrEmpty(assetDisposer.resPath))
|
|
|
- // {
|
|
|
- // GFGAsset.Release(assetDisposer.resPath);
|
|
|
- // assetDisposer.resPath = null;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // SpriteRenderer spr = gameObj_t.GetComponent<SpriteRenderer>();
|
|
|
- // if (spr != null)
|
|
|
- // {
|
|
|
- // GameObject.Destroy(spr);
|
|
|
- // }
|
|
|
- GameObject.DestroyImmediate(gameObj_t);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private static GameObject AddAnimationObj(string res, string objName, GameObject parentObj, int sortingOrder)
|
|
|
{
|
|
|
string resPath = ResPathUtil.GetDressUpAnimationPath(res);
|
|
@@ -376,6 +358,10 @@ namespace GFGGame
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
+ if(CheckGameObjExisted(parentObj, objName, resPath))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
var prefab = GFGAsset.Load<GameObject>(resPath);
|
|
|
var gameObj = GameObject.Instantiate(prefab);
|
|
|
AddAssetReleaser(gameObj, resPath);
|
|
@@ -404,13 +390,37 @@ namespace GFGGame
|
|
|
return gameObj;
|
|
|
}
|
|
|
|
|
|
- private static bool TryRemoveObj(GameObject parentObj, string aniObjName)
|
|
|
+ private static void TryAddEffectObj(string res, string objName, GameObject parentObj, int sortingOrder, bool inAniDir)
|
|
|
+ {
|
|
|
+ var resPath = ResPathUtil.GetDressUpEffectPath(res, inAniDir);
|
|
|
+ if (!VEngine.Versions.Contains(resPath))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (CheckGameObjExisted(parentObj, objName, resPath))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GameObject effPre = GFGAsset.Load<GameObject>(resPath);
|
|
|
+ var gameObj = GameObject.Instantiate(effPre);
|
|
|
+ AddAssetReleaser(gameObj, resPath);
|
|
|
+ gameObj.transform.SetParent(parentObj.transform, false);
|
|
|
+ gameObj.name = objName;
|
|
|
+ var sortingGroup = gameObj.transform.GetComponent<SortingGroup>();
|
|
|
+ if (sortingGroup != null)
|
|
|
+ {
|
|
|
+ GameObject.Destroy(sortingGroup);
|
|
|
+ }
|
|
|
+ SetRenderersOrder(gameObj, sortingOrder + 1);//特效层默认高一个层级
|
|
|
+ }
|
|
|
+
|
|
|
+ private static bool TryRemoveObj(GameObject parentObj, string objName)
|
|
|
{
|
|
|
if (parentObj == null)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
- Transform transform = parentObj.transform.Find(aniObjName);
|
|
|
+ Transform transform = parentObj.transform.Find(objName);
|
|
|
if (transform != null)
|
|
|
{
|
|
|
GameObject gameObj = transform.gameObject;
|
|
@@ -423,6 +433,32 @@ namespace GFGGame
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private static bool CheckGameObjExisted(GameObject parentObj, string objName, string resPath)
|
|
|
+ {
|
|
|
+ if (parentObj == null)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Transform transform = parentObj.transform.Find(objName);
|
|
|
+ if (transform != null)
|
|
|
+ {
|
|
|
+ GameObject gameObj = transform.gameObject;
|
|
|
+ if (gameObj != null)
|
|
|
+ {
|
|
|
+ var assetReleaser = gameObj.GetComponent<AssetReleaser>();
|
|
|
+ if (assetReleaser != null)
|
|
|
+ {
|
|
|
+ if (assetReleaser.resPath == resPath)
|
|
|
+ {
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
public static GameObject CreateAnimationObj(string resPath)
|
|
|
{
|
|
|
// string resPath = ResPathUtil.GetCardAnimationPath(res);
|
|
@@ -436,26 +472,6 @@ namespace GFGGame
|
|
|
return gameObj;
|
|
|
}
|
|
|
|
|
|
- private static void TryAddEffectObj(string res, string objName, GameObject parentObj, int sortingOrder, bool inAni)
|
|
|
- {
|
|
|
- var resPath = ResPathUtil.GetDressUpEffectPath(res, inAni);
|
|
|
- if (!VEngine.Versions.Contains(resPath))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- GameObject effPre = GFGAsset.Load<GameObject>(resPath);
|
|
|
- var gameObj = GameObject.Instantiate(effPre);
|
|
|
- AddAssetReleaser(gameObj, resPath);
|
|
|
- gameObj.transform.SetParent(parentObj.transform, false);
|
|
|
- gameObj.name = objName;
|
|
|
- var sortingGroup = gameObj.transform.GetComponent<SortingGroup>();
|
|
|
- if (sortingGroup != null)
|
|
|
- {
|
|
|
- GameObject.Destroy(sortingGroup);
|
|
|
- }
|
|
|
- SetRenderersOrder(gameObj, sortingOrder + 1);//特效层默认高一个层级
|
|
|
- }
|
|
|
-
|
|
|
public static void LoadSpritePos(string res, out float tx, out float ty)
|
|
|
{
|
|
|
string resPath = ResPathUtil.GetDressUpPath(res, "bytes");
|