コード例 #1
0
        public AssetBundle LoadAssetBundle(string bundleName, bool cache = true)
        {
            if (assetBundleCache.ContainsKey(bundleName))
            {
                return(assetBundleCache[bundleName]);
            }
            AssetBundle bundle = null;

            var memory = BundleLoader.LoadFileMemory(LocalVersionConfig.bundleRelativePath + "/" + bundleName + BundleConfig.suffix);

            using (var bundleStream = BundleEncode.DeompressAndDecryptLZMA(memory, password))
            {
                if (bundleStream == null)
                {
                    return(bundle);
                }
                bundle = AssetBundle.CreateFromMemoryImmediate(bundleStream.ToArray());
                if (bundle == null)                             // 如果没有则直接返回
                {
                    return(bundle);
                }
            }
            if (cache)
            {
                assetBundleCache.Add(bundleName, bundle);
            }
            return(bundle);
        }
コード例 #2
0
        private IEnumerator LoadBundle(WWW www, byte[] data, HandleLoadBundle callback, bool load)
        {
            AssetBundle bundle = null;

            if (load)
            {
                if (www != null)
                {
                    bundle = www.assetBundle;
                }
                else
                {
                    bundle = AssetBundle.CreateFromMemoryImmediate(data);
                }
                yield return(null);
            }
            if (callback != null)
            {
                callback(bundle);
            }
            if (www != null)
            {
                www.Dispose();
            }
            www = null;
            yield break;
        }
コード例 #3
0
ファイル: Asset.cs プロジェクト: liuxx220/GameApp
    ///--------------------------------------------------------------------------------------------
    /// <summary>
    /// 同步加载资源
    /// </summary>
    ///--------------------------------------------------------------------------------------------
    public void LoadBundle(string bundleName, bool bAsynLoad)
    {
        source = bundleName;
#if UNITY_EDITOR
        loadRes = LOADRES_TYPE.LOAD_PERFAB;
        if (bAsynLoad)
        {
            // 这是一个异步加载过程
            LoadAsset();
        }
        else
        {
            // 这是一个同步加载过程
            string strPath = GetResPathByType() + source.Replace(".prefab", "");
            mainAsset = Resources.Load(strPath) as Object;
        }
#else
        loadRes = LOADRES_TYPE.LOAD_ASSETBUNDLE;
        if (bAsynLoad)
        {
            // 这是一个异步加载过程
            LoadAsset();
        }
        else
        {
            // 从 assetbundle 加载资源
            byte[] stream = null;
            string uri    = Util.DataPath + source.ToLower() + ".assetbundle";
            stream = File.ReadAllBytes(uri);
            bundle = AssetBundle.CreateFromMemoryImmediate(stream);
        }
#endif
    }
コード例 #4
0
        public void OnApplicationStart()
        {
            var assetBundle = AssetBundle.CreateFromMemoryImmediate(Resources.chinko2);

            chinkoPrefab = assetBundle.mainAsset as GameObject;
            assetBundle.Unload(false);
        }
コード例 #5
0
        private IEnumerator loadLuaBundle(bool domain)
        {
            string keyName   = "";
            string luaP      = Utils.GetAssetFullPath("font.u3d");
            WWW    luaLoader = new WWW(luaP);

            yield return(luaLoader);

            if (luaLoader.error == null)
            {
#if UNITY_5_3
                AssetBundle item = AssetBundle.LoadFromMemory(luaLoader.bytes);
#else
                AssetBundle item = AssetBundle.CreateFromMemoryImmediate(luaLoader.byts);
#endif
                TextAsset[] all = item.LoadAllAssets <TextAsset>();
                foreach (var ass in all)
                {
                    keyName           = ass.name;
                    luacache[keyName] = ass.bytes;
                }

                item.Unload(true);
                luaLoader.Dispose();
            }

            if (domain)
            {
                DoMain();
            }
        }
