コード例 #1
0
ファイル: NGUIStuffs.cs プロジェクト: kybird/PhoenixProject
	public static void CreateDynamic(string preName, PsdLayerToNGUI.Data data, 
		PsdLayerCommandParser.Control c)
	{
#if UNITY_3_5
#else
		if (data.trueTypeFont == null){
			Debug.LogError("True Type Font doens't set");
			return;
		}
		
		NGUIFontCreator.fontPrefabPath = preName + "_Font_" + c.fontSize + ".prefab";
		NGUISettings.ambigiousFont = data.trueTypeFont;
		NGUISettings.fontSize = c.fontSize;
#endif
	}
コード例 #2
0
	private static void SetLabelAppearance(UILabel label, PsdLayerCommandParser.Control c)
	{
		PsdLayerToNGUI.SetLabelAppearance(label, c, Vector3.zero);
	}
コード例 #3
0
	private static PsdLayerCommandParser.Control FindDynamicFontContainer(
		PsdLayerCommandParser.Control c)
	{
		if (c.fontSize > 0)
			return c;
		
		for (var i=0; i<c.sources.Count; ++i)
		{
			var src = c.sources[i];
			if (src.fontSize > 0)
				return src;
		}
		return null;
	}
コード例 #4
0
	private static bool UpdateNGUIAnimation(GameObject owner, PsdLayerCommandParser.Control c)
	{
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		if (Selection.activeGameObject == null)
			return false;
		
		var ani = Util.FindComponent<PsdLayerSpriteAnimation>(Selection.activeGameObject);
		if (ani != null && c.children.Count > 0)
		{
			var names = new List<string>();
			for (var i=0; i<c.children.Count; ++i){
				names.Add(c.children[i].fullName);
			}
			names.Sort();
			ani.SetSprites(names.ToArray());
			ani.fps = c.fps;
			
			PsdLayerToNGUI.MoveAndResize(ani.gameObject, c.children[0]);
			return true;
		}
		return false;
	}
コード例 #5
0
	private static bool UpdateVirtualView(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"virtualview", new string[]{
			"virtualview.bg", ".item", 
			".vscrollbar.bg", ".vscrollbar.fg", 
			".hscrollbar.bg", ".hscrollbar.fg"
		});
		
		var bg = arr[0];
		var item = arr[1];
		//**todo
//		var vscrollbar_bg = arr[2];
//		var vscrollbar_fg = arr[3];
//		var hscrollbar_bg = arr[4];
//		var hscrollbar_fg = arr[5];
		
		if (bg != null)
		{
			owner = Util.FindGameObjectRecursively(owner, bg.name, true);
			if (owner == null)
				return false;
			
			var bgSprite = Util.FindGameObjectRecursively(owner, "Bg", true);
			if (bgSprite == null)
				return false;
			{
				PsdLayerToNGUI.MoveAndResize(bgSprite, bg);
			}
			
			//**todo
//			var vscrollbar = null as UIScrollBar;
//			if (vscrollbar_bg != null || vscrollbar_fg != null)
//			{
//				NGUIWidgetCreator.mScrollBG = 
//					vscrollbar_bg != null ? vscrollbar_bg.fullName : vscrollbar_fg.fullName;
//				
//				NGUIWidgetCreator.mScrollFG = 
//					vscrollbar_fg != null ? vscrollbar_fg.fullName : vscrollbar_bg.fullName;
//				
//				NGUIWidgetCreator.CreateScrollBar(owner);
//				
//				vscrollbar = Util.FindComponent<UIScrollBar>(Selection.activeGameObject);
//				vscrollbar.direction = UIScrollBar.Direction.Vertical;
//			}
//			if (vscrollbar != null)
//			{
//				PsdLayerToNGUI.MoveAndResize(vscrollbar.gameObject, vscrollbar_bg);
//				
//				var go = vscrollbar.gameObject;
//				var c2 = vscrollbar_bg;
//				var x = (float)c2.area.left;
//				var y = (float)c2.area.top;
//				{
//					x -= (float)targetWidth/2f;
//					x += (float)c2.area.width/2f;
//					y -= (float)targetHeight/2f;
//					
//					var pos = new Vector3(Mathf.RoundToInt(x), Mathf.RoundToInt(-y), 0);
//					pos.z = go.transform.localPosition.z;
//					go.transform.localPosition = pos;
//				}
//			}
//			
//			var hscrollbar = null as UIScrollBar;
//			if (hscrollbar_bg != null || hscrollbar_fg != null)
//			{
//				NGUIWidgetCreator.mScrollBG = 
//					hscrollbar_bg != null ? hscrollbar_bg.fullName : hscrollbar_fg.fullName;
//				
//				NGUIWidgetCreator.mScrollFG = 
//					hscrollbar_fg != null ? hscrollbar_fg.fullName : hscrollbar_bg.fullName;
//				
//				NGUIWidgetCreator.CreateScrollBar(owner);
//				
//				hscrollbar = Util.FindComponent<UIScrollBar>(Selection.activeGameObject);
//				hscrollbar.direction = UIScrollBar.Direction.Horizontal;
//			}
//			if (hscrollbar != null)
//			{
//				PsdLayerToNGUI.MoveAndResize(hscrollbar.gameObject, hscrollbar_bg);
//				
//				var go = hscrollbar.gameObject;
//				var c2 = hscrollbar_bg;
//				var x = (float)c2.area.left;
//				var y = (float)c2.area.top;
//				{
//					x -= (float)targetWidth/2f;
//					y -= (float)targetHeight/2f;
//					y += (float)c2.area.height/2f;
//					
//					var pos = new Vector3(Mathf.RoundToInt(x), Mathf.RoundToInt(-y), 0);
//					pos.z = go.transform.localPosition.z;
//					go.transform.localPosition = pos;
//				}
//			}
			
			var view = Util.FindComponent<PsdLayerVirtualView>(owner);
			if (view == null)
				return false;
			{
				view.bg = bgSprite.transform;
				
				var box = Util.FindComponent<BoxCollider>(owner, true);
				box.center = bgSprite.transform.localPosition;
				box.size = bgSprite.transform.localScale;
			}
			
			var panel = Util.FindComponent<UIPanel>(owner);
			if (panel == null)
				return false;
			{
				panel.depth = PsdLayerToNGUI.data.nguiPanelDepth++;
				panel.clipping = UIDrawCall.Clipping.SoftClip;
				panel.baseClipRegion = new Vector4(
					bgSprite.transform.localPosition.x, 
					bgSprite.transform.localPosition.y, bg.area.width, bg.area.height);
			}
			
			//**todo
//			view.verticalScrollBar = vscrollbar;
//			view.horizontalScrollBar = hscrollbar;
			
			if (item != null)
			{
				var itemGo = Util.FindGameObject(view.gameObject, "Item", true);
				
				foreach (var child in item.children)
				{
					if (!UpdateNGUI(itemGo, child))
						CreateNGUI(itemGo, child);
				}
				view.item = itemGo.transform;
				
				Util.SetXYCenterAmongChildren(itemGo);
			}
			Selection.activeGameObject = view.gameObject;
		}
		else
		{
			return false;
		}
		
		return true;
	}
