コード例 #1
0
        public static void CheckMaterial(BridgeEdge bridgeEdge)
        {
            if (!bridgeEdge.m_MeshRenderer.material.HasProperty(stressId))
            {
                Material originalMaterial       = null;
                Material originalSharedMaterial = null;
                try
                {
                    int             hashCode             = bridgeEdge.GetHashCode();
                    List <Material> originalMaterialList = originMaterials[hashCode];
                    if (originalMaterialList != null)
                    {
                        originalMaterial       = originalMaterialList[0];
                        originalSharedMaterial = originalMaterialList[1];
                    }

                    originMaterials.Remove(hashCode);
                }
                catch (KeyNotFoundException)
                {
                    staticLogger.LogMessage("Edge has no original material, assuming it's fine");
                }

                if (originalMaterial != null)
                {
                    bridgeEdge.m_MeshRenderer.material = originalMaterial;
                }

                if (originalSharedMaterial != null)
                {
                    bridgeEdge.m_MeshRenderer.sharedMaterial = originalSharedMaterial;
                }
            }
        }
コード例 #2
0
 static void SetMaterialColor(BridgeEdge edge, Color c)
 {
     if (edge.m_Material.m_MaterialType == BridgeMaterialType.SPRING && edge.m_SpringCoilVisualization && edge.m_MeshRenderer.material.color != springDefault)
     {
         edge.m_SpringCoilVisualization.m_FrontLink.m_MeshRenderer.material.color = c;
         edge.m_SpringCoilVisualization.m_BackLink.m_MeshRenderer.material.color  = c;
     }
     if (c == cycleRGB)
     {
         CreateRainbowStartingPoint(edge);
     }
     if (edge.m_Material.m_MaterialType == BridgeMaterialType.HYDRAULICS)
     {
         if (ColorHydraulicPistons.Value)
         {
             edge.m_MeshRenderer.material.color = c;
         }
         if (ColorHydraulicSleeve.Value)
         {
             edge.CreateHydraulicVisualization();
             edge.m_HydraulicEdgeVisualization.SetColor(c);
         }
     }
     else
     {
         edge.m_MeshRenderer.material.color = c;
     }
     //staticLogger.LogMessage("Set "+ edge.m_Material.m_MaterialType.ToString() + " edge color to: " + c);
 }
コード例 #3
0
        public static void addBungeeSpring(BridgeEdge edge)
        {
            BridgeSpring s = new BridgeSpring();

            s.m_FreeLengthOverrideMultiplier = 1f;
            edge.m_SpringCoilVisualization   = s;
        }
コード例 #4
0
        private static void SetShaderColor(BridgeEdge bridgeEdge, float stressNormalized, float stressNormalizedSigned)
        {
            Color minColor;
            Color maxColor;

            if (stressNormalizedSigned <= 0.0f)
            {
                minColor = minTensileColor;
                maxColor = maxTensileColor;
            }
            else
            {
                minColor = minCompressiveColor;
                maxColor = maxCompressiveColor;
            }

            if (minColor == null || maxColor == null)
            {
                return;
            }

            Color desiredColor = Color.Lerp(minColor, maxColor, stressNormalized);

            if (bridgeEdge.m_MeshRenderer.material.HasProperty(stressId))
            {
                originMaterials[bridgeEdge.GetHashCode()] = new List <Material> {
                    bridgeEdge.m_MeshRenderer.material, bridgeEdge.m_MeshRenderer.sharedMaterial
                };
                bridgeEdge.m_MeshRenderer.material       = new Material(Shader.Find("Standard"));
                bridgeEdge.m_MeshRenderer.sharedMaterial = new Material(Shader.Find("Standard"));
            }
            bridgeEdge.m_MeshRenderer.material.color       = desiredColor;
            bridgeEdge.m_MeshRenderer.sharedMaterial.color = desiredColor;
        }
コード例 #5
0
            static void Postfix(ref Poly.Physics.EdgeHandle e, ref BridgeEdge brokenEdge)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                if (!newEdge)
                {
                    staticLogger.LogError("no new edge set in create debris");
                    return;
                }
                SetDebrisColor(newEdge.m_MeshRenderer.material, brokenEdge.m_MeshRenderer.material);
                if (brokenEdge.m_Material.m_MaterialType == BridgeMaterialType.REINFORCED_ROAD)
                {
                    SetDebrisColor(newEdge.m_MeshRenderer.materials[1], brokenEdge.m_MeshRenderer.materials[1]);
                }
                if (brokenEdge.m_HydraulicEdgeVisualization != null)
                {
                    foreach (MeshRenderer meshRenderer in newEdge.m_HydraulicEdgeVisualization.GetComponentsInChildren <MeshRenderer>())
                    {
                        SetDebrisColor(meshRenderer.material, brokenEdge.m_HydraulicEdgeVisualization.GetComponentsInChildren <MeshRenderer>()[0].material);
                    }
                }

                newEdge = null;
            }