コード例 #6
0
    public CAssetBundleParser(string relativePath, byte[] bytes, Action <AssetBundle> callback = null)
    {
        if (Debug.isDebugBuild)
        {
            _startTime = Time.realtimeSinceStartup;
        }

        Callback     = callback;
        RelativePath = relativePath;

        var func    = BundleBytesFilter ?? DefaultParseAb;
        var abBytes = func(relativePath, bytes);

        switch (Mode)
        {
        case CAssetBundleParserMode.Async:
            CreateRequest          = AssetBundle.CreateFromMemory(abBytes);
            CreateRequest.priority = _autoPriority++;     // 后进先出, 一个一个来
            CResourceModule.Instance.StartCoroutine(WaitCreateAssetBundle(CreateRequest));
            break;

        case CAssetBundleParserMode.Sync:
            OnFinish(AssetBundle.CreateFromMemoryImmediate(abBytes));
            break;

        default:
            throw new Exception("Error CAssetBundleParserMode: " + Mode);
        }
    }
コード例 #7
0
        // CreateFromFile(注意这种方法只能用于standalone程序)这是最快的加载方法
        // AssetBundle.CreateFromFile 这个函数仅支持未压缩的资源。这是加载资产包的最快方式。自己被这个函数坑了好几次,一定是非压缩的资源,如果压缩式不能加载的,加载后,内容也是空的
        protected void loadFromAssetBundle()
        {
            m_appURL = Path.Combine(StartUtil.getLocalReadDir(), "Module/App.unity3d");

            //AssetBundle assetBundle = AssetBundle.CreateFromFile(m_appURL);
            byte[]      bytes       = StartUtil.LoadFileByte(m_appURL);
            AssetBundle assetBundle = AssetBundle.CreateFromMemoryImmediate(bytes);

            if (assetBundle != null)
            {
                //string[] nameList = assetBundle.GetAllAssetNames();
#if UNITY_5
                // Unity5
                Object bt = assetBundle.LoadAsset(m_appPath);
#elif UNITY_4_6 || UNITY_4_5
                // Unity4
                Object bt = assetBundle.Load(m_appPath);
#endif
                GameObject appGo = Instantiate(bt) as GameObject;
                appGo.name = m_appName;            // 程序里面获取都是按照 "App" 获取名字的
                GameObject noDestroy = GameObject.Find("NoDestroy");
                Object.DontDestroyOnLoad(noDestroy);
                appGo.transform.parent = noDestroy.transform;
                assetBundle.Unload(false);
            }
            else
            {
                Debug.Log("Module/App.unity3d 加载失败");
            }
        }
コード例 #8
0
    /// <summary>
    /// lua bundle
    /// </summary>
    /// <returns></returns>
    private IEnumerator loadLuaBundle(bool domain, LuaFunction onLoadedFn)
    {
        string keyName   = "";
        string luaP      = CUtils.GetAssetFullPath("font.u3d");
        WWW    luaLoader = new WWW(luaP);

        yield return(luaLoader);

        if (luaLoader.error == null)
        {
            byte[]      byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV);
            AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts);

            TextAsset[] all = item.LoadAllAssets <TextAsset>();
            foreach (var ass in all)
            {
                keyName           = ass.name;
                luacache[keyName] = ass;
            }

            item.Unload(false);
            luaLoader.Dispose();
        }

        DoUnity3dLua();
        if (domain)
        {
            DoMain();
        }

        if (onLoadedFn != null)
        {
            onLoadedFn.Call();
        }
    }
コード例 #9
0
    public AssetBundle LoadBundle(string name)
    {
        if (m_BundlesMap.ContainsKey(name) && m_BundlesMap[name] != null)
        {
            return(m_BundlesMap[name]);
        }
        else
        {
            byte[]      stream = null;
            AssetBundle bundle = null;

            string url = Util.DataPath + name.ToLower() + ".assetbundle";
            stream = File.ReadAllBytes(url);
            bundle = AssetBundle.CreateFromMemoryImmediate(stream);
            if (m_BundlesMap.ContainsKey(name))
            {
                m_BundlesMap[name] = bundle;
            }
            else
            {
                m_BundlesMap.Add(name, bundle);
            }
            return(bundle);
        }
    }