コード例 #6
0
	private static bool UpdateNGUILabel(GameObject owner, PsdLayerCommandParser.Control c)
	{
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		if (Selection.activeGameObject == null)
			return false;
		
		var label = Util.FindComponent<UILabel>(Selection.activeGameObject);
		if (label != null)
			PsdLayerToNGUI.SetLabelAppearance(label, c);
		else
			return false;
		
		return true;
	}
コード例 #7
0
	private static bool UpdateNGUIToggle(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"checkbox,toggle", new string[]{".normal", ".checked", ".label"});

		var normal = arr[0];
		var check = arr[1];
		var label = arr[2];
		
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		if (Selection.activeGameObject == null)
			return false;
		var cb = Util.FindComponent<UIToggle>(Selection.activeGameObject);
		
		if (normal != null)
		{
			if (cb != null)
			{
				var btn = Util.FindComponent<UIButton>(cb);
				{
					Util.FindComponent<UISprite>(btn.tweenTarget).spriteName = normal.fullName;
				}
				(cb.activeSprite as UISprite).spriteName = check != null ? check.fullName : normal.fullName;
			}
			else
				return false;
		}
		else
		{
			return false;
		}
		
		PsdLayerToNGUI.SetButtonAppearance(Selection.activeGameObject, normal, null, true);
		
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label);
		
		return true;
	}
コード例 #8
0
	private static bool UpdateNGUIButton(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"button", new string[]{".normal", ".hover", ".pressed", ".label"});

		var normal = arr[0];
		var hover = arr[1];
		var push = arr[2];
		var label = arr[3];
		
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		if (Selection.activeGameObject == null)
			return false;
		var ib = Util.FindComponent<UIImageButton>(Selection.activeGameObject);
		var b = Util.FindComponent<UIButton>(Selection.activeGameObject);
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		
		if (normal != null && push  != null)
		{
			if (ib != null)
			{
				ib.normalSprite = normal.fullName;
				ib.hoverSprite = hover == null ? normal.fullName : hover.fullName;
				ib.pressedSprite = push.fullName;
			}
			else if (b != null && b.tweenTarget != null)
			{
				Util.FindComponent<UISprite>(b.tweenTarget).spriteName = normal.fullName;
			}
			else
				return false;
		}
		else if (normal != null)
		{
			if (ib != null)
			{
				ib.normalSprite = normal.fullName;
				ib.hoverSprite = hover == null ? normal.fullName : hover.fullName;
				ib.pressedSprite = hover == null ? normal.fullName : hover.fullName;
			}
			else if (b != null && b.tweenTarget != null)
			{
				var spr = Util.FindComponent<UISprite>(b.tweenTarget);
				if (spr != null)
					spr.spriteName = normal.fullName;
			}
			else
				return false;
			
			if (uilabel != null && normal.type == PsdLayerCommandParser.ControlType.LabelButton)
			{
				label = normal;
			}
		}
		else
		{
			return false;
		}
		
		PsdLayerToNGUI.SetButtonAppearance(Selection.activeGameObject, normal, uilabel, true);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label);
		
		return true;
	}