コード例 #6
0
 static void Postfix(ref BridgeEdge __instance)
 {
     if (__instance.m_OriginalColors != null)
     {
         __instance.m_OriginalColors[0].a += 0.001f * GamingSpeedMultiplier.Value;
         SetMaterialColor(__instance, Rainbow(__instance.m_OriginalColors[0].a));
     }
 }
コード例 #7
0
            static void Postfix(ref BridgeEdge __result)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                newEdge = __result;
            }
コード例 #8
0
            private static void Postfix(BridgeEdge edge)
            {
                if (!instance.CheckForCheating())
                {
                    return;
                }

                instance.removeCount(edge.m_Material.m_MaterialType);
            }
コード例 #9
0
        public static void CreateRainbowStartingPoint(BridgeEdge edge)
        {
            var aPos = edge.m_JointA.m_BuildPos;
            var bPos = edge.m_JointB.m_BuildPos;

            var midpoint = Vector3.Lerp(aPos, bPos, 0.5f);

            float ret = midpoint.x * GamingDistanceXMultiplier.Value + midpoint.y * GamingDistanceYMultiplier.Value;

            edge.m_OriginalColors = new Color[] { new Color(0, 0, 0, ret * .1f) };
        }
コード例 #10
0
            static void Prefix(PolyPhysics.Rope rope)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                BridgeEdge edge = rope.userData != null ? (BridgeEdge)rope.userData : (BridgeEdge)rope.edge.userData;

                RestoreColor(edge.m_MeshRenderer.material);
            }
コード例 #11
0
    public void PlaceBridgeEdge(BridgeType bridgeType, Direction edgeSide)
    {
        BridgeEdge bridgeEdge = (BridgeEdge)InstantiateTileAttributeGO <BridgeEdge>();

        bridgeEdge.WithBridgeEdgeSide(edgeSide);
        bridgeEdge.WithBridgeType(bridgeType);
        bridgeEdge.SetSprite();
        bridgeEdge.SetTile(Tile);

        Tile.AddBridgeEdge(bridgeEdge);
    }
コード例 #12
0
 static void Postfix(ref BridgeEdge __result)
 {
     if (__result)
     {
         //staticLogger.LogMessage("edgesLeftToCreateAfterThemeChange " + edgesLeftToCreateAfterThemeChange);
         if (GameStateManager.GetState() != GameState.SIM && (edgesLeftToCreateAfterThemeChange <= 0))
         {
             if (hotkeyIndexDown != -1)
             {
                 Color c = ColorArr[hotkeyIndexDown];
                 if (c == randomColor)
                 {
                     c = new UnityEngine.Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
                     staticLogger.LogMessage("Generated " + __result.m_Material.m_MaterialType.ToString() + " with random color: " + c);
                 }
                 else if (c == springDefault)
                 {
                     c.a -= 0.001f;
                 }
                 if (c != cycleRGB || __result.m_OriginalColors != null)
                 {
                     SetMaterialColor(__result, c);
                 }
                 else
                 {
                     CreateRainbowStartingPoint(__result);
                 }
             }
             //else
             //{
             //    //staticLogger.LogMessage(__result.m_Material.m_MaterialType + " Color: " + __result.m_MeshRenderer.material.color);
             //}
         }
         else
         {
             //Runs when re-creating colored edges when switching theme / going back to editor
             for (int i = 0; i < bridgeEdgeProxyList.Count; i++)
             {
                 if (bridgeEdgeProxyList[i].m_NodeA_Guid.Equals(__result.m_JointA.m_Guid) && bridgeEdgeProxyList[i].m_NodeB_Guid.Equals(__result.m_JointB.m_Guid))
                 {
                     Color colorFromList = bridgeEdgeColorList[i];
                     SetMaterialColor(__result, colorFromList);
                     if (colorFromList == cycleRGB)
                     {
                         CreateRainbowStartingPoint(__result);
                         SetMaterialColor(__result, Rainbow(__result.m_OriginalColors[0].a));
                     }
                 }
             }
             edgesLeftToCreateAfterThemeChange--;
         }
     }
 }