コード例 #10
0
        /// <summary>
        /// Instantiate a new game object given its previously serialized DataNode.
        /// You can serialize game objects by using GameObject.Serialize(), but be aware that serializing only
        /// works fully in the Unity Editor. Prefabs can't be located automatically outside of the Unity Editor.
        /// </summary>

        static public GameObject Instantiate(this DataNode data)
        {
            GameObject child = null;

            byte[] assetBytes = data.GetChild <byte[]>("assetBundle");

            if (assetBytes != null)
            {
                GameObject prefab;

                if (!mCachedBundles.TryGetValue(assetBytes, out prefab))
                {
#if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
                    AssetBundle qr = AssetBundle.CreateFromMemoryImmediate(assetBytes);
#else
                    AssetBundle qr = AssetBundle.LoadFromMemory(assetBytes);
#endif
                    if (qr != null)
                    {
                        prefab = qr.mainAsset as GameObject;
                    }
                    if (prefab == null)
                    {
                        prefab = new GameObject(data.name);
                    }
                    mCachedBundles[assetBytes] = prefab;
                }

                child      = GameObject.Instantiate(prefab) as GameObject;
                child.name = data.name;
            }
            else
            {
                string path = data.GetChild <string>("prefab");

                if (!string.IsNullOrEmpty(path))
                {
                    GameObject prefab = UnityTools.LoadPrefab(path);

                    if (prefab != null)
                    {
                        child      = GameObject.Instantiate(prefab) as GameObject;
                        child.name = data.name;
                        child.SetActive(true);
                    }
                    else
                    {
                        child = new GameObject(data.name);
                    }
                }
                else
                {
                    child = new GameObject(data.name);
                }

                child.Deserialize(data, true);
            }
            return(child);
        }
コード例 #11
0
    private static int CreateFromMemoryImmediate(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        AssetBundle bundle = AssetBundle.CreateFromMemoryImmediate(LuaScriptMgr.GetArrayNumber <byte>(L, 1));

        LuaScriptMgr.Push(L, bundle);
        return(1);
    }
コード例 #12
0
ファイル: Dynamite.cs プロジェクト: RedJohn260/MSC-Mods
        public override void Update()
        {
            if (Application.loadedLevelName == "GAME")
            {
                try
                {
                    if (!m_isLoaded)
                    {
                        if (GameObject.Find("fish trap(itemx)") == null)
                        {
                            return;
                        }

                        // load bundle
                        var path = ModLoader.GetModAssetsFolder(this);
                        if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL") && Application.platform == RuntimePlatform.WindowsPlayer)
                        {
                            path = Path.Combine(path, "bundle-linux");                             // apparently fixes opengl
                        }
                        else if (Application.platform == RuntimePlatform.WindowsPlayer)
                        {
                            path = Path.Combine(path, "bundle-windows");
                        }
                        else if (Application.platform == RuntimePlatform.OSXPlayer)
                        {
                            path = Path.Combine(path, "bundle-osx");
                        }
                        else if (Application.platform == RuntimePlatform.LinuxPlayer)
                        {
                            path = Path.Combine(path, "bundle-linux");
                        }

                        if (!File.Exists(path))
                        {
                            ModConsole.Error("Couldn't find asset bundle from path " + path);
                        }
                        else
                        {
                            m_bundle = AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(path));
                            GameObject.Instantiate(m_bundle.LoadAsset <GameObject>("ExplosivesPrefab"))
                            .AddComponent <BoxBehaviour>();
                            m_bundle.Unload(false);
                        }

                        m_isLoaded = true;
                    }
                }
                catch (Exception e)
                {
                    m_isLoaded = true;
                    ModConsole.Error(e.ToString());
                }
            }
            else if (Application.loadedLevelName != "GAME" && m_isLoaded)
            {
                m_isLoaded = false;
            }
        }
コード例 #13
0
ファイル: ResourceManager.cs プロジェクト: zh423328/RunAway
        /// <summary>
        ///   载入场景流
        /// </summary>
        ///
        public AssetBundle LoadSceneAssetBundle(string sceneurl)
        {
            byte[]      stream = null;
            AssetBundle bundle = null;

            stream = File.ReadAllBytes(sceneurl);
            bundle = AssetBundle.CreateFromMemoryImmediate(stream); //关联数据的素材绑定
            return(bundle);
        }