コード例 #9
0
	private static bool CreateNGUIComboBox(GameObject owner, PsdLayerCommandParser.Control c)
	{
		if (NGUISettings.ambigiousFont == null)
			return false;
		
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"combobox", new string[]{".bg", ".bar", ".listbg", ".label"});

		var bg = arr[0];
		var bar = arr[1];
		var listbg = arr[2];
		var label = arr[3];
		
		if (bg != null)
		{
			NGUIWidgetCreator.mListBG = bg.fullName;
			NGUIWidgetCreator.mListFG = bar == null ? bg.fullName : bar.fullName;
			NGUIWidgetCreator.mListHL = listbg == null ? bg.fullName : listbg.fullName;
			NGUIWidgetCreator.CreatePopup(owner, true);
		}
		else
		{
			return false;
		}
		
		PsdLayerToNGUI.SetButtonAppearance(Selection.activeGameObject, bg, null, true);
		
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label);
		{
			var spr = Util.FindComponent<UISprite>(Selection.activeGameObject);
			uilabel.width = (int)spr.transform.localScale.x;
			uilabel.transform.localPosition = Vector3.zero;
		}
		
		var p = Util.FindComponent<UIPopupList>(Selection.activeGameObject);
		p.highlightColor = Color.gray;
		if (label != null)
		{
			p.textColor = label.color;
			if (!string.IsNullOrEmpty(label.text))
			{
				p.items.Clear();
				var lines = label.text.Split('\n');
				foreach (var line in lines)
				{
					if (!string.IsNullOrEmpty(line))
						p.items.Add(line);
				}
			}
		}
		return true;
	}
コード例 #10
0
	private static bool CreateNGUIButton(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"button", new string[]{".normal", ".hover", ".pressed", ".label"});

		var normal = arr[0];
		var hover = arr[1];
		var push = arr[2];
		var label = arr[3];
		
		if (normal != null && push  != null)
		{
			NGUIWidgetCreator.mImage0 = normal.fullName;
			NGUIWidgetCreator.mImage1 = hover == null ? normal.fullName : hover.fullName;
			NGUIWidgetCreator.mImage2 = push.fullName;
			NGUIWidgetCreator.CreateImageButton(owner);
		}
		else if (normal != null && c.type == PsdLayerCommandParser.ControlType.Button)
		{
			NGUIWidgetCreator.mButton = normal.fullName;
			NGUIWidgetCreator.CreateButton(owner);
		}
		else if (c.type == PsdLayerCommandParser.ControlType.LabelButton)
		{
			NGUIWidgetCreator.mButton = normal.fullName;
			NGUIWidgetCreator.CreateButton(owner);
			label = normal;
		}
		else
		{
			return false;
		}
		
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		PsdLayerToNGUI.SetButtonAppearance(Selection.activeGameObject, normal, uilabel, true);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label);
		
		return true;
	}
コード例 #11
0
	private static bool CreateNGUISprite(GameObject owner, PsdLayerCommandParser.Control c)
	{
		PsdLayerToNGUI.SetSlicedSprite(c.fullName, c.sliceArea);
		NGUIWidgetCreator.CreateSprite(owner, c.fullName, c.sliceArea != null );
		return true;
	}
