Exemplo n.º 1
0
    static int CreateGameObjectByPool(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.GameObject), typeof(UnityEngine.GameObject), typeof(bool)))
            {
                UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.ToObject(L, 1);
                UnityEngine.GameObject arg1 = (UnityEngine.GameObject)ToLua.ToObject(L, 2);
                bool arg2 = LuaDLL.lua_toboolean(L, 3);
                UnityEngine.GameObject o = GameObjectManager.CreateGameObjectByPool(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(UnityEngine.GameObject), typeof(bool)))
            {
                string arg0 = ToLua.ToString(L, 1);
                UnityEngine.GameObject arg1 = (UnityEngine.GameObject)ToLua.ToObject(L, 2);
                bool arg2 = LuaDLL.lua_toboolean(L, 3);
                UnityEngine.GameObject o = GameObjectManager.CreateGameObjectByPool(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: GameObjectManager.CreateGameObjectByPool"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 2
0
    private void LoadQueue()
    {
        if (currentNum >= count)
        {
            RunCallBack();
            Destroy();
            return;
        }
        PreloadResourcesDataGenerate da = queueRes[currentNum];

        currentNum++;
        //Debug.Log("da.m_key " + da.m_key);
        try
        {
            Type resType = ReflectionUtils.GetTypeByTypeFullName(da.m_ResType);

            //  object loadRes = AssetsPoolManager.Load(da.m_key);
            AssetsPoolManager.LoadAsync(da.m_key, resType, (LoadState loadState, object loadRes) =>
            {
                if (loadState.isDone)
                {
                    if (loadRes != null)
                    {
                        if (loadRes is GameObject)
                        {
                            GameObject prefab         = (GameObject)loadRes;
                            List <GameObject> resList = new List <GameObject>();
                            for (int i = 0; i < da.m_instantiateNum; i++)
                            {
                                GameObject obj = GameObjectManager.CreateGameObjectByPool(prefab);
                                resList.Add(obj);
                            }
                            foreach (var obj in resList)
                            {
                                GameObjectManager.DestroyGameObjectByPool(obj, !da.m_createInstanceActive);
                            }
                        }
                        else
                        {
                            AssetsPoolManager.DestroyByPool(da.m_key);
                        }
                    }
                    else
                    {
                        if (loadRes == null)
                        {
                            Debug.LogError("Error: 预加载失败  key:" + da.m_key);
                        }
                    }
                    RunCallBack();
                    LoadQueue();
                }
            });
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            LoadQueue();
        }
    }
Exemplo n.º 3
0
    public static void Init()
    {
        if (!isInit)
        {
            isInit = true;

            GameObject instance = GameObject.Find("UIManager");

            if (instance == null)
            {
                instance = GameObjectManager.CreateGameObjectByPool("UIManager");
            }

            UIManagerGo = instance;

            s_UILayerManager = instance.GetComponent <UILayerManager>();
            s_UIAnimManager  = instance.GetComponent <UIAnimManager>();
            s_UIStackManager = instance.GetComponent <UIStackManager>();
            s_EventSystem    = instance.GetComponentInChildren <EventSystem>();

            if (Application.isPlaying)
            {
                DontDestroyOnLoad(instance);
            }
        }
    }
Exemplo n.º 4
0
        public void Init(ScrollBackGroundComponent root, int index)
        {
            m_node = new GameObject("nodel_" + index);
            m_node.transform.SetParent(root.transform);
            m_node.transform.localPosition = Vector3.zero;

            m_root = root;

            Vector3 pos = Vector3.zero;

            for (int i = 0; i < m_scrollList.Count; i++)
            {
                GameObject     go = GameObjectManager.CreateGameObjectByPool(m_scrollList[i], m_node);
                SpriteRenderer sr = go.GetComponent <SpriteRenderer>();
                m_rendererList.Add(sr);

                if (i == 0)
                {
                    pos.x -= sr.sprite.textureRect.width / sr.sprite.pixelsPerUnit / 2;
                }

                pos.x += sr.sprite.textureRect.width / sr.sprite.pixelsPerUnit;
                pos.y  = sr.sprite.textureRect.height / sr.sprite.pixelsPerUnit / 2;

                go.transform.localPosition = pos;
            }
        }
Exemplo n.º 5
0
    public static UIWindowBase CreateUIWindow(string UIName)
    {
        Debug.Log("CreateUIWindow " + UIName);

        GameObject   UItmp        = GameObjectManager.CreateGameObjectByPool(UIName, UIManagerGo);
        UIWindowBase UIWIndowBase = UItmp.GetComponent <UIWindowBase>();

        UISystemEvent.Dispatch(UIWIndowBase, UIEvent.OnInit);  //派发OnInit事件

        UIWIndowBase.windowStatus = UIWindowBase.WindowStatus.Create;

        try
        {
            UIWIndowBase.InitWindow(GetUIID(UIName));
        }
        catch (Exception e)
        {
            Debug.LogError(UIName + "OnInit Exception: " + e.ToString());
        }

        AddHideUI(UIWIndowBase);

        UILayerManager.SetLayer(UIWIndowBase);      //设置层级

        return(UIWIndowBase);
    }
Exemplo n.º 6
0
    //private void LoadQueue()
    //{
    //    if (currentNum >= count)
    //    {
    //        RunCallBack();
    //        Destroy();
    //        return;
    //    }
    //    PreloadResourcesDataGenerate da = queueRes[currentNum];
    //    currentNum++;
    //    //Debug.Log("da.m_key " + da.m_key);
    //    try
    //    {
    //        string typeStr = da.m_ResType.ToString().Replace("_", ".");
    //        Type resType= ReflectionUtils.GetTypeByTypeFullName(typeStr);

    //        //  object loadRes = ResourceManager.Load(da.m_key);
    //        ResourceManager.LoadAsync(da.m_key, resType, (LoadState loadState, object loadRes) =>
    //         {
    //         if (loadState.isDone)
    //         {

    //             if (loadRes != null )
    //                {
    //                    if (loadRes is GameObject )
    //                    {
    //                        GameObject prefab = (GameObject)loadRes;
    //                        List<GameObject> resList = new List<GameObject>();
    //                        for (int i = 0; i < da.m_instantiateNum; i++)
    //                        {
    //                            GameObject obj = GameObjectManager.CreateGameObjectByPool(prefab);
    //                            resList.Add(obj);

    //                        }
    //                        foreach (var obj in resList)
    //                        {
    //                            GameObjectManager.DestroyGameObjectByPool(obj, !da.m_createInstanceActive);
    //                        }
    //                    }
    //                    else
    //                    {
    //                        ResourceManager.DestroyByPool(da.m_key);
    //                    }
    //                }
    //                else
    //                {
    //                    if (loadRes == null)
    //                    {
    //                        Debug.LogError("Error: 预加载失败  key:" + da.m_key);
    //                    }
    //                }
    //                RunCallBack();
    //                LoadQueue();
    //            }
    //         });
    //    }
    //    catch (Exception e)
    //    {
    //        Debug.LogError(e);
    //        LoadQueue();
    //    }
    //}
    private IEnumerator LoadQueue()
    {
        while (true)
        {
            if (currentNum >= count)
            {
                RunCallBack();
                Destroy();
                break;
            }
            PreloadResourcesDataGenerate da = queueRes[currentNum];
            currentNum++;
            //Debug.Log("预加载:" + da.m_key);
            try
            {
                string typeStr = da.m_ResType.ToString().Replace("_", ".");
                Type   resType = ReflectionUtils.GetTypeByTypeFullName(typeStr);

                if (resType == typeof(GameObject))
                {
                    List <GameObject> resList = new List <GameObject>();
                    for (int i = 0; i < da.m_instantiateNum; i++)
                    {
                        GameObject obj = GameObjectManager.CreateGameObjectByPool(da.m_key);
                        if (obj)
                        {
                            resList.Add(obj);
                        }
                    }
                    foreach (var obj in resList)
                    {
                        GameObjectManager.DestroyGameObjectByPool(obj, !da.m_createInstanceActive);
                    }
                }
                else
                {
                    object loadRes = ResourceManager.Load(da.m_key);
                    if (loadRes == null)
                    {
                        Debug.LogError("Error: 预加载失败  key:" + da.m_key);
                    }
                    else
                    {
                        ResourceManager.DestoryAssetsCounter(da.m_key);
                    }
                }
                RunCallBack();
                if (currentNum >= count)
                {
                    Destroy();
                    break;
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            yield return(new WaitForEndOfFrame());
        }
    }
Exemplo n.º 7
0
        public GameObject CreateEffect(string effectName)
        {
            GameObject po = GameObjectManager.CreateGameObjectByPool(effectName, RectTransform.gameObject);

            m_effectList.Add(po);

            return(po.gameObject);
        }
Exemplo n.º 8
0
        void CreateSprite(GroundInfo info)
        {
            GameObject     go = GameObjectManager.CreateGameObjectByPool(info.spriteName, m_node);
            SpriteRenderer sr = go.GetComponent <SpriteRenderer>();

            m_rendererList.Add(sr);

            go.transform.localPosition = new Vector3(info.rect.x, info.rect.y, 0);
        }
Exemplo n.º 9
0
 public void CreateSkillAreaTip(EntityBase entity, SkillStatusComponent status)
 {
     if (RangeTip == null)
     {
         GameObject tip = GameObjectManager.CreateGameObjectByPool("AreaTips");
         RangeTip = tip.GetComponent <CreatMesh>();
     }
     RangeTip.gameObject.SetActive(true);
     RangeTip.SetMesh(entity, status.m_currentSkillData.SkillInfo.m_EffectArea, true, status.m_currentSkillData.SkillInfo.m_AreaTexture);
 }
Exemplo n.º 10
0
        public void UIManagerLoadTest()
        {
            //ResourcesConfigManager.Initialize();

            GameObject manager = GameObjectManager.CreateGameObjectByPool("UIManager");

            Assert.AreNotEqual(manager.GetComponent <UILayerManager>(), null);
            Assert.AreNotEqual(manager.GetComponent <UIAnimManager>(), null);
            Assert.AreNotEqual(manager.GetComponentInChildren <Camera>(), null);
        }
Exemplo n.º 11
0
    public void SetItem(string itemName)
    {
        m_ItemName = itemName;
        //m_rectTransform = GetComponent<RectTransform>();

        Rebuild(CanvasUpdate.Layout);

        UpdateBound();
        SetLayout();

        m_itemPrefab = GameObjectManager.CreateGameObjectByPool(m_ItemName);
        m_itemSize   = m_itemPrefab.GetComponent <RectTransform>().sizeDelta;
    }
Exemplo n.º 12
0
        public void ChangeModel(string modelName)
        {
            int layer = model.layer;

            GameObjectManager.DestroyGameObjectByPool(model);

            model = GameObjectManager.CreateGameObjectByPool(modelName);
            model.transform.SetParent(root.transform);
            model.transform.localPosition    = new Vector3(0, 0, 0);
            model.transform.localEulerAngles = Vector3.zero;
            model.transform.localScale       = Vector3.one;

            model.SetLayer(layer);
        }
Exemplo n.º 13
0
    public static GameObject Create(string prefabName, out RenderTexture tex)
    {
        GameObject temp0 = new GameObject("UIModelShow");
        GameObject temp1 = new GameObject("Camera");

        temp1.transform.SetParent(temp0.transform);
        temp1.transform.localPosition = new Vector3(0, 5000, 0);
        Camera ca = temp1.AddComponent <Camera>();

        ca.clearFlags       = CameraClearFlags.SolidColor;
        ca.backgroundColor  = new Color(0, 0, 0, 5 / 255f);
        ca.orthographic     = true;
        ca.orthographicSize = 0.68f;
        ca.depth            = 100;
        ca.cullingMask      = 1 << LayerMask.NameToLayer("UI");

        GameObject root = new GameObject("Root");

        root.transform.SetParent(temp1.transform);
        root.transform.localPosition = new Vector3(0, 0, 100);
        root.transform.eulerAngles   = new Vector3(0, 180, 0);

        GameObject obj = GameObjectManager.CreateGameObjectByPool(prefabName);

        obj.transform.SetParent(root.transform);
        obj.transform.localPosition    = new Vector3(0, 0, 0);
        obj.transform.localEulerAngles = Vector3.zero;

        Transform[] trans = obj.GetComponentsInChildren <Transform>();
        for (int i = 0; i < trans.Length; i++)
        {
            trans[i].gameObject.layer = LayerMask.NameToLayer("UI");
        }

        SkinnedMeshRenderer[] mes = obj.GetComponentsInChildren <SkinnedMeshRenderer>();
        for (int i = 0; i < mes.Length; i++)
        {
            mes[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            mes[i].receiveShadows    = false;
        }

        tex = new RenderTexture(512, 512, 100);
        tex.autoGenerateMips = false;
        tex.anisoLevel       = 1;

        //  tex.antiAliasing = 2

        ca.targetTexture = tex;
        return(obj);
    }
Exemplo n.º 14
0
    public void SetData(string itemName, List <Dictionary <string, object> > dataList)
    {
        for (int i = 0; i < dataList.Count; i++)
        {
            GameObject item = GameObjectManager.CreateGameObjectByPool(itemName, m_rect.gameObject);
            m_itemList.Add(item);

            //设置数据
            ScaleScrollItemBase ssi = item.GetComponent <ScaleScrollItemBase>();
            ssi.Init(i);
            ssi.SetData(dataList[i]);

            //调整位置
            item.transform.localPosition = new Vector3(i * m_itemSpace, 0, 0);
        }
    }
Exemplo n.º 15
0
    public UIBase CreateItem(string itemName, string prantName, bool isActive)
    {
        GameObject item = GameObjectManager.CreateGameObjectByPool(itemName, GetGameObject(prantName), isActive);

        item.transform.localScale = Vector3.one;
        UIBase UIItem = item.GetComponent <UIBase>();

        if (UIItem == null)
        {
            throw new Exception("CreateItem Error : ->" + itemName + "<- don't have UIBase Component!");
        }

        UIItem.Init(m_childUIIndex++);
        UIItem.UIName = UIEventKey + "_" + UIItem.UIName;

        m_ChildList.Add(UIItem);

        return(UIItem);
    }
Exemplo n.º 16
0
    public UIBase CreateItem(GameObject itemObj, GameObject parent, bool isActive)
    {
        GameObject item = GameObjectManager.CreateGameObjectByPool(itemObj, parent, isActive);

        item.transform.localScale    = Vector3.one;
        item.transform.localPosition = Vector3.zero;
        UIBase UIItem = item.GetComponent <UIBase>();

        if (UIItem == null)
        {
            throw new Exception("CreateItem Error : ->" + itemObj.name + "<- don't have UIBase Component!");
        }

        UIItem.Init(UIEventKey, m_childUIIndex++);
        UIItem.UIName = UIEventKey + "_" + UIItem.UIName;

        m_ChildList.Add(UIItem);

        return(UIItem);
    }
Exemplo n.º 17
0
    ReusingScrollItemBase GetItem()
    {
        ReusingScrollItemBase result = null;

        if (m_itemCaches.Count > 0)
        {
            result = m_itemCaches[0];
            result.gameObject.SetActive(true);
            result.OnShow();
            m_itemCaches.RemoveAt(0);

            m_items.Add(result);
            return(result);
        }

        result = GameObjectManager.CreateGameObjectByPool(m_itemPrefab).GetComponent <ReusingScrollItemBase>();
        result.Init(m_items.Count);
        m_items.Add(result);

        return(result);
    }
Exemplo n.º 18
0
    public override void OnEnterStatus()
    {
        Debug.Log("DPI :" + Screen.dpi + " FontSize" + GUIUtil.FontSize);

        InputOperationEventProxy.LoadEventCreater <CustomEvent>();
        InputManager.AddListener <CustomEvent>(OnEventCallBack);

        GameObject go = GameObjectManager.CreateGameObjectByPool("gogo");

        go.transform.position = new Vector3(0, 0, 300);

        go.transform.localScale = new Vector3(100, 100, 100);

        UIManager.OpenUIWindow <testWindow>();

        AnimSystem.Move(go, null, new Vector3(0, 0, 600), time: 1, repeatType: RepeatType.PingPang);


        AnimSystem.Move(go, null, Vector3.one, callBack: (object[] obj) => { }
                        , parameter: new object[] { });
    }
Exemplo n.º 19
0
    public static UIModelShowData CreateModelData(string prefabName,
                                                  string layerName        = null,
                                                  bool?orthographic       = null,
                                                  float?orthographicSize  = null,
                                                  Color?backgroundColor   = null,
                                                  Vector3?localPosition   = null,
                                                  Vector3?eulerAngles     = null,
                                                  Vector3?localScale      = null,
                                                  Vector3?texSize         = null,
                                                  bool isPutPool          = false,
                                                  float?nearClippingPlane = null,
                                                  float?farClippingPlane  = null)
    {
        //默认值设置
        layerName = layerName ?? s_defaultLayer;
        Vector3 localPositionTmp     = localPosition ?? s_defaultLocationPosition;
        Vector3 eulerAnglesTmp       = eulerAngles ?? s_defaultEulerAngles;
        Vector3 texSizeTmp           = texSize ?? s_defaultTexSize;
        Vector3 localScaleTmp        = localScale ?? s_defaultLocalScale;
        Color   backgroundColorTmp   = backgroundColor ?? s_defaultBackgroundColor;
        float   orthographicSizeTmp  = orthographicSize ?? c_defaultOrthographicSize;
        bool    orthographicTmp      = orthographic ?? c_defaultOrthographic;
        float   fieldOfView          = orthographicSize ?? c_defaultFOV;
        float   nearClippingPlaneTmp = nearClippingPlane ?? s_clippingPlanes.x;
        float   farClippingPlaneTmp  = farClippingPlane ?? s_clippingPlanes.y;
        //构造Camera
        UIModelShowData data = new UIModelShowData();

        data.isPutPool = isPutPool;

        GameObject uiModelShow = new GameObject("UIShowModelCamera");

        data.top = uiModelShow;

        GameObject camera = new GameObject("Camera");

        camera.transform.SetParent(uiModelShow.transform);
        camera.transform.localPosition = Vector3.zero;
        Camera ca = camera.AddComponent <Camera>();

        data.camera = ca;

        ca.clearFlags       = CameraClearFlags.SolidColor;
        ca.backgroundColor  = backgroundColorTmp;
        ca.orthographic     = orthographicTmp;
        ca.orthographicSize = orthographicSizeTmp;
        ca.fieldOfView      = fieldOfView;
        ca.depth            = 100;
        ca.nearClipPlane    = nearClippingPlaneTmp;
        ca.farClipPlane     = farClippingPlaneTmp;
        ca.cullingMask      = 1 << LayerMask.NameToLayer(layerName);

        GameObject root = new GameObject("Root");

        data.root = root;

        root.transform.SetParent(camera.transform);
        root.transform.localPosition = localPositionTmp;
        root.transform.eulerAngles   = eulerAnglesTmp;
        root.transform.localScale    = localScaleTmp;

        //创建模型
        GameObject obj = GameObjectManager.CreateGameObjectByPool(prefabName);

        data.model = obj;

        obj.transform.SetParent(root.transform);
        obj.transform.localPosition    = new Vector3(0, 0, 0);
        obj.transform.localEulerAngles = Vector3.zero;
        obj.transform.localScale       = Vector3.one;

        obj.SetLayer(LayerMask.NameToLayer(layerName));

        SkinnedMeshRenderer[] mes = obj.GetComponentsInChildren <SkinnedMeshRenderer>();
        for (int i = 0; i < mes.Length; i++)
        {
            mes[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            mes[i].receiveShadows    = false;
        }

        //设置randerTexture
        RenderTexture tex = new RenderTexture((int)texSizeTmp.x, (int)texSizeTmp.y, (int)texSizeTmp.z);

        data.renderTexture = tex;

        tex.autoGenerateMips = false;
        tex.anisoLevel       = 1;

        ca.targetTexture = tex;

        modelShowList.Add(data);
        ResetModelShowPosition();

        return(data);
    }
Exemplo n.º 20
0
    //掉落专用
    public static void ShowEffect(string effectName, string modelName, Vector3 fromPos, Vector3 toPos1, int characterID, float toTime1, float waitTime, float toTime2)
    {
        if (modelName == "null")
        {
            return;
        }
        float[] contralRadius = { 4, 1 };

        GameObject model   = GameObjectManager.CreateGameObjectByPool(modelName, isSetActive: false);
        PoolObject effectP = null;

        if (effectName != "null")
        {
            effectP = GameObjectManager.GetPoolObject(effectName);
            GameObject effect = effectP.gameObject;
            effect.transform.parent        = model.transform;
            effect.transform.localPosition = Vector3.zero;
        }


        Animator modelAni = model.GetComponentInChildren <Animator>();

        if (modelAni != null)
        {
            modelAni.Play(0);
        }
        model.transform.position = fromPos;

        model.transform.LookAt(toPos1);//可能不需要,如果性能不好,就去掉
        model.SetActive(true);

        AnimSystem.Move(model, fromPos, toPos1, time: toTime1, interp: InterpType.OutQuart);


        if (toTime2 > 0)
        {
            Timer.DelayCallBack(toTime1 + waitTime, (o) =>
            {
                //if (CharacterManager.GetCharacterIsExit(characterID))
                //{
                //    //AnimSystem.BezierMove(model, from: toPos1, to: CharacterManager.GetCharacter(characterID).transform.position, time: toTime2, delayTime: 0, t_Bezier_contralRadius: contralRadius, interp: InterpType.Default);

                //    Timer.DelayCallBack( toTime2, (o2) =>
                //        {
                //            if (effectP != null)
                //            {
                //                GameObjectManager.DestroyPoolObject(effectP);
                //            }


                //            GameObjectManager.DestroyGameObjectByPool(model, true);
                //        });
                //}
                //else
                //{
                //    if (effectP != null)
                //    {
                //        GameObjectManager.DestroyPoolObject(effectP);
                //    }
                //    GameObjectManager.DestroyGameObjectByPool(model, true);
                //}
            });
        }
    }
Exemplo n.º 21
0
    public UIBase CreateItem(GameObject itemObj, GameObject parent, bool isActive)
    {
        GameObject item = GameObjectManager.CreateGameObjectByPool(itemObj, parent, isActive);

        return(SetItem(item));
    }