コード例 #14
0
ファイル: BundleLoader.cs プロジェクト: garudaxc/UnityToFbx
    public void LoadAssetBundle()
    {
        for (int i = 0; i < assetsToRead.Count; i++)
        {
            byte[] src = File.ReadAllBytes(assetsToRead[i].bundle);

            AssetBundle b = AssetBundle.CreateFromMemoryImmediate(src);

            for (int j = 0; j < assetsToRead[i].assets.Count; j++)
            {
                string assetName = assetsToRead[i].assets[j];
                string ext       = assetName.Substring(assetName.LastIndexOf('.'));

                if (ext == ".fbx")
                {
                    GameObject go   = b.LoadAsset <GameObject>(assetName);
                    GameObject inst = GameObject.Instantiate(go);

                    gameobjects.Add(inst);
                    Debug.Log(inst);
                }
                else if (ext == ".png" || ext == ".tga")
                {
                    Texture t = b.LoadAsset <Texture>(assetName);
                    this.textures.Add(t);
                }
                else if (ext == ".shader")
                {
                    //Shader s = b.LoadAsset<Shader>(assetName);
                    //this.shaders.Add(s);
                }
                else if (ext == ".txt")
                {
                    TextAsset t = b.LoadAsset <TextAsset>(assetName);
                    this.textAssets.Add(t);
                }
                else if (ext == ".mat")
                {
                    Material mat = b.LoadAsset <Material>(assetName);
                    this.materials.Add(mat);
                }
                else if (ext == ".controller")
                {
                    RuntimeAnimatorController anim = b.LoadAsset <RuntimeAnimatorController>(assetName);
                    this.animation.Add(anim);

                    Animator a = gameobjects[0].GetComponent <Animator>();
                    if (a != null)
                    {
                        a.runtimeAnimatorController = RuntimeAnimatorController.Instantiate <RuntimeAnimatorController>(anim);
                    }
                }
            }

            b.Unload(false);
        }
    }
