Esempio n. 1
0
    private void loadNodeBack(string name, object obj, object[] arg)
    {
        MapNodeEx   node = arg[0] as MapNodeEx;
        AssetBundle ab   = obj as AssetBundle;
        GameObject  go   = GameObject.Instantiate(ab.Load(node.name)) as GameObject;

        go.transform.position   = node.position;
        go.transform.rotation   = node.rotation;
        go.transform.localScale = node.scale;
    }
Esempio n. 2
0
    public MapNodeEx ToMapNodeEx()
    {
        MapNodeEx node = new MapNodeEx();

        node.name          = this.name;
        node.assetBundle   = this.assetPath;
        node.textureBundle = this.texture;
        node.position      = new Vector3((float)this.position[0], (float)this.position[1], (float)this.position[2]);
        node.rotation      = new Quaternion((float)this.rotation[0], (float)this.rotation[1], (float)this.rotation[2], (float)this.rotation[3]);
        node.scale         = new Vector3((float)this.scale[0], (float)this.scale[1], (float)this.scale[2]);
        return(node);
    }
Esempio n. 3
0
    static void ExportAssets()
    {
        Debug.Log("**************init begin*****************");
        List <MapNodeEx> lstNode = new List <MapNodeEx>();

        GameObject[] gos        = GameObject.FindGameObjectsWithTag(EXPORT_TAG);
        string[]     scenePath  = EditorApplication.currentScene.Split('/');
        string[]     sceneNames = scenePath[scenePath.Length - 1].Split('.');
        string       SceneName  = sceneNames[0];
        string       localdir   = PrefabsPath + SceneName + "/Prefabs/";
        string       buildDIR   = EXPORT_PATH + SceneName + "/";

        if (!Directory.Exists(localdir))
        {
            Directory.CreateDirectory(localdir);
        }
        if (!Directory.Exists(buildDIR))
        {
            Directory.CreateDirectory(buildDIR);
        }

        List <MapAssets> lstAsset = MapSerializerTool.JsonToAssetList(EXPORT_PATH + "asset.json");

        AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
        Debug.Log("**************init end*****************");

        Debug.Log("**************Build Prefab begin*****************");
        foreach (GameObject go in gos)
        {
            string file = localdir + go.name.Replace("(Clone)", "") + ".prefab";
            CreatePrefab(go, file);

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

            lstNode.Add(node);
        }
        Debug.Log("**************Build Prefab End*****************");

        Debug.Log("**************AssetBundle Build begin*****************");
        int asset_index = 0;
        List <UnityEngine.Object> lstObj = new List <UnityEngine.Object>();

        for (int i = 0; i < lstNode.Count; i++)
        {
            MapNodeEx node            = lstNode[i];
            string    assetBundlePath = SceneName + asset_index + ".o";
            node.assetBundle = assetBundlePath;
            UnityEngine.Object asset = AssetDatabase.LoadMainAssetAtPath(node.assetPath);
            ///// check the resource is not already export ////
            bool existNode = false;
            for (int k = 0; k < lstAsset.Count && !existNode; k++)
            {
                MapAssets mapAsset = lstAsset[k];
                foreach (string objName in mapAsset.Objects)
                {
                    if (objName == asset.name)
                    {
                        existNode        = true;
                        node.assetBundle = mapAsset.Name;
                        break;
                    }
                }
            }

            // if the asset if not already export , then it can export.
            if (!existNode && !lstObj.Contains(asset))
            {
                lstObj.Add(asset);
            }

            if (lstObj.Count >= EXPORT_OBJECT_NUM || i >= (lstNode.Count - 1))
            {
                BuildPipeline.PushAssetDependencies();
                BuildPipeline.BuildAssetBundle(null, lstObj.ToArray(), Application.dataPath + "/../" + buildDIR + assetBundlePath, BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies);
                BuildPipeline.PopAssetDependencies();
                MapAssets mapAsset = new MapAssets();
                mapAsset.Name = assetBundlePath;
                foreach (UnityEngine.Object item in lstObj)
                {
                    mapAsset.Objects.Add(item.name);
                }
                lstAsset.Add(mapAsset);
                lstObj.Clear();
                asset_index++;
            }
        }
        Debug.Log("**************AssetBundle Build end*****************");

        Debug.Log("**************Map infomation Build begin*****************");
        Map map = new Map();

        map.name    = SceneName;
        map.objects = new List <MapNode>();
        foreach (MapNodeEx item in lstNode)
        {
            map.objects.Add(item.ToMapNode());
        }
        string mapInfoPath    = buildDIR + "map.p";
        string mapInfoTxtPath = PrefabsPath + "map.txt";

        MapSerializerTool.SerializeObjectAndSave(map, mapInfoTxtPath);
        AssetDatabase.Refresh();
        UnityEngine.Object mapInfoObj = AssetDatabase.LoadAssetAtPath(mapInfoTxtPath, typeof(TextAsset));
        BuildPipeline.BuildAssetBundle(mapInfoObj, null, Application.dataPath + "/../" + mapInfoPath);
        Debug.Log("**************Map infomation Build end*****************");

        Debug.Log("**************Ending begin*****************");
        Directory.Delete(PrefabsPath, true);
        MapSerializerTool.SerializeObjectAndSave(lstAsset, EXPORT_PATH + "asset.json");
        AssetDatabase.Refresh();
        Debug.Log("**************Ending end*****************");
    }