//The base tab is the outline surrounding the color picker, as well as teh "Player Color" label and associated "Selected Color" image. private static void InitializeBaseTabElement(RectTransform joinServerBackground, GameObject playerSettingsPanel) { GameObject baseTab = playerSettingsPanel.RequireGameObject("BaseTab"); //Re-position the border RectTransform baseTabTransform = (RectTransform)baseTab.transform; baseTabTransform.anchoredPosition = new Vector2(0.5f, 0.5f); baseTabTransform.anchorMin = new Vector2(0.5f, 0.5f); baseTabTransform.anchorMax = new Vector2(0.5f, 0.5f); baseTabTransform.pivot = new Vector2(0.5f, 0.5f); //Resize the border to match the new parent. Capture the original width so we can make adjustments to child controls later //because the existing elements all have some really weird anchor settings the prevent them from moving automatically. float originalBaseTabWidth = baseTabTransform.rect.width; baseTabTransform.sizeDelta = new Vector2(joinServerBackground.rect.width, baseTabTransform.rect.height); //Move the SelectedColor element over to the right enough to match the shrinkage of the base tab. GameObject baseTabSelectedColor = baseTabTransform.RequireGameObject("SelectedColor"); Image baseTabSelectedColorImage = baseTabSelectedColor.GetComponent <Image>(); baseTabSelectedColorImage.rectTransform.anchoredPosition = new Vector2( baseTabSelectedColorImage.rectTransform.anchoredPosition.x + (originalBaseTabWidth - baseTabTransform.rect.width) / 2, baseTabSelectedColorImage.rectTransform.anchoredPosition.y); //Place the "Player Color" label to the right of the SelectedColor image and shrink it to fit the new tab region. GameObject baseTabTextGameObject = baseTabTransform.RequireGameObject("Text"); RectTransform baseTabTextTransform = (RectTransform)baseTabTextGameObject.transform; baseTabTextTransform.anchorMin = new Vector2(0.5f, 0.5f); baseTabTextTransform.anchorMax = new Vector2(0.5f, 0.5f); baseTabTextTransform.pivot = new Vector2(0.5f, 0.5f); baseTabTextTransform.sizeDelta = new Vector2(80, 35); baseTabTextTransform.anchoredPosition = new Vector2( baseTabSelectedColorImage.rectTransform.anchoredPosition.x + baseTabTextTransform.rect.width / 2f + 22f, baseTabSelectedColorImage.rectTransform.anchoredPosition.y); Text baseTabText = baseTabTextGameObject.GetComponent <Text>(); baseTabText.text = "Player Color"; //This resizes the actual Image that outlines all of the UI elements. GameObject baseTabBackgroundGameObject = baseTabTransform.RequireGameObject("Background"); Image baseTabBackgroundImage = baseTabBackgroundGameObject.GetComponent <Image>(); baseTabBackgroundImage.rectTransform.sizeDelta = new Vector2(joinServerBackground.rect.width, baseTabTransform.rect.height); //This removes the extra "tabs" from the base texture. Texture2D newBaseTabTexture = baseTabBackgroundImage.sprite.texture.Clone(); TextureBlock textureBlock = new TextureBlock(3, 3, 160, (int)(baseTabBackgroundImage.sprite.textureRect.height - 71f)); IColorSwapStrategy alphaChannelSwapper = new AlphaChannelSwapper(0f); HsvSwapper baseTabBackgroundSwapper = new HsvSwapper(alphaChannelSwapper); baseTabBackgroundSwapper.SetHueRange(185f, 215f); baseTabBackgroundSwapper.SetAlphaRange(0f, 175f); newBaseTabTexture.SwapTextureColors(baseTabBackgroundSwapper, textureBlock); baseTabBackgroundImage.sprite = Sprite.Create(newBaseTabTexture, new Rect(baseTabBackgroundImage.sprite.textureRect), new Vector2(0f, 0f)); }
private TextureBlock GetTextureBlock(Texture2D texture, int x, int y, int blockSize, Color32[] pixels) { var blockWidth = x * blockSize + blockSize <= texture.width ? blockSize : texture.width - x * blockSize; var blockHeight = y * blockSize + blockSize <= texture.height ? blockSize : texture.height - y * blockSize; var colors = GetBlockColors(x * blockSize, y * blockSize, blockWidth, blockHeight, texture.width, pixels); // アルファ値0のピクセルの色を統一. for (var i = 0; i < colors.Length; i++) { if (colors[i].a == 0f) { colors[i] = new Color32(0, 0, 0, 0); } } var isAllTransparent = colors.All(c => c.a == 0f); var colorHash = GetPixelColorsHash(blockWidth, blockHeight, blockSize, colors); var blockId = GetHashId(colorHash); var blockData = new TextureBlock() { width = blockWidth, height = blockHeight, colors = colors, isAllTransparent = isAllTransparent, blockId = blockId, }; return(blockData); }
static public TextureBlock?getTexture(string name) { var key = name.ToLower(); if (srcTexs.ContainsKey(key)) { if (srcTexs[key] == null) { var tex = Resources.Load(name, typeof(Texture2D)) as Texture2D; srcTexs[key] = TextureBlock.Create(tex, new Rect(0, 0, 1, 1)); } return(srcTexs[name].Value); } foreach (var v in allBlocks) { if (v.Value.details.ContainsKey(key)) { if (srcTexs[v.Key] == null) { var tex = Resources.Load(v.Key, typeof(Texture2D)) as Texture2D; srcTexs[v.Key] = TextureBlock.Create(tex, new Rect(0, 0, 1, 1)); } var texs = srcTexs[v.Key].Value.tex; Rect suv = v.Value.details[key]; //suv.x /= texs.width; //suv.y /= texs.height; //suv.width /= texs.width; //suv.height /= texs.height; suv.y = 1 - suv.y - suv.height; return(srcTexs[v.Key].Value.Create(suv)); } } return(null); }
public static Color[] GetMainTexturePixelBlock( this Material material, TextureBlock textureBlock) { Texture2D mainTexture = (Texture2D)material.mainTexture; return(mainTexture.GetPixels(textureBlock.X, textureBlock.Y, textureBlock.BlockWidth, textureBlock.BlockHeight)); }
//This applies a color filter to a specific region of a 2D texture. public static void SwapTextureColors( this Texture2D texture, HsvSwapper filter, TextureBlock textureBlock) { Color[] pixels = texture.GetPixels(textureBlock.X, textureBlock.Y, textureBlock.BlockWidth, textureBlock.BlockHeight); filter.SwapColors(pixels); texture.SetPixels(textureBlock.X, textureBlock.Y, textureBlock.BlockWidth, textureBlock.BlockHeight, pixels); texture.Apply(); }
//This applies a color filter to a specific region of a 2D texture. public static void UpdateMainTextureColors( this Material material, Color[] pixels, //IColorSwapStrategy colorSwapStrategy, TextureBlock textureBlock) { Texture2D mainTexture = (Texture2D)material.mainTexture; //Color[] pixels = mainTexture.GetPixels(textureBlock.X, textureBlock.Y, textureBlock.BlockWidth, textureBlock.BlockHeight); //pixelIndexes.ForEach(pixelIndex => pixels[pixelIndex] = colorSwapStrategy.SwapColor(pixels[pixelIndex])); mainTexture.SetPixels(textureBlock.X, textureBlock.Y, textureBlock.BlockWidth, textureBlock.BlockHeight, pixels); mainTexture.Apply(); }
void onSelectFile(string filename) { //TextureAtlas tdata = null; { tdata = TextureBlockMgr.getDetail(filename); selectTex = TextureBlockMgr.getTexture(filename).Value; } spritesAtlasDetail.Clear(); foreach (var ani in tdata.details) { spritesAtlasDetail.Add(ani.Key); } }
//以源图块的中心点应用矩阵 public void DrawRect(TextureBlock src, Vector2 size, Matrix4x4 dest, Color c) { Vector2 v1 = dest.MultiplyPoint(new Vector2(-size.x / 2, -size.y / 2)); Vector2 v2 = dest.MultiplyPoint(new Vector2(size.x / 2, -size.y / 2)); Vector2 v3 = dest.MultiplyPoint(new Vector2(-size.x / 2, size.y / 2)); Vector2 v4 = dest.MultiplyPoint(new Vector2(size.x / 2, size.y / 2)); var uv1 = new Vector2(src.uv.xMin, src.uv.yMin); var uv2 = new Vector2(src.uv.xMax, src.uv.yMin); var uv3 = new Vector2(src.uv.xMin, src.uv.yMax); var uv4 = new Vector2(src.uv.xMax, src.uv.yMax); AddTri(v1, v2, v3, uv1, uv2, uv3, c, c, c, src.tex); AddTri(v3, v2, v4, uv3, uv2, uv4, c, c, c, src.tex); }
public void DrawRect(TextureBlock src, Rect dest, Color c) { Vector2 v1 = (new Vector2(dest.xMin, dest.yMin)); Vector2 v2 = (new Vector2(dest.xMax, dest.yMin)); Vector2 v3 = (new Vector2(dest.xMin, dest.yMax)); Vector2 v4 = (new Vector2(dest.xMax, dest.yMax)); var uv1 = new Vector2(src.uv.xMin, src.uv.yMin); var uv2 = new Vector2(src.uv.xMax, src.uv.yMin); var uv3 = new Vector2(src.uv.xMin, src.uv.yMax); var uv4 = new Vector2(src.uv.xMax, src.uv.yMax); AddTri(v1, v2, v3, uv1, uv2, uv3, c, c, c, src.tex); AddTri(v3, v2, v4, uv3, uv2, uv4, c, c, c, src.tex); }
public void DrawRect(TextureBlock src, Vector2 size, Vector2 pos, Color c) { Vector2 v1 = (new Vector2(pos.x - size.x / 2, pos.y - size.y / 2)); Vector2 v2 = (new Vector2(pos.x + size.x / 2, pos.y - size.y / 2)); Vector2 v3 = (new Vector2(pos.x - size.x / 2, pos.y + size.y / 2)); Vector2 v4 = (new Vector2(pos.x + size.x / 2, pos.y + size.y / 2)); var uv1 = new Vector2(src.uv.xMin, src.uv.yMin); var uv2 = new Vector2(src.uv.xMax, src.uv.yMin); var uv3 = new Vector2(src.uv.xMin, src.uv.yMax); var uv4 = new Vector2(src.uv.xMax, src.uv.yMax); AddTri(v1, v2, v3, uv1, uv2, uv3, c, c, c, src.tex); AddTri(v3, v2, v4, uv3, uv2, uv4, c, c, c, src.tex); //throw new System.NotImplementedException(); }
private void LoadTexturesFromCategorie(TextureBlock block) { var controls = new Control[FlowLayoutPanel_Textures.Controls.Count]; FlowLayoutPanel_Textures.Controls.CopyTo(controls, 0); FlowLayoutPanel_Textures.SuspendLayout(); foreach (Control c in controls) { if (c is PictureBox) { Highlighter1.SetHighlightColor(c, eHighlightColor.None); FlowLayoutPanel_Textures.Controls.Remove(c); } } foreach (Material mat in block.Textures) { TextureLoadedInfos info = mat.Tag as TextureLoadedInfos; var pb = new PictureBox() { Image = mat.Image, SizeMode = PictureBoxSizeMode.Zoom, Tag = mat, Size = new Size(70, 70) }; pb.Click += PictureBox_Clicked; pb.MouseEnter += PictureBox_MouseEnter; pb.MouseLeave += PictureBox_MouseLeave; pb.MouseClick += PictureBox_MouseClick; var lbl = new LabelX() { Text = info.Name, Size = new Size(70, 14), Location = new System.Drawing.Point(1, 55), TextAlignment = StringAlignment.Center }; pb.Controls.Add(lbl); lbl.Click += (sender, e) => PictureBox_Clicked(pb, e); lbl.MouseEnter += (sender, e) => PictureBox_MouseEnter(pb, e); lbl.MouseLeave += (sender, e) => PictureBox_MouseLeave(pb, e); lbl.MouseClick += (sender, e) => PictureBox_MouseClick(pb, e); FlowLayoutPanel_Textures.Controls.Add(pb); } FlowLayoutPanel_Textures.ResumeLayout(); }
internal TextureBlock(int x, int y, int size) { X = x; Y = y; Size = size; if (size > Sprite.MIN_SIZE) { int div2 = size / 2; _children = new TextureBlock[2, 2]; for (int yi = 0; yi < 2; yi++) { for (int xi = 0; xi < 2; xi++) { _children[xi, yi] = new TextureBlock(xi * div2 + x, yi * div2 + y, div2); } } } }
public void DrawRect(TextureBlock src, Vector2 size, Vector2 orient, Matrix4x4 dest, Color c) { float xmin = -orient.x; float xmax = (size.x - orient.x); float ymin = -(size.y - orient.y); float ymax = orient.y; Vector2 v1 = dest.MultiplyPoint(new Vector2(xmin, ymin)); Vector2 v2 = dest.MultiplyPoint(new Vector2(xmax, ymin)); Vector2 v3 = dest.MultiplyPoint(new Vector2(xmin, ymax)); Vector2 v4 = dest.MultiplyPoint(new Vector2(xmax, ymax)); var uv1 = new Vector2(src.uv.xMin, src.uv.yMin); var uv2 = new Vector2(src.uv.xMax, src.uv.yMin); var uv3 = new Vector2(src.uv.xMin, src.uv.yMax); var uv4 = new Vector2(src.uv.xMax, src.uv.yMax); AddTri(v1, v2, v3, uv1, uv2, uv3, c, c, c, src.tex); AddTri(v3, v2, v4, uv3, uv2, uv4, c, c, c, src.tex); }
/// <summary> /// Called when the window is loading, only to be used by the startup process. /// </summary> void Window_Load(object sender, EventArgs e) { SysConsole.Output(OutputType.INIT, "Window generated!"); DPIScale = Window.Width / CVars.r_width.ValueF; SysConsole.Output(OutputType.INIT, "DPIScale is " + DPIScale + "!"); SysConsole.Output(OutputType.INIT, "Loading base textures..."); PreInitRendering(); Textures = new TextureEngine(); Textures.InitTextureSystem(this); ItemFrame = Textures.GetTexture("ui/hud/item_frame"); SysConsole.Output(OutputType.INIT, "Loading shaders..."); Shaders = new ShaderEngine(); GLVendor = GL.GetString(StringName.Vendor); CVars.s_glvendor.Value = GLVendor; GLVersion = GL.GetString(StringName.Version); CVars.s_glversion.Value = GLVersion; GLRenderer = GL.GetString(StringName.Renderer); CVars.s_glrenderer.Value = GLRenderer; SysConsole.Output(OutputType.INIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer); if (GLVendor.ToLowerFast().Contains("intel")) { SysConsole.Output(OutputType.INIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')"); Shaders.MCM_GOOD_GRAPHICS = false; } Shaders.InitShaderSystem(this); View3D.CheckError("Load - Shaders"); SysConsole.Output(OutputType.INIT, "Loading rendering helper..."); Rendering = new Renderer(Textures, Shaders); Rendering.Init(); SysConsole.Output(OutputType.INIT, "Preparing load screen..."); Texture load_screen = Textures.GetTexture("ui/menus/loadscreen"); load_screen.Bind(); Shaders.ColorMultShader.Bind(); Establish2D(); Rendering.RenderRectangle(0, 0, Window.Width, Window.Height); Window.SwapBuffers(); SysConsole.Output(OutputType.INIT, "Loading block textures..."); TBlock = new TextureBlock(); TBlock.Generate(this, CVars, Textures); View3D.CheckError("Load - Textures"); SysConsole.Output(OutputType.INIT, "Loading fonts..."); Fonts = new GLFontEngine(Shaders); Fonts.Init(this); FontSets = new FontSetEngine(Fonts); FontSets.Init(this); View3D.CheckError("Load - Fonts"); SysConsole.Output(OutputType.INIT, "Loading animation engine..."); Animations = new AnimationEngine(); SysConsole.Output(OutputType.INIT, "Loading model engine..."); Models = new ModelEngine(); Models.Init(Animations, this); SysConsole.Output(OutputType.INIT, "Loading general graphics settings..."); CVars.r_vsync.OnChanged += onVsyncChanged; onVsyncChanged(CVars.r_vsync, null); CVars.r_cloudshadows.OnChanged += onCloudShadowChanged; View3D.CheckError("Load - General Graphics"); SysConsole.Output(OutputType.INIT, "Loading UI engine..."); UIConsole.InitConsole(); // TODO: make this non-static InitChatSystem(); View3D.CheckError("Load - UI"); SysConsole.Output(OutputType.INIT, "Preparing rendering engine..."); InitRendering(); View3D.CheckError("Load - Rendering"); SysConsole.Output(OutputType.INIT, "Loading particle effect engine..."); Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) }; SysConsole.Output(OutputType.INIT, "Preparing mouse, keyboard, and gamepad handlers..."); KeyHandler.Init(); GamePadHandler.Init(); View3D.CheckError("Load - Keyboard/mouse"); SysConsole.Output(OutputType.INIT, "Building the sound system..."); Sounds = new SoundEngine(); Sounds.Init(this, CVars); View3D.CheckError("Load - Sound"); SysConsole.Output(OutputType.INIT, "Building game world..."); BuildWorld(); View3D.CheckError("Load - World"); SysConsole.Output(OutputType.INIT, "Preparing networking..."); Network = new NetworkBase(this); RegisterDefaultEntityTypes(); View3D.CheckError("Load - Net"); SysConsole.Output(OutputType.INIT, "Playing background music..."); BackgroundMusic(); CVars.a_musicvolume.OnChanged += onMusicVolumeChanged; CVars.a_musicpitch.OnChanged += onMusicPitchChanged; CVars.a_music.OnChanged += onMusicChanged; CVars.a_echovolume.OnChanged += OnEchoVolumeChanged; OnEchoVolumeChanged(null, null); SysConsole.Output(OutputType.INIT, "Setting up screens..."); TheMainMenuScreen = new MainMenuScreen(this); TheGameScreen = new GameScreen(this); TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this); SysConsole.Output(OutputType.INIT, "Preparing inventory..."); InitInventory(); SysConsole.Output(OutputType.INIT, "Showing main menu..."); ShowMainMenu(); SysConsole.Output(OutputType.INIT, "Trying to grab RawGamePad..."); try { RawGamePad = new XInput(); } catch (Exception ex) { SysConsole.Output(OutputType.INIT, "Failed to grab RawGamePad: " + ex.Message); } View3D.CheckError("Load - Final"); SysConsole.Output(OutputType.INIT, "Ready and looping!"); }
/// <summary> /// Called when the window is loading, only to be used by the startup process. /// </summary> void Window_Load(object sender, EventArgs e) { SysConsole.Output(OutputType.CLIENTINIT, "Window generated!"); DPIScale = Window.Width / CVars.r_width.ValueF; SysConsole.Output(OutputType.CLIENTINIT, "DPIScale is " + DPIScale + "!"); SysConsole.Output(OutputType.CLIENTINIT, "Setting up a game engine backend placeholder..."); FakeEngine(); SysConsole.Output(OutputType.CLIENTINIT, "Loading base textures..."); PreInitRendering(); Textures = new TextureEngine(); Textures.InitTextureSystem(Files); ItemFrame = Textures.GetTexture("ui/hud/item_frame"); CWindow.Textures = Textures; SysConsole.Output(OutputType.CLIENTINIT, "Loading shaders..."); Shaders = new ShaderEngine(); GLVendor = GL.GetString(StringName.Vendor); GLVersion = GL.GetString(StringName.Version); GLRenderer = GL.GetString(StringName.Renderer); SysConsole.Output(OutputType.CLIENTINIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer); if (GLVendor.ToLowerFast().Contains("intel")) { SysConsole.Output(OutputType.CLIENTINIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')"); Shaders.MCM_GOOD_GRAPHICS = false; } Shaders.InitShaderSystem(); CWindow.Shaders = Shaders; Engine.GetShaders(); GraphicsUtil.CheckError("Load - Shaders"); SysConsole.Output(OutputType.CLIENTINIT, "Loading animation engine..."); Animations = new AnimationEngine(); CWindow.Animations = Animations; SysConsole.Output(OutputType.CLIENTINIT, "Loading model engine..."); Models = new ModelEngine(); Models.Init(Animations, CWindow); LODHelp = new ModelLODHelper(this); CWindow.Models = Models; SysConsole.Output(OutputType.CLIENTINIT, "Loading rendering helper..."); Rendering = new Renderer(Textures, Shaders, Models); Rendering.Init(); CWindow.Rendering3D = Rendering; CWindow.Rendering2D = new Renderer2D(Textures, Shaders); CWindow.Rendering2D.Init(); SysConsole.Output(OutputType.CLIENTINIT, "Preparing load screen..."); load_screen = Textures.GetTexture("ui/menus/loadscreen"); Establish2D(); SWLoading.Start(); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Loading block textures..."); TBlock = new TextureBlock(); TBlock.Generate(this, CVars, Textures, false); GraphicsUtil.CheckError("Load - Textures"); SysConsole.Output(OutputType.CLIENTINIT, "Loading fonts..."); Fonts = new GLFontEngine(Textures, Shaders); Fonts.Init(Files); FontSets = new FontSetEngine(Fonts); FontSets.Init((subdat) => Languages.GetText(Files, subdat), () => Ortho, () => GlobalTickTimeLocal); GraphicsUtil.CheckError("Load - Fonts"); PassLoadScreen(); CWindow.FontSets = FontSets; CWindow.GLFonts = Fonts; SysConsole.Output(OutputType.CLIENTINIT, "Loading general graphics settings..."); CVars.r_vsync.OnChanged += OnVsyncChanged; OnVsyncChanged(CVars.r_vsync, EventArgs.Empty); CVars.r_cloudshadows.OnChanged += OnCloudShadowChanged; CVars.r_transpll.OnChanged += OnLLChanged; OnLLChanged(CVars.r_transpll, EventArgs.Empty); GraphicsUtil.CheckError("Load - General Graphics"); SysConsole.Output(OutputType.CLIENTINIT, "Loading UI engine..."); UIConsole.InitConsole(); // TODO: make this non-static InitChatSystem(); PassLoadScreen(); GraphicsUtil.CheckError("Load - UI"); SysConsole.Output(OutputType.CLIENTINIT, "Preparing rendering engine..."); InitRendering(); GraphicsUtil.CheckError("Load - Rendering"); SysConsole.Output(OutputType.CLIENTINIT, "Loading particle effect engine..."); Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) }; SysConsole.Output(OutputType.CLIENTINIT, "Preparing mouse and keyboard handlers..."); KeyHandler.Init(); Gamepad = new GamePadHandler(); Gamepad.Init(this); PassLoadScreen(); GraphicsUtil.CheckError("Load - Keyboard/mouse"); SysConsole.Output(OutputType.CLIENTINIT, "Building the sound system..."); Sounds.Init(Engine); GraphicsUtil.CheckError("Load - Sound"); SysConsole.Output(OutputType.CLIENTINIT, "Building game world..."); BuildWorld(); PassLoadScreen(); GraphicsUtil.CheckError("Load - World"); SysConsole.Output(OutputType.CLIENTINIT, "Preparing networking..."); Network = new NetworkBase(this); RegisterDefaultEntityTypes(); GraphicsUtil.CheckError("Load - Net"); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Loading Voxel computer..."); try { VoxelComputer = new VoxelComputeEngine(); VoxelComputer.Init(this); } catch (Exception ex) { SysConsole.Output(ex); } PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Playing background music..."); BackgroundMusic(); CVars.a_musicvolume.OnChanged += OnMusicVolumeChanged; CVars.a_musicpitch.OnChanged += OnMusicPitchChanged; CVars.a_music.OnChanged += OnMusicChanged; CVars.a_echovolume.OnChanged += OnEchoVolumeChanged; OnEchoVolumeChanged(null, null); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Setting up screens..."); TheMainMenuScreen = new MainMenuScreen(this); TheGameScreen = new GameScreen(this); TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this); TheLoadScreen = new LoadScreen(this); CScreen = TheMainMenuScreen; SysConsole.Output(OutputType.CLIENTINIT, "Trying to grab RawGamePad..."); try { RawGamePad = new XInput(); } catch (Exception ex) { SysConsole.Output(OutputType.CLIENTINIT, "Failed to grab RawGamePad: " + ex.Message); } SysConsole.Output(OutputType.CLIENTINIT, "Preparing inventory..."); InitInventory(); PassLoadScreen(); SysConsole.Output(OutputType.CLIENTINIT, "Creating sky..."); CreateSkyBox(); SysConsole.Output(OutputType.CLIENTINIT, "Requesting a menu server..."); LocalServer?.ShutDown(); LocalServer = new Server(28009) { IsMenu = true }; // TODO: Grab first free port? Object locky = new Object(); bool ready = false; Schedule.StartAsyncTask(() => { LocalServer.StartUp("menu", () => { lock (locky) { ready = true; } }); }); while (true) { lock (locky) { if (ready) { break; } } PassLoadScreen(); Thread.Sleep(50); } SysConsole.Output(OutputType.CLIENTINIT, "Connecting to a menu server..."); Network.LastConnectionFailed = false; Network.Connect("localhost", "28009", true, null); // TODO: Grab accurate local IP? Stopwatch sw = new Stopwatch(); sw.Start(); bool annc = false; while (true) { if (Network.LastConnectionFailed) { SysConsole.Output(OutputType.CLIENTINIT, "Failed to connect to menu server! Failing!"); Window.Close(); return; } if (Network.IsAlive) { break; } sw.Stop(); long ms = sw.ElapsedMilliseconds; sw.Start(); if (ms > 10000 && !annc) { annc = true; SysConsole.Output(OutputType.WARNING, "Taking weirdly long, did something fail?!"); } if (ms > 20000) { SysConsole.Output(OutputType.CLIENTINIT, "Timed out while trying to connect to menu server! Failing!"); Window.Close(); return; } PassLoadScreen(); Thread.Sleep(50); } SysConsole.Output(OutputType.CLIENTINIT, "Showing main menu..."); ShowMainMenu(); GraphicsUtil.CheckError("Load - Final"); SysConsole.Output(OutputType.CLIENTINIT, "Ready and looping!"); }
public static TextureBlock Fill(this TextureBlock block, Color color) { block.Texture.DrawRectangle(new Rect(block.X, block.Y, block.Width, block.Height), color); return(block); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); TextureBlock block = (TextureBlock)target; MeshFilter meshFilter = block.GetComponent <MeshFilter>(); MeshRenderer meshRenderer = block.GetComponent <MeshRenderer>(); BezierCurve curve = block.GetComponent <BezierCurve>(); Mesh mesh = new Mesh(); mesh.name = "Mesh"; int vertsInRow = block.widthSegments + 1; int vertsInCol = block.heightSegments + 1; int numIndices = block.widthSegments * block.heightSegments * TextureBlock.VERTS_IN_TRIANGLE * TextureBlock.TRIS_PER_QUAD; if (block.twoSided) { numIndices *= 2; } int numVertices = vertsInRow * vertsInCol; Vector3[] vertices = new Vector3[numVertices]; Vector2[] uvs = new Vector2[numVertices]; int[] indices = new int[numIndices]; Vector4[] tangents = new Vector4[numVertices]; Vector4 tangent = new Vector4(1f, 0f, 0f, -1f); int index = 0; float uvFactorX = 1.0f / block.widthSegments; float uvFactorY = 1.0f / block.heightSegments; float segmentHeight = block.height / block.heightSegments; //generate vertices for (int y = 0; y < vertsInCol; y++) { float uvX = 0; for (int x = 0; x < vertsInRow; x++) { Vector3 pt = curve.GetLocalPoint((float)x / (float)block.widthSegments); vertices[index] = new Vector3(pt.x, pt.y + y * segmentHeight, pt.z); tangents[index] = tangent; if (x > 0) { uvX += uvFactorX /*Vector3.Distance(vertices[index], vertices[index - 1]) */ /*/ block.blockMaterial.textureLength * /; } float newUvX = block.flipImageX ? (1 - uvX) : uvX; uvs[index++] = new Vector2(newUvX, y * uvFactorY); } } index = 0; //generate triangle indices for (int y = 0; y < block.heightSegments; y++) { for (int x = 0; x < block.widthSegments; x++) { indices[index] = (y * vertsInRow) + x; indices[index + 1] = ((y + 1) * vertsInRow) + x; indices[index + 2] = (y * vertsInRow) + x + 1; indices[index + 3] = ((y + 1) * vertsInRow) + x; indices[index + 4] = ((y + 1) * vertsInRow) + x + 1; indices[index + 5] = (y * vertsInRow) + x + 1; index += TextureBlock.VERTS_IN_TRIANGLE * TextureBlock.TRIS_PER_QUAD; } if (block.twoSided) { for (int x = 0; x < block.widthSegments; x++) { indices[index] = (y * vertsInRow) + x; indices[index + 1] = (y * vertsInRow) + x + 1; indices[index + 2] = ((y + 1) * vertsInRow) + x; indices[index + 3] = ((y + 1) * vertsInRow) + x; indices[index + 4] = (y * vertsInRow) + x + 1; indices[index + 5] = ((y + 1) * vertsInRow) + x + 1; index += TextureBlock.VERTS_IN_TRIANGLE * TextureBlock.TRIS_PER_QUAD; } } } mesh.vertices = vertices; mesh.uv = uvs; mesh.triangles = indices; mesh.tangents = tangents; mesh.RecalculateNormals(); meshFilter.mesh = mesh; meshRenderer.material = block.blockMaterial; EditorUtility.SetDirty(block); }
public static TextureBlock Create(Texture2D tex, Rect uv) { TextureBlock tb = new TextureBlock(tex, uv); return tb; }
public static TextureBlock Create(Texture2D tex, Rect uv) { TextureBlock tb = new TextureBlock(tex, uv); return(tb); }
public TextureReplacedEventArgs(TextureBlock block, Material texture) { Block = block; Texture = texture; }