コード例 #15
0
    static int CreateFromMemoryImmediate(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        byte[]      objs0 = LuaScriptMgr.GetArrayNumber <byte>(L, 1);
        AssetBundle o     = AssetBundle.CreateFromMemoryImmediate(objs0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
コード例 #16
0
    private static int CreateFromMemoryImmediate(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        byte[]      arrayNumber = LuaScriptMgr.GetArrayNumber <byte>(L, 1);
        AssetBundle obj         = AssetBundle.CreateFromMemoryImmediate(arrayNumber);

        LuaScriptMgr.Push(L, obj);
        return(1);
    }
コード例 #17
0
        /// <summary>
        /// Creates from byte array.
        /// </summary>
        /// <returns>The from byte array.</returns>
        /// <param name="bytes">Bytes.</param>
        public static AssetBundle LoadFromMemory(System.Array bytes)
        {
            byte[] bts = (byte[])bytes;
#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
            AssetBundle ab = AssetBundle.CreateFromMemoryImmediate(bts);
#else
            AssetBundle ab = AssetBundle.LoadFromMemory(bts);
#endif
            return(ab);
        }
コード例 #18
0
    /// <summary>
    /// 载入素材
    /// </summary>
    public AssetBundle LoadBundle(string name)
    {
        byte[]      stream = null;
        AssetBundle bundle = null;
        string      uri    = Util.DataPath + name.ToLower() + ".assetbundle";

        stream = File.ReadAllBytes(uri);
        bundle = AssetBundle.CreateFromMemoryImmediate(stream); //关联数据的素材绑定
        return(bundle);
    }
コード例 #19
0
        public override void EndDo()
        {
            if (m_nFileSize <= 0)
            {
                Log.Error("{0}不存在,请检查资源!", m_strResName);
                m_eState = IResource.EResourceState.EResourceState_Complete;
                OnFinish();
                return;
            }

            // 同步创建assetBundle

            try
            {
#if (UNITY_5)
                m_abRes = AssetBundle.LoadFromMemory(m_FileBuff);
#else
                m_abRes = AssetBundle.CreateFromMemoryImmediate(m_FileBuff);
#endif
            }
            catch (System.Exception ex)
            {
                Log.Error("加载资源出错:{0}", ex.Message);
            }

            m_eState = IResource.EResourceState.EResourceState_Loaded;

            if (m_abRes == null)
            {
                Log.Error("CreateFromMemoryImmediate失败:{0}", m_strResName);
                OnFinish();
                return;
            }

            // 资源加载完成处理
            OnLoaded(m_abRes);
            bool unload = true;
            for (int i = 0; i < customParams.Count; i++)
            {
                bool c = (bool)customParams[i];
                if (c == false)
                {
                    unload = false;
                    break;
                }
            }
            if (unload)
            {
                m_abRes.Unload(false);
                m_abRes = null;
            }
            m_FileBuff = null;

            OnFinish();
        }
コード例 #20
0
ファイル: LoadAssets.cs プロジェクト: Kreyren/MSCModLoader
 /// <summary>
 /// Loads assetbundle from Resources
 /// </summary>
 /// <param name="assetBundleFromResources">Resource path</param>
 /// <returns>Unity AssetBundle</returns>
 public static AssetBundle LoadBundle(byte[] assetBundleFromResources)
 {
     if (assetBundleFromResources != null)
     {
         return(AssetBundle.CreateFromMemoryImmediate(assetBundleFromResources));
     }
     else
     {
         throw new Exception(string.Format("<b>LoadBundle() Error:</b> Resource doesn't exists{0}", Environment.NewLine));
     }
 }
コード例 #21
0
        public void CreateSettingsUI()
        {
            AssetBundle ab = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.settingsui);

            //AssetBundle ab = LoadAssets.LoadBundle(this, "settingsui.unity3d");

            UI = ab.LoadAsset <GameObject>("MSCLoader Settings.prefab");

            ModButton         = ab.LoadAsset <GameObject>("ModButton.prefab");
            ModButton_Invalid = ab.LoadAsset <GameObject>("ModButton_Invalid.prefab");

            ModLabel = ab.LoadAsset <GameObject>("ModViewLabel.prefab");

            KeyBind = ab.LoadAsset <GameObject>("KeyBind.prefab");

            modSettingsButton = ab.LoadAsset <GameObject>("Button_ms.prefab");
            //For mod settings
            Checkbox = ab.LoadAsset <GameObject>("Checkbox.prefab");
            setBtn   = ab.LoadAsset <GameObject>("Button.prefab");
            slider   = ab.LoadAsset <GameObject>("Slider.prefab");
            textBox  = ab.LoadAsset <GameObject>("TextBox.prefab");
            header   = ab.LoadAsset <GameObject>("Header.prefab");

            UI = UnityEngine.Object.Instantiate(UI);
            UI.AddComponent <ModUIDrag>();
            UI.name = "MSCLoader Settings";

            settings = UI.AddComponent <SettingsView>().Setup(this);

            modUpdateButton      = UnityEngine.Object.Instantiate(modSettingsButton);
            modUpdateButton.name = "MSCLoader Update button";
            modUpdateButton.transform.SetParent(ModUI.GetCanvas().transform, false);
            modUpdateButton.GetComponent <Button>().onClick.AddListener(() => CheckForUpdateButton());
            modUpdateButton.transform.GetChild(0).GetComponent <Text>().text = "Check Updates";
            modUpdateButton.SetActive((bool)modSetButton.GetValue());
            modUpdateButton.AddComponent <SetButtonPos>().button = modUpdateButton;

            modSettingsButton      = UnityEngine.Object.Instantiate(modSettingsButton);
            modSettingsButton.name = "MSCLoader Settings button";
            modSettingsButton.transform.SetParent(ModUI.GetCanvas().transform, false);
            modSettingsButton.GetComponent <Button>().onClick.AddListener(() => settings.ToggleVisibility());
            modSettingsButton.SetActive((bool)modSetButton.GetValue());

            ab.Unload(false);

            // FREDTWEAK
            Transform canvas = GameObject.Find("MSCLoader Canvas").transform.Find("MSCLoader Settings/MSCLoader SettingsContainer/Settings/SettingsView");

            canvas.GetChild(0).gameObject.SetActive(false);
            canvas.GetChild(1).gameObject.SetActive(false);
            canvas.GetChild(2).gameObject.SetActive(false);

            GameObject.Find("MSCLoader Canvas").transform.Find("MSCLoader Settings/MSCLoader SettingsContainer/ModKeyBinds/KeyBindsView/Text").GetComponent <Text>().text = "<color=lime><b>LMB</b></color> - Cancel\n<color=lime><b>RMB</b></color> - Set to None";
        }
コード例 #22
0
            /// <summary>
            /// Returns a copy of the world particle collider prefab
            /// </summary>
            public static GameObject GetWorldParticleCollider()
            {
                Stream stream = typeof(PlanetParticleEmitter).Assembly.GetManifestResourceStream("Kopernicus.Components.Assets.WorldParticleCollider.unity3d");

                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, (int)stream.Length);
                AssetBundle bundle   = AssetBundle.CreateFromMemoryImmediate(buffer);
                GameObject  collider = Instantiate(bundle.LoadAsset("WorldParticleCollider", typeof(GameObject))) as GameObject;

                bundle.Unload(true);
                return(collider);
            }
