コード例 #1
0
        /// <summary>
        ///     Handles the aspects of WWObject Instantiation that rely on the resource metadata.
        /// </summary>
        /// <param name="gameObject">The base GameObject which contains only resource, location, and rotation data</param>
        /// <param name="metadata">The metadata which will be used to construct the WWObject</param>
        /// <returns></returns>
        public static WWObject ConstructWWObject(GameObject gameObject, WWResourceMetadata metadata)
        {
            // Make the GameObject into a Tile, Prop, etc.
            Type type = WWTypeHelper.ConvertToSysType(metadata.wwObjectMetadata.type);

            /*Debug.Log(gameObject.name);
             * if (gameObject.name == "Skeleton(Clone)" || gameObject.name == "Zombie(Clone)")
             * {
             *
             * } else if (gameObject.name == "Tile_FloorBrick(Clone)" || gameObject.name == "Tile_Staircase(Clone)")
             * {
             *  //terrain
             *  gameObject.layer = 9;
             * } else {
             *  //obstacle
             *  gameObject.layer = 8;
             * }*/
            var wwObject = gameObject.AddComponent(type) as WWObject;

            // Scale the object to the current tile scale.
            wwObject.transform.localScale = Vector3.one * CoordinateHelper.tileLengthScale * gameObject.transform.localScale.x;// * metadata.wwObjectMetadata.baseTileSize;

            // remove the WWResourceMetadata component for a microptimization
#if UNITY_EDITOR
            Object.DestroyImmediate(wwObject.GetComponent <WWResourceMetadata>());
#else
            GameObject.Destroy(wwObject.GetComponent <WWResourceMetadata>());
#endif

            wwObject.gameObject.SetActive(true);

            return(wwObject);
        }
コード例 #2
0
        /// <summary>
        ///     Handles the aspects of WWObject Instantiation that rely on the resource metadata.
        /// </summary>
        /// <param name="gameObject">The base GameObject which contains only resource, location, and rotation data</param>
        /// <param name="metadata">The metadata which will be used to construct the WWObject</param>
        /// <returns></returns>
        public static WWObject ConstructWWObject(GameObject gameObject, WWResourceMetadata metadata)
        {
            // Make the GameObject into a Tile, Prop, etc.
            Type type     = WWTypeHelper.ConvertToSysType(metadata.wwObjectMetadata.type);
            var  wwObject = gameObject.AddComponent(type) as WWObject;

            // Scale the object to the current tile scale.
            wwObject.transform.localScale = Vector3.one * CoordinateHelper.tileLengthScale;

            // remove the WWResourceMetadata component for a microptimization
#if UNITY_EDITOR
            Object.DestroyImmediate(wwObject.GetComponent <WWResourceMetadata>());
#else
            GameObject.Destroy(wwObject.GetComponent <WWResourceMetadata>());
#endif

            wwObject.gameObject.SetActive(true);

            return(wwObject);
        }