Пример #1
0
        public static WWObject Instantiate(WWObjectData objectData)
        {
            Vector3 spawnPos = CoordinateHelper.WWCoordToUnityCoord(objectData.wwTransform.coordinate);

            // Load resource and check to see if it is valid.
            WWResource         resource = WWResourceController.GetResource(objectData.resourceTag);
            GameObject         gameObject;
            WWResourceMetadata resourceMetadata = resource.GetMetaData();

            if (resource.GetPrefab() == null)
            {
                gameObject       = GameObject.CreatePrimitive(PrimitiveType.Cube);
                resourceMetadata = gameObject.AddComponent <WWResourceMetadata>();
                gameObject.transform.Translate(spawnPos);
            }
            else
            {
                if (resource.GetMetaData() == null)
                {
                    Debug.Log("There is no metadata for this resource, so it cannot be instantiated.");
                    return(null);
                }
                // Create a GameObject at the correct location and rotation.
                gameObject = Object.Instantiate(resource.GetPrefab(), spawnPos,
                                                Quaternion.Euler(0, objectData.wwTransform.rotation, 0));
            }

            // Use ResourceMetaData to construct the object.
            WWObject wwObject = ConstructWWObject(gameObject, resourceMetadata);

            // Give the new WWObject the data used to create it.
            wwObject.Init(objectData, resourceMetadata);
            wwObject.SetTransform(objectData.wwTransform);
            return(wwObject);
        }
Пример #2
0
        // Use this for initialization
        private void Start()
        {
            WWResourceController.LoadResource("white", null, "whiteCube");
            WWResourceController.LoadResource("tree", null, "treeProp");

            var imagePath = "Heightmaps/MazeHeightmap";
            var heightmap = Resources.Load <Texture2D>(imagePath);

            List <Coordinate> terrainCoordinates = TerrainGenerator.CreateTerrainFromImage(heightmap);
        }
Пример #3
0
        private void Awake()
        {
            // Need to make sure Manager registry is initialized first
            groundPlane = new Plane(Vector3.up, Vector3.up);

            foreach (string s in ResourceLoader.FindAssetBundlePaths())
            {
                Debug.Log(s);
            }

            possibleTiles = WWResourceController.GetResourceKeysByAssetBundle("ww_basic_assets", "characters");
            Debug.LogWarning(possibleTiles.Count);
        }
Пример #4
0
        public void SetPossibleObjectKeys(string assetBundleTag)
        {
            if (doFilter)
            {
                possibleObjects = WWResourceController.GetResourceKeysByAssetBundleFiltered(assetBundleTag, filterType);
            }
            else
            {
                possibleObjects = WWResourceController.GetResourceKeysByAssetBundle(assetBundleTag);
            }

            WWObjectGunManager.assetBundleTag = assetBundleTag;

            Debug.Log("doFilter: " + doFilter + ", filterType: " + filterType + ", currentAssetBundle: " + assetBundleTag);
        }
Пример #5
0
        /// <summary>
        ///     Gets the list of possible objects for the object gun based on
        /// </summary>
        /// <param name="doFilter"></param>
        /// <param name="filterType"></param>
        public void SetPossibleObjectKeys(bool doFilter, WWType filterType)
        {
            if (doFilter)
            {
                possibleObjects = WWResourceController.GetResourceKeysByAssetBundleFiltered(assetBundleTag, filterType);
            }
            else
            {
                possibleObjects = WWResourceController.GetResourceKeysByAssetBundle(assetBundleTag);
            }

            this.doFilter   = doFilter;
            this.filterType = filterType;

            Debug.Log("doFilter: " + doFilter + ", filterType: " + filterType + ", currentAssetBundle: " + assetBundleTag);
        }
Пример #6
0
        /// <summary>
        /// Loads from the resourceTag a WWObject, then attempts to find a valid rotation for the WWObject,
        /// such that it fits with existing Objects at the specified Coordinate Index, and finally places and
        /// adds the WWObject wall to the active Scene Graph.
        /// </summary>
        /// <param name="coordIndex">The coordinate index for this perimeter wall</param>
        /// <param name="perimeterWallOpening">The direction for the perimeter wall</param>
        /// <param name="resourceTag">The resource tag for of the WWObject to place as the perimeter wall.</param>
        private static void TryToPlaceWall(IntVector3 coordIndex, WWWalls perimeterWallOpening, string resourceTag)
        {
            // the collisions that need to be taken into account to see if the WWObject belonging to resourceTag can fit
            WWWalls wallsToFit = ~perimeterWallOpening |
                                 ManagerRegistry.Instance.GetAnInstance <SceneGraphManager>().
                                 GetWallsAtCoordinate(new Coordinate(coordIndex));
            WWResource         resource         = WWResourceController.GetResource(resourceTag);
            WWResourceMetadata resourceMetadata = resource.GetMetaData();

            // Try possible rotations for the resource, and place the resource at the first rotation that fits.
            for (var r = 0; r < 360; r += 90) // only rotations of 90 degrees are valid
            {
                WWWalls wallToPlace = WWWallsHelper.GetRotatedWWWalls(resourceMetadata, r);
                bool    doesCollide = Convert.ToBoolean(wallToPlace & wallsToFit); // should be 0 or False if no collision
                if (!doesCollide)
                {
                    PlaceWallObject(coordIndex, r, resourceTag); // add the wall to the active Scene Graph
                    return;                                      // a valid rotation was found for the WWObject, no need to try further rotations
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Given a resourceTag, loads the WWObject belonging to the resource and returns a list of all possible
        /// valid rotations for the WWObject that do not collide with existing WWObjects at the given position
        /// in the active Scene Graph. Useful for assisting the player with auto rotation of tiles.
        /// </summary>
        /// <param name="position">The Unity Space position to convert to Coordinate Index to determine valid rotations in.</param>
        /// <param name="resourceTag">The resourceTag belonging to the desired WWObject.</param>
        /// <returns></returns>
        public static List <int> GetPossibleRotations(Vector3 position, string resourceTag)
        {
            var        result     = new List <int>(); // the resulting list of possible rotations, currently empty
            Coordinate coordinate = CoordinateHelper.UnityCoordToWWCoord(position);
            WWWalls    wallsToFit = ManagerRegistry.Instance.GetAnInstance <SceneGraphManager>().GetWallsAtCoordinate(coordinate);

            // check to see if any of the 4 possible rotations would fit given resource's walls
            WWResource         resource         = WWResourceController.GetResource(resourceTag);
            WWResourceMetadata resourceMetadata = resource.GetMetaData();

            for (var r = 0; r < 360; r += 90) // only rotations of 90 degrees are valid
            {
                WWWalls newWalls    = WWWallsHelper.GetRotatedWWWalls(resourceMetadata, r);
                bool    doesCollide = Convert.ToBoolean(newWalls & wallsToFit); // should be 0 or False if no collision
                if (!doesCollide)
                {
                    result.Add(r);
                }
            }
            return(result);
        }
 public static void Setup()
 {
     WWResourceController.LoadResource("white", null, "whiteCube");
     WWResourceController.LoadResource("tree", null, "treeProp");
 }