예제 #1
0
    public Transform GetVisualization(T key, bool translucent = false)
    {
        Transform result = null;

        if (VisualizationTransformCache.ContainsKey(key))
        {
            result = VisualizationTransformCache[key];
            result.gameObject.SetActive(true);
        }
        else
        {
            result = GameObject.Instantiate <Transform>(GetPrefab(key));
            if (typeof(T) == typeof(Module))
            {
                ModuleGameplay g = result.GetComponent <ModuleGameplay>();
                if (g != null)
                {
                    GameObject.Destroy(g);
                }
            }
            PrefabCacheUtils.RecurseDisableColliderSetTranslucentRenderer(result, PrefabCacheUtils.TranslucentValidPlanningMaterial);
            VisualizationTransformCache[key] = result;
        }

        return(result);
    }
예제 #2
0
    protected override void BeforeMarshal(Transform t = null)
    {
        base.BeforeMarshal(t);

        if (owner == null)
        {
            owner = t.GetComponent <ModuleGameplay>();
        }

        Base.SerializeFlexData(this, owner);
    }
예제 #3
0
    internal void AssignConnections(Matter matterType, ModuleGameplay from, ModuleGameplay to, Transform fromT, Transform toT)
    {
        if (Data == null)
        {
            Data = new PipelineData();
        }

        Data.MatterType = matterType;
        Data.From       = from;
        Data.To         = to;

        if (fromT != null && toT != null)
        {
            Data.fromPos = fromT.position;
            Data.toPos   = toT.position;
        }

        this.transform.GetChild(0).localScale = new Vector3(1f, 1f, (Vector3.Distance(data.fromPos, data.toPos) / 2) * 10f);

        if (from is GasStorage)
        {
            (from as GasStorage).SpecifyCompound(matterType);
        }
        else if (to is GasStorage)
        {
            (to as GasStorage).SpecifyCompound(matterType);
        }

        IndustryExtensions.AddAdjacentPumpable(from, to);

        if (data.MatterType != Matter.Unspecified)
        {
            int index = (int)data.MatterType + 6;

            if (index < CompoundUVSet.Length && CompoundUVSet[index] != null)
            {
                MeshFilter.mesh = CompoundUVSet[index];
                NorthVis.mesh   = NorthFlowVisualizationUVSet[index];
                SouthVis.mesh   = SouthFlowVisualizationUVSet[index];
            }
        }
    }
예제 #4
0
    internal void AssignConnections(Matter matterType, ModuleGameplay from, ModuleGameplay to, Transform fromT, Transform toT)
    {
        if (Data == null)
        {
            Data = new PipelineData();
        }

        Data.MatterType = matterType;
        Data.From       = from;
        Data.To         = to;

        if (fromT != null && toT != null)
        {
            Data.fromPos = fromT.position;
            Data.toPos   = toT.position;
        }

        Transform lowerT = fromT, higherT = toT;

        if (fromT.position.y > toT.position.y)
        {
            lowerT  = toT;
            higherT = fromT;
        }

        Alpha.ElbowUp.position = lowerT.position;
        Alpha.ElbowUp.rotation = lowerT.rotation * Quaternion.Euler(-90f, 0f, -90f);
        Beta.ElbowUp.position  = higherT.position;
        Beta.ElbowUp.rotation  = higherT.rotation * Quaternion.Euler(-90f, 0f, -90f);

        float valveYDistanceDelta = higherT.position.y - lowerT.position.y;

        //if (valveYDistanceDelta < MinElbowOverZ)
        //    valveYDistanceDelta = MinElbowOverZ;

        Alpha.ElbowOver.localPosition = new Vector3(0.448f, 0f, MinElbowOverZ + valveYDistanceDelta);
        //for now, beta (higher) is at the minimum
        //it may need to be at some other minimum, causing "arching" pipes
        Beta.ElbowOver.localPosition = new Vector3(0.448f, 0f, MinElbowOverZ);

        Vector3 alphaElbowLookAtBeta = new Vector3(Beta.ElbowOver.position.x, Alpha.ElbowOver.position.y, Beta.ElbowOver.position.z);

        Alpha.ElbowOver.LookAt(alphaElbowLookAtBeta);
        Alpha.ElbowOver.localRotation *= Quaternion.Euler(0f, 0f, -90f);
        Vector3 betaElbowLookAtBeta = new Vector3(Alpha.ElbowOver.position.x, Beta.ElbowOver.position.y, Alpha.ElbowOver.position.z);

        Beta.ElbowOver.LookAt(betaElbowLookAtBeta);
        Beta.ElbowOver.localRotation *= Quaternion.Euler(0f, 0f, -90f);

        Crosspipe.position = (Alpha.ElbowOver.position + Beta.ElbowOver.position) / 2f;
        Crosspipe.position = new Vector3(Crosspipe.position.x, Beta.ElbowOver.position.y, Crosspipe.position.z);
        Crosspipe.LookAt(Alpha.ElbowOver);

        Crosspipe.localScale = new Vector3(1f, 1f, ((Vector3.Distance(Alpha.ElbowOver.position, Beta.ElbowOver.position) - ElbowXZDiameter) / 2) * 10f);

        Alpha.Vertical.localPosition = new Vector3(VerticalLocalX, 0f, Alpha.ElbowOver.localPosition.z / 2f);
        Alpha.Vertical.localScale    = new Vector3(1f, 1f, ((Vector3.Distance(Alpha.ElbowUp.position, Alpha.ElbowOver.position) - ElbowYDiameter) / 2) * 10f);
        //for now we don't stretch the beta (higher) pipe
        //it may need to be at some other minimum, causing "arching" pipes
        //Beta.Vertical.localScale = new Vector3(1f, 1f, ((Vector3.Distance(Beta.ElbowUp.position, Beta.ElbowOver.position) / 2) - ElbowYDiameter) * 10f);

        if (from is GasStorage)
        {
            (from as GasStorage).SpecifyCompound(matterType);
        }
        else if (to is GasStorage)
        {
            (to as GasStorage).SpecifyCompound(matterType);
        }

        IndustryExtensions.AddAdjacentPumpable(from, to);

        if (data.MatterType != Matter.Unspecified)
        {
            int index = (int)data.MatterType + 6;

            if (index < CompoundUVSet.Length && CompoundUVSet[index] != null)
            {
                MeshFilter.mesh = CompoundUVSet[index];
                Alpha.VerticalMeshFilter.mesh = CompoundUVSet[index];
                Beta.VerticalMeshFilter.mesh  = CompoundUVSet[index];
                NorthVis.mesh = NorthFlowVisualizationUVSet[index];
                SouthVis.mesh = SouthFlowVisualizationUVSet[index];
            }
        }
    }