public static MaterialExistence CheckIfMaterialExists(MouldingColour.Id id) { if (File.Exists(MaterialPathUtility.GetPath(id))) { return(MaterialExistence.Current); } if (File.Exists(MaterialPathUtility.GetPath(id, true))) { return(MaterialExistence.Legacy); } // FIXME Remove when colour palette experiments are over. #if UNITY_EDITOR if (MouldingColour.GetBI()) { if (File.Exists(MaterialPathUtility.GetPath(id, false, true))) { return(MaterialExistence.Current); } if (File.Exists(MaterialPathUtility.GetPath(id, true, true))) { return(MaterialExistence.Legacy); } } #endif return(MaterialExistence.None); }
public override bool IsVisible() { foreach (var connection in connections) { // FIXME Temporary fix to tube removal while we work on connections that are related/non-rejecting but not connected. // FIXME This fix allows for tubes to work without reimporting existing models. Should be removed at a later state. if (connection.IsRelevantForTube()) { var connectedTo = connection.GetConnection(); if (!connectedTo) { return(true); } var notCovering = (connection.flags & Connection.flagsCoveringTube) == 0 || (connectedTo.flags & Connection.flagsCoveringTube) == 0; notCovering |= MouldingColour.IsAnyTransparent(part.materialIDs) || MouldingColour.IsAnyTransparent(connectedTo.field.connectivity.part.materialIDs); if (notCovering) { return(true); } } } return(false); }
public static MouldingColourPicker Show(Action <Color> colourPicked, bool excludeTransparent = false, bool excludeBrightYellow = false, bool excludeLegacy = true) { onColourPicked = colourPicked; MouldingColourPicker.excludeTransparent = excludeTransparent; MouldingColourPicker.excludeBrightYellow = excludeBrightYellow; MouldingColourPicker.excludeLegacy = excludeLegacy; if (colourTextures == null) { MouldingColour.Id[] mouldingColourValues = (MouldingColour.Id[])Enum.GetValues(typeof(MouldingColour.Id)); colourTextures = new Texture2D[mouldingColourValues.Length]; colourNames = new string[mouldingColourValues.Length]; colourTransparent = new bool[mouldingColourValues.Length]; colourLabelColours = new Color[mouldingColourValues.Length]; for (int i = 0; i < mouldingColourValues.Length; ++i) { var colour = MouldingColour.GetColour(mouldingColourValues[i]); var colourTex = new Texture2D(1, 1); colourTex.SetPixel(0, 0, colour); colourTex.Apply(); colourTextures[i] = colourTex; colourNames[i] = ObjectNames.NicifyVariableName(mouldingColourValues[i].ToString()); colourTransparent[i] = colour.a < 1.0f; colourLabelColours[i] = colour.grayscale > 0.3f ? Color.black : Color.white; } } var window = GetWindow <MouldingColourPicker>(true, "Moulding Colour Picker", true); return(window); }
protected override void Reset() { base.Reset(); m_FlashColour = MouldingColour.GetColour(MouldingColour.Id.BrightRed) * 2.0f; m_IconPath = "Assets/LEGO/Gizmos/LEGO Behaviour Icons/Lose Action.png"; }
private void OnGUI() { var colourColumnCount = Mathf.FloorToInt((position.width - 3) / (40.0f + 3.0f)); var colourStyle = new GUIStyle(GUI.skin.button); colourStyle.fixedWidth = 40.0f; colourStyle.fixedHeight = 40.0f; var labelStyle = new GUIStyle(GUI.skin.label); labelStyle.alignment = TextAnchor.LowerRight; MouldingColour.Id[] mouldingColourValues = (MouldingColour.Id[])Enum.GetValues(typeof(MouldingColour.Id)); int i = 0; int x = 0; int y = 0; while (i < mouldingColourValues.Length) { var colourId = mouldingColourValues[i]; var colour = MouldingColour.GetColour(colourId); if (!(excludeTransparent && colour.a < 1.0f) && !(excludeBrightYellow && (colourId == MouldingColour.Id.BrightYellow)) && !(excludeLegacy && MouldingColour.IsLegacy(colourId))) { var drawRect = new Rect(x * 43.0f + 3.0f, y * 43.0f + 3.0f, 40.0f, 40.0f); var boxRect = new Rect(drawRect.x - 1.0f, drawRect.y - 1.0f, drawRect.width + 2.0f, drawRect.height + 2.0f); GUI.Box(boxRect, new GUIContent("", colourNames[i])); EditorGUI.DrawTextureTransparent(drawRect, colourTextures[i], ScaleMode.ScaleToFit); labelStyle.normal.textColor = colourLabelColours[i]; GUI.Label(drawRect, ((int)colourId).ToString(), labelStyle); // Detect click. if (Event.current.type == EventType.MouseDown) { if (boxRect.Contains(Event.current.mousePosition)) { onColourPicked(MouldingColour.GetColour(mouldingColourValues[i])); Close(); } } x++; if (x == colourColumnCount) { x = 0; y++; } } i++; } }
private Material GetMaterial(int id) { // FIXME Remove when colour palette experiments are over. var useBI = MouldingColour.GetBI(); var path = MaterialPathUtility.GetPath((MouldingColour.Id)id, false, useBI); if (File.Exists(path)) { return(AssetDatabase.LoadAssetAtPath <Material>(path)); } else { path = MaterialPathUtility.GetPath((MouldingColour.Id)id, true, useBI); return(AssetDatabase.LoadAssetAtPath <Material>(path)); } }
public override bool IsVisible() { var connectedTo = connection.GetConnection(); if (!connectedTo) { return(true); } else { var notCovering = (connection.flags & Connection.flagsCoveringKnob) == 0 || (connectedTo.flags & Connection.flagsCoveringKnob) == 0; notCovering |= MouldingColour.IsAnyTransparent(part.materialIDs) || MouldingColour.IsAnyTransparent(connectedTo.field.connectivity.part.materialIDs); return(notCovering); } }
public static Material LoadMaterial(MouldingColour.Id id, bool legacy) { // FIXME Remove when colour palette experiments are over. #if UNITY_EDITOR if (MouldingColour.GetBI()) { var biMaterial = AssetDatabase.LoadAssetAtPath <Material>(MaterialPathUtility.GetPath(id, legacy, true)); if (biMaterial) { return(biMaterial); } } #endif #if UNITY_EDITOR return(AssetDatabase.LoadAssetAtPath <Material>(MaterialPathUtility.GetPath(id, legacy))); #else return(null); #endif }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var mouldingColourAttribute = (MouldingColourAttribute)attribute; var colour = property.colorValue; var mouldingColourId = MouldingColour.GetId(colour); // Draw label position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); // Create box and tooltip. GUI.Box(position, new GUIContent("", ObjectNames.NicifyVariableName((int)mouldingColourId + " - " + mouldingColourId.ToString()))); // Draw rects with colour. var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f - alphaBarHeight); var alphaRect = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height, Mathf.Round((position.width - 2.0f) * colour.a), alphaBarHeight); var blackRect = new Rect(position.x + 1.0f + alphaRect.width, position.y + 1.0f + colorRect.height, position.width - 2.0f - alphaRect.width, alphaBarHeight); EditorGUI.DrawRect(colorRect, new Color(colour.r, colour.g, colour.b)); EditorGUI.DrawRect(alphaRect, Color.white); EditorGUI.DrawRect(blackRect, Color.black); // Detect click. if (Event.current.type == EventType.MouseDown) { if (position.Contains(Event.current.mousePosition)) { MouldingColourPicker.Show((c) => { property.colorValue = c; property.serializedObject.ApplyModifiedProperties(); }, mouldingColourAttribute.excludeTransparent, mouldingColourAttribute.excludeBrightYellow, mouldingColourAttribute.excludeLegacy ); } } }
protected override void Reset() { base.Reset(); m_FlashColour = MouldingColour.GetColour(MouldingColour.Id.BrickYellow) * 2.0f; }
private void DrawMouldingColour(int colourID, int listIndex, bool multipleValues) { var position = EditorGUILayout.GetControlRect(); // Draw label position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Moulding Colour " + listIndex)); if (multipleValues) { // Create box and tooltip. GUI.Box(position, new GUIContent("", "Multiple colours selected")); var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f); var lineRect = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height / 2.0f, 10.0f, 1.0f); EditorGUI.DrawRect(colorRect, new Color32(209, 209, 209, 255)); EditorGUI.DrawRect(lineRect, Color.grey); } else { var mouldingColourID = (MouldingColour.Id)colourID; var colour = MouldingColour.GetColour(mouldingColourID); // Create box and tooltip. GUI.Box(position, new GUIContent("", ObjectNames.NicifyVariableName((int)mouldingColourID + " - " + mouldingColourID.ToString()))); // Draw rects with colour. var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f - alphaBarHeight); var alphaRect = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height, Mathf.Round((position.width - 2.0f) * colour.a), alphaBarHeight); var blackRect = new Rect(position.x + 1.0f + alphaRect.width, position.y + 1.0f + colorRect.height, position.width - 2.0f - alphaRect.width, alphaBarHeight); EditorGUI.DrawRect(colorRect, new Color(colour.r, colour.g, colour.b)); EditorGUI.DrawRect(alphaRect, Color.white); EditorGUI.DrawRect(blackRect, Color.black); } // Detect click. if (Event.current.type == EventType.MouseDown) { if (position.Contains(Event.current.mousePosition)) { MouldingColourPicker.Show((c) => { // Collect all parts to record for undo. foreach (var target in targets) { var brickTarget = (Brick)target; Undo.RegisterFullObjectHierarchyUndo(brickTarget.gameObject, "Changed Material"); int indexOffset = 0; foreach (var partTarget in brickTarget.parts) { if (indexOffset <= listIndex && listIndex < indexOffset + partTarget.materialIDs.Count) { Undo.RegisterFullObjectHierarchyUndo(partTarget.gameObject, "Changed Material"); break; } indexOffset += partTarget.materialIDs.Count; } } // Collect all parts to change the material. foreach (var target in targets) { var brickTarget = (Brick)target; int indexOffset = 0; foreach (var partTarget in brickTarget.parts) { if (indexOffset <= listIndex && listIndex < indexOffset + partTarget.materialIDs.Count) { // Update material ID. partTarget.materialIDs[listIndex - indexOffset] = (int)MouldingColour.GetId(c); // Collect all materials. LXFMLDoc.Brick.Part.Material[] materials = new LXFMLDoc.Brick.Part.Material[partTarget.materialIDs.Count]; for (var i = 0; i < partTarget.materialIDs.Count; ++i) { materials[i] = new LXFMLDoc.Brick.Part.Material() { colorId = partTarget.materialIDs[i], shaderId = 0 }; } // Update the part materials. ModelImporter.SetMaterials(partTarget, materials, partTarget.legacy); // Update knobs and tubes of this brick and the bricks it is connected to directly. var connectedBricks = partTarget.brick.GetConnectedBricks(false); connectedBricks.Add(partTarget.brick); foreach (var brick in connectedBricks) { foreach (var part in brick.parts) { if (!part.legacy && part.connectivity) { foreach (var connectionField in part.connectivity.connectionFields) { foreach (var connection in connectionField.connections) { connection.UpdateKnobsAndTubes(); } } } } } break; } indexOffset += partTarget.materialIDs.Count; } } // Collect all parts to record prefab instance modifications. foreach (var target in targets) { var brickTarget = (Brick)target; if (PrefabUtility.IsPartOfAnyPrefab(brickTarget.gameObject)) { PrefabUtility.RecordPrefabInstancePropertyModifications(brickTarget.gameObject); } int indexOffset = 0; foreach (var partTarget in brickTarget.parts) { if (indexOffset <= listIndex && listIndex < indexOffset + partTarget.materialIDs.Count) { if (PrefabUtility.IsPartOfAnyPrefab(partTarget.gameObject)) { PrefabUtility.RecordPrefabInstancePropertyModifications(partTarget.gameObject); } break; } indexOffset += partTarget.materialIDs.Count; } } }, false, false, true ); } } }
private void DrawMouldingColour(SerializedProperty property, GUIContent label) { var position = EditorGUILayout.GetControlRect(); // Draw label position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); if (property.hasMultipleDifferentValues) { // Create box and tooltip. GUI.Box(position, new GUIContent("", "Multiple colours selected")); var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f); var lineRect = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height / 2.0f, 10.0f, 1.0f); EditorGUI.DrawRect(colorRect, new Color32(209, 209, 209, 255)); EditorGUI.DrawRect(lineRect, Color.grey); } else { var mouldingColourId = (MouldingColour.Id)property.intValue; var colour = MouldingColour.GetColour(mouldingColourId); // Create box and tooltip. GUI.Box(position, new GUIContent("", ObjectNames.NicifyVariableName((int)mouldingColourId + " - " + mouldingColourId.ToString()))); // Draw rects with colour. var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f - alphaBarHeight); var alphaRect = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height, Mathf.Round((position.width - 2.0f) * colour.a), alphaBarHeight); var blackRect = new Rect(position.x + 1.0f + alphaRect.width, position.y + 1.0f + colorRect.height, position.width - 2.0f - alphaRect.width, alphaBarHeight); EditorGUI.DrawRect(colorRect, new Color(colour.r, colour.g, colour.b)); EditorGUI.DrawRect(alphaRect, Color.white); EditorGUI.DrawRect(blackRect, Color.black); } // Detect click. if (Event.current.type == EventType.MouseDown) { if (position.Contains(Event.current.mousePosition)) { MouldingColourPicker.Show((c) => { property.intValue = (int)MouldingColour.GetId(c); // Collect all materials. LXFMLDoc.Brick.Part.Material[] materials = new LXFMLDoc.Brick.Part.Material[materialIDsProp.arraySize]; for (var i = 0; i < materialIDsProp.arraySize; ++i) { materials[i] = new LXFMLDoc.Brick.Part.Material() { colorId = materialIDsProp.GetArrayElementAtIndex(i).intValue, shaderId = 0 }; } // Run through all targeted parts and record them for undo. foreach (var target in targets) { var partTarget = (Part)target; // Register state before updating materials. Undo.RegisterFullObjectHierarchyUndo(partTarget.gameObject, "Changed Material"); } // Run through all targeted parts and update them. foreach (var target in targets) { var partTarget = (Part)target; // Update the part materials. ModelImporter.SetMaterials(partTarget, materials, legacyProp.boolValue); // Apply the new colour to the serialized property. property.serializedObject.ApplyModifiedProperties(); // Update knobs and tubes of this brick and the bricks it is connected to directly. var connectedBricks = partTarget.brick.GetConnectedBricks(false); connectedBricks.Add(partTarget.brick); foreach (var brick in connectedBricks) { foreach (var part in brick.parts) { if (!part.legacy) { foreach (var connectionField in part.connectivity.connectionFields) { foreach (var connection in connectionField.connections) { connection.UpdateKnobsAndTubes(); } } } } } } }, false, false, true ); } } }