コード例 #1
0
    /// <summary>
    /// 只在根节点创建prefab
    /// </summary>
    /// <param name="go"></param>
    /// <param name="path"></param>
    /// <returns></returns>
    SceneNodeE CreateNew_v2(GameObject go, string path)
    {
        SceneNodeE node = null;
        string     file = path + go.name.Replace("(Clone)", "") + ".prefab";

        node = CreateNewSceneNodeE_v2(go, file);
        CreatePrefab(go, file);

        return(node);
    }
コード例 #2
0
    SceneNodeE CreateNew_V4(GameObject go, string path)
    {
        SceneNodeE node = null;

        Renderer r = go.GetComponent <Renderer>();

        Renderer[] rs = go.GetComponentsInChildren <Renderer>();


        return(node);
    }
コード例 #3
0
    SceneNodeE CreateNewSceneNodeE_v2(GameObject go, string path)
    {
        SceneNodeE node = new SceneNodeE();

        node.name          = go.name.Replace("(Clone)", "");
        node.assetPath     = path;
        node.textureBundle = "none";
        node.assetBundle   = "none";
        node.position      = go.transform.position;
        node.rotation      = go.transform.rotation;
        node.scale         = go.transform.localScale;

        return(node);
    }
コード例 #4
0
    void PrepareObjectAsset_v3(SceneNodeE node, List <Object> objects)
    {
        Object asset = AssetDatabase.LoadMainAssetAtPath(node.assetPath);

        if (asset)
        {
            string file = GetAssetBundle(asset.name);
            if (file != "none")
            {
                node.assetBundle = file;
                return;
            }
            SetAssetBundle(asset.name, GetAssetPackName(SceneName), mAssets);
            if (!objects.Contains(asset))
            {
                objects.Add(asset);
            }
        }
    }
コード例 #5
0
    void OnExportAssets()
    {
        GameObject[] gos = GameObject.FindGameObjectsWithTag(NeedExportTag);

        string[] scenePath = EditorApplication.currentScene.Split('/');
        string[] sceneName = scenePath[scenePath.Length - 1].Split('.');
        SceneName = sceneName[0];
        string localdir = PrefabsPath + SceneName + "/Prefabs/";

        Directory.CreateDirectory(localdir);
        //必须刷新
        AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);

        Debug.Log("**************Build Prefab begin*****************");
        foreach (GameObject go in gos)
        {
            SceneNodeE root = createNewNode(go, localdir);
            AddNodeToList(root);
        }
        Debug.Log("**************Build Prefab End*****************");
        SaveSceneNew_v3();
    }
コード例 #6
0
    void writeObjectToScene(Scene scene, SceneNodeE node)
    {
        SceneNode obj = new SceneNode();

        obj.name      = node.name;
        obj.assetPath = node.assetBundle;
        obj.texture   = node.textureBundle;
        if (node.textures != null)
        {
            obj.texture += "@" + node.textures;
        }

        string Value = node.position.ToString();
        string pos   = Value.Substring(1, Value.Length - 2);

        string[] axis = pos.Split(',');
        obj.position[0] = System.Double.Parse(axis[0]);
        obj.position[1] = System.Double.Parse(axis[1]);
        obj.position[2] = System.Double.Parse(axis[2]);

        Value           = node.rotation.ToString();
        pos             = Value.Substring(1, Value.Length - 2);
        axis            = pos.Split(',');
        obj.rotation[0] = System.Double.Parse(axis[0]);
        obj.rotation[1] = System.Double.Parse(axis[1]);
        obj.rotation[2] = System.Double.Parse(axis[2]);
        obj.rotation[3] = System.Double.Parse(axis[3]);

        Value        = node.scale.ToString();
        pos          = Value.Substring(1, Value.Length - 2);
        axis         = pos.Split(',');
        obj.scale[0] = System.Double.Parse(axis[0]);
        obj.scale[1] = System.Double.Parse(axis[1]);
        obj.scale[2] = System.Double.Parse(axis[2]);

        scene.objects.Add(obj);
    }
コード例 #7
0
 void AddNodeToList(SceneNodeE node)
 {
     PrefabsList.Add(node);
 }
