|
@@ -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))
|
|
|
+ {
|
|
|
+ string resPath = ResPathUtil.GetDressUpAnimationPath(actionRes);
|
|
|
+ if (CheckGameObjExisted(parentObj, BODY_ANIMATION_NAME, resPath))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- res = BODY_DEFAULT_RES_NAME;
|
|
|
+ string resPath = ResPathUtil.GetDressUpPath(BODY_DEFAULT_RES_NAME, extPng);
|
|
|
+ if (CheckGameObjExisted(parentObj, BODY_SPRITE_NAME, resPath))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //清理旧的
|
|
|
- TryRemoveObj(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)
|
|
@@ -243,17 +259,17 @@ namespace GFGGame
|
|
|
//清理旧的
|
|
|
var spritObjName = string.Format(FORMAT_SPRITE_NAME, itemCfg.subType, layerId);
|
|
|
TryRemoveObj(parentObj, spritObjName);
|
|
|
- var aniObjName = string.Format(FORMAT_ANIMATION_NAME, itemCfg.subType, layerId);
|
|
|
- TryRemoveObj(parentObj, aniObjName);
|
|
|
+ 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) =>
|
|
|
{
|
|
@@ -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)
|
|
@@ -370,6 +390,30 @@ namespace GFGGame
|
|
|
return gameObj;
|
|
|
}
|
|
|
|
|
|
+ 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)
|
|
@@ -428,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");
|