public void Initialise(PropTypes _type, Tile _tile, PropRotation _rotation = PropRotation.FACING_FRONT, bool doSpawnAnim = true) { List <Tile> tileList = new List <Tile>(); tileList.Add(_tile); Initialise(_type, tileList, _rotation, doSpawnAnim); }
public void SetProp(PropTypes type, int drawable, int texture) { switch (type) { case PropTypes.Hats: _hats[0] = drawable; _hats[1] = texture; API.SetPedPropIndex(Game.PlayerPed.Handle, 0, drawable, texture, true); break; case PropTypes.Glasses: _glasses[0] = drawable; _glasses[1] = texture; API.SetPedPropIndex(Game.PlayerPed.Handle, 1, drawable, texture, true); break; case PropTypes.Ears: _ears[0] = drawable; _ears[1] = texture; API.SetPedPropIndex(Game.PlayerPed.Handle, 2, drawable, texture, true); break; case PropTypes.Watches: _watches[0] = drawable; _watches[1] = texture; API.SetPedPropIndex(Game.PlayerPed.Handle, 3, drawable, texture, true); break; } }
/* Set the prop type for the rotation selector */ public void SetPropType(PropTypes _type) { propDesc.text = PropProperties.GetDescription(_type); frontBrush.Initialise(_type, PropRotation.FACING_FRONT); leftBrush.Initialise(_type, PropRotation.FACING_LEFT); backBrush.Initialise(_type, PropRotation.FACING_BACK); rightBrush.Initialise(_type, PropRotation.FACING_RIGHT); }
/* Get prop waypoint intended entity */ public static PropWaypointUser GetWaypointTarget(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return((PropWaypointUser)0); } return((PropWaypointUser)thisTile.waypointFor); }
/* Is the prop a waypoint? */ public static bool IsWaypoint(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(false); } return(thisTile.isWaypoint); }
/* Get the tile's script class as string */ public static string GetScriptClassName(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(""); } return(thisTile.scriptName); }
/* Is the tile a scripted object? */ public static bool IsScriptedObject(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(false); } return(thisTile.isScripted); }
/* Get the sprite of a tile */ public static PropSprites GetSpriteSet(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(null); } return(thisTile.spriteSet); }
/* Get prop POI type */ public static PoiType GetPOIType(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return((PoiType)0); } return(thisTile.poiType); }
/* Get prop waypoint type */ public static PropWaypointType GetWaypointType(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return((PropWaypointType)(-1)); } return((PropWaypointType)thisTile.waypointType); }
/* Get the description of a prop */ public static string GetDescription(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(""); } return(thisTile.propDesc); }
/* Get the props's z-offset */ public static int GetZOffset(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(0); } return(thisTile.zOffset); }
/* Get prop POI goon count */ public static int GetPOIGoonCount(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(0); } return(thisTile.poiGoonCount); }
/* Show this prop show up in the editor UI? */ public static bool IsVisibleInEditor(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(false); } return(!thisTile.hideInEditor); }
/* Should this prop's tile be classed as unpathable? */ public static bool IsUnpathable(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return(false); } return(thisTile.isUnpathable); }
/* Get prop placement location */ public static PropPlacement GetPlacementLocation(PropTypes type) { PropData thisTile = GetProp(type); if (thisTile == null) { return((PropPlacement)0); } return(thisTile.placement); }
/* Set prop type & rotation */ public void Initialise(PropTypes _type, PropRotation _rot) { rotationOverride = _rot; objectType = _type; gameObject.GetComponent <Image>().sprite = PropProperties.GetSpriteSet(objectType).GetByRotation(rotationOverride).sprite; gameObject.SetActive((gameObject.GetComponent <Image>().sprite != null)); if (draggableObject) { draggableObject.GetComponent <DraggableEditorComponent>().Initialise(_type, _rot); } }
/* Get a tile object from enum */ private static PropData GetProp(PropTypes type) { foreach (PropData aProp in propData) { if (aProp.propName == type) { return(aProp); } } Debug.LogError("Cannot find requested prop '" + type + "' - it may have been deleted! Map should be updated."); return(null); }
public PropUI(UIMenu menu, string title, int prop, PropTypes type) { Menu = InteractionMenu.Instance._interactionMenuPool.AddSubMenuOffset(menu, title, new PointF(5, Screen.Height / 2)); Menu.OnMenuClose += sender => { ClothesManager.Instance.SaveProps(); }; var drawables = new List <dynamic>(); for (int i = 0; i < API.GetNumberOfPedPropDrawableVariations(Game.PlayerPed.Handle, prop); i++) { drawables.Add(""); } Drawables = new UIMenuSliderItem("Drawables", drawables, 0); Drawables.Index = API.GetPedPropIndex(Game.PlayerPed.Handle, prop); Menu.AddItem(Drawables); Drawables.OnSliderChanged += (sender, index) => { var textures = new List <dynamic>(); if (Textures != null && Menu.MenuItems[1] != null) { Menu.RemoveItemAt(1); } textures.Clear(); for (int i = 0; i < API.GetNumberOfPedPropTextureVariations(Game.PlayerPed.Handle, prop, index); i++) { textures.Add(""); } Textures = new UIMenuSliderItem("Textures", textures, 0); Menu.AddItem(Textures); ClothesManager.Instance.SetProp(type, index, 0); Textures.OnSliderChanged += (textsender, textindex) => { ClothesManager.Instance.SetProp(type, index, textindex); }; InteractionMenu.Instance._interactionMenuPool.RefreshIndex(); }; }
public IEnumerator Load(int level_guid) { loadedInDebug = false; AsyncPropAndTileSetup.Instance.LoadConfigs(); while (!TileProperties.Loaded || !PropProperties.Loaded) { yield return(new WaitForEndOfFrame()); } if (!didTriggerMetaUpdate) { StartCoroutine(RefreshLevelData()); } while (!hasUpdatedMetas) { yield return(new WaitForEndOfFrame()); } Unload(); //Find our metadata LevelMetadata ourMeta = null; foreach (LevelMetadata meta in LevelMetadata) { if (meta.levelGUID == level_guid) { ourMeta = meta; break; } } if (ourMeta == null) { Debug.LogError("Cannot find requested level GUID!"); yield break; } metadata = ourMeta; metadata.SetLoadState(false); Debug.Log("Loading level: " + metadata.levelName + " (GUID " + metadata.levelGUID + ")"); int invisibleProps = 0; int invisibleTiles = 0; string configFile = Application.streamingAssetsPath + "/LEVELS/" + metadata.levelName + ".dwb"; #if !UNITY_WEBGL if (File.Exists(configFile)) //It's ok not to exist if we're in editor { #endif //Load our level config levelData = null; StartCoroutine(FileLoader.Instance.LoadAsBytes(configFile, LoadCallback)); while (levelData == null || !levelData.CanRead) { yield return(new WaitForEndOfFrame()); } //Read our level config BinaryReader reader = new BinaryReader(levelData); int versionNum = reader.ReadInt32(); if (!(versionNum == LevelFileVersion.VERSION_NUM)) //This can allow through back-supported config versions { Debug.LogError("Tried to load an outdated level file!"); reader.Close(); yield break; } if (versionNum != LevelFileVersion.VERSION_NUM) { Debug.LogWarning("This level uses file version " + versionNum + " (latest is " + LevelFileVersion.VERSION_NUM + "). While this version is supported, please re-save the level in editor ASAP to keep updated with the latest features."); } int tileCount = reader.ReadInt32(); Vector2 gridDims = new Vector2(reader.ReadInt16(), reader.ReadInt16()); if (gridDims != theGrid.GridTileDims) { Debug.LogError("Grid resizing is unsupported! This level is invalid."); reader.Close(); yield break; } //Load occupiers int tileOccupierCount = reader.ReadInt32(); for (int i = 0; i < tileOccupierCount; i++) { Tile parentTile = theGrid.AllTiles[reader.ReadInt32()]; int enumIndex = reader.ReadInt16(); if (!Enum.IsDefined(typeof(TileTypes), enumIndex)) { Debug.LogError("ERROR! When loading, a tile's occupier was of a type that no longer exists."); continue; } //Populate the tile's occupier GameObject parentTileObject = null; parentTileObject = Instantiate(worldTileObject, parentTile.Position, Quaternion.identity) as GameObject; TileTypes tileType = (TileTypes)enumIndex; #if UNITY_EDITOR if (!TileProperties.IsVisibleInEditor(tileType)) { invisibleTiles++; } #endif parentTileObject.GetComponent <LevelTileEntity>().Initialise(tileType, parentTile, false); } //Load props int tilePropCount = reader.ReadInt32(); for (int i = 0; i < tilePropCount; i++) { if (versionNum == 13) { reader.BaseStream.Position += 4; } int enumIndex = reader.ReadInt16(); PropRotation rotation = (PropRotation)reader.ReadInt16(); int propTileCount = reader.ReadInt32(); List <Tile> propTiles = new List <Tile>(); for (int x = 0; x < propTileCount; x++) { propTiles.Add(theGrid.AllTiles[reader.ReadInt32()]); } if (!Enum.IsDefined(typeof(PropTypes), enumIndex)) { Debug.LogError("ERROR! When loading, a tile's prop was of a type that no longer exists."); continue; } PropTypes propType = (PropTypes)enumIndex; GameObject parentTileDecoratorObject = Instantiate(worldPropObject, propTiles[0].Position, Quaternion.identity) as GameObject; #if UNITY_EDITOR if (!PropProperties.IsVisibleInEditor(propType)) { invisibleProps++; } #endif parentTileDecoratorObject.GetComponent <LevelPropEntity>().Initialise(propType, propTiles, rotation, false); } //Load some metadata metadata.SetGoonCount(reader.ReadInt32()); metadata.SetHazardCount(reader.ReadInt32()); reader.Close(); //Refresh all sprites to get the right contexts for (int i = 0; i < Grid.AllTiles.Count; i++) { if (Grid.AllTiles[i].IsOccupied) { Grid.AllTiles[i].Occupier.RefreshSprite(); } } metadata.SetLoadState(true); #if !UNITY_WEBGL } else { //User is just starting to create this level metadata.SetLoadState(true); LevelEditor.Instance.SaveLevel(); } #endif //Show/hide grid depending on editor state GetComponent <SpriteRenderer>().enabled = IsInEditor; if (invisibleProps == 0 && invisibleTiles == 0) { Debug.Log("Level loaded without warnings!"); } else { Debug.LogWarning("Level loaded successfully, but contains " + invisibleProps + " deprecated props and " + invisibleTiles + " deprecated tiles. Consider updating this content."); } LevelLoadCompleted?.Invoke(); validateNextTick = true; }
/* Set prop type */ public void SetPropType(PropTypes _type) { propType = _type; gameObject.GetComponent <Image>().sprite = PropProperties.GetSpriteSet(propType).editorUISprite; }
public void Initialise(PropTypes _type, List <Tile> _tiles, PropRotation _rotation = PropRotation.FACING_FRONT, bool doSpawnAnim = true) { if (_tiles.Count == 0) { Debug.LogError("Failed to init prop! No tiles have been passed for us to occupy!"); Destroy(this.gameObject); return; } gridTile = _tiles; //_tiles[0] should be our origin. The others can be in any order! propType = _type; childObject = gameObject.transform.GetChild(0).gameObject; ourSprite = childObject.GetComponent <SpriteRenderer>(); ourCollider = GetComponent <PolygonCollider2D>(); if (!doSpawnAnim) { GetComponent <Animator>().speed = 9999; } hasInitialised = true; spriteSet = PropProperties.GetSpriteSet(propType); //Try and apply ourselves as the prop to our passed tile(s) for (int i = 0; i < gridTile.Count; i++) { gridTile[i].SetProp(null, true, false); //We have to force animations off, else the coroutine time throws off the execution order. TODO: nicer fix? } for (int i = 0; i < gridTile.Count; i++) { if (!gridTile[i].SetProp(this)) { Debug.LogWarning("Failed to init prop! Most likely dumb user has tried to decorate an unoccupied tile."); foreach (Tile aTile in gridTile) { aTile.SetProp(null); } Destroy(this.gameObject); return; } if (i == 0) { gridTile[i].SetPropOrigin(); } } //Set rotation-based sprite/collider and sorting SetRotation(_rotation); int offset = (int)(LevelManager.Instance.Grid.GridTileDims.y - _tiles[0].GridPos.y); ourSprite.sortingOrder = (5 * offset) + offset + TileProperties.GetZOffset(_tiles[0].Occupier.Type) + PropProperties.GetZOffset(propType) + 3; //For neatness in the editor, parent to the grid this.gameObject.transform.parent = LevelManager.Instance.Grid.gameObject.transform; //Remove touchable layer if out of editor if (!LevelManager.Instance.IsInEditor) { gameObject.layer = 0; gameObject.transform.GetChild(0).gameObject.layer = 0; //If scriptable object, try to assign script if (PropProperties.IsScriptedObject(propType)) { try { string componentType = PropProperties.GetScriptClassName(propType); gameObject.AddComponent(System.Type.GetType(componentType)); } catch (System.Exception e) { Debug.LogError("Failed to assign script to scripted object!"); Debug.LogError(e.Message); } } } }