コード例 #8
0
    void PrepareTextureAsset_v3(SceneNodeE node, List <Object> textures)
    {
        GameObject go = GameObject.Find(node.name);

        if (!go)
        {
            return;
        }

        //material=texture,material0=texture0;render1()
        bool first = true;

        foreach (Renderer render in go.GetComponentsInChildren <Renderer>())
        {
            if (!first)
            {
                node.textures += ";";
            }
            for (int i = 0; i < render.sharedMaterials.Length; i++)
            {
                Texture tex = render.sharedMaterials[i].mainTexture;
                if (!tex)
                {
                    continue;
                }
                string asset = GetAssetBundleTexture(tex.name);
                //if (first)
                //{
                //    node.textures = tex.name;
                //    first = false;
                //}
                //else
                //{
                //    node.textures += ";" + tex.name;
                //}
                if (first)
                {
                    node.textures = render.sharedMaterials[i].name + "=" + tex.name;
                }
                else
                {
                    node.textures += "," + render.sharedMaterials[i].name + "=" + tex.name;
                }

                node.hasTexture = true;
                if (asset != "none")
                {
                    node.textureBundle = asset;
                    continue;
                }
                SetAssetBundle(tex.name, GetTexturePackName(SceneName), mAssetsTexture);
                bool bExist = false;
                foreach (Texture t in textures)
                {
                    if (t.name == tex.name)
                    {
                        bExist = true;
                    }
                }

                if (!bExist)
                {
                    textures.Add(tex);
                }
            }
        }
    }
コード例 #9
0
    void SaveSceneObject_v3()
    {
        BuildAssetBundleOptions options = BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies;

        List <Object> objects        = new List <Object>();
        List <Object> objectsTexture = new List <Object>();

        //game objects
        string localDir = exportPath + "AssetBundles/";

        //must create directory before buildAssetBundle
        Directory.CreateDirectory(localDir);

        BuildPipeline.PushAssetDependencies();


        mTexturePackIndex = 0;
        if (TextureAlone)
        {
            //先打包贴图
            for (int i = 0; i < PrefabsList.Count; i++)
            {
                SceneNodeE nodeE = PrefabsList[i];
                if (PrepareTextures != null)
                {
                    PrepareTextures(nodeE, objectsTexture);
                }
                if (!nodeE.hasTexture)
                {
                    continue;
                }
                int    texCount  = objectsTexture.Count;
                string texBundle = exportPath + GetTexturePackName(SceneName);//localDir + SceneName + "_" + pack + ".t";

                if (nodeE.textureBundle == "none")
                {
                    nodeE.textureBundle = GetTexturePackName(SceneName);
                    //SetAssetBundle(nodeE.textures, nodeE.textureBundle, mAssetsTexture);
                }

                if (texCount >= NumOfObjects ||
                    (i == PrefabsList.Count - 1) && texCount > 0)
                {
                    BuildPipeline.BuildAssetBundle(null, objectsTexture.ToArray(), texBundle, options);
                    mTexturePackIndex++;

                    objectsTexture.Clear();
                }
            }
        }


        mAssetPackIndex = 0;
        //打包游戏对象
        for (int i = 0; i < PrefabsList.Count; i++)
        {
            SceneNodeE node = PrefabsList[i];

            if (PrepareObjects != null)
            {
                PrepareObjects(node, objects);
            }
            int objectCount = objects.Count;

            string Bundle = exportPath + GetAssetPackName(SceneName);//localDir + SceneName + "_" + pack + ".o";

            if (node.assetBundle == "none")
            {
                node.assetBundle = GetAssetPackName(SceneName);//"AssetBundles/" + SceneName + "_" + pack + ".o";
                //SetAssetBundle(node.name, node.assetBundle, mAssets);
            }

            if (objectCount >= NumOfObjects ||
                (i == PrefabsList.Count - 1) && objectCount > 0)
            {
                BuildPipeline.PushAssetDependencies();
                BuildPipeline.BuildAssetBundle(null, objects.ToArray(), Bundle, options);
                BuildPipeline.PopAssetDependencies();

                mAssetPackIndex++;

                objects.Clear();
            }
        }
        BuildPipeline.PopAssetDependencies();

        string srcNavMeshPath = GetNavMeshPath();
        Object navObj         = AssetDatabase.LoadMainAssetAtPath(srcNavMeshPath);

        if (navObj)
        {
            // 打包导航网格部分 [2/17/2012 Ivan]
            BuildPipeline.PushAssetDependencies();
            string tarPath = exportPath + SceneName + "/" + SceneName + ".NavMesh";
            Directory.CreateDirectory(exportPath + SceneName);
            BuildPipeline.BuildAssetBundle(navObj, null, tarPath, options);
            BuildPipeline.PopAssetDependencies();
        }

        DestroyAllPrefab();
    }
コード例 #10
0
    public string SceneNodeToJson(SceneNodeE node)
    {
        string json = JsonMapper.ToJson(node);

        return(json);
    }