/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~对象构建~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    /// <summary>
    /// 创建对象
    /// </summary>
    /// <typeparam name="T">脚本文件</typeparam>
    /// <param name="file">资源路径,不填会创建空对象</param>
    /// <returns></returns>
    private EffectBase NewObject <T>(string file = "")
    {
        GameObject obj = GameObjectUtils.BuildObject("Prefab/EmptyObject");

        if (obj == null)
        {
            return(null);
        }
        SceneLayerUtils.AddChild(obj.transform);
        Component gameObj = obj.GetComponent(typeof(T));

        if (gameObj == null)
        {
            gameObj = obj.AddComponent(typeof(T));
        }

        EffectBase eff = gameObj as EffectBase;

        eff.name = file;
        eff.LoadResource(file);
        return(eff);
    }
示例#2
0
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~对象集合~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    /// <summary>
    /// 创建对象
    /// </summary>
    /// <typeparam name="T">脚本文件</typeparam>
    /// <param name="file">资源路径</param>
    public BaseObject NewObject <T>(string file, Transform parent = null)
    {
        if (string.IsNullOrEmpty(file))
        {
            file = "Prefab/EmptyNode";
        }
        //构建对象
        GameObject obj = GameObjectUtils.BuildObject(file);

        if (obj == null)
        {
            return(null);
        }

        //父节点
        if (parent == null)
        {
            SceneLayerUtils.AddChild(obj.transform);
        }
        else
        {
            obj.transform.SetParent(parent, false);
        }

        //脚本
        BaseObject base_obj = null;

        if (obj.GetComponent(typeof(T)) == null)
        {
            base_obj = obj.AddComponent(typeof(T)) as BaseObject;
        }
        else
        {
            base_obj = obj.GetComponent(typeof(T)) as BaseObject;
        }

        return(base_obj);
    }