/// <summary> /// Creates a new DefineColor based on the specified input text. /// </summary> /// <param name="input">The input text to get a match for. For example, "blue = #00f".</param> /// <returns>Returns the new DefineColor, or null if a no matches were found for the specified input.</returns> public static DefineColor Create(string input) { const string pattern = @"^(?<colorName>\w+)\s*=\s*(?<hexCode>#([0-9a-f]){3}(([0-9a-f]){3})?)"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(input); if (matches.Count == 0) { return(null); } DefineColor defineColor = new DefineColor(); defineColor.colorName = RegexHelper.GetValue <string>(matches, "colorName"); defineColor.hexCode = RegexHelper.GetValue <string>(matches, "hexCode"); return(defineColor); }
void SettingAnswerList() { int row = Random.Range(0, ROW); int col = Random.Range(0, COL); DefineColor.ColorStateInitialize(); boxes[row, col].SetColor(memorizeColorList[questionIndex]); DefineColor.SetColorState(memorizeColorList[questionIndex]); for (int _row = 0; _row < 2; _row++) { for (int _col = 0; _col < 2; _col++) { if (_row == row && _col == col) { continue; } boxes[_row, _col].SetColor(DefineColor.RandomColorUnique); } } }
/// <summary> /// 获取颜色索引(映射不上时默认返回黑色) /// </summary> /// <param name="color"></param> /// <returns></returns> public static short GetColorIndex(DefineColor color) { return(ColorMappings.ContainsKey(color) ? ColorMappings[color] : IndexedColors.Black.Index); }
private void ExecuteCommandLine(string text) { SuperVector superVector = SuperVector.Create(text); if (superVector != null) { CreateOrUpdateSuperVector(superVector); return; } SetColor setColor = SetColor.Create(text); if (setColor != null) { ChangeVectorColor(setColor.vectorName, setColor.hexCode); return; } SetNamedColor setNamedColor = SetNamedColor.Create(text); if (setNamedColor != null) { string hexCode; if (colorLookups.ContainsKey(setNamedColor.colorName)) { hexCode = colorLookups[setNamedColor.colorName]; ChangeVectorColor(setNamedColor.vectorName, hexCode); } else { Debug.LogError($"\"{setNamedColor.colorName}\" needs to be defined first!!!"); } return; } DefineColor defineColor = DefineColor.Create(text); if (defineColor != null) { DefineColorName(defineColor.colorName, defineColor.hexCode); return; } MoveVector moveVector = MoveVector.Create(text); if (moveVector != null) { MoveVectorTo(moveVector.vector1, moveVector.vector2); return; } SumVectors sumVectors = SumVectors.Create(text); if (sumVectors != null) { SumAllVectors(sumVectors.newVectorName, sumVectors.vector1, sumVectors.vector2, sumVectors.vector3, sumVectors.vector4, sumVectors.vector5); return; } NegativeVector negativeVector = NegativeVector.Create(text); if (negativeVector != null) { MakeVectorNegative(negativeVector.vectorName); return; } AssignNegativeVector assignNegativeVector = AssignNegativeVector.Create(text); if (assignNegativeVector != null) { CreateNegativeVector(assignNegativeVector.existingVectorName, assignNegativeVector.newVectorName); return; } VectorCommand vectorCommand = VectorCommand.Create(text); if (vectorCommand != null) { HandleVectorCommand(vectorCommand.command, vectorCommand.vectorName); return; } OffsetVector offsetVector = OffsetVector.Create(text); if (offsetVector != null) { OffsetVectorBy(offsetVector.vectorName, offsetVector.offsetX, offsetVector.offsetY, offsetVector.offsetZ); return; } }