コード例 #23
0
        void GetAssetPoolBundles()
        {
            string relativePath = BuildPath + "/" + BundleConfig.versionFileName;

            var memory = File.ReadAllBytes(relativePath);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                byte[] length = null;
                int    offset = System.Runtime.InteropServices.Marshal.SizeOf(typeof(int));
                memoryStream.Write(memory, 0, offset);
                length = memoryStream.ToArray();
                var versionLength = BitConverter.ToInt32(length, 0);


                memoryStream.Position = 0;
                memoryStream.Write(memory, offset, versionLength);
                byte[] versionByte = memoryStream.ToArray();
                using (MemoryStream versionStream = new MemoryStream(versionByte))
                {
                    string versionContent = "";
                    StreamUtils.Read(versionStream, out versionContent);
                    currVersion = JsonMapper.ToObject <VersionConfig>(versionContent);
                }

                offset = offset + versionByte.Length;
                int limit = memory.Length - offset;

                memoryStream.Position = 0;
                memoryStream.Write(memory, offset, limit);
                byte[] buffer = memoryStream.ToArray();
                int    index  = 0;
                int    count  = 0;
                foreach (var item in currVersion.bundles)
                {
                    Debug.Log("Item is : " + item.name);
                    count = (int)item.size;
                    using (MemoryStream bundleStream = new MemoryStream()){
                        bundleStream.Write(buffer, index, count);
                        //File.WriteAllBytes (BuildPath + "/" + item.name + BundleConfig.suffix, bundleStream.ToArray ());
                        var decryptBuffer = BundleEncode.DeompressAndDecryptLZMA(bundleStream.ToArray(), BundleConfig.password);
                        var assetbundle   = AssetBundle.CreateFromMemoryImmediate(decryptBuffer.ToArray());
                        foreach (var entry in item.include)
                        {
                            Debug.Log("Asset Name is : " + entry);
                        }
                        assetbundle.Unload(true);
                    }
                    index += count;
                }
            }
        }
コード例 #24
0
            // Load the AssetBundle with the object
            public void SetFromString(string s)
            {
                string[] split = s.Split(':');
                if (!File.Exists(KSPUtil.ApplicationRootPath + "GameData/" + split[0]))
                {
                    Logger.Active.Log("Couldn't find asset file at path: " + KSPUtil.ApplicationRootPath + "GameData/" + split[0]);
                    return;
                }
                AssetBundle bundle = AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/" + split[0]));

                value = UnityEngine.Object.Instantiate(bundle.LoadAsset <T>(split[1]));
                bundle.Unload(true);
            }