コード例 #13
0
 static void Postfix(ref EdgeHandle e, ref BridgeEdge brokenEdge)
 {
     newEdge.m_MeshRenderer.material.color = brokenEdge.m_MeshRenderer.material.color;
     if (brokenEdge.m_OriginalColors != null)
     {
         newEdge.m_OriginalColors = brokenEdge.m_OriginalColors;
     }
     if (brokenEdge.m_HydraulicEdgeVisualization != null)
     {
         newEdge.m_HydraulicEdgeVisualization.SetColor(brokenEdge.m_HydraulicEdgeVisualization.GetComponentsInChildren <MeshRenderer>()[0].material.color);
     }
 }
コード例 #14
0
 public static void Postfix(
     BridgeJoint jointA,
     BridgeJoint jointB,
     BridgeMaterialType materialType,
     ref BridgeEdge __result,
     PolyPhysics.Edge physicsEdge_onlyUsedWhenBreakingEdgesInSimulation = null
     )
 {
     if (!shouldRun())
     {
         return;
     }
     if (materialType == BridgeMaterialType.BUNGINE_ROPE)
     {
         addBungeeSpring(__result);
     }
 }
コード例 #15
0
 private static void Postfix(float __result)
 {
     // __result will be equal to the max stress that was present.
     if (!configPausingIsEnabled.Value)
     {
         return;
     }
     if (__result == 1f)
     {
         if ((!firstBreakWasFound) || configEveryBreak.Value)
         {
             PauseGame();
             firstBreakWasFound = true;
             float      highestStress = 0f;
             float      stress;
             BridgeEdge mostLikelyBroken = new BridgeEdge();
             foreach (BridgeEdge edge in BridgeEdges.m_Edges)
             {
                 edge.UnHighlight();
                 if (edge.m_PhysicsEdge)
                 {
                     if (edge.m_PhysicsEdge.handle)
                     {
                         stress = Math.Abs(edge.m_PhysicsEdge.handle.stressNormalizedSigned);
                         if (highestStress < stress)
                         {
                             highestStress    = stress;
                             mostLikelyBroken = edge;
                         }
                     }
                 }
             }
             if (configHighlightFirstBreak.Value)
             {
                 if (mostLikelyBroken != null)
                 {
                     mostLikelyBroken.Highlight(Color.red);
                 }
             }
         }
     }
 }
コード例 #16
0
        private static void SetEdgeColor(BridgeEdge edge, Color stressCol)
        {
            if (edge.m_Material.m_MaterialType == BridgeMaterialType.ROPE || edge.m_Material.m_MaterialType == BridgeMaterialType.CABLE)
            {
                foreach (BridgeRope bridgeRope in BridgeRopes.m_BridgeRopes)
                {
                    if ((UnityEngine.Object)bridgeRope.m_ParentEdge == (UnityEngine.Object)edge)
                    {
                        bridgeRope.SetStressColor(0.0f);
                        foreach (BridgeLink link in bridgeRope.m_Links)
                        {
                            SetMaterialColor(((MeshRenderer)bridgeLinkMeshRendererField.GetValue(link)).material, stressCol);
                        }
                    }
                }
            }

            if (edge.m_Material.m_MaterialType == BridgeMaterialType.SPRING)
            {
                BridgeSprings.SetStressColorForEdge(edge, 0.0f);
                SetMaterialColor(edge.m_SpringCoilVisualization.m_FrontLink.m_MeshRenderer.material, stressCol);
                SetMaterialColor(edge.m_SpringCoilVisualization.m_BackLink.m_MeshRenderer.material, stressCol);
            }

            if (edge.m_Material.m_MaterialType == BridgeMaterialType.REINFORCED_ROAD)
            {
                SetMaterialColor(edge.m_MeshRenderer.materials[1], stressCol);
            }

            if (edge.m_HydraulicEdgeVisualization != null)
            {
                edge.m_HydraulicEdgeVisualization.SetStressColorForEdge(edge, 0.0f);
                foreach (MeshRenderer meshRenderer in edge.m_HydraulicEdgeVisualization.GetComponentsInChildren <MeshRenderer>())
                {
                    SetMaterialColor(meshRenderer.material, stressCol);
                }
            }

            edge.SetStressColor(0.0f);
            SetMaterialColor(edge.m_MeshRenderer.material, stressCol);
        }
