Пример #1
0
    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);
    }
Пример #2
0
    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);
    }
Пример #3
0
        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();
        }
Пример #4
0
        // ブロック設置時に、そのブロックに所定のスクリプトを貼り付ける関数
        // 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;
            }
        }
Пример #5
0
            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);
            }
Пример #6
0
        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();
     }
 }
Пример #9
0
        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);
            }
        }
Пример #10
0
 public void AddKey(KeyInputController input, BlockBehaviour extLogic, MExtKey key)
 {
     foreach (var kk in key.UpdatedKeyCodes)
     {
         input.AddMKey(extLogic, key, (KeyCode)kk.Value);
     }
 }
Пример #11
0
 /// <summary>
 /// Creates a Block handler.
 /// </summary>
 /// <param name="bb">BlockBehaviour object.</param>
 public VectorThruster(BlockBehaviour bb) : base(bb)
 {
     if (scriptType == null)
     {
         ResolveFieldInfo(bs);
     }
 }
Пример #12
0
 public void RemoveRocketTarget(BlockBehaviour rocket)
 {
     if (rocketTargetDict.ContainsKey(rocket))
     {
         rocketTargetDict.Remove(rocket);
     }
 }
Пример #13
0
    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;
            }
        }
    }
Пример #14
0
 public void RemoveAllBindingsWithBlock(BlockBehaviour block)
 {
     foreach (var key in Keybindings.Keys)
     {
         Keybindings[key].RemoveAll(binding => binding.Block == block);
     }
 }
Пример #15
0
        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());
        }
Пример #17
0
 //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);
     }
 }
Пример #18
0
 protected void Awake()
 {
     ModContext     = SingleInstance <Logic> .Instance;
     BB             = GetComponent <BlockBehaviour>();
     machineHandler = ModContext.GetMachineHandler(BB);
     rigidbody      = GetComponent <Rigidbody>();
     SafeAwake();
 }
Пример #19
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent <BlockBehaviour>())
     {
         BlockBehaviour behaviour = other.GetComponent <BlockBehaviour>();
         behaviour.Activate(_forkType.type);
     }
 }
Пример #20
0
 private void OnTriggerExit(Collider other)
 {
     if (other.GetComponent <BlockBehaviour>())
     {
         BlockBehaviour behaviour = other.GetComponent <BlockBehaviour>();
         behaviour.DeActivate();
     }
 }
Пример #21
0
 /// <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;
 }
Пример #22
0
        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);
        }
Пример #23
0
        private void Awake()
        {
            children = GetComponentInChildren <NeedleController>();
            rb       = GetComponent <Rigidbody2D>();

            behaviour = new BlockBehaviour();
            behaviour.Init(transform, rb, velocity);
        }
Пример #24
0
 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;
 }
Пример #25
0
 public override void Plug(BlockBehaviour blockBehaviour)
 {
     base.Plug(blockBehaviour);
     _renderer         = blockBehaviour.GetComponent <Renderer>();
     _cameraController = Camera.main.GetComponent <CameraController>();
     _block            = blockBehaviour;
     _cameraController.AddFadeoutTarget(this);
 }
Пример #26
0
 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;
 }
Пример #27
0
        // メソッド
        private void Awake()
        {
            // BlockBehaviourを取得
            BB = GetComponent <BlockBehaviour>();

            // ブロックの設定画面にトグルを追加
            toggle = BB.AddToggle("toggle", "wiki tutorial toggle", false);
        }
Пример #28
0
 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);
        }
Пример #30
0
        /// <summary>对没有进阶属性的零件添加进阶属性控件 </summary>
        private void AddSliders(Transform block)
        {
            BlockBehaviour blockbehaviour = block.GetComponent <BlockBehaviour>();

            if (!HasEnhancement(blockbehaviour))
            {
                AddSliders(blockbehaviour);
            }
        }
 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();
     }
 }