コード例 #12
0
	private static bool CreateNGUI(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var succeeded = false;
		var moveAndResize = true;
		
		// try to create dynamic font
		
		var extractor = PsdLayerToNGUI.data.currentExtractor;
		if (PsdLayerToNGUI.data.fontType == Data.FontType.Dynamic && extractor != null)
		{
			var dynamicFontContainer = PsdLayerToNGUI.FindDynamicFontContainer(c);
			if (dynamicFontContainer != null && dynamicFontContainer.fontSize > 0)
			{
				var currentPath = PsdLayerToNGUI.CurrentPath;
				var name = extractor.PsdFileName.Substring(0, extractor.PsdFileName.Length - 4);
				NGUIFontCreator.CreateDynamic(currentPath + name, PsdLayerToNGUI.data, dynamicFontContainer);
			}
		}
		
		switch (c.type)
		{
		case PsdLayerCommandParser.ControlType.Container:
		case PsdLayerCommandParser.ControlType.Panel:
		case PsdLayerCommandParser.ControlType.SpriteFont:
			{
				var gg = Util.CreateEmptyGameObject(owner);
				
				if (c.type == PsdLayerCommandParser.ControlType.SpriteFont)
				{
					gg.AddComponent<PsdLayerSpriteFont>();
				}
				else if (c.type == PsdLayerCommandParser.ControlType.Panel)
				{
					var panel = gg.AddComponent<UIPanel>();
					panel.depth = PsdLayerToNGUI.data.nguiPanelDepth++;
				}
				
				foreach (var c2 in c.children)
				{
					CreateNGUI(gg, c2);
				}
				
				Util.SetXYCenterAmongChildren(gg);
				Selection.activeGameObject = gg;
			}
			succeeded = true;
			moveAndResize = false;
			break;

		case PsdLayerCommandParser.ControlType.Button:
		case PsdLayerCommandParser.ControlType.LabelButton:
			succeeded = CreateNGUIButton(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.Toggle:
			succeeded = CreateNGUIToggle(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.ComboBox:
			succeeded = CreateNGUIComboBox(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.Input:
			succeeded = CreateNGUIEditBox(owner, c, false);
			break;
			
		case PsdLayerCommandParser.ControlType.Password:
			succeeded = CreateNGUIEditBox(owner, c, true);
			break;
			
		case PsdLayerCommandParser.ControlType.Label:
			succeeded = CreateNGUILabel(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.VScrollBar:
			succeeded = CreateNGUIScrollBar(owner, c, true);
			break;
			
		case PsdLayerCommandParser.ControlType.HScrollBar:
			succeeded = CreateNGUIScrollBar(owner, c, false);
			break;
			
		case PsdLayerCommandParser.ControlType.ScrollView:
			succeeded = CreateNGUIScrollView(owner, c);
			moveAndResize = false;
			break;
			
		case PsdLayerCommandParser.ControlType.VirtualView:
			succeeded = CreateVirtualView(owner, c);
			moveAndResize = false;
			break;
			
		case PsdLayerCommandParser.ControlType.Texture:
			succeeded = CreateTexture(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.SpriteAnimation:
			succeeded = CreateNGUIAnimation(owner, c);
			moveAndResize = false;
			break;

		case PsdLayerCommandParser.ControlType.Script:
			break;
			
		default:
			succeeded = CreateNGUISprite(owner, c);
			break;
		}
		
		if (succeeded)
		{
			var go = Selection.activeGameObject;
			go.name = c.name;
			
			for (var i=0; i<c.sources.Count; ++i)
			{
				if (c.sources[i].type == PsdLayerCommandParser.ControlType.Script)
				{
					var userScript = go.AddComponent<PsdLayerUserScript>();
					userScript.data = c.sources[i].text;
				}
			}
			
			if (moveAndResize)
			{
				PsdLayerToNGUI.MoveAndResize(go, c);
			}
		}
		return succeeded;
	}
コード例 #13
0
	private static void CreateNGUIs(GameObject rootGo, GameObject owner,
		string psdFileName, List<PsdLayerExtractor.Layer> layers)
	{
		if (!PsdLayerToNGUI.data.createControls)
			return;
		
		var root = Util.FindComponent<UIRoot>(rootGo);
		{
			root.manualHeight = 
			root.maximumHeight = 
			root.minimumHeight = PsdLayerToNGUI.data.targetHeight;
		}
		var anchor = Util.FindComponent<UIAnchor>(root);
		if (anchor != null)
		{
			anchor.side = UIAnchor.Side.Center;
		}
		
		var pa = new PsdLayerCommandParser();
		pa.Parse(psdFileName, layers);

		foreach (var c in pa.root.children)
		{
			PsdLayerToNGUI.CreateNGUI(owner, c);
		}
	}
コード例 #14
0
	private static void MoveAndResize(GameObject go, PsdLayerCommandParser.Control c)
	{
		// set depth and init
		
		var widgets = Util.FindComponents<UIWidget>(go);
		if (widgets != null)
		{
			foreach (var widget in widgets)
			{
				widget.depth = PsdLayerToNGUI.data.nguiDepth++;
				widget.pivot = UIWidget.Pivot.Center;
				widget.cachedTransform.localPosition = Vector3.zero;
			}
		}
		
		// set size
		
		var thisWidget = go.GetComponent<UIWidget>();
		var w = (float)c.area.width;
		var h = (float)c.area.height;
		{
			var sprs = Util.FindComponents<UISprite>(go);
			if (sprs != null)
			{
				foreach (var spr in sprs)
				{
					spr.width = Mathf.RoundToInt(w);
					spr.height = Mathf.RoundToInt(h);
				}
			}
			
			if (c.type != PsdLayerCommandParser.ControlType.VirtualView)
			{
				var collider = Util.FindComponent<BoxCollider>(go);
				if (collider != null)
				{
					var z = 0f;
					if (NGUIRootCreator.camType == UICreateNewUIWizard.CameraType.Simple2D)
						z = collider.center.z;
					
					collider.center = new Vector3(0, 0, Mathf.RoundToInt(z));
					collider.size = new Vector3(
						Mathf.RoundToInt(w), 
						Mathf.RoundToInt(h), 1);
				}
			}
			
			if (c.hasBoxCollider)
			{
				var label = Util.FindComponent<UILabel>(go);
				if (label != null)
				{
					Util.FindComponent<BoxCollider>(go, true);
				}
			
				var sprite = Util.FindComponent<UISprite>(go);
				if (sprite != null)
				{
					var box = Util.FindComponent<BoxCollider>(go, true);
					box.center = new Vector3(
						Mathf.RoundToInt(box.center.x), 
						Mathf.RoundToInt(box.center.y), 0.1f); // in case
					box.size = new Vector3(
						Mathf.RoundToInt(w), 
						Mathf.RoundToInt(h), 1);
				}
			}
			
			if (c.type == PsdLayerCommandParser.ControlType.Texture)
			{
				var tex = Util.FindComponent<UITexture>(go);
				if (tex != null)
				{
					tex.width = Mathf.RoundToInt(w);
					tex.height = Mathf.RoundToInt(h);
				}
			}
		}
		if (thisWidget as UILabel != null)
		{
			thisWidget.MakePixelPerfect();
		}
		
		// set position
		
		var x = (float)c.area.left;
		var y = (float)c.area.top;
		{
			x -= (float)PsdLayerToNGUI.data.targetWidth * 0.5f;
			y -= (float)PsdLayerToNGUI.data.targetHeight * 0.5f;
			x += (float)w * 0.5f;
			y += (float)h * 0.5f;
		}
		
		var parent = go.transform.parent;
		var root = Util.ClosestComponent<UIRoot>(go);
		
		var pos = new Vector3(Mathf.Round(x), Mathf.Round(-y), 0);
		pos.z = 0;
		
		go.transform.parent = root.transform;
		go.transform.localPosition = pos;
		go.transform.parent = parent;
		
		// set sprite align

		if (c.type == PsdLayerCommandParser.ControlType.Sprite)
		{
			var spr2 = Util.FindComponent<UISprite>(go);
			if (spr2 != null)
			{
				spr2.pivot = (UIWidget.Pivot)c.align;
			}
		}
		
		// set label align
		
		var labels = Util.FindComponents<UILabel>(go);
		foreach (var label in labels)
		{
			foreach (var src in c.sources)
			{
				if (src.type == PsdLayerCommandParser.ControlType.Label || 
				    src.type == PsdLayerCommandParser.ControlType.LabelButton)
				{
					label.pivot = (UIWidget.Pivot)src.align;
					break;
				}
			}
		}
	}
コード例 #15
0
	private static void SetLabelAppearance(UILabel label, PsdLayerCommandParser.Control c, Vector3 labelSize)
	{
		if (label == null)
			return;
		
		if (c != null)
		{
			// try to create dynamic font
			
			var extractor = PsdLayerToNGUI.data.currentExtractor;
			if (PsdLayerToNGUI.data.fontType == Data.FontType.Dynamic && extractor != null)
			{
				if (c.fontSize > 0)
				{
					var currentPath = PsdLayerToNGUI.CurrentPath;
					var name = extractor.PsdFileName.Substring(0, extractor.PsdFileName.Length - 4);
					NGUIFontCreator.CreateDynamic(currentPath + name, PsdLayerToNGUI.data, c);
				}
			}
			
			label.ambigiousFont = NGUISettings.ambigiousFont;
			
			if (c.bold)
			{
				label.effectStyle = UILabel.Effect.Outline;
				label.effectColor = new Color(c.color.r, c.color.g, c.color.b, 0.8f);
			}
			
			label.text = c.text;
			label.color = c.color;
			label.height = Mathf.RoundToInt(c.area.height);
			label.fontSize = c.fontSize;
			
			if (labelSize != Vector3.zero){
				label.width = Mathf.RoundToInt(labelSize.x * 0.98f);
			}
			else{
				label.width = Mathf.RoundToInt(c.area.width);
			}
		}
		else
		{
			label.text = "";
			label.color = Color.black;
		}
	}
コード例 #16
0
	private static bool UpdateNGUI(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var succeeded = false;
		var moveAndResize = true;
		
		switch (c.type)
		{
		case PsdLayerCommandParser.ControlType.Container:
		case PsdLayerCommandParser.ControlType.Panel:
		case PsdLayerCommandParser.ControlType.SpriteFont:
			{
				var gg = Util.FindGameObjectRecursively(owner, c.name, true);
				if (gg == null){
					gg = Util.CreateEmptyGameObject(owner);
				}
				
				if (c.type == PsdLayerCommandParser.ControlType.SpriteFont)
				{
					Util.FindComponent<PsdLayerSpriteFont>(gg, true);
				}
				else if (c.type == PsdLayerCommandParser.ControlType.Panel)
				{
					var panel = Util.FindComponent<UIPanel>(gg, true);
					panel.depth = PsdLayerToNGUI.data.nguiPanelDepth++;
				}
				
				foreach (var c2 in c.children)
				{
					if (!UpdateNGUI(gg, c2)){
						CreateNGUI(gg, c2);
					}
				}
				
				Util.SetXYCenterAmongChildren(gg);
				Selection.activeGameObject = gg;
			}
			succeeded = true;
			moveAndResize = false;
			break;
			
		case PsdLayerCommandParser.ControlType.Button:
		case PsdLayerCommandParser.ControlType.LabelButton:
			succeeded = UpdateNGUIButton(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.Toggle:
			succeeded = UpdateNGUIToggle(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.ComboBox:
			succeeded = UpdateNGUIComboBox(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.Input:
			succeeded = UpdateNGUIEditBox(owner, c, false);
			break;
			
		case PsdLayerCommandParser.ControlType.Password:
			succeeded = UpdateNGUIEditBox(owner, c, true);
			break;
			
		case PsdLayerCommandParser.ControlType.Label:
			succeeded = UpdateNGUILabel(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.VScrollBar:
			succeeded = UpdateNGUIScrollBar(owner, c, true);
			break;
			
		case PsdLayerCommandParser.ControlType.HScrollBar:
			succeeded = UpdateNGUIScrollBar(owner, c, false);
			break;
			
		case PsdLayerCommandParser.ControlType.ScrollView:
			succeeded = UpdateNGUIScrollView(owner, c);
			moveAndResize = false;
			break;
			
		case PsdLayerCommandParser.ControlType.VirtualView:
			succeeded = UpdateVirtualView(owner, c);
			moveAndResize = false;
			break;
			
		case PsdLayerCommandParser.ControlType.Texture:
			succeeded = UpdateTexture(owner, c);
			break;
			
		case PsdLayerCommandParser.ControlType.SpriteAnimation:
			succeeded = UpdateNGUIAnimation(owner, c);
			moveAndResize = false;
			break;

		case PsdLayerCommandParser.ControlType.Script:
			break;
			
		default:
			succeeded = UpdateNGUISprite(owner, c);
			break;
		}
		
		if (succeeded)
		{
			var go = Selection.activeGameObject;
			go.name = c.name;
			
			for (var i=0; i<c.sources.Count; ++i)
			{
				if (c.sources[i].type == PsdLayerCommandParser.ControlType.Script)
				{
					var userScript = Util.FindComponent<PsdLayerUserScript>(go, true);
					userScript.data = c.sources[i].text;
				}
			}
			
			if (moveAndResize)
			{
				PsdLayerToNGUI.MoveAndResize(go, c);
			}
		}
		return succeeded;
	}
コード例 #17
0
	private static bool UpdateNGUISprite(GameObject owner, PsdLayerCommandParser.Control c)
	{
		SetSlicedSprite(c.fullName, c.sliceArea);
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		return Selection.activeGameObject != null;
	}
コード例 #18
0
	private static bool CreateNGUIToggle(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"toggle,checkbox", new string[]{".normal", ".checked", ".label"});

		var normal = arr[0];
		var check = arr[1];
		var label = arr[2];
		
		if (normal != null)
		{
			NGUIWidgetCreator.mCheckBG = normal.fullName;
			NGUIWidgetCreator.mCheck = check != null ? check.fullName : normal.fullName;
			NGUIWidgetCreator.CreateToggle(owner);
		}
		else
		{
			return false;
		}
		
		PsdLayerToNGUI.SetButtonAppearance(Selection.activeGameObject, normal, null, true);
		
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label);
		
		return true;
	}
コード例 #19
0
	private static bool UpdateNGUIComboBox(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"combobox", new string[]{".bg", ".bar", ".listbg", ".label"});

		var bg = arr[0];
		var bar = arr[1];
		var listbg = arr[2];
		var label = arr[3];
		
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		if (Selection.activeGameObject == null)
			return false;
		var pl = Util.FindComponent<UIPopupList>(Selection.activeGameObject);
		var b = Util.FindComponent<UIButton>(Selection.activeGameObject);
		
		if (bg != null)
		{
			if (pl != null && b != null)
			{
				pl.backgroundSprite = bg.fullName;
				pl.highlightSprite = listbg == null ? bg.fullName : listbg.fullName;
				Util.FindComponent<UISprite>(b.tweenTarget).spriteName = bar == null ? bg.fullName : bar.fullName;
			}
			else
				return false;
		}
		else
		{
			return false;
		}
		
		PsdLayerToNGUI.SetButtonAppearance(Selection.activeGameObject, bg, null, true);
		
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label);
		{
			var spr = Util.FindComponent<UISprite>(Selection.activeGameObject);
			uilabel.width = (int)spr.transform.localScale.x;
			uilabel.transform.localPosition = Vector3.zero;
		}
		
		var p = Util.FindComponent<UIPopupList>(Selection.activeGameObject);
		p.highlightColor = Color.gray;
		if (label != null)
		{
			p.textColor = label.color;
			if (!string.IsNullOrEmpty(label.text))
			{
				p.items.Clear();
				var lines = label.text.Split('\n');
				foreach (var line in lines)
				{
					if (!string.IsNullOrEmpty(line))
						p.items.Add(line);
				}
			}
		}
		return true;
	}
コード例 #20
0
	private static bool CreateNGUIEditBox(GameObject owner, PsdLayerCommandParser.Control c, bool password)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			password ? "password" : "editbox", new string[]{".bg", ".label"});

		var normal = arr[0];
		var label = arr[1];
		
		if (normal != null)
		{
			NGUIWidgetCreator.mInputBG = normal.fullName;
			NGUIWidgetCreator.CreateInput(owner, password);
			Util.FindComponent<UIInput>(Selection.activeGameObject).activeTextColor = normal.color;
		}
		else
		{
			return false;
		}
		
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		var sprite = Util.FindComponent<UISprite>(Selection.activeGameObject);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label, sprite.localSize);
		
		return true;
	}
コード例 #21
0
	private static bool UpdateNGUIEditBox(GameObject owner, PsdLayerCommandParser.Control c, bool password)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			password ? "password" : "editbox,input", new string[]{".bg", ".label"});

		var normal = arr[0];
		var label = arr[1];
		
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		if (Selection.activeGameObject == null)
			return false;
		
		var eb = Util.FindComponent<UIInput>(Selection.activeGameObject);
		
		if (normal != null)
		{
			if (eb != null)
			{
				Util.FindComponent<UISprite>(eb).spriteName = c.fullName;
				eb.activeTextColor = label.color;
				eb.inputType = password ? UIInput.InputType.Password : UIInput.InputType.Standard;
			}
		}
		else
		{
			return false;
		}
		
		var uilabel = Util.FindComponent<UILabel>(Selection.activeGameObject);
		var sprite = Util.FindComponent<UISprite>(Selection.activeGameObject);
		PsdLayerToNGUI.SetLabelAppearance(uilabel, label, sprite.localSize);
		
		return true;
	}
