public void Draw(int x, int y, Block block) { //Debug.Log("draw (" + x + "," + y + "): " + block); BlockBehaviour bb = renderedBlocks[x, y].GetComponent <BlockBehaviour>(); bb.UpdateComponents(block); }
void CreateLevel() { for (int i = 0; i < levelSize; ++i) { for (int j = 0; j < levelSize; ++j) { GameObject block = Instantiate(blockPrefab, new Vector3(i * blockGap, Random.Range(-pillarScale, pillarScale + 1), j * blockGap), Quaternion.identity) as GameObject; block.transform.localScale *= blockScale; BlockBehaviour bBehave = block.AddComponent <BlockBehaviour>(); int blockType = Random.Range(0, pillarChance); bBehave.Init(blockType, defaultChance, permanentChance, fragileChance, holdsDataChance, pillarChance, pillarScale); if (bBehave.blocktype == BlockType.HoldsData) { GameObject data = Instantiate(dataPrefab) as GameObject; data.hideFlags = HideFlags.HideInHierarchy; data.transform.position = block.transform.position + new Vector3(0, Random.Range(-(float)dataHeightDistanceMin, -dataHeightDistanceMax), 0); datas.Add(data); } block.transform.parent = blockParent.transform; blocks.Add(block); if (i == centralPoint && j == centralPoint) { GameObject sphere = Instantiate(outerSphere, new Vector3(i * blockGap, transform.position.y, j * blockGap), Quaternion.identity) as GameObject; sphere.transform.localScale = sphereScale; } } } AIManager.instance.Populate(levelSize, blockGap, pillarScale, blockScale); }
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(); }
// ブロック設置時に、そのブロックに所定のスクリプトを貼り付ける関数 // Blockは、設置したブロックを表す public void AddScript(Block block) { // 生成したブロックのBlockBehaviourコンポーネントを取得する BlockBehaviour internalObject = block.BuildingBlock.InternalObject; // そのブロックがスクリプトを貼り付けるべきブロックであるなら、貼り付ける if (BlockDict.ContainsKey(internalObject.BlockID)) { Type type = BlockDict[internalObject.BlockID]; try { // まだ所定のスクリプトが貼り付けられていない場合にのみ、貼り付ける if (internalObject.GetComponent(type) == null) { internalObject.gameObject.AddComponent(type); Mod.Log("Added Script"); } } catch { Mod.Error("AddScript Error!"); } return; } }
private bool IsSingleOrDestroyed(Collider collider) { Transform transform = collider.transform; if (BB.ParentMachine.finishedPhysics) { return(false); } BlockBehaviour componentInParent = transform.GetComponentInParent <BlockBehaviour>(); if (componentInParent == null) { return(true); } if (componentInParent == BB) { return(false); } if (BB.IgnoreStatic.IsActive && IsStatic(componentInParent.Rigidbody)) { return(false); } for (int j = 0; j < componentInParent.DestroyOnSimulate.Length; j++) { GameObject gameObject = componentInParent.DestroyOnSimulate[j]; if (gameObject != null && gameObject.transform == transform) { return(true); } } return(false); }
public void AfterEdit(MapperType mapper) { // We cannot use undo system for PIOs, because they are dymanic // trying to save them will result in exception on 'undo' while // getting mapper type inside OnEditField if (mapper is MCustom <string> ) { BlockMapper.OnEditField(BlockBehaviour, mapper); } else { Player localPlayer = Player.GetLocalPlayer(); if (localPlayer == null || localPlayer.IsHost) { return; } var tempdata = new XDataHolder(); BlockBehaviour.OnSave(tempdata); tempdata.Encode(out byte[] dataBytes); var message = ModContext.CpuInfoMessage.CreateMessage( this.BlockBehaviour, dataBytes ); ModNetworking.SendToHost(message); } }
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 SpawnChild() { blockModified = false; if (blockToSpawn != null) { Destroy(blockToSpawn.gameObject); } if (!FunnyMode.IsActive) { foreach (var pair in PrefabMaster.BlockPrefabs) { if (pair.Value.name == 模块ID.Selection) { blockToSpawn = Instantiate(pair.Value.gameObject).GetComponent <BlockBehaviour>(); blockToSpawn.gameObject.SetActive(false); break; } } } else { funEnumerator = PrefabMaster.BlockPrefabs.GetEnumerator(); while (funEnumerator.MoveNext()) { if (funEnumerator.Current.Value.name == 模块ID.Selection) { return; } } funEnumerator = PrefabMaster.BlockPrefabs.GetEnumerator(); funEnumerator.MoveNext(); } }
private category GetBlockCategory(BlockBehaviour block) { var id = block.BlockID; if (weapons.Contains(id)) { return(category.Weaponry); } else if (basic.Contains(id)) { return(category.Basic); } else if (armour.Contains(id)) { return(category.Armour); } else if (machanical.Contains(id)) { return(category.Machanical); } else if (flight.Contains(id)) { return(category.Flight); } else if (automation.Contains(id)) { return(category.Automation); } else { return(category.ModBlock); } }
public void AddKey(KeyInputController input, BlockBehaviour extLogic, MExtKey key) { foreach (var kk in key.UpdatedKeyCodes) { input.AddMKey(extLogic, key, (KeyCode)kk.Value); } }
/// <summary> /// Creates a Block handler. /// </summary> /// <param name="bb">BlockBehaviour object.</param> public VectorThruster(BlockBehaviour bb) : base(bb) { if (scriptType == null) { ResolveFieldInfo(bs); } }
public void RemoveRocketTarget(BlockBehaviour rocket) { if (rocketTargetDict.ContainsKey(rocket)) { rocketTargetDict.Remove(rocket); } }
private float scaleRatio = 1.125f * 5; // Ratio for scale of playfield // Start is called before the first frame update void Start() { // Calculate and set the scale of playfield float actualScale = scaleRatio / playfieldSize; transform.localScale = new Vector3(actualScale, actualScale, actualScale); // Allocate block array _block = new BlockBehaviour[playfieldSize * playfieldSize]; // Loop over each row for (int i = 0; i < playfieldSize; i++) { // Loop over all items in a row for (int j = 0; j < playfieldSize; j++) { // Create block GameObject block = Instantiate(blockPrefab, transform); // Calculate the position in array int pos = ((i * playfieldSize) + j); // Set block name block.name = "Block " + pos; // Find BlockBehaviour BlockBehaviour blockBehaviour = block.GetComponent <BlockBehaviour>(); // Set block color float colorX = (float)(pos % playfieldSize) / (playfieldSize - 1); float colorY = (pos / (float)playfieldSize) / (playfieldSize - 1); blockBehaviour.bgColor = new Color((1 - colorX) * 1, colorY * 1, colorX * 1); // Find if playfield is even bool even = playfieldSize % 2 == 0; // Calculate block starting position float x = even ? (-(playfieldSize / 2f) + j) + 0.5f : Mathf.Ceil(-(playfieldSize / 2f) + j); float y = even ? (-(-(playfieldSize / 2f) + i)) - 0.5f : Mathf.Floor(-(-(playfieldSize / 2f) + i)); // Move block to starting position block.transform.localPosition = new Vector3(x, y); // Set block target position (the same as start position) blockBehaviour.posX = x; blockBehaviour.posY = y; // Find block label // If playfield size is bigger than 5x5 use numbers. // If playfield size is smaller than 5x5 use letters. string displayLabel = playfieldSize > 5 ? ("" + (pos + 1)) : ("" + Char.ConvertFromUtf32(65 + pos)); // Set block label blockBehaviour.label = displayLabel; // Setup reference in array _block[pos] = blockBehaviour; } } }
public void RemoveAllBindingsWithBlock(BlockBehaviour block) { foreach (var key in Keybindings.Keys) { Keybindings[key].RemoveAll(binding => binding.Block == block); } }
static void OnPropsChanged(BlockProps[] scope, Level level, byte id) { scope[id].Changed = true; if (scope == Block.Props) { BlockBehaviour.SetupCoreHandlers(); BlockProps.Save("core", scope); } else if (scope == BlockDefinition.GlobalProps) { Level[] loaded = LevelInfo.Loaded.Items; foreach (Level lvl in loaded) { if (lvl.CustomBlockDefs[id] != BlockDefinition.GlobalDefs[id]) { continue; } lvl.CustomBlockProps[id] = BlockDefinition.GlobalProps[id]; } BlockProps.Save("global", scope); } else { BlockProps.Save("lvl_" + level.name, scope); } }
private static Collider[] MakeColliders(BlockBehaviour block, Transform parent) { List <Collider> cols = new List <Collider>(); if (block.hasMyBounds) { foreach (var col in block.myBounds.childColliders) { if (!col || col.isTrigger || !col.enabled || !col.gameObject.activeInHierarchy) { continue; } GameObject cg = new GameObject(col.name); cg.layer = 2; cg.transform.position = Vector3.up * -4000f; if (col is BoxCollider) { BoxCollider sourceBox = col as BoxCollider; BoxCollider box = cg.AddComponent <BoxCollider>(); box.center = sourceBox.center; box.size = sourceBox.size; box.material = sourceBox.material; IgnoreAllBlocksInMachine(box, block.ParentMachine); cols.Add(box); } else if (col is SphereCollider) { SphereCollider sourceSphere = col as SphereCollider; SphereCollider sphere = cg.AddComponent <SphereCollider>(); sphere.center = sourceSphere.center; sphere.radius = sourceSphere.radius; sphere.material = sourceSphere.material; IgnoreAllBlocksInMachine(sphere, block.ParentMachine); cols.Add(sphere); } else if (col is CapsuleCollider) { CapsuleCollider sourceCapsule = col as CapsuleCollider; CapsuleCollider capsule = cg.AddComponent <CapsuleCollider>(); capsule.center = sourceCapsule.center; capsule.radius = sourceCapsule.radius; capsule.height = sourceCapsule.height; capsule.material = sourceCapsule.material; IgnoreAllBlocksInMachine(capsule, block.ParentMachine); cols.Add(capsule); } cg.transform.position = col.transform.position; cg.transform.rotation = col.transform.rotation; cg.transform.localScale = col.transform.lossyScale; cg.transform.parent = parent; } } return(cols.ToArray()); }
//Block Drops public void DropAssign(BlockBehaviour block, int dropNumber) { //Checkea vidas y cantidad de bloques es divisible por 3 if (currentLives > 0 && blockList.Count % 3 == 0) { Instantiate(dropList[dropNumber], block.transform.position, transform.rotation); } }
protected void Awake() { ModContext = SingleInstance <Logic> .Instance; BB = GetComponent <BlockBehaviour>(); machineHandler = ModContext.GetMachineHandler(BB); rigidbody = GetComponent <Rigidbody>(); SafeAwake(); }
private void OnTriggerEnter(Collider other) { if (other.GetComponent <BlockBehaviour>()) { BlockBehaviour behaviour = other.GetComponent <BlockBehaviour>(); behaviour.Activate(_forkType.type); } }
private void OnTriggerExit(Collider other) { if (other.GetComponent <BlockBehaviour>()) { BlockBehaviour behaviour = other.GetComponent <BlockBehaviour>(); behaviour.DeActivate(); } }
/// <summary> /// Creates a Block handler. /// </summary> /// <param name="bb">BlockBehaviour object.</param> public FlyingSpiral(BlockBehaviour bb) : base(bb) { fc = bb.GetComponent <FlyingController>(); automaticToggle = automaticFieldInfo.GetValue(fc) as MToggle; toggleMode = toggleFieldInfo.GetValue(fc) as MToggle; reverseToggle = reverseFieldInfo.GetValue(fc) as MToggle; rigidbody = rigidbodyFieldInfo.GetValue(fc) as Rigidbody; }
public void AfterEdit_ServerRecv(byte[] data) { var xholder = new XDataHolder(); xholder.Decode(data, 0); BlockBehaviour.OnLoad(xholder, CopyMode.All); //BlockBehaviour.ParentMachine.UndoSystem.EditBlockField(BlockBehaviour.Guid, xdata, xdata); }
private void Awake() { children = GetComponentInChildren <NeedleController>(); rb = GetComponent <Rigidbody2D>(); behaviour = new BlockBehaviour(); behaviour.Init(transform, rb, velocity); }
public MExtKey(string displayName, string key, KeyCode defaultKey, BlockBehaviour parent, bool isEmulator = false) : base(displayName, key, defaultKey, isEmulator) { Parent = parent; Text = new MText(displayName, key + "_text", ""); Text.TextChanged += Text_TextChanged; KeysChanged += MExtKey_KeysChanged; }
public override void Plug(BlockBehaviour blockBehaviour) { base.Plug(blockBehaviour); _renderer = blockBehaviour.GetComponent <Renderer>(); _cameraController = Camera.main.GetComponent <CameraController>(); _block = blockBehaviour; _cameraController.AddFadeoutTarget(this); }
public MExtKey(int nameLocalisationId, string key, KeyCode defaultKey, BlockBehaviour parent, bool isEmulator = false) : base(nameLocalisationId, key, defaultKey, isEmulator) { Parent = parent; Text = new MText(nameLocalisationId, key + "_text", ""); Text.TextChanged += Text_TextChanged; KeysChanged += MExtKey_KeysChanged; }
// メソッド private void Awake() { // BlockBehaviourを取得 BB = GetComponent <BlockBehaviour>(); // ブロックの設定画面にトグルを追加 toggle = BB.AddToggle("toggle", "wiki tutorial toggle", false); }
public override void Plug(BlockBehaviour blockBehaviour) { base.Plug(blockBehaviour); _isDisplaced = false; _directionOfTravel = BlockFace.Unknown; _block = blockBehaviour; _animator = blockBehaviour.GetComponent <Animator>(); }
private bool CheckInRange(BlockBehaviour target) { Vector3 positionDiff = target.gameObject.transform.position - smoothLook.position; float angleDiff = Vector3.Angle(positionDiff.normalized, smoothLook.forward); bool forward = Vector3.Dot(positionDiff, smoothLook.forward) > 0; return(forward && angleDiff < searchAngle); }
/// <summary>对没有进阶属性的零件添加进阶属性控件 </summary> private void AddSliders(Transform block) { BlockBehaviour blockbehaviour = block.GetComponent <BlockBehaviour>(); if (!HasEnhancement(blockbehaviour)) { AddSliders(blockbehaviour); } }