예제 #1
0
        /// <summary>
        /// 从缓存池中加载对象
        /// </summary>
        /// <param name="prefab"></param>
        /// <param name="set"></param>
        /// <returns></returns>
        private GameObject GetPreviewFromPool(GameObject prefab, PreviewSet set)
        {
            GameObject instence = null;

            if (pool.ContainsKey(prefab) && pool[prefab].Count > 0)
            {
                instence = pool[prefab].Dequeue();
                if (instence)
                {
                    SetTranform(instence.transform, set);
                    instence.gameObject.SetActive(true);
                }
            }
            return(instence);
        }
예제 #2
0
        /// <summary>
        /// 内部创建预制体
        /// </summary>
        /// <param name="prefab"></param>
        /// <param name="set"></param>
        /// <returns></returns>
        private static GameObject CreatePreviewInternal(GameObject prefab, PreviewSet set)
        {
            var renderObjs = prefab.GetComponentsInChildren <Renderer>();
            var instence   = new GameObject(prefab.name);

            if (renderObjs.Length > 0)
            {
                foreach (var item in renderObjs)
                {
                    var render = Object.Instantiate(item);
                    render.transform.SetParent(instence.transform);
                }
            }

            SetTranform(instence.transform, set);
            ScaleInstence(instence, prefab);
            instence.transform.SetParent(actionSystem.transform);
            return(instence);
        }
예제 #3
0
 /// <summary>
 /// 设置物体的坐标
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="set"></param>
 public static void SetTranform(Transform obj, PreviewSet set)
 {
     obj.transform.position    = set.position;
     obj.transform.eulerAngles = set.eulerAngle;
 }