void Awake() { //facesForRandom=new string[faces.Length]; facesTextures = new Dictionary <string, Texture>(); if (instance == null) { instance = this; int i = 0; foreach (var face in faces) { facesTextures.Add(face.name, face); //facesForRandom[i] = face.name; i++; } } }
private static T GetInner <T>(GraphicRequest req, HeadCoverage coverage) where T : Graphic, new() { string oldPath = req.path; string name = Path.GetFileNameWithoutExtension(oldPath); string newPath = MergedHairPath + name + "_" + coverage; req.path = newPath; if (AllGraphics.TryGetValue(req, out Graphic graphic)) { return((T)graphic); } // no graphics found, create => graphic = Activator.CreateInstance <T>(); // // Check if textures already present and readable, else create if (ContentFinder <Texture2D> .Get(req.path + "_back", false) != null) { graphic.Init(req); // graphic.MatFront.mainTexture = ContentFinder<Texture2D>.Get(newPath + "_front"); // graphic.MatSide.mainTexture = ContentFinder<Texture2D>.Get(newPath + "_side"); // graphic.MatBack.mainTexture = ContentFinder<Texture2D>.Get(newPath + "_back"); } else { req.path = oldPath; graphic.Init(req); Texture2D temptexturefront = graphic.MatFront.mainTexture as Texture2D; Texture2D temptextureside = graphic.MatSide.mainTexture as Texture2D; Texture2D temptextureback = graphic.MatBack.mainTexture as Texture2D; Texture2D temptextureside2 = (graphic as Graphic_Multi_Four)?.MatLeft.mainTexture as Texture2D; temptexturefront = FaceTextures.MakeReadable(temptexturefront); temptextureside = FaceTextures.MakeReadable(temptextureside); temptextureback = FaceTextures.MakeReadable(temptextureback); temptextureside2 = FaceTextures.MakeReadable(temptextureside2); // new mask textures if (coverage == HeadCoverage.UpperHead) { _maskTexFrontBack = FaceTextures.MaskTexUppherheadFrontBack; _maskTexSide = FaceTextures.MaskTexUpperheadSide; } else { _maskTexFrontBack = FaceTextures.MaskTexFullheadFrontBack; _maskTexSide = FaceTextures.MaskTexFullheadSide; } CutOutHair(ref temptexturefront, _maskTexFrontBack); CutOutHair(ref temptextureside, _maskTexSide); CutOutHair(ref temptextureback, _maskTexFrontBack); CutOutHair(ref temptextureside2, _maskTexSide); req.path = newPath; // if (!name.NullOrEmpty() && !File.Exists(req.path + "_front.png")) // { // byte[] bytes = temptexturefront.EncodeToPNG(); // File.WriteAllBytes(req.path + "_front.png", bytes); // byte[] bytes2 = temptextureside.EncodeToPNG(); // File.WriteAllBytes(req.path + "_side.png", bytes2); // byte[] bytes3 = temptextureback.EncodeToPNG(); // File.WriteAllBytes(req.path + "_back.png", bytes3); // } temptexturefront.Compress(true); temptextureside.Compress(true); temptextureback.Compress(true); temptextureside2.Compress(true); temptexturefront.mipMapBias = 0.5f; temptextureside.mipMapBias = 0.5f; temptextureback.mipMapBias = 0.5f; temptextureside2.mipMapBias = 0.5f; temptexturefront.Apply(false, true); temptextureside.Apply(false, true); temptextureback.Apply(false, true); temptextureside2.Apply(false, true); graphic.MatFront.mainTexture = temptexturefront; graphic.MatSide.mainTexture = temptextureside; graphic.MatBack.mainTexture = temptextureback; ((Graphic_Multi_Four)graphic).MatLeft.mainTexture = temptextureside2; // Object.Destroy(temptexturefront); // Object.Destroy(temptextureside); // Object.Destroy(temptextureback); } AllGraphics.Add(req, graphic); // } return((T)graphic); }
public BlockType(string name, FaceTextures textures = null, bool isSolid = true) { Name = name; FaceTextures = textures ?? new FaceTextures(); IsSolid = isSolid; }