コード例 #22
0
	private static bool CreateNGUILabel(GameObject owner, PsdLayerCommandParser.Control c)
	{
		NGUIWidgetCreator.CreateLabel(owner);
		
		var label = Util.FindComponent<UILabel>(Selection.activeGameObject);
		PsdLayerToNGUI.SetLabelAppearance(label, c);
		
		return true;
	}
コード例 #23
0
	private static bool UpdateNGUIScrollBar(GameObject owner, PsdLayerCommandParser.Control c, bool vertical)
	{
		//**todo
//		var arr = PsdLayerToNGUI.FindControlSources(c, 
//			"scrollbar", new string[]{".bg", ".fg"});
//		
//		var scrollbar = null as UIScrollBar;
//		var scrollbar_bg = arr[0];
//		var scrollbar_fg = arr[1];
//		
//		if (scrollbar_bg != null || scrollbar_fg != null)
//		{
//			NGUIWidgetCreator.mScrollBG = 
//				scrollbar_bg != null ? scrollbar_bg.fullName : scrollbar_fg.fullName;
//			
//			NGUIWidgetCreator.mScrollFG = 
//				scrollbar_fg != null ? scrollbar_fg.fullName : scrollbar_bg.fullName;
//			
//			NGUIWidgetCreator.CreateScrollBar(owner);
//			
//			scrollbar = Util.FindComponent<UIScrollBar>(Selection.activeGameObject);
//			scrollbar.direction = UIScrollBar.Direction.Vertical;
//			return false;
//		}
//		else
//			return false;
//		
//		if (scrollbar != null)
//		{
//			PsdLayerToNGUI.MoveAndResize(scrollbar.gameObject, scrollbar_bg);
//			
//			var go = scrollbar.gameObject;
//			var c2 = scrollbar_bg;
//			var x = (float)c2.area.left;
//			var y = (float)c2.area.top;
//			if (vertical)
//			{
//				x -= (float)targetWidth/2f;
//				x += (float)c2.area.width/2f;
//				y -= (float)targetHeight/2f;
//			}
//			else
//			{
//				x -= (float)targetWidth/2f;
//				y -= (float)targetHeight/2f;
//				y += (float)c2.area.height/2f;
//			}
//			var pos = new Vector3(Mathf.RoundToInt(x), Mathf.RoundToInt(-y), 0);
//			pos.z = go.transform.localPosition.z;
//			go.transform.localPosition = pos;
//		}
		return false;
	}
