static public void VerifyLanguageCode(string code) { Dictionary <string, string> languageDict; CreateLanguageCodeMapping(); try { code = languageToCode [code]; } catch {} if (!allLanguages.TryGetValue(code, out languageDict)) { string stringsFile = PlanetUnityResourceCache.GetTextFile("Languages/" + code + "/Localizable.strings"); if (stringsFile == null) { // default to English in cases where stringsFile = PlanetUnityResourceCache.GetTextFile("Languages/en/Localizable.strings"); } if (stringsFile != null) { Dictionary <string, string> currentLanguage = new Dictionary <string, string> (); MatchCollection matches = Regex.Matches(stringsFile, "\"([^\"]+)\"\\s*=\\s*\"([^\"]+)\""); foreach (Match match in matches) { currentLanguage.Add(match.Groups [1].Value, match.Groups [2].Value); } allLanguages.Add(code, currentLanguage); } } }
public virtual void LoadImageWithResourcePath(string p) { resourcePath = p; if (image == null) { Debug.Log(" ********** ERROR: PUImage image is null!! **********"); return; } LoadSprite(p, PlanetUnityResourceCache.GetSprite(p, PlanetUnityOverride.ForceActualSprites)); }
static public PUGameObject LoadXML(string xmlPath, GameObject parent) { PUGameObject loadedGameObject = (PUGameObject)PlanetUnity2.loadXML(PlanetUnityResourceCache.GetAsset <TextAsset>(xmlPath).bytes, parent, null); #if UNITY_EDITOR if (planetUnityContainer != null) { foreach (Transform t in planetUnityContainer.GetComponentsInChildren <Transform>()) { t.gameObject.hideFlags = HideFlags.DontSave; } } #endif return(loadedGameObject); }
public virtual void LoadImageWithResourcePath(string p) { resourcePath = p; if (image == null) { Debug.Log(" ********** ERROR: PUImage image is null!! **********"); return; } image.sprite = PlanetUnityResourceCache.GetSprite(p); if (image.sprite != null) { Vector4 border = image.sprite.border; if (!border.x.Equals(0) || !border.y.Equals(0) || !border.z.Equals(0) || !border.w.Equals(0)) { image.type = Image.Type.Sliced; } } if (type != null) { if (type == PlanetUnity2.ImageType.filled) { image.type = Image.Type.Filled; } if (type == PlanetUnity2.ImageType.aspectFilled) { image.type = Image.Type.Filled; image.preserveAspect = true; } if (type == PlanetUnity2.ImageType.simple) { image.type = Image.Type.Simple; } if (type == PlanetUnity2.ImageType.sliced) { image.type = Image.Type.Sliced; } if (type == PlanetUnity2.ImageType.tiled) { image.type = Image.Type.Tiled; } } }
public override void gaxb_init() { base.gaxb_init(); if (title == null) { gameObject.name = "<ImageButton/>"; } button = gameObject.AddComponent <Button> (); if (pressedResourcePath != null || highlightedResourcePath != null || disabledResourcePath != null) { button.transition = Selectable.Transition.SpriteSwap; SpriteState states = button.spriteState; if (pressedResourcePath != null) { states.pressedSprite = PlanetUnityResourceCache.GetSprite(pressedResourcePath, PlanetUnityOverride.ForceActualSprites); } if (highlightedResourcePath != null) { states.highlightedSprite = PlanetUnityResourceCache.GetSprite(highlightedResourcePath, PlanetUnityOverride.ForceActualSprites); } if (disabledResourcePath != null) { states.disabledSprite = PlanetUnityResourceCache.GetSprite(disabledResourcePath, PlanetUnityOverride.ForceActualSprites); } button.spriteState = states; } if (onTouchUp != null) { PlanetUnityButtonHelper.SetOnTouchUp(this, button, onTouchUp); } if (onTouchDown != null) { PlanetUnityButtonHelper.SetOnTouchDown(this, button, onTouchDown); } }
public MeshHelper(int maxQuads, string texturePath, string shaderName) { quads = new MeshQuad[maxQuads]; mesh = new Mesh(); mesh.name = texturePath; mesh.subMeshCount = 0; vertices = new Vector3[maxQuads * 4]; normals = new Vector3[maxQuads * 4]; uv = new Vector2[maxQuads * 4]; uv2 = new Vector2[maxQuads * 4]; colors32 = new Color32[maxQuads * 4]; triangles = new int[maxQuads * 6]; for (int i = 0; i < maxQuads; i++) { triangles [i * 6 + 0] = i * 4 + 0; triangles [i * 6 + 1] = i * 4 + 1; triangles [i * 6 + 2] = i * 4 + 2; triangles [i * 6 + 3] = i * 4 + 2; triangles [i * 6 + 4] = i * 4 + 1; triangles [i * 6 + 5] = i * 4 + 3; } mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uv; mesh.uv2 = uv2; mesh.colors32 = colors32; mesh.triangles = triangles; gameObject = new GameObject(mesh.name, typeof(MeshRenderer), typeof(MeshFilter)); MeshFilter filter = (MeshFilter)gameObject.GetComponent(typeof(MeshFilter)); filter.mesh = mesh; gameObject.GetComponent <Renderer>().material = new Material(Shader.Find(shaderName)); gameObject.GetComponent <Renderer>().material.color = new Color(1, 1, 1, 1); gameObject.GetComponent <Renderer>().material.mainTexture = PlanetUnityResourceCache.GetTexture(texturePath); }
void Start() { // Check to see if this is an app resource, if so load it directly Texture2D localImage = PlanetUnityResourceCache.GetTexture(path); if (localImage != null) { RawImage rawImage = gameObject.AddComponent <RawImage> (); rawImage.texture = localImage; if (onComplete != null) { onComplete(new Vector2(rawImage.texture.width, rawImage.texture.height)); } GameObject.Destroy(this); return; } // Check to see if this is an app resource, if so load it directly Sprite localSprite = PlanetUnityResourceCache.GetSprite(path, true); if (localSprite != null) { Image image = gameObject.AddComponent <Image> (); image.sprite = localSprite; if (onComplete != null) { onComplete(image.sprite.rect.size); } GameObject.Destroy(this); return; } if (path.StartsWith("http://") || path.StartsWith("https://")) { www = new WWW(path); return; } www = new WWW("file://" + path); }
public virtual void LoadIntoPUGameObject(PUScrollRect parent, object data) { scrollRect = parent; cellData = data; string xmlPath = XmlPath(); if (xmlPath != null) { puGameObject = (PUGameObject)PlanetUnity2.loadXML(PlanetUnityResourceCache.GetAsset <TextAsset>(xmlPath).bytes, parent.contentObject, null); // Attach all of the PlanetUnity objects try { FieldInfo field = this.GetType().GetField("scene"); if (field != null) { field.SetValue(this, puGameObject); } puGameObject.PerformOnChildren(val => { PUGameObject oo = val as PUGameObject; if (oo != null && oo.title != null) { field = this.GetType().GetField(oo.title); if (field != null) { field.SetValue(this, oo); } } return(true); }); } catch (Exception e) { UnityEngine.Debug.Log("TableCell error: " + e); } try { // Attach all of the named GameObjects FieldInfo[] fields = this.GetType().GetFields(); foreach (FieldInfo field in fields) { if (field.FieldType == typeof(GameObject)) { GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject)); foreach (GameObject pObject in pAllObjects) { if (pObject.name.Equals(field.Name)) { field.SetValue(this, pObject); } } } } } catch (Exception e) { UnityEngine.Debug.Log("TableCell error: " + e); } } else { puGameObject = new PUGameObject(); puGameObject.SetFrame(0, 0, 0, 60, 0, 0, "bottom,left"); puGameObject.LoadIntoPUGameObject(parent); puGameObject.gameObject.transform.SetParent(parent.contentObject.transform, false); } puGameObject.parent = table; // We want to bridge all notifications to my scope; this allows developers to handle notifications // at the table cell level, or at the scene controller level, with ease NotificationCenter.addObserver(this, "*", puGameObject, (args, name) => { NotificationCenter.postNotification(scrollRect.Scope(), name, args); }); cellGameObject = puGameObject.gameObject; cellTransform = cellGameObject.transform as RectTransform; tableTransform = scrollRect.rectTransform; tableContentTransform = scrollRect.contentObject.transform as RectTransform; UpdateContents(); }
private void UpdatePositionTable() { Vector3 rectCenter = rectTransform.rect.center; Color[] pixelArray = null; Texture2D imageMask = null; if (imageMaskPath != null) { imageMask = PlanetUnityResourceCache.GetTexture(imageMaskPath); if (imageMask != null) { pixelArray = imageMask.GetPixels(); } } for (int i = 0; i < posMax; i++) { if (emitMode == PlanetUnity2.ParticleEmitMode.Edge) { float s = 0.5f; // add a random position around the edge of the quad switch (UnityEngine.Random.Range(0, 4)) { case 0: positionLUT [i] = new Vector3(UnityEngine.Random.Range(-s, s), 0.0f, -s); break; case 1: positionLUT [i] = new Vector3(UnityEngine.Random.Range(-s, s), 0.0f, s); break; case 2: positionLUT [i] = new Vector3(-s, 0.0f, UnityEngine.Random.Range(-s, s)); break; case 3: positionLUT [i] = new Vector3(s, 0.0f, UnityEngine.Random.Range(-s, s)); break; } } if (emitMode == PlanetUnity2.ParticleEmitMode.Fill) { // add a random position on the interior of the quad float s = 0.45f; positionLUT [i] = new Vector3( UnityEngine.Random.Range(-s, s), 0.0f, UnityEngine.Random.Range(-s, s) ); } if (emitMode == PlanetUnity2.ParticleEmitMode.Image) { // add a random position on the interior of the supplied image if (pixelArray == null) { float s = 0.5f; positionLUT [i] = new Vector3( UnityEngine.Random.Range(-s, s), 0.0f, UnityEngine.Random.Range(-s, s) ); } else { int bail = 500; while (bail-- > 0) { int x = UnityEngine.Random.Range(0, imageMask.width); int y = UnityEngine.Random.Range(0, imageMask.height); Color c = pixelArray [y * imageMask.width + x]; if (c.a >= 0.3f) { positionLUT [i] = new Vector3( ((float)x / (float)imageMask.width) - 0.5f, 0.0f, ((float)y / (float)imageMask.height) - 0.5f ); break; } } } } } }
public void LoadStoryFromMarkdown(string pathToMarkdown) { string markdownString = PlanetUnityResourceCache.GetTextFile(pathToMarkdown); // run the parser on the content Markdown md = new Markdown(); md.ExtraMode = true; StringBuilder currentString = new StringBuilder(); Block currentBlock = null; Stack <BlockType> listStack = new Stack <BlockType>(); Room currentRoom = null; Dialog currentDialog = null; Action CommitMarkdownBlock = () => { if (currentBlock == null) { return; } if (currentBlock.blockType == BlockType.p) { } if (currentBlock.blockType == BlockType.h1) { if (currentRoom != null) { AllRooms[currentRoom.hashtag] = currentRoom; } currentRoom = new Room(); currentRoom.hashtag = "#" + currentString.ToString(); } if (currentBlock.blockType == BlockType.ol_end) { currentRoom.responses.RemoveAt(currentRoom.responses.Count - 1); } if (currentBlock.blockType == BlockType.ol || currentBlock.blockType == BlockType.ol_li) { if (currentRoom != null) { currentDialog = new Dialog(); currentRoom.responses.Add(currentDialog); } } if (currentBlock.blockType == BlockType.dt) { if (currentRoom != null) { currentRoom.character = currentString.ToString(); } } if (currentBlock.blockType == BlockType.dd) { if (currentRoom != null) { currentRoom.text = currentString.ToString(); } } if (currentBlock.blockType == BlockType.h2) { if (currentRoom != null) { AllRooms[currentRoom.hashtag] = currentRoom; } currentRoom = null; Cutscene currentCutscene = new Cutscene(); string cutsceneNameCombined = currentString.ToString(); string[] parts = cutsceneNameCombined.Split("->".ToCharArray()); currentCutscene.hashtag = "##" + parts[0].Trim(); currentCutscene.room = parts[2].Trim(); AllRooms[currentCutscene.hashtag] = currentCutscene; } if (currentBlock.blockType == BlockType.h3) { } if (currentBlock.blockType == BlockType.h4) { } if (currentBlock.blockType == BlockType.h5) { } if (currentBlock.blockType == BlockType.h6) { } if (currentBlock.blockType == BlockType.hr) { } if (currentBlock.blockType == BlockType.quote) { } if (currentBlock.blockType == BlockType.quote_end) { } if (currentBlock.blockType == BlockType.ul) { listStack.Push(currentBlock.blockType); //mdStyle.Begin_UnorderedList(container); } if (currentBlock.blockType == BlockType.ul_end) { listStack.Pop(); //mdStyle.End_UnorderedList(container); } if (currentBlock.blockType == BlockType.ul_li) { //mdStyle.Create_UL_LI(container, currentString.ToString()); } if (currentBlock.blockType == BlockType.codeblock) { } if (currentBlock.blockType == BlockType.table_spec) { } }; Dictionary <string, LinkDefinition> definitions; string htmlTranslation = md.Transform(markdownString, out definitions, (block, token, tokenString) => { if (block != null) { //Debug.Log ("block: " + block.blockType + " :: " + block.Content); CommitMarkdownBlock(); currentBlock = block; currentString.Length = 0; } if (token != null) { //Debug.Log ("token: " + token.type); if (token.type == TokenType.img) { //mdStyle.Create_IMG(container, link.def.url, link.link_text); } if (token.type == TokenType.Text) { currentString.Append(tokenString, token.startOffset, token.length); } if (token.type == TokenType.code_span) { //mdStyle.Tag_Code(container, currentString, true); //currentString.Append(tokenString, token.startOffset, token.length); //mdStyle.Tag_Code(container, currentString, false); } if (token.type == TokenType.open_strong) { //mdStyle.Tag_Strong(container, currentString, true); } if (token.type == TokenType.close_strong) { //mdStyle.Tag_Strong(container, currentString, false); } if (token.type == TokenType.br) { //mdStyle.Tag_BreakingReturn(container, currentString); } if (token.type == TokenType.link) { LinkInfo link = token.data as LinkInfo; if (currentDialog != null) { currentDialog.room = link.def.url; currentDialog.text = "\"" + link.link_text + "\""; } } if (token.type == TokenType.open_em) { //mdStyle.Tag_Emphasis(container, currentString, true); } if (token.type == TokenType.close_em) { //mdStyle.Tag_Emphasis(container, currentString, false); } } }); if (currentRoom != null) { AllRooms[currentRoom.hashtag] = currentRoom; } //PrintAllRooms (); }
public override void gaxb_init() { gameObject = new GameObject("<Text/>", typeof(RectTransform)); canvasRenderer = gameObject.AddComponent <CanvasRenderer> (); text = gameObject.AddComponent <Text> (); if (onLinkClick != null || OnLinkClickAction != null || GlobalOnLinkClickAction != null) { gameObject.AddComponent <DetectTextClick> (); DetectTextClick script = gameObject.GetComponent <DetectTextClick> (); script.entity = this; } if (title == null && value != null) { gameObject.name = string.Format("\"{0}\"", value); } if (fontColor != null) { text.color = fontColor.Value; } if (font != null) { text.font = PlanetUnityResourceCache.GetFont(font); } else { text.font = PlanetUnityResourceCache.GetFont(PlanetUnityOverride.defaultFont()); } if (fontSize != null) { text.fontSize = (int)fontSize; } if (lineSpacing != null) { text.lineSpacing = lineSpacing.Value; } if (sizeToFit) { text.resizeTextForBestFit = true; } if (maxFontSize != null) { text.resizeTextMaxSize = maxFontSize.Value; } if (minFontSize != null) { text.resizeTextMinSize = minFontSize.Value; } if (vOverflow) { text.verticalOverflow = VerticalWrapMode.Overflow; } if (hOverflow) { text.horizontalOverflow = HorizontalWrapMode.Overflow; } if (fontStyle != null) { if (fontStyle == PlanetUnity2.FontStyle.bold) { text.fontStyle = FontStyle.Bold; } if (fontStyle == PlanetUnity2.FontStyle.italic) { text.fontStyle = FontStyle.Italic; } if (fontStyle == PlanetUnity2.FontStyle.normal) { text.fontStyle = FontStyle.Normal; } if (fontStyle == PlanetUnity2.FontStyle.boldAndItalic) { text.fontStyle = FontStyle.BoldAndItalic; } } if (alignment != null) { if (alignment == PlanetUnity2.TextAlignment.lowerCenter) { text.alignment = TextAnchor.LowerCenter; } if (alignment == PlanetUnity2.TextAlignment.lowerLeft) { text.alignment = TextAnchor.LowerLeft; } if (alignment == PlanetUnity2.TextAlignment.lowerRight) { text.alignment = TextAnchor.LowerRight; } if (alignment == PlanetUnity2.TextAlignment.middleCenter) { text.alignment = TextAnchor.MiddleCenter; } if (alignment == PlanetUnity2.TextAlignment.middleLeft) { text.alignment = TextAnchor.MiddleLeft; } if (alignment == PlanetUnity2.TextAlignment.middleRight) { text.alignment = TextAnchor.MiddleRight; } if (alignment == PlanetUnity2.TextAlignment.upperCenter) { text.alignment = TextAnchor.UpperCenter; } if (alignment == PlanetUnity2.TextAlignment.upperLeft) { text.alignment = TextAnchor.UpperLeft; } if (alignment == PlanetUnity2.TextAlignment.upperRight) { text.alignment = TextAnchor.UpperRight; } } if (value != null) { text.text = PlanetUnityStyle.ReplaceStyleTags(value); } text.material = new Material(Shader.Find("UI/Default Font")); }
public void LoadImageWithResourcePath(string p) { resourcePath = p; image.texture = PlanetUnityResourceCache.GetTexture(p); }
public void LoadTrackFile(int gameLevel) { int levelIdx = (gameLevel - 1) % 4; string levelFilePath = string.Format("Game/maps/map{0}", levelIdx); string trackString = PlanetUnityResourceCache.GetTextFile(levelFilePath); Sprite[] allSprites = Resources.LoadAll <Sprite>(Path.GetDirectoryName("Game/scenary/scenary")); int numScenary = allSprites.Length; int index = 0; foreach (char c in trackString) { if (c >= '0' && c <= '1') { int tileX = index % roadDimensions; int tileY = ((roadDimensions - 1) - index / roadDimensions); roadMap [tileX, tileY] = (byte)(c - '0'); index++; } else if (c >= '2' && c <= '9') { int tileX = index % roadDimensions; int tileY = ((roadDimensions - 1) - index / roadDimensions); roadMap [tileX, tileY] = (byte)((c - '0') + 2); index++; } else if (c == '?') { int tileX = index % roadDimensions; int tileY = ((roadDimensions - 1) - index / roadDimensions); roadMap [tileX, tileY] = (byte)(Random.Range(0, numScenary) + 2); index++; } } // Add random scenary for (int i = 0; i < 600; i++) { int randX = Random.Range(5, 95); int randY = Random.Range(5, 95); byte type = (byte)(Random.Range(0, numScenary) + 2); if (roadMap [randX, randY] == 0) { // Check all neighbors, we need grass all around us bool allGrass = true; for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (roadMap [randX + x, randY + y] != 0) { allGrass = false; } } } // I must be within 2 of a road bool hasRoad = false; for (int x = -2; x <= 2; x++) { for (int y = -2; y <= 2; y++) { if (roadMap [randX + x, randY + y] != 0) { hasRoad = true; } } } if (allGrass && hasRoad) { roadMap [randX, randY] = type; } } } }