/// <summary> /// Initializes and returns new Block handler object. /// Each block should only have one Block handler. /// </summary> /// <param name="bb">BlockBehaviour object.</param> /// <returns>LenchScripterMod.Block object.</returns> private static BlockHandler CreateBlock(BlockBehaviour bb) { BlockHandler block; if (Types.ContainsKey(bb.GetBlockID())) { block = (BlockHandler)Activator.CreateInstance(Types[bb.GetBlockID()], new object[] { bb }); } else { block = new BlockHandler(bb); } bbToBlockHandler[bb] = block; return(block); }
private void SpawnChild() { if (blockToSpawn != null) { if (blockToSpawn.GetBlockID() == 模块ID.Value) { return; } Destroy(blockToSpawn.gameObject); } if (!FunnyMode.IsActive) { blockToSpawn = Instantiate(PrefabMaster.BlockPrefabs[对应的IDs[模块ID.Value]].blockBehaviour); blockToSpawn.gameObject.SetActive(false); //blockToSpawn.transform.SetParent(this.transform); } else { funEnumerator = PrefabMaster.BlockPrefabs.GetEnumerator(); while (funEnumerator.MoveNext()) { if (funEnumerator.Current.Value.ID == 对应的IDs[模块ID.Value]) { return; } } funEnumerator = PrefabMaster.BlockPrefabs.GetEnumerator(); funEnumerator.MoveNext(); } }
private void BlockInfo(int id) { BlockBehaviour bb = block.GetComponent <BlockBehaviour>(); GUILayout.Label("Name: " + block.name); GUILayout.Label("ID: " + bb.GetBlockID()); GUILayout.Label("GUID: " + bb.Guid); GUILayout.Space(25.0f); if (GUILayout.Button(new GUIContent("Copy to Clipboard", "Copies the GUID to the Clipboard"))) { TextEditor te = new TextEditor { content = new GUIContent(bb.Guid.ToString()) }; te.SelectAll(); te.Copy(); } if (GUILayout.Button(new GUIContent("Close", "Closes the Block Info Window"))) { _bInfo = false; } LastTooltip = GUI.tooltip; GUI.DragWindow(); }
/// <summary> /// Gets controls for a given BlockBehaviour object. /// </summary> /// <param name="block">BlockBehaviour of the block.</param> /// <returns>Returns a list of controls.</returns> public static List <Control> GetBlockControls(BlockBehaviour block) { if (Blocks.ContainsKey(block.Guid)) { return(Blocks[block.Guid]); } var controls = CreateBlockControls(block.GetBlockID(), block.Guid); Blocks.Add(block.Guid, controls); return(controls); }
/// <summary> /// Adds sliders to the block. /// </summary> /// <param name="block">BlockBehaviour script</param> private static void AddSliders(BlockBehaviour block) { if (block.GetBlockID() == (int)BlockType.Cannon) { var currentMapperTypes = block.MapperTypes; currentMapperTypes.Add(explosionTypeToggle); currentMapperTypes.Add(impactDetectionSlider); currentMapperTypes.Add(explosionDelaySlider); currentMapperTypes.Add(explosionPowerSlider); currentMapperTypes.Add(explosionRangeSlider); currentMapperTypes.Add(cannonBallTrailEnabled); currentMapperTypes.Add(cannonBallTrailColor); currentMapperTypes.Add(cannonBallTrailLength); mapperTypesField.SetValue(block, currentMapperTypes); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="block"></param> /// <param name="blockType"></param> public static void SetComponent <T>(BlockBehaviour block, BlockType blockType) where T : Component { T component = block.GetComponent <T>(); if (block.GetBlockID() == (int)blockType) { if (component == null) { block.gameObject.AddComponent <T>(); } } else { if (component != null) { Destroy(component); } } }
public static void SetToggle(BlockBehaviour block, BlockType blockType, string key, string displayName, ToggleHandler toggleHandler) { if (block.GetBlockID() != (int)blockType) { return; } var result = block.Toggles.Find(match => match.Key == key); if (result == null) { result = new MToggle(displayName, key, Controller.Instance.GetBool(block, key)); if (toggleHandler != null) { result.Toggled += toggleHandler; } var currentMapperTypes = block.MapperTypes; currentMapperTypes.Add(result); _MapperTypes.SetValue(block, currentMapperTypes); } }
/// <summary> /// Returns true if block already has added sliders. /// Returns true on other blocks than the Cannon. /// </summary> /// <param name="block">BlockBehaviour of the block.</param> public static bool HasSliders(BlockBehaviour block) { return(!(block.GetBlockID() == (int)BlockType.Cannon) || block.MapperTypes.Exists(match => match.Key == "explosiontype")); }