Пример #1
0
        /// <summary>
        /// 设置Prefab
        /// </summary>
        /// <param name="targetObject"></param>
        /// <param name="prefabInfo"></param>
        static public Coroutine SetObjectPrefab(GameObject targetObject, Neptune.NodePrefabInfo prefabInfo, System.Action finishCallback = null)
        {
            if (targetObject == null || prefabInfo == null)
            {
                Debug.LogError("[LevelObjectHelper SetObjectPrefab Error]: targetObject or prefabInfo is null");
                return(null);
            }

            if (!string.IsNullOrEmpty(prefabInfo.PrefabFile))
            {
                return(MainGame.HeartBehavior.StartCoroutine(CoSetObjectPrefab(targetObject, prefabInfo, finishCallback)));
            }

            return(null);
        }
        static int _m_SetObjectPrefab_xlua_st_(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



            int __gen_param_count = LuaAPI.lua_gettop(L);

            try {
                if (__gen_param_count == 3 && translator.Assignable <UnityEngine.GameObject>(L, 1) && translator.Assignable <Neptune.NodePrefabInfo>(L, 2) && translator.Assignable <System.Action>(L, 3))
                {
                    UnityEngine.GameObject targetObject   = (UnityEngine.GameObject)translator.GetObject(L, 1, typeof(UnityEngine.GameObject));
                    Neptune.NodePrefabInfo prefabInfo     = (Neptune.NodePrefabInfo)translator.GetObject(L, 2, typeof(Neptune.NodePrefabInfo));
                    System.Action          finishCallback = translator.GetDelegate <System.Action>(L, 3);

                    UnityEngine.Coroutine __cl_gen_ret = xc.Dungeon.LevelObjectHelper.SetObjectPrefab(targetObject, prefabInfo, finishCallback);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
                if (__gen_param_count == 2 && translator.Assignable <UnityEngine.GameObject>(L, 1) && translator.Assignable <Neptune.NodePrefabInfo>(L, 2))
                {
                    UnityEngine.GameObject targetObject = (UnityEngine.GameObject)translator.GetObject(L, 1, typeof(UnityEngine.GameObject));
                    Neptune.NodePrefabInfo prefabInfo   = (Neptune.NodePrefabInfo)translator.GetObject(L, 2, typeof(Neptune.NodePrefabInfo));

                    UnityEngine.Coroutine __cl_gen_ret = xc.Dungeon.LevelObjectHelper.SetObjectPrefab(targetObject, prefabInfo);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to xc.Dungeon.LevelObjectHelper.SetObjectPrefab!"));
        }
Пример #3
0
        /// <summary>
        /// 设置Prefab协程函数
        /// </summary>
        /// <param name="targetObject"></param>
        /// <param name="prefabInfo"></param>
        /// <returns></returns>
        static private IEnumerator CoSetObjectPrefab(GameObject targetObject, Neptune.NodePrefabInfo prefabInfo, System.Action finishCallback)
        {
            PrefabResource prefabRes = new PrefabResource();
            string         path      = "Assets/" + prefabInfo.PrefabFile;

            yield return(MainGame.HeartBehavior.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_prefab(path, prefabRes)));

            if (prefabRes == null || prefabRes.obj_ == null)
            {
                GameDebug.LogError("Set object prefab " + path + " error, can not load prefab!");
                yield break;
            }

            if (targetObject != null && prefabInfo != null)
            {
                Transform trans = prefabRes.obj_.transform;
                trans.parent        = targetObject.transform;
                trans.localPosition = prefabInfo.LocalPosition;
                trans.localScale    = prefabInfo.LocalScale;
                trans.localRotation = prefabInfo.LocalRotation;

                CollectionObjectBehaviour collectionObjectBehaviour = targetObject.GetComponent <CollectionObjectBehaviour>();
                if (collectionObjectBehaviour != null)
                {
                    collectionObjectBehaviour.OnResLoaded();
                }

                if (finishCallback != null)
                {
                    finishCallback();
                }
            }
            else
            {
                GameDebug.LogError("Set object prefab " + path + " error, target object is null!");
            }
        }