예제 #1
0
        /// <summary>
        /// Gets a primitive mesh from the cache if it exists, otherwise creates a new one
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Mesh GetPrimitiveMesh(PrimitiveType type)
        {
            if (!PrimitiveHelper.primitiveMeshes.ContainsKey(type))
            {
                PrimitiveHelper.CreatePrimitiveMesh(type);
            }

            return(PrimitiveHelper.primitiveMeshes[type]);
        }
예제 #2
0
        /// <summary>
        /// Creates a new instance of the Primative Mesh Type as a gameobject with a mesh filter
        /// and mesh renderer
        /// </summary>
        /// <param name="type"></param>
        /// <param name="withCollider"></param>
        /// <returns></returns>
        public static GameObject CreatePrimitive(PrimitiveType type, bool withCollider)
        {
            if (withCollider)
            {
                return(GameObject.CreatePrimitive(type));
            }

            GameObject gameObject = new GameObject(type.ToString());
            MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

            meshFilter.sharedMesh = PrimitiveHelper.GetPrimitiveMesh(type);
            gameObject.AddComponent <MeshRenderer>();

            return(gameObject);
        }