Пример #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject joe  = JObject.Load(reader);
            var     type = joe["type"].Value <string>();

            Node node;

            if (type == "request")
            {
                node = new RequestNode();
            }
            else if (type == "pack")
            {
                node = new PackNode();
            }
            else if (type == "script")
            {
                node = new ScriptNode();
            }
            else
            {
                throw new ZealotException("Could not deserialize node, unknown type");
            }
            serializer.Populate(joe.CreateReader(), node);
            return(node);
        }
Пример #2
0
        public void Process(ProcessPaymentEvent e, PackNode pack, [JoinAll] Optional <SelectedMethodNode> methodNodeOptional)
        {
            long amount = pack.xCrystalsPack.Amount;

            if (!pack.Entity.HasComponent <SpecialOfferComponent>())
            {
                amount = (long)Math.Round((double)(pack.goods.SaleState.AmountMultiplier * amount));
            }
            e.TotalAmount = amount + pack.xCrystalsPack.Bonus;
        }
Пример #3
0
		void UnityPack () {
			Texture2D[] texs = new Texture2D[nodes.Count];
			Rect[] rects = new Rect[nodes.Count];
			packedFontMap = new Texture2D( 1, 1 );
			for (int i = 0; i < nodes.Count; i++) {
				texs[i] = new Texture2D( (int) nodes[i].rect.width, (int) nodes[i].rect.height );
				texs[i].SetPixels( fontMap.GetPixels( (int) nodes[i].rect.x, (int) nodes[i].rect.y, (int) nodes[i].rect.width, (int) nodes[i].rect.height ) );
			}


			rects = packedFontMap.PackTextures( texs, packBuffer );
			for (int i = 0; i < nodes.Count; i++) {
				PackNode newNode = new PackNode( startPackNodeList[i] );
				newNode.ResultRect = rects[i];
				resultPackNodeList.Add( newNode );
			}


			byte[] bytes = packedFontMap.EncodeToPNG();
			System.IO.File.WriteAllBytes( packedfontMapPath, bytes );

			CharacterInfo[] OutCharacterInfo = new CharacterInfo[nodes.Count];
			for (int i = 0; i < resultPackNodeList.Count; i++) {
				Rect newUvRect = resultPackNodeList[i].ResultRect;
				if (resultPackNodeList[i].SameOrient) {
					if (resultPackNodeList[i].CI.flipped) {
						newUvRect.y = newUvRect.y + newUvRect.height;
						newUvRect.height = newUvRect.height * -1;
					} else {
						//The rect hasnt been rotated, and wasnt originally flipped anyway.
					}
				} else {
					if (resultPackNodeList[i].CI.flipped) {
						resultPackNodeList[i].CI.flipped = false;
					} else {
						newUvRect.y = newUvRect.y + newUvRect.height;
						newUvRect.height = newUvRect.height * -1;
						resultPackNodeList[i].CI.flipped = true;
						resultPackNodeList[i].CI.vert.width = resultPackNodeList[i].ResultRect.height;
						resultPackNodeList[i].CI.vert.height = resultPackNodeList[i].ResultRect.width * -1;
					}
				}

				resultPackNodeList[i].CI.uv = newUvRect;
				OutCharacterInfo[resultPackNodeList[i].CIIndex] = resultPackNodeList[i].CI;
			}

			packedFont.characterInfo = OutCharacterInfo;
			EditorUtility.SetDirty( packedFont );
			EditorApplication.SaveAssets();
			AssetDatabase.Refresh();

			packedFont.material.mainTexture = (Texture2D) AssetDatabase.LoadAssetAtPath( packedfontMapPath, typeof( Texture2D ) );
			Debug.Log( "Pack Complete, Result texture size: " + packedFontMap.width + "x" + packedFontMap.height + " = " + packedFontMap.width * packedFontMap.height + " Pixels" );
			Debug.Log( "Pack fits inside " + packMaxSizeX + "x" + packMaxSizeY + " = " + packMaxSizeX * packMaxSizeY + " Pixels, and contains " + resultPackNodeList.Count + " characters" );

		}
