コード例 #1
0
    private void SpawnNewModule()
    {
        ModuleData targetData = GetSpawnModuleData();

        if (targetData.ModuleType != EModuleType.NONE)
        {
            ModuleBase newModule = ModuleManager.Instance.RequestSpawnModule(targetData, this);
            if (newModule == null)
            {
                Debug.LogError("Spawn New Module Error!!!");
                return;
            }

            newModule.IsOnConveyor = true;

            Vector3 conveyorTarget = new Vector3(0.0f, 0.0f, 0.0f);
            switch (this.ModuleDirection)
            {
            case EModuleDirection.UP:
                if (ModuleManager.Instance.ModulePositionData.TryGetValue(new Vector2(this.ModuleIndex.x, this.ModuleIndex.y + 1), out conveyorTarget))
                {
                    newModule.AddConveyorTarget(new Vector3(conveyorTarget.x, MODULE_ON_CONVEYOR_HIGH, conveyorTarget.z));
                }
                break;

            case EModuleDirection.DOWN:
                if (ModuleManager.Instance.ModulePositionData.TryGetValue(new Vector2(this.ModuleIndex.x, this.ModuleIndex.y - 1), out conveyorTarget))
                {
                    newModule.AddConveyorTarget(new Vector3(conveyorTarget.x, MODULE_ON_CONVEYOR_HIGH, conveyorTarget.z));
                }
                break;

            case EModuleDirection.LEFT:
                if (ModuleManager.Instance.ModulePositionData.TryGetValue(new Vector2(this.ModuleIndex.x - 1, this.ModuleIndex.y), out conveyorTarget))
                {
                    newModule.AddConveyorTarget(new Vector3(conveyorTarget.x, MODULE_ON_CONVEYOR_HIGH, conveyorTarget.z));
                }
                break;

            case EModuleDirection.RIGHT:
                if (ModuleManager.Instance.ModulePositionData.TryGetValue(new Vector2(this.ModuleIndex.x + 1, this.ModuleIndex.y), out conveyorTarget))
                {
                    newModule.AddConveyorTarget(new Vector3(conveyorTarget.x, MODULE_ON_CONVEYOR_HIGH, conveyorTarget.z));
                }
                break;
            }
            newModule.ConveyorSpeed = this.mConveyorSpeed;
        }
    }