コード例 #25
0
ファイル: ModBehaviour.cs プロジェクト: RedJohn260/MSC-Mods
        private IEnumerator SetupMod()
        {
            while (GameObject.Find("PLAYER") == null ||
                   GameObject.Find("PLAYER/Pivot/Camera/FPSCamera/FPSCamera/AudioRain") == null)
            {
                yield return(null);
            }

            ModConsole.Print("Dirt mod loading assetbundle...");
            var path = MSCDirtMod.assetPath;

            if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL") && Application.platform == RuntimePlatform.WindowsPlayer)
            {
                path = Path.Combine(path, "bundle-linux");                 // apparently fixes opengl
            }
            else if (Application.platform == RuntimePlatform.WindowsPlayer)
            {
                path = Path.Combine(path, "bundle-windows");
            }
            else if (Application.platform == RuntimePlatform.OSXPlayer)
            {
                path = Path.Combine(path, "bundle-osx");
            }
            else if (Application.platform == RuntimePlatform.LinuxPlayer)
            {
                path = Path.Combine(path, "bundle-linux");
            }

            if (!File.Exists(path))
            {
                ModConsole.Error("Couldn't find asset bundle from path " + path);
                yield break;
            }

            m_bundle = AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(path));
            LoadAssets();

            ModConsole.Print("Dirt mod doing final setup...");
            m_rainAudioSource = GameObject.Find("PLAYER/Pivot/Camera/FPSCamera/FPSCamera/AudioRain").GetComponent <AudioSource>();

            m_satsuma     = PlayMakerGlobals.Instance.Variables.GetFsmGameObject("TheCar").Value;
            m_carDynamics = m_satsuma.GetComponentInChildren <CarDynamics>();
            m_wiperPivot  = m_satsuma.transform.FindChild("Wipers/WiperLeftPivot");

            ModConsole.Print("Setting up buckets...");
            SetupBuckets();
            ModConsole.Print("Setting up audio...");
            SetupAudio();
            ModConsole.Print("Dirt Mod Setup!");
            m_isSetup = true;
        }
コード例 #26
0
        public override void OnMenuLoad()
        {
            AssetBundle bundle = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.edmmenucolls);

            MenuColls = GameObject.Instantiate <GameObject>(bundle.LoadAsset <GameObject>("MenuColls.prefab"));
            SaveData saveData = SaveUtility.Load <SaveData>();

            MenuColls.transform.position    = saveData.carPosition;
            MenuColls.transform.eulerAngles = saveData.carRotation;

            bundle.Unload(false);

            GameObject.DontDestroyOnLoad(MenuColls);
        }
コード例 #27
0
        public static AssetBundle LoadBundle(Mod mod, string bundleName)
        {
            string bundle = Path.Combine(ModLoader.GetModAssetsFolder(mod), bundleName);

            if (File.Exists(bundle))
            {
                try { ModConsole.Print(string.Format("Loading Asset: {0}...", bundleName)); } catch { }
                return(AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(bundle)));
            }
            else
            {
                throw new FileNotFoundException(string.Format("<b>LoadBundle() Error:</b> File not found: <b>{0}</b>{1}", bundleName, Environment.NewLine), bundleName);
            }
        }
コード例 #28
0
ファイル: WoodCarrier.cs プロジェクト: RedJohn260/MSC-Mods
        public override void Update()
        {
            if (Application.loadedLevelName == "GAME")
            {
                if (!m_isLoaded)
                {
                    if (GameObject.Find("PLAYER") == null)
                    {
                        return;
                    }

                    var path = ModLoader.GetModAssetsFolder(this);
                    if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL") && Application.platform == RuntimePlatform.WindowsPlayer)
                    {
                        path = Path.Combine(path, "bundle-linux");                         // apparently fixes opengl
                    }
                    else if (Application.platform == RuntimePlatform.WindowsPlayer)
                    {
                        path = Path.Combine(path, "bundle-windows");
                    }
                    else if (Application.platform == RuntimePlatform.OSXPlayer)
                    {
                        path = Path.Combine(path, "bundle-osx");
                    }
                    else if (Application.platform == RuntimePlatform.LinuxPlayer)
                    {
                        path = Path.Combine(path, "bundle-linux");
                    }

                    if (!File.Exists(path))
                    {
                        ModConsole.Error("Couldn't find asset bundle from path " + path);
                        return;
                    }

                    m_bundle = AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(path));

                    var asset = m_bundle.LoadAsset <GameObject>("WoodCarrierPrefab");
                    GameObject.Instantiate(asset).AddComponent <WoodCarrierBehaviour>().id = "home";
                    GameObject.Instantiate(asset).AddComponent <WoodCarrierBehaviour>().id = "cottage";

                    m_bundle.Unload(false);
                    m_isLoaded = true;
                }
            }
            else if (Application.loadedLevelName != "GAME" && m_isLoaded)
            {
                m_isLoaded = false;
            }
        }