Пример #4
0
 public void UpdatePack(GoodsChangedEvent e, PackNode pack, [JoinAll] SingleNode <ShopXCrystalsComponent> shop)
 {
     shop.component.UpdatePackage(pack.Entity);
 }
Пример #5
0
		//get the top rect from the heap
		void GetFromHeap () {
			getPackNode = startPackNodeList[0];
			startPackNodeList[0] = startPackNodeList[startPackNodeList.Count - 1];
			startPackNodeList.RemoveAt( startPackNodeList.Count - 1 );
			CheckBelow( 0 );
		}
Пример #6
0
		//Start the Rect Packer according to the selected gui buttons
		void BeginPack () {
			System.DateTime TimeA = System.DateTime.Now;
			packComplete = false;
			if (packedFont == null) {

				packedFont = new Font();
				string path = AssetDatabase.GetAssetPath( font );
				path = path.Insert( path.IndexOf( ".fontsettings" ), "(Packed)" );
				AssetDatabase.CreateAsset( packedFont, path );


				SerializedObject SO = new SerializedObject( packedFont );
				SerializedProperty p = SO.FindProperty( "m_LineSpacing" );
				p.floatValue = font.lineHeight;
				SO.ApplyModifiedProperties();


				Material fontMaterial = new Material( defaultShader );
				path = AssetDatabase.GetAssetPath( font.material );
				path = path.Insert( path.IndexOf( ".mat" ), "(Packed)" );
				AssetDatabase.CreateAsset( fontMaterial, path );
				packedFont.material = fontMaterial;

				packedfontMapPath = AssetDatabase.GetAssetPath( fontMap );
				packedfontMapPath = packedfontMapPath.Insert( packedfontMapPath.LastIndexOf( "." ), "(Packed)" );
			}

			startPackNodeList = new List<PackNode>();
			resultPackNodeList = new List<PackNode>();
			anchors = new List<Vector2>();
			partitions = new List<Rect>();


			for (int i = 0; i < nodes.Count; i++) {
				PackNode newNode = new PackNode();
				newNode.CIIndex = i;
				if (nodes[i].ch == " ") {
					font.characterInfo[i].vert = new Rect( 0, 0, 1, 1 );
					nodes[i].rect.width = 1;
					nodes[i].rect.height = 1;
				}

				newNode.CI = font.characterInfo[i];
				newNode.StartRect = nodes[i].rect;
				newNode.ResultRect = newNode.StartRect;
				newNode.ResultRect.width += packBuffer;
				newNode.ResultRect.height += packBuffer;
				startPackNodeList.Add( newNode );
			}


			int Total = 0;
			for (int i = 0; i < startPackNodeList.Count; i++) {
				Total += (int) (startPackNodeList[i].ResultRect.width * startPackNodeList[i].ResultRect.height);
			}
			Total = (int) Mathf.Sqrt( Total );
			Total = NearestPOT( Total );
			packSizeX = packSizeY = Total;


			for (int i = 0; i < startPackNodeList.Count; i++) { //Sort rects according to toolbar choice
				switch (packSort) {
					case 0:
						startPackNodeList[i].Height = startPackNodeList[i].ResultRect.height;
						break;
					case 1:
						startPackNodeList[i].Height = startPackNodeList[i].ResultRect.width;
						startPackNodeList[i].ResultRect = new Rect( startPackNodeList[i].ResultRect.x, startPackNodeList[i].ResultRect.y, startPackNodeList[i].ResultRect.height, startPackNodeList[i].ResultRect.width );
						startPackNodeList[i].SameOrient = !startPackNodeList[i].SameOrient;
						break;
					case 2:
						if (startPackNodeList[i].ResultRect.height > startPackNodeList[i].ResultRect.width) {
							startPackNodeList[i].Height = startPackNodeList[i].ResultRect.height;
						} else {
							startPackNodeList[i].Height = startPackNodeList[i].ResultRect.width;
							startPackNodeList[i].ResultRect = new Rect( startPackNodeList[i].ResultRect.x, startPackNodeList[i].ResultRect.y, startPackNodeList[i].ResultRect.height, startPackNodeList[i].ResultRect.width );
							startPackNodeList[i].SameOrient = !startPackNodeList[i].SameOrient;
						}
						break;
					case 3:
						if (startPackNodeList[i].ResultRect.height > startPackNodeList[i].ResultRect.width) {
							startPackNodeList[i].Height = startPackNodeList[i].ResultRect.width;
							startPackNodeList[i].ResultRect = new Rect( startPackNodeList[i].ResultRect.x, startPackNodeList[i].ResultRect.y, startPackNodeList[i].ResultRect.height, startPackNodeList[i].ResultRect.width );
							startPackNodeList[i].SameOrient = !startPackNodeList[i].SameOrient;
						} else {
							startPackNodeList[i].Height = startPackNodeList[i].ResultRect.height;
						}
						break;
				}
			}

			if (packMethod != 4) {
				for (int i = startPackNodeList.Count - 1; i > 0; i--) {
					CheckAbove( i );
				}
			}

			switch (packMethod) { //Pack rects according to toolbar choice
				case 0:
					SimplePack();
					break;
				case 1:
					SwitchbackPack();
					break;
				case 2:
					PartitionPack();
					break;
				case 3:
					AnchorPack();
					break;
				case 4:
					UnityPack();
					break;
			}

			if (packMethod != 4)
				DrawResult( resultPackNodeList );
			packComplete = true;

			ViewReset();

			System.TimeSpan TimeB = System.DateTime.Now - TimeA;
			Debug.Log( "Time taken: " + string.Format( "{0:ss ffffff}", TimeB ) );
		}
