GoWrapper +GGraph 更新GameObject 后 渲染顺序的问题

用Example 17 - Model 的例子,先创建模型,然后按键响应往模型节点"Particle View 0"添加粒子特效,并且调用了CacheRenderers,渲染的结果是模型在粒子前面,但如果SetNativeObject之前就把粒子特效放进去,渲染结果是正确的粒子在模型前面,以下是代码,粒子特效是随便做的一个prefab,如何才能在更新GameObject的时候,保持渲染的正确性
 


using UnityEngine;
using FairyGUI;
public class ModelMain : MonoBehaviour
{
GComponent _mainView;
    GameObject _model;
    GoWrapper _goWrapper;
void Start()
{
Application.targetFrameRate = 60;
Stage.inst.onKeyDown.Add(OnKeyDown);
_mainView = this.GetComponent<UIPanel>().ui;
Object prefab = Resources.Load("Role/npc");
        _model = (GameObject)Object.Instantiate(prefab);
        //SetNativeObject之前就把粒子放进去,好像没问题
        //var liziPf = Resources.Load("Role/Particle1");
        //GameObject liziGo = (GameObject)Object.Instantiate(liziPf);
        //var aa = GameObject.Find("Particle View 01");
        //liziGo.transform.parent = aa.transform;
        //liziGo.transform.localPosition = new Vector3(0.67f, 0.03f, 1.25f);
  
        _model.transform.localPosition = new Vector3(61, -89, 1000); //set z to far from UICamera is important!
        _model.transform.localScale = new Vector3(180, 180, 180);
        _model.transform.localEulerAngles = new Vector3(0, 100, 0);
        _goWrapper = new GoWrapper(_model);
        _mainView.GetChild("holder").asGraph.SetNativeObject(_goWrapper);
}

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            var liziPf = Resources.Load("Role/Particle1");
            GameObject liziGo = (GameObject)Object.Instantiate(liziPf);
            Transform[] effects = liziGo.GetComponentsInChildren<Transform>();
            foreach(var effect in effects)
            {
                effect.gameObject.layer = _model.layer;
            }
            var aa = GameObject.Find("Particle View 01");
            liziGo.transform.parent = aa.transform;
            liziGo.transform.localPosition = new Vector3(0.67f, 0.03f, 1.25f);
            _goWrapper.CacheRenderers();
        }
    }
    void OnKeyDown(EventContext context)
{

        //if (context.inputEvent.keyCode == KeyCode.Escape)
        //{
        // Application.Quit();
        //}
    }
}
 
no.png yes.png
已邀请:

谷主

赞同来自:

GoWrapper里代码很简单,调试看看。

wayaya1985

赞同来自:

知道问题了,要把例子特效的sortingOrder手动设置大于模型的sortingOrder,CacheRenderers内部会把所有renderer做升序排列

要回复问题请先登录注册