コード例 #29
0
        public AssetBundle LoadAssetBundle(string bundleName, bool cache = true)
        {
            if (assetBundleCache.ContainsKey(bundleName))
            {
                return(assetBundleCache[bundleName]);
            }
            string      path1  = Application.temporaryCachePath + "/" + localVersionConfig.bundleRelativePath + "/" + bundleName + suffix;
            string      path2  = localVersionConfig.bundleRelativePath + "/" + bundleName;
            AssetBundle bundle = null;

            if (File.Exists(path1))
            {
                using (var bundleStream = DeompressAndDecryptLZMA(path1))
                {
                    if (bundleStream == null)
                    {
                        return(bundle);
                    }
                    bundle = AssetBundle.CreateFromMemoryImmediate(bundleStream.ToArray());
                    if (bundle == null)
                    {
                        return(bundle);
                    }
                    if (cache)
                    {
                        assetBundleCache.Add(bundleName, bundle);
                    }
                }
            }
            else
            {
                using (var bundleStream = DeompressAndDecryptLZMA(path2, true))
                {
                    if (bundleStream == null)
                    {
                        return(bundle);
                    }
                    bundle = AssetBundle.CreateFromMemoryImmediate(bundleStream.ToArray());
                    if (bundle == null)
                    {
                        return(bundle);
                    }
                    if (cache)
                    {
                        assetBundleCache.Add(bundleName, bundle);
                    }
                }
            }
            return(bundle);
        }
コード例 #30
0
        public override void OnLoad()
        {
            CREATORSYSTEM.assetBundle = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.cdplayer);
            ItemPivot = GameObject.Find("PLAYER").transform.Find("Pivot/AnimPivot/Camera/FPSCamera/1Hand_Assemble/ItemPivot");

            if (PlayMakerGlobals.Instance.Variables.GetFsmGameObject("SongDatabaseCD").Value != null)
            {
                CDsongdatabase = PlayMakerGlobals.Instance.Variables.GetFsmGameObject("SongDatabaseCD");
            }

            var CDsInScene = Resources.FindObjectsOfTypeAll <GameObject>().Where(x => x.name.Contains("cd(item"));

            for (var i = 0; i < CDsInScene.Count(); i++)
            {
                var thisCD = CDsInScene.ToArray()[i].AddComponent <CD>();
                var clips  = new List <AudioClip>();

                switch (thisCD.name)
                {
                case "cd(item1)":
                    clips.AddRange(CDsongdatabase.Value.GetComponents <PlayMakerArrayListProxy>()[0]._arrayList.ToArray().Select(x => (AudioClip)x));
                    thisCD.Clips = clips.ToArray();
                    thisCD.Part  = thisCD.gameObject;
                    thisCD.ID    = 1;
                    ModConsole.Print($"CD 1: {clips.Count} Tracks found");
                    break;

                case "cd(item2)":
                    clips.AddRange(CDsongdatabase.Value.GetComponents <PlayMakerArrayListProxy>()[1]._arrayList.ToArray().Select(x => (AudioClip)x));
                    thisCD.Clips = clips.ToArray();
                    thisCD.Part  = thisCD.gameObject;
                    thisCD.ID    = 2;
                    ModConsole.Print($"CD 2: {clips.Count} Tracks found");
                    break;

                case "cd(item3)":
                    clips.AddRange(CDsongdatabase.Value.GetComponents <PlayMakerArrayListProxy>()[2]._arrayList.ToArray().Select(x => (AudioClip)x));
                    thisCD.Clips = clips.ToArray();
                    thisCD.Part  = thisCD.gameObject;
                    thisCD.ID    = 3;
                    ModConsole.Print($"CD 3: {clips.Count} Tracks found");
                    break;
                }

                CDs.Add(thisCD);
            }

            ModConsole.Print($"CDplayerBase: CD List Length = {CDs.Count}");
        }