コード例 #17
0
            static void Prefix(BridgeEdge newEdge, BridgeEdge sourceEdge)
            {
                Color c = sourceEdge.m_MeshRenderer.material.color;

                if (sourceEdge.m_OriginalColors != null)
                {
                    c = cycleRGB;
                }
                if (sourceEdge.m_Material.m_MaterialType == BridgeMaterialType.HYDRAULICS)
                {
                    if (ColorHydraulicSleeve.Value)
                    {
                        c = sourceEdge.m_HydraulicEdgeVisualization.GetComponentsInChildren <MeshRenderer>()[0].material.color;
                    }
                }

                //If both sleeve and piston should be coloured, but they are different in the source, the source is uncolored -> don't color the pasted one
                if (!(ColorHydraulicSleeve.Value && ColorHydraulicPistons.Value && (sourceEdge.m_MeshRenderer.material.color != c)))
                {
                    SetMaterialColor(newEdge, c); //Set copy paste material color if no color key is held down
                }
            }
コード例 #18
0
            static void Postfix()
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                float      worstEdgeStress = 0.0f;
                BridgeEdge worstEdge       = null;

                foreach (BridgeEdge edge in BridgeEdges.m_Edges)
                {
                    float stress = 0.0f;
                    if (edge.m_PhysicsEdge)
                    {
                        stress = maxStressSelected ? maxStress[edge.m_PhysicsEdge] : curStress[edge.m_PhysicsEdge];
                    }
                    bool compression = stress > 0.0;
                    stress = edge.m_IsBroken ? 0.0f : stress;
                    stress = Mathf.Abs(stress);
                    if (stress > worstEdgeStress)
                    {
                        worstEdgeStress = stress;
                        worstEdge       = edge;
                    }
                    stress = Mathf.Pow(stress, stressExponent[selectedExponent].Value);
                    Vector3 hsv       = compression ? Vector3.Lerp(colCompressionMin.Value, colCompressionMax.Value, stress) : Vector3.Lerp(colTensionMin.Value, colTensionMax.Value, stress);
                    Color   stressCol = Color.HSVToRGB(hsv.x, hsv.y, hsv.z);

                    SetEdgeColor(edge, stressCol);
                }

                if (highlightWorst.Value && worstEdge)
                {
                    SetEdgeColor(worstEdge, colHighlight.Value);
                }
            }
コード例 #19
0
            static void Prefix(GameState state)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                if (GameStateManager.GetState() == GameState.SIM && state == GameState.BUILD)
                {
                    if (markWorst.Value && GameStateSim.m_NumBridgeBreaks == 0)
                    {
                        float            worstStress = 0.0f;
                        PolyPhysics.Edge worstEdge   = null;
                        foreach (var edge in maxStress)
                        {
                            if (Mathf.Abs(edge.Value) > worstStress)
                            {
                                worstStress = Mathf.Abs(edge.Value);
                                worstEdge   = edge.Key;
                            }
                        }
                        BridgeEdge byPhysicsEdge = BridgeEdges.FindByPhysicsEdge(worstEdge);
                        if (byPhysicsEdge && worstStress > 0.01f)
                        {
                            BridgeEdgeProxy proxy = new BridgeEdgeProxy(byPhysicsEdge);
                            proxy.m_NodeA_Guid = (UnityEngine.Object)byPhysicsEdge.m_StartSimJointA != (UnityEngine.Object)null ? byPhysicsEdge.m_StartSimJointA.m_Guid : proxy.m_NodeA_Guid;
                            proxy.m_NodeB_Guid = (UnityEngine.Object)byPhysicsEdge.m_StartSimJointB != (UnityEngine.Object)null ? byPhysicsEdge.m_StartSimJointB.m_Guid : proxy.m_NodeB_Guid;
                            GameStateBuild.SetFirstBreakEdge(proxy);
                        }
                    }
                }

                originalColor.Clear();
                maxStress.Clear();
                curStress.Clear();
            }
コード例 #20
0
            private static void Postfix(ref BridgeEdge __instance, ref float stressNormalized, ref MaterialPropertyBlock ___m_MaterialPropertyBlock, ref int ___m_ShaderIDForStress, ref int ___m_ShaderIDForColorBlind)
            {
                if (stressNormalized == 0f)
                {
                    CheckMaterial(__instance);
                    return;
                }

                float alteredStress;

                if (configThresholdModeIsEnabled.Value)
                {
                    alteredStress = stressNormalized >= configThresholdModeMinStress.Value ? 1.0f : stressNormalized;
                }
                else
                {
                    alteredStress = stressNormalized;
                }

                if (configTensileCompressiveModeIsEnabled.Value)
                {
                    if (__instance.m_PhysicsEdge)
                    {
                        Edge edge = __instance.m_PhysicsEdge;
                        if (edge.handle)
                        {
                            PluginMain.SetShaderColor(__instance, alteredStress, edge.handle.stressNormalizedSigned);
                        }
                    }
                }
                else
                {
                    ___m_MaterialPropertyBlock.SetFloat(___m_ShaderIDForColorBlind, Profile.m_ColorBlindModeOn ? 1f : 0f);
                    __instance.m_MeshRenderer.SetPropertyBlock(___m_MaterialPropertyBlock);
                }
            }