Пример #7
0
			public PackNode ( PackNode f ) {
				this.CI = f.CI;
				this.CIIndex = f.CIIndex;
				this.StartRect = f.StartRect;
				this.ResultRect = f.ResultRect;
				this.Height = f.Height;
				this.SameOrient = f.SameOrient;
			}
Пример #8
0
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 public static void TreePack( List<Element> _elements, 
                               int _atlasWidth, 
                               int _atlasHeight, 
                               int _padding,
                               bool _allowRotate )
 {
     PackNode root = new PackNode( new Rect( 0,
                                             0,
                                             _atlasWidth,
                                             _atlasHeight ) );
     foreach ( Element el in _elements ) {
         Vector2? pos = root.Insert (el, _padding, _allowRotate);
         if (pos != null) {
             el.x = (int)pos.Value.x;
             el.y = (int)pos.Value.y;
         }
         else {
             // log warning but continue processing other elements
             throw new LayoutException( "Failed to layout atlas element " + el.id );
         }
     }
 }
Пример #9
0
        public Vector2? Insert( Element _el, int _padding, bool _allowRotate )
        {
            // when this node is already occupied (when it has children),
            // forward to child nodes recursively
            if (right != null) {
                Vector2? pos = right.Insert(_el, _padding, _allowRotate);
                if (pos != null)
                    return pos;
                return bottom.Insert(_el, _padding, _allowRotate);
            }

            // determine trimmed and padded sizes
            float elWidth = _el.rotatedWidth;
            float elHeight = _el.rotatedHeight;
            float paddedWidth = elWidth + _padding;
            float paddedHeight = elHeight + _padding;

            // trimmed element size must fit within current node rect
            if ( elWidth > rect.width || elHeight > rect.height ) {

                if ( _allowRotate == false )
                    return null;

                if ( elHeight > rect.width || elWidth > rect.height ) {
                    return null;
                }
                else {
                    _el.rotated = !_el.rotated;
                    elWidth = _el.rotatedWidth;
                    elHeight = _el.rotatedHeight;
                    paddedWidth = elWidth + _padding;
                    paddedHeight = elHeight + _padding;
                }
            }

            // create first child node in remaining space to the right, using elHeight
            // so that only other elements with the same height or less can be added there
            // (we do not use paddedHeight, because the padding area is reserved and should
            // never be occupied)
            right = new PackNode( new Rect ( rect.x + paddedWidth,
                                             rect.y,
                                             rect.width - paddedWidth,
                                             elHeight ) );

            // create second child node in remaining space at the bottom, occupying the entire width
            bottom = new PackNode( new Rect ( rect.x,
                                              rect.y + paddedHeight,
                                              rect.width,
                                              rect.height - paddedHeight ) );

            // return position where to put element
            return new Vector2( rect.x, rect.y );
        }