コード例 #24
0
	private static bool CreateNGUIScrollView(GameObject owner, PsdLayerCommandParser.Control c)
	{
		var arr = PsdLayerToNGUI.FindControlSources(c, 
			"scrollview", new string[]{
			"scrollview.bg", ".item", 
			".vscrollbar.bg", ".vscrollbar.fg", 
			".hscrollbar.bg", ".hscrollbar.fg"
		});
		
		var bg = arr[0];
		var item = arr[1];
		//**todo
//		var vscrollbar_bg = arr[2];
//		var vscrollbar_fg = arr[3];
//		var hscrollbar_bg = arr[4];
//		var hscrollbar_fg = arr[5];
		
		if (bg != null)
		{
			owner = Util.CreateEmptyGameObject(owner);
			owner.name = bg.name;
			
			var bgSprite = null as GameObject;
			{
				NGUIWidgetCreator.CreateSprite(owner, c.fullName, bg.sliceArea != null );
				
				bgSprite = Selection.activeGameObject;
				bgSprite.AddComponent<BoxCollider>();
				bgSprite.name = "Bg";
				
				PsdLayerToNGUI.MoveAndResize(bgSprite, bg);
			}
			
			//**todo
//			var vscrollbar = null as UIScrollBar;
//			if (vscrollbar_bg != null || vscrollbar_fg != null)
//			{
//				NGUIWidgetCreator.mScrollBG = 
//					vscrollbar_bg != null ? vscrollbar_bg.fullName : vscrollbar_fg.fullName;
//				
//				NGUIWidgetCreator.mScrollFG = 
//					vscrollbar_fg != null ? vscrollbar_fg.fullName : vscrollbar_bg.fullName;
//				
//				NGUIWidgetCreator.CreateScrollBar(owner);
//				
//				vscrollbar = Util.FindComponent<UIScrollBar>(Selection.activeGameObject);
//				vscrollbar.direction = UIScrollBar.Direction.Vertical;
//			}
//			if (vscrollbar != null)
//			{
//				PsdLayerToNGUI.MoveAndResize(vscrollbar.gameObject, vscrollbar_bg);
//				
//				var go = vscrollbar.gameObject;
//				var c2 = vscrollbar_bg;
//				var x = (float)c2.area.left;
//				var y = (float)c2.area.top;
//				{
//					x -= (float)targetWidth/2f;
//					x += (float)c2.area.width/2f;
//					y -= (float)targetHeight/2f;
//					
//					var pos = new Vector3(Mathf.RoundToInt(x), Mathf.RoundToInt(-y), 0);
//					pos.z = go.transform.localPosition.z;
//					go.transform.localPosition = pos;
//				}
//			}
//			
//			var hscrollbar = null as UIScrollBar;
//			if (hscrollbar_bg != null || hscrollbar_fg != null)
//			{
//				NGUIWidgetCreator.mScrollBG = 
//					hscrollbar_bg != null ? hscrollbar_bg.fullName : hscrollbar_fg.fullName;
//				
//				NGUIWidgetCreator.mScrollFG = 
//					hscrollbar_fg != null ? hscrollbar_fg.fullName : hscrollbar_bg.fullName;
//				
//				NGUIWidgetCreator.CreateScrollBar(owner);
//				
//				hscrollbar = Util.FindComponent<UIScrollBar>(Selection.activeGameObject);
//				hscrollbar.direction = UIScrollBar.Direction.Horizontal;
//			}
//			if (hscrollbar != null)
//			{
//				PsdLayerToNGUI.MoveAndResize(hscrollbar.gameObject, hscrollbar_bg);
//				
//				var go = hscrollbar.gameObject;
//				var c2 = hscrollbar_bg;
//				var x = (float)c2.area.left;
//				var y = (float)c2.area.top;
//				{
//					x -= (float)targetWidth/2f;
//					y -= (float)targetHeight/2f;
//					y += (float)c2.area.height/2f;
//					
//					var pos = new Vector3(Mathf.RoundToInt(x), Mathf.RoundToInt(-y), 0);
//					pos.z = go.transform.localPosition.z;
//					go.transform.localPosition = pos;
//				}
//			}
			
			var panelgo = Util.CreateEmptyGameObject(owner);
			panelgo.name = "ScrollView";
			panelgo.transform.localPosition = new Vector3(0, 0 -1);
			{
				var panel = panelgo.AddComponent<UIPanel>();
				panel.depth = PsdLayerToNGUI.data.nguiPanelDepth++;

				var view = panelgo.AddComponent<UIScrollView>();
				//**todo
//				view.verticalScrollBar = vscrollbar;
//				view.horizontalScrollBar = hscrollbar;
				view.showScrollBars = UIScrollView.ShowCondition.WhenDragging;
				view.movement = UIScrollView.Movement.Vertical;
				
				Util.FindComponent<UIDragScrollView>(bgSprite, true).scrollView = view;
				
				if (item != null)
				{
					foreach (var child in item.children)
						CreateNGUI(panelgo, child);
					
					Util.SetXYCenterAmongChildren(panelgo);
				}
				
				panel.clipping = UIDrawCall.Clipping.SoftClip;
				panel.baseClipRegion = new Vector4(
					panel.transform.localPosition.x, 
					-panel.transform.localPosition.y, bg.area.width, bg.area.height);
			}

			Selection.activeGameObject = owner;
		}
		else
		{
			return false;
		}
		
		return true;
	}