コード例 #21
0
 static void Prefix(ref BridgeEdge newEdge, ref BridgeEdge sourceEdge)
 {
     newEdge.m_MeshRenderer.material.color = sourceEdge.m_MeshRenderer.material.color;
 }
コード例 #22
0
 static void Postfix(ref BridgeEdge __result)
 {
     newEdge = __result;
 }
コード例 #23
0
    private ISerialisableTileAttribute CreateSerialisableTileAttribute(Tile tile, ITileAttribute tileAttribute)
    {
        if (tileAttribute.GetType() == typeof(TileObstacle))
        {
            TileObstacle tileObstacle = tileAttribute as TileObstacle;
            SerialisableTileObstacleAttribute serialisableTileObstacleAttribute =
                new SerialisableTileObstacleAttribute(
                    new TileConnectionScoreInfo(tileObstacle.ConnectionScore, tileObstacle.SpriteNumber));
            return(serialisableTileObstacleAttribute);
        }
        else if (tileAttribute.GetType() == typeof(PlayerExit))
        {
            PlayerExit playerExit = tileAttribute as PlayerExit;

            SerialisablePlayerExitAttribute serialisablePlayerExitAttribute = new SerialisablePlayerExitAttribute(
                new TileConnectionScoreInfo(playerExit.ConnectionScore, playerExit.SpriteNumber));
            return(serialisablePlayerExitAttribute);
        }
        else if (tileAttribute.GetType() == typeof(PlayerOnly))
        {
            SerialisablePlayerOnlyAttribute serialisablePlayerOnlyAttribute = new SerialisablePlayerOnlyAttribute();
            return(serialisablePlayerOnlyAttribute);
        }
        else if (tileAttribute.GetType() == typeof(PlayerSpawnpoint))
        {
            SerialisablePlayerSpawnpointAttribute serialisablePlayerSpawnpointAttribute = new SerialisablePlayerSpawnpointAttribute();
            return(serialisablePlayerSpawnpointAttribute);
        }
        else if (tileAttribute.GetType() == typeof(EnemySpawnpoint))
        {
            EnemySpawnpoint enemySpawnpoint = tileAttribute as EnemySpawnpoint;
            SerialisableEnemySpawnpointAttribute serialisableEnemySpawnpointAttribute = new SerialisableEnemySpawnpointAttribute(enemySpawnpoint.TileAreas);
            return(serialisableEnemySpawnpointAttribute);
        }
        else if (tileAttribute.GetType() == typeof(MazeLevelEntry))
        {
            MazeLevelEntry mazeLevelEntry = tileAttribute as MazeLevelEntry;
            SerialisableMazeLevelEntryAttribute serialisableMazeLevelEntryAttribute = new SerialisableMazeLevelEntryAttribute(mazeLevelEntry.MazeLevelName);
            return(serialisableMazeLevelEntryAttribute);
        }
        else if (tileAttribute.GetType() == typeof(BridgePiece))
        {
            BridgePiece          bridgePiece          = tileAttribute as BridgePiece;
            BridgePieceDirection bridgePieceDirection = bridgePiece.BridgePieceDirection;

            SerialisableBridgePieceAttribute serialisableBridgePieceAttribute = new SerialisableBridgePieceAttribute(bridgePieceDirection);
            return(serialisableBridgePieceAttribute);
        }
        else if (tileAttribute.GetType() == typeof(BridgeEdge))
        {
            BridgeEdge bridgeEdge = tileAttribute as BridgeEdge;

            SerialisableBridgeEdgeAttribute serialisableBridgeEdgeAttribute = new SerialisableBridgeEdgeAttribute(bridgeEdge.EdgeSide);
            return(serialisableBridgeEdgeAttribute);
        }
        else if (tileAttribute.GetType() == typeof(MusicInstrumentCase))
        {
            SerialisableMusicInstrumentCaseAttribute serialisableMusicInstrumentCaseAttribute = new SerialisableMusicInstrumentCaseAttribute();
            return(serialisableMusicInstrumentCaseAttribute);
        }
        else
        {
            Logger.Error($"Could not serialise the tile attribute {tileAttribute.GetType()}");
            return(null);
        }
    }