コード例 #1
0
    public static MachineVisual Create(MachineInfo machineInfo, Transform parent)
    {
        MachineVisual instance = Instantiate(machineInfo.prefab, parent);

        instance.machineInfo = machineInfo;
        instance.Initialize();
        return(instance);
    }
コード例 #2
0
 public void Initialize()
 {
     if (_prefab)
     {
         prefab = _prefab;
     }
     else
     {
         prefab = ScriptableObjects.instance.machineVisualDefault;
     }
 }
コード例 #3
0
 void InitializeHologram()
 {
     instance = MachineVisual.Create(machineInfo, transform);
     Renderer[] machineRenderers = instance.machineRenderers;
     for (int i = 0, len = machineRenderers.Length; i < len; ++i)
     {
         Renderer machineRenderer = machineRenderers[i];
         machineRenderer.sharedMaterial    = hologramMaterial;
         machineRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
     }
     instance.categoryRenderer.enabled = false;
     instance.textRenderer.enabled     = false;
 }
コード例 #4
0
ファイル: Machine.cs プロジェクト: Tristyn/if_source
    public void Initialize()
    {
        transform.localPosition = bounds.min;

        if (machineInfo.prefab)
        {
            instance = MachineVisual.Create(machineInfo, transform);
        }
        else
        {
            GameObject instanceGameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            instance = instanceGameObject.AddComponent <MachineVisual>();
            instance.transform.SetParent(transform, false);
            Destroy(instance.GetComponent <BoxCollider>());
            Transform instanceTransform = instance.transform;
            instanceTransform.localPosition = (Vector3)machineInfo.size * 0.5f;
            instanceTransform.localScale    = machineInfo.size;
        }

        gameObject.SetAllLayers(Layer.machines);

        inventory = Inventory.CreateInventory(machineInfo);

        if (machineInfo.purchaseItem.itemInfo != null)
        {
            canOutput                = true;
            machinePurchaser         = gameObject.AddComponent <MachinePurchaser>();
            machinePurchaser.machine = this;
            if (!machinePlacer)
            {
                machinePlacer         = gameObject.AddComponent <MachinePlacer>();
                machinePlacer.machine = this;
            }
        }
        if (machineInfo.sellItem.itemInfo != null)
        {
            canInput              = true;
            machineSeller         = gameObject.AddComponent <MachineSeller>();
            machineSeller.machine = this;
        }
        if (machineInfo.assembler)
        {
            canInput                 = true;
            canOutput                = true;
            machineAssembler         = gameObject.AddComponent <MachineAssembler>();
            machineAssembler.machine = this;
            if (!machinePlacer)
            {
                machinePlacer         = gameObject.AddComponent <MachinePlacer>();
                machinePlacer.machine = this;
            }
        }

        if (machinePurchaser)
        {
            machinePurchaser.Initialize();
        }
        if (machineSeller)
        {
            machineSeller.Initialize();
        }
        if (machineAssembler)
        {
            machineAssembler.Initialize();
        }
        if (machinePlacer)
        {
            machinePlacer.Initialize();
        }

        Dictionary <Vector3Int, Conveyor> conveyors = ConveyorSystem.instance.conveyors;

        for (int x = bounds.min.x, lenx = bounds.max.x; x <= lenx; ++x)
        {
            for (int y = bounds.min.y, leny = bounds.max.y; y <= leny; ++y)
            {
                for (int z = bounds.min.z, lenz = bounds.max.z; z <= lenz; ++z)
                {
                    if (conveyors.TryGetValue(new Vector3Int(x, y, z), out Conveyor conveyor))
                    {
                        conveyor.LinkMachine(this);
                    }
                }
            }
        }

        FindConveyors();
        RecycleInvalidConveyors();
    }