コード例 #25
0
	private static bool UpdateTexture(GameObject owner, PsdLayerCommandParser.Control c)
	{
		Selection.activeGameObject = Util.FindGameObjectRecursively(owner, c.name, true);
		if (Selection.activeGameObject == null)
			return false;

		var tex = Util.FindComponent<UITexture>(Selection.activeGameObject);
		if (tex != null)
		{
			//**todo
			//tex.mainTexture = AssetDatabase.LoadAssetAtPath(c.pa.srcFilePath, typeof(Texture2D)) as Texture2D;
			return true;
		}
		return false;
	}
コード例 #26
0
	private static bool CreateTexture(GameObject owner, PsdLayerCommandParser.Control c)
	{
		NGUIWidgetCreator.CreateSimpleTexture(owner);
		
		var tex = Util.FindComponent<UITexture>(Selection.activeGameObject);
		if (tex != null)
		{
			//**todo
			//tex.mainTexture = AssetDatabase.LoadAssetAtPath(c.pa.srcFilePath, typeof(Texture2D)) as Texture2D;
			return true;
		}
		return false;
	}
コード例 #27
0
	private static PsdLayerCommandParser.Control[] FindControlSources(
		PsdLayerCommandParser.Control c, string controlName, string[] sourceNames)
	{
		var controlNames = controlName.Split(',');
		var sources = new PsdLayerCommandParser.Control[sourceNames.Length];
		for (var i=0; i<c.sources.Count; ++i)
		{
			var src = c.sources[i];
			SetSlicedSprite(src.fullName, src.sliceArea);
			
			var first = false;
			foreach (var name in controlNames)
			{
				if (first = src.command.EndsWith(name))
					break;
			}
			
			if (first || src.command.EndsWith(sourceNames[0]))
			{
				sources[0] = src;
			}
			else
			{
				for (var n=1; n<sources.Length; ++n)
				{
					if (src.command.EndsWith(sourceNames[n]))
						sources[n] = src;
				}
			}
		}
		return sources;
	}
