Example #1
0
        /// <summary>
        /// 获取某一模板对象的实例
        /// </summary>
        /// <param name="name"></param>
        public GameObject GetTemplate(string name, Transform parent = null, bool isActive = true)
        {
            if (!IsTemplateExist(name))
            {
                GameDebug.LogError("template not exist :" + name);
                return(null);
            }

            TemplateCache cache = this.templateDic[name];

            if (parent == null)
            {
                if (cache.template != null)
                {
                    var cache_parent = cache.template.transform.parent;
                    if (cache_parent != null)
                    {
                        parent = cache.template.transform.parent;
                    }
                }
            }

            GameObject obj = cache.GetTemplateInstance(parent);

            CommonTool.SetActive(obj, isActive);

            return(obj);
        }
Example #2
0
        /// <summary>
        /// 获取物品模版的实例
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="newInstance"></param>
        /// <returns></returns>
        public GameObject GetItemGameObj(Transform parent, bool newInstance = false)
        {
            if (cachedItems == null)
            {
                return(null);
            }

            if (newInstance)
            {
                var template = cachedItems.template;

                var game_object = GameObject.Instantiate <GameObject>(template, parent);
                CommonTool.SetActive(game_object, true);
                return(game_object);
            }

            return(cachedItems.GetTemplateInstance(parent));
        }