Esempio n. 1
0
 private void onSucc()
 {
     mainWindow = KAssetBundle.InstantiateView <MainWindow>("mainwindow");
     Debug.Log(Time.frameCount + "|after|instantiate");
     mainWindow.SetContent(null);
     Debug.Log(Time.frameCount + "|after|setdata");
 }
Esempio n. 2
0
        public override void LoadData()
        {
            Debug.Log("xxxx");
            Debug.LogError("MainSceneManager|do|nothing");

            StartCoroutine(KAssetBundle.LoadPersistentAB(new string[] { "View/mainwindow" }, onSucc, onError));
        }
Esempio n. 3
0
    /// <summary>
    /// 在预加载的AB实例化特效,可以指定parent,为方便额外的控制,返回值是Transform
    /// </summary>
    public static Transform PlayFX(string abName, Transform parent = null)
    {
        Transform eff = KAssetBundle.InstantiateEffect(abName);

        if (parent != null)
        {
            eff.SetParent(parent, false);
        }

        bool  isLoop      = false;
        float maxDuration = 0f;

        ParticleSystem[] particleSystemArray = eff.GetComponentsInChildren <ParticleSystem>(false);        //inactive的不参与处理
        for (int i = 0; i < particleSystemArray.Length; i++)
        {
            isLoop = isLoop || particleSystemArray[i].loop;
            if (particleSystemArray[i].duration > maxDuration)
            {
                maxDuration = particleSystemArray[i].duration;
            }
        }

        if (!isLoop)
        {
            //非循环的特效才添加
            KEffectControl effControl = eff.gameObject.AddComponent <KEffectControl>();
            effControl.duration = maxDuration;
        }

        return(eff);
    }
Esempio n. 4
0
        /// <summary>
        /// 切换场景的统一调用,简化切换场景的代码
        /// </summary>
        public static void SwitchScene(string[] preloadABs, string sceneName)
        {
            KSceneManager ks = GetCurKScene();

            ks.StartCoroutine(KAssetBundle.LoadPersistentAB(preloadABs, () => {
                SceneManager.LoadSceneAsync(sceneName);
            }));
        }
        private void onSucc()
        {
            LoadingProgressWindow loadingProgressWindow = KAssetBundle.InstantiateView <LoadingProgressWindow>();

            loadingProgressWindow.SetContent(null);

            KSceneManager.SwitchScene();
        }
Esempio n. 6
0
        /// <summary>
        /// 当场景加载完后,调用此方法来处理
        /// </summary>
        public static void Load()
        {
            Scene scene = SceneManager.GetActiveScene();             //默认组件与场景名一致

            KAssetBundle.ApplyShaderForEditorMode(scene);

            // 添加EventSystem
            EventSystem eventSystem = GameObject.FindObjectOfType <EventSystem>();

            Debug.Log("eventSystem|" + eventSystem);
            if (eventSystem == null)
            {
                Debug.Log("load|EventSystem|Prefab");
                GameObject origGo = Resources.Load <GameObject>("EventSystem");
                GameObject newGo  = GameObject.Instantiate <GameObject>(origGo);
                newGo.name = origGo.name;
            }

            //如果没有,则先添加组件
            KSceneManager ks = GetCurKScene();

            if (null == ks)
            {
                GameObject go = new GameObject();
                go.name = "__" + scene.name + "__";

                System.Type t = null;

                string defaultClassName = "KScene." + scene.name + "Manager";

                // 场景管理组件钩子
                t = KSceneHook.GetManagerType(scene.name);

                if (t == null)
                {
                    Debug.Log("use|default|type|" + defaultClassName);
                    t = System.Type.GetType(defaultClassName);
                }

                if (t == null)
                {
                    Debug.LogError("cannot|find|default|type|" + defaultClassName);
                }
                else
                {
                    ks = (KSceneManager)go.AddComponent(t);
                }
            }

            if (ks != null)
            {
                ks.LoadData();
            }
            else
            {
                Debug.LogError("cannot|find|ks");
            }
        }
        private static void LoadSelectedAssetBundle()
        {
            Object obj  = Selection.activeObject;
            string path = AssetDatabase.GetAssetPath(obj);

            KAssetBundle.LoadByPath(path, (ab) =>
            {
                Sprite sprite = ab.LoadAsset <Sprite>(ab.name);

                Image image  = GameObject.FindObjectOfType <Image>();
                image.sprite = sprite;
                image.SetNativeSize();

                image.SetAllDirty();
            });
        }
Esempio n. 8
0
    /// <summary>
    /// 在预加载的AB实例化特效,可以指定parent,为方便额外的控制,返回值是Transform
    /// </summary>
    /// <param name="duration">特效生存周期</param>
    public static Transform PlayFX(string abName, float duration, Transform parent = null)
    {
        Transform eff = KAssetBundle.InstantiateEffect(abName);

        if (parent != null)
        {
            eff.SetParent(parent, false);
        }

        // 设置特效生存周期
        KEffectControl effControl = eff.gameObject.AddComponent <KEffectControl>();

        effControl.duration = duration;

        return(eff);
    }
Esempio n. 9
0
 /// <summary>
 /// 从AB加载配置表
 /// </summary>
 public static IEnumerator LoadData(string jsonFilePath)
 {
     yield return(KAssetBundle.LoadFromStreamAssets(jsonFilePath, OnLoadDataSucc, OnLoadDataError));
 }
 public override void LoadData()
 {
     StartCoroutine(KAssetBundle.LoadPersistentAB(new string[] {
         KAssetBundle.GetViewPah(typeof(LoadingProgressWindow).Name)
     }, onSucc));
 }