コード例 #28
0
	private static bool CreateNGUIAnimation(GameObject owner, PsdLayerCommandParser.Control c)
	{
		if (PsdLayerToNGUI.CreateNGUISprite(owner, c) && c.children.Count > 0){
			var ani = Selection.activeGameObject.AddComponent<PsdLayerSpriteAnimation>();
			var names = new List<string>();
			for (var i=0; i<c.children.Count; ++i){
				names.Add(c.children[i].fullName);
			}
			names.Sort();
			ani.SetSprites(names.ToArray());
			ani.fps = c.fps;
			
			PsdLayerToNGUI.MoveAndResize(ani.gameObject, c.children[0]);
			return true;
		}
		return false;
	}
コード例 #29
0
	private static void UpdateNGUIs(GameObject owner, 
		string psdFileName, List<PsdLayerExtractor.Layer> layers)
	{
		var pa = new PsdLayerCommandParser();
		pa.Parse(psdFileName, layers);

		foreach (var c in pa.root.children)
		{
			if (!PsdLayerToNGUI.UpdateNGUI(owner, c))
				PsdLayerToNGUI.CreateNGUI(owner, c);
		}
	}
コード例 #30
0
	private static void SetButtonAppearance(
		GameObject go, PsdLayerCommandParser.Control c, UILabel label, bool enable)
	{
		var btn = Util.FindComponent<UIButton>(go);
		var btnScale = Util.FindComponent<UIButtonScale>(go);
		var btnOffset = Util.FindComponent<UIButtonOffset>(go);
		UIWidget btnBackground = null;
		if (btn != null)
		{
			btn.enabled = enable;
			btn.hover = Color.yellow;
			btn.pressed = new Color(.7f, .7f, .7f, 1f);
			
			btnBackground = Util.FindComponent<UIWidget>(btn.tweenTarget);
			
			if (c.type == PsdLayerCommandParser.ControlType.LabelButton){
				if (btnBackground != null){
					btnBackground.alpha = 0;
				}
				btn.tweenTarget = label.gameObject;
				btnBackground = Util.FindComponent<UIWidget>(btn.tweenTarget);
			}
		}
		if (btnScale != null)
		{
			btnScale.hover = Vector3.one;
			btnScale.pressed = new Vector3(0.998f, 0.998f, 1);
		}
		if (btnOffset != null)
		{
			btnOffset.pressed = Vector3.zero;
		}
		
		var imgbtn = Util.FindComponent<UIImageButton>(go);
		if (imgbtn != null)
		{
			imgbtn.target.spriteName = imgbtn.normalSprite;
		}
		
		var toggle = Util.FindComponent<UIToggle>(go);
		if (toggle != null && c.sources.Count == 1)
		{
			btnBackground.color = new Color(.7f, .7f, .7f, 1f);
		}
	}