Esempio n. 1
0
    /// <summary>
    /// It's often useful to be able to tell which keys are used in localization, and which are not.
    /// For this to work properly it's advised to play through the entire game and view all localized content before hitting the Stop button.
    /// </summary>

    void OnDisable()
    {
        string final             = "";
        BetterList <string> full = new BetterList <string>();

        // Create a list of all the known keys
        foreach (KeyValuePair <string, string> pair in mDictionary)
        {
            full.Add(pair.Key);
        }

        // Sort the full list
        full.Sort(delegate(string s1, string s2) { return(s1.CompareTo(s2)); });

        // Create the final string with the localization keys
        for (int i = 0; i < full.size; ++i)
        {
            string key = full[i];
            string val = mDictionary[key].Replace("\n", "\\n");
            if (mUsed.Contains(key))
            {
                final += key + " = " + val + "\n";
            }
            else
            {
                final += "//" + key + " = " + val + "\n";
            }
        }

        // Show the final report in a format that makes it easy to copy/paste into the original localization file
        if (!string.IsNullOrEmpty(final))
        {
            Debug.Log("// Localization Report\n\n" + final);
        }
    }
Esempio n. 2
0
        public void ShowUI(uint eLayoutType, uint eLogicModuleIndex)
        {
            if (m_uiDisactiveList.Contains(eLogicModuleIndex))
            {
                m_uiDisactiveList.Remove(eLogicModuleIndex);
            }

            uint curActiveMoudleIndex;

            if (m_uiActiveDict.TryGetValue(eLayoutType, out curActiveMoudleIndex))
            {
                if (curActiveMoudleIndex == eLogicModuleIndex)
                {
                    return;
                }
                // 隐藏逻辑界面
                LogicModule module = LogicModuleManager.Inst.GetLogicModule(curActiveMoudleIndex);
                if (null != module)
                {
                    module.SetVisible(false);
                }
                m_uiActiveDict[eLayoutType] = eLogicModuleIndex;
            }
            else
            {
                m_uiActiveDict.Add(eLayoutType, eLogicModuleIndex);
            }
        }
Esempio n. 3
0
 public static byte[] getCache(string url)
 {
     if (AssetCacheURL.Contains(url))
     {
         int i = AssetCacheURL.IndexOf(url);
         return(AssetCacheDATA[i].ReadFile());
     }
     //if(AssetCache.ContainsKey(url)){
     //  return AssetCache[url];
     //}
     return(null);
 }
Esempio n. 4
0
 public void AddPrefabPool(string s, int amount = 5)
 {
     if (mPoolList == null || !mPoolList.Contains(s))
     {
         PrefabPool prePool = GetPrefabPool(s, amount);
         if (prePool != null)
         {
             spawnPool._perPrefabPoolOptions.Add(prePool);
             spawnPool.CreatePrefabPool(prePool);
         }
     }
 }
Esempio n. 5
0
    public void AddWidget(UIWidget w)
    {
        if (w != null && !mWidgets.Contains(w))
        {
            mWidgets.Add(w);
            if (!mChanged.Contains(w.material))
            {
                mChanged.Add(w.material);
            }

            mDepthChanged = true;
        }
    }
Esempio n. 6
0
 public void MarkMaterialAsChanged(Material mat, bool sort)
 {
     if (mat != null)
     {
         if (sort)
         {
             mDepthChanged = true;
         }
         if (!mChanged.Contains(mat))
         {
             mChanged.Add(mat);
         }
     }
 }
Esempio n. 7
0
    //public override CharacterState CreateBattleMonster(MonsterData md, GameObject parent)
    //{
    //    string modelName = (GameLibrary.isMoba && (md.groupIndex != 99) && (md.groupIndex != 100) && (md.groupIndex != 101)) || sceneType == SceneType.TP ? md.attrNode.icon_name + md.groupIndex : md.attrNode.icon_name;
    //    GameObject go = null;
    //    if (enemyModel.ContainsKey(modelName))
    //    {
    //        go = Instantiate(enemyModel[modelName]);
    //        go.transform.parent = parent.transform;
    //        go.transform.localPosition = Vector3.zero;
    //    }
    //    else
    //    {
    //        go = Resource.CreateCharacter(modelName, parent);
    //    }

    //    CharacterState mCs = null;
    //    if (go != null)
    //    {
    //        mCs = BattleUtil.AddMoveComponents(go);
    //        if (BattleUtil.IsBoss(md))
    //        {
    //            mCs.pm.nav.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;
    //            mCs.pm.nav.avoidancePriority = 59;
    //        }
    //        else
    //        {
    //            mCs.pm.nav.obstacleAvoidanceType = ObstacleAvoidanceType.LowQualityObstacleAvoidance;
    //        }
    //        mCs.pm.nav.stoppingDistance = 0.2f;
    //        mCs.InitData(md);
    //        mCs.OnDead += (CharacterState cs) => RemoveCs(cs);
    //        if (md.state != Modestatus.Boss)
    //            mCs.AddHpBar();
    //        go.transform.position = BattleUtil.GetNearestNavPos(go);
    //        mCs.CharData.monsterAreaId = md.monsterAreaId;
    //        AddCs(mCs);

    //    }
    //    return mCs;
    //}

    public override void AddCs(CharacterState cs)
    {
        base.AddCs(cs);
        if (cs.groupIndex == 99)
        {
            if (!wildMonster.Contains(cs))
            {
                cs.OnDead += RemoveCs;
                wildMonster.Add(cs);
            }
            if (!wildMonster1.Contains(cs) && cs.CharData.monsterAreaId == 1)
            {
                cs.OnDead += RemoveCs;
                wildMonster1.Add(cs);
            }
            if (!wildMonster2.Contains(cs) && cs.CharData.monsterAreaId == 2)
            {
                cs.OnDead += RemoveCs;
                wildMonster2.Add(cs);
            }
            if (!wildMonster3.Contains(cs) && cs.CharData.monsterAreaId == 3)
            {
                cs.OnDead += RemoveCs;
                wildMonster3.Add(cs);
            }
        }
        else if (cs.groupIndex == 100)
        {
            if (!wildMonsterRed.Contains(cs))
            {
                cs.OnDead += RemoveCs;
                wildMonsterRed.Add(cs);
            }
            if (!wildRed1.Contains(cs) && cs.CharData.monsterAreaId == 1)
            {
                cs.OnDead += RemoveCs;
                wildRed1.Add(cs);
            }
            if (!wildRed2.Contains(cs) && cs.CharData.monsterAreaId == 2)
            {
                cs.OnDead += RemoveCs;
                wildRed2.Add(cs);
            }
            if (!wildRed3.Contains(cs) && cs.CharData.monsterAreaId == 3)
            {
                cs.OnDead += RemoveCs;
                wildRed3.Add(cs);
            }
        }
    }
Esempio n. 8
0
    /// <summary>
    /// Add the specified widget to the managed list.
    /// </summary>

    public void AddWidget(UIWidget w)
    {
        if (w != null)
        {
#if UNITY_EDITOR
            if (w.cachedTransform.parent != null)
            {
                UIWidget parentWidget = NGUITools.FindInParents <UIWidget>(w.cachedTransform.parent.gameObject);

                if (parentWidget != null)
                {
                    w.cachedTransform.parent = parentWidget.cachedTransform.parent;
                    Debug.LogError("You should never nest widgets! Parent them to a common game object instead. Forcefully changing the parent.", w);

                    // If the error above gets triggered, it means that you parented one widget to another.
                    // If left unchecked, this may lead to odd behavior in the UI. Consider restructuring your UI.
                    // For example, if you were trying to do this:

                    // Widget #1
                    //  |
                    //  +- Widget #2

                    // You can do this instead, fixing the problem:

                    // GameObject (scale 1, 1, 1)
                    //  |
                    //  +- Widget #1
                    //  |
                    //  +- Widget #2
                }
            }
#endif

            UINode node = AddTransform(w.cachedTransform);

            if (node != null)
            {
                node.widget   = w;
                w.visibleFlag = 1;

                if (!mWidgets.Contains(w))
                {
                    mWidgets.Add(w);

                    if (!mChanged.Contains(w.material))
                    {
                        mChanged.Add(w.material);
                        mChangedLastFrame = true;
                    }
                    mDepthChanged = true;
                    mWidgetsAdded = true;
                }
            }
            else
            {
                Debug.LogError("Unable to find an appropriate root for " + NGUITools.GetHierarchy(w.gameObject) +
                               "\nPlease make sure that there is at least one game object above this widget!", w.gameObject);
            }
        }
    }
Esempio n. 9
0
 void OnEnable()
 {
     if (!list.Contains(this))
     {
         list.Add(this);
     }
 }
Esempio n. 10
0
 private bool IsEmojiImage(string spriteName)
 {
     if (mListOfSprites.Contains(spriteName))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 11
0
    /// <summary>
    /// 判断给定id的物品是否在砸蛋界面的展示列表中;
    /// </summary>
    /// <param name="itemid"></param>
    /// <returns></returns>
    public static bool GetItemIsInShowItems(int itemid)
    {
        BetterList <int> result = new BetterList <int>();

        result = GetShowItemsItemID();

        return(result.Contains(itemid));
    }
Esempio n. 12
0
    void UpdateMainCompressTextureList()
    {
        NGUISettings.mainCompressTextureList.textureList.Clear();

        System.Type         listType = typeof(UICompressTextureList);
        string[]            paths    = AssetDatabase.FindAssets("t:Prefab");
        BetterList <Object> list     = new BetterList <Object>();

        for (int i = 0; i < paths.Length; ++i)
        {
            string path       = paths[i];
            string prefabName = AssetDatabase.GUIDToAssetPath(path);
            Object obj        = AssetDatabase.LoadMainAssetAtPath(prefabName);

            if (obj == null || list.Contains(obj))
            {
                continue;
            }
            if (obj.name == "CompressTextureList")
            {
                continue;
            }

            Object t = (obj as GameObject).GetComponent(listType);
            if (t != null && !list.Contains(t))
            {
                list.Add(t);
            }
        }
        list.Sort(delegate(Object a, Object b) { return(a.name.CompareTo(b.name)); });

        foreach (UICompressTextureList textureList in list)
        {
            foreach (TextureData data in textureList.textureList)
            {
                TextureData d = new TextureData();
                d.Name      = data.Name;
                d.bAlpha    = data.bAlpha;
                d.AlphaName = data.AlphaName;
                NGUISettings.mainCompressTextureList.textureList.Add(d);
            }
        }

        NGUITools.SetDirty(NGUISettings.mainCompressTextureList.gameObject);
        AssetDatabase.SaveAssets();
    }
Esempio n. 13
0
 //将GameObject设置回不被激活的状态
 public void DeSpawn(GameObject go)
 {
     if (!_active.Contains(go))
     {
         return;
     }
     _active.Remove(go);
     _inactive.Add(go);
     go.SetActive(false);
 }
Esempio n. 14
0
    public void SetShowType(BetterList <MoneyBarType> showTypes)
    {
        Init();

        for (int i = 0, j = (int)MoneyBarType.Max; i < j; i++)
        {
            GameObject go = getGameobjectBySortid(i);
            go.SetActive(showTypes.Contains((MoneyBarType)i));
        }

        grid.repositionNow = true;
    }
Esempio n. 15
0
    /// <summary>
    /// 通过逻辑控制关闭(CloseChildFunc)的字图标不会再次打开;
    /// </summary>
    /// <param name="id"></param>
    private void InnerOpenChildFunc(int id)
    {
        MenuTableItem item = GetItem(id);

        if (item == null)
        {
            return;
        }

        // 不是子图标;
        if (item.parentid <= 0)
        {
            return;
        }

        if (mIgnoreList.Contains(id))
        {
            return;
        }

        openChild(id);
    }
Esempio n. 16
0
    void OnMailItemClicked(GameObject go)
    {
        if (markedList.Contains(go))
        {
            markedList.Remove(go);
        }
        else
        {
            markedList.Add(go);
        }

        markedBtn.transform.Find("Number").GetComponent <UILabel> ().text = markedList.size.ToString();

        Debug.Log("Marked amount: " + markedList.size);
    }
Esempio n. 17
0
    public static AINode GetNodeForSearching(int _index)
    {
        if (_index < 0 || _index >= Nodes.size)
        {
            return(null);
        }

        AINode node = Nodes[_index];

        if (!SearchRecord.Contains(node.LocationIndex))
        {
            SearchRecord.Add(node.LocationIndex);
        }

        return(node);
    }
Esempio n. 18
0
    private void SetOptimalPath(bool _isSelected)
    {
        if (_isSelected && !optimalPath.Contains(BlackBord.TargetLocationIndex))
        {
            messageLabel.text = MSG_NOPATH;
            return;
        }

        int imax = optimalPath.size - 1;

        //Debug.Log(" optimalPath.size ===========>>  " + optimalPath.size);
        for (int i = 0; i < imax; i++)
        {
            agentList[optimalPath[i]].SetAgentAsPathNode(_isSelected);
        }
    }
Esempio n. 19
0
    public static BetterList <int> GetAllTitleGroupId()
    {
        BetterList <int> res = new BetterList <int>();

        IDictionaryEnumerator itr = DataManager.TitleGroupTable.GetEnumerator();

        while (itr.MoveNext())
        {
            if (res.Contains((int)itr.Key))
            {
                continue;
            }

            res.Add((int)itr.Key);
        }
        return(res);
    }
Esempio n. 20
0
 public void RemoveCD(CD cd)
 {
     if (cds.Contains(cd))
     {
         cds.Remove(cd);
         if (cd.OnRemove != null)
         {
             cd.OnRemove(cd.CountLeft, cd.Id);
         }
         if (cd.OnCd != null)
         {
             cd.OnCd = null;
         }
         if (cd != null)
         {
             cd = null;
         }
     }
 }
Esempio n. 21
0
    public BetterList <int> GetEffectMallItemIDs()
    {
        BetterList <MallTableItem> temp = GetEffectMallItems();

        if (temp == null)
        {
            return(null);
        }

        BetterList <int> res = new BetterList <int>();

        foreach (MallTableItem item in temp)
        {
            if (res.Contains(item.resId))
            {
                continue;
            }

            res.Add(item.resId);
        }

        return(res);
    }
    private void OnCollisionExit(Collision collisionInfo)
    {
        while (rightBlockingObjects.Contains(collisionInfo.gameObject))
        {
            rightBlockingObjects.Remove(collisionInfo.gameObject);
        }

        while (leftBlockingObjects.Contains(collisionInfo.gameObject))
        {
            leftBlockingObjects.Remove(collisionInfo.gameObject);
        }

        LevelFloor platform = collisionInfo.gameObject.GetComponent <LevelFloor>();

        if (platform != null)
        {
            if (currentPlatform == platform)
            {
                isGrounded      = false;
                currentPlatform = null;
            }
        }
    }
Esempio n. 23
0
	/// <summary>
	/// Draw the custom wizard.
	/// </summary>

	void OnGUI ()
	{
		Event currentEvent = Event.current;
		EventType type = currentEvent.type;

		int x = cellPadding, y = cellPadding;
		int width = Screen.width - cellPadding;
		int spacingX = cellSize + cellPadding;
		int spacingY = spacingX;
		if (mMode == Mode.DetailedMode) spacingY += 32;

		GameObject dragged = draggedObject;
		bool isDragging = (dragged != null);
		int indexUnderMouse = GetCellUnderMouse(spacingX, spacingY);
		Item selection = isDragging ? FindItem(dragged) : null;
		string searchFilter = NGUISettings.searchField;

		int newTab = mTab;

		GUILayout.BeginHorizontal();
		if (GUILayout.Toggle(newTab == 0, "1", "ButtonLeft")) newTab = 0;
		if (GUILayout.Toggle(newTab == 1, "2", "ButtonMid")) newTab = 1;
		if (GUILayout.Toggle(newTab == 2, "3", "ButtonMid")) newTab = 2;
		if (GUILayout.Toggle(newTab == 3, "4", "ButtonMid")) newTab = 3;
		if (GUILayout.Toggle(newTab == 4, "5", "ButtonRight")) newTab = 4;
		GUILayout.EndHorizontal();

		if (mTab != newTab)
		{
			Save();
			mTab = newTab;
			mReset = true;
			NGUISettings.SetInt("NGUI Prefab Tab", mTab);
			Load();
		}

		if (mReset && type == EventType.Repaint)
		{
			mReset = false;
			foreach (Item item in mItems) GeneratePreview(item, null);
			RectivateLights();
		}

		// Search field
		GUILayout.BeginHorizontal();
		{
			string after = EditorGUILayout.TextField("", searchFilter, "SearchTextField", GUILayout.Width(Screen.width - 20f));

			if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
			{
				after = "";
				GUIUtility.keyboardControl = 0;
			}

			if (searchFilter != after)
			{
				NGUISettings.searchField = after;
				searchFilter = after;
			}
		}
		GUILayout.EndHorizontal();

		bool eligibleToDrag = (currentEvent.mousePosition.y < Screen.height - 40);

		if (type == EventType.MouseDown)
		{
			mMouseIsInside = true;
		}
		else if (type == EventType.MouseDrag)
		{
			mMouseIsInside = true;

			if (indexUnderMouse != -1 && eligibleToDrag)
			{
				// Drag operation begins
				if (draggedObjectIsOurs) DragAndDrop.StartDrag("Prefab Tool");
				currentEvent.Use();
			}
		}
		else if (type == EventType.MouseUp)
		{
			DragAndDrop.PrepareStartDrag();
			mMouseIsInside = false;
			Repaint();
		}
		else if (type == EventType.DragUpdated)
		{
			// Something dragged into the window
			mMouseIsInside = true;
			UpdateVisual();
			currentEvent.Use();
		}
		else if (type == EventType.DragPerform)
		{
			// We've dropped a new object into the window
			if (dragged != null)
			{
				if (selection != null)
				{
					DestroyTexture(selection);
					mItems.Remove(selection);
				}

				AddItem(dragged, indexUnderMouse);
				draggedObject = null;
			}
			mMouseIsInside = false;
			currentEvent.Use();
		}
		else if (type == EventType.DragExited || type == EventType.Ignore)
		{
			mMouseIsInside = false;
		}

		// If the mouse is not inside the window, clear the selection and dragged object
		if (!mMouseIsInside)
		{
			selection = null;
			dragged = null;
		}

		// Create a list of indices, inserting an entry of '-1' underneath the dragged object
		BetterList<int> indices = new BetterList<int>();

		for (int i = 0; i < mItems.size; )
		{
			if (dragged != null && indices.size == indexUnderMouse)
				indices.Add(-1);

			if (mItems[i] != selection)
			{
				if (string.IsNullOrEmpty(searchFilter) ||
					mItems[i].prefab.name.IndexOf(searchFilter, System.StringComparison.CurrentCultureIgnoreCase) != -1)
						indices.Add(i);
			}
			++i;
		}

		// There must always be '-1' (Add/Move slot) present
		if (!indices.Contains(-1)) indices.Add(-1);

		// We want to start dragging something from within the window
		if (eligibleToDrag && type == EventType.MouseDown && indexUnderMouse > -1)
		{
			GUIUtility.keyboardControl = 0;

			if (currentEvent.button == 0 && indexUnderMouse < indices.size)
			{
				int index = indices[indexUnderMouse];

				if (index != -1 && index < mItems.size)
				{
					selection = mItems[index];
					draggedObject = selection.prefab;
					dragged = selection.prefab;
					currentEvent.Use();
				}
			}
		}
		//else if (type == EventType.MouseUp && currentEvent.button == 1 && indexUnderMouse > mItems.size)
		//{
		//    NGUIContextMenu.AddItem("Reset", false, RemoveItem, index);
		//    NGUIContextMenu.Show();
		//}

		// Draw the scroll view with prefabs
		mPos = GUILayout.BeginScrollView(mPos);
		{
			Color normal = new Color(1f, 1f, 1f, 0.5f);

			for (int i = 0; i < indices.size; ++i)
			{
				int index = indices[i];
				Item ent = (index != -1) ? mItems[index] : selection;

				if (ent != null && ent.prefab == null)
				{
					mItems.RemoveAt(index);
					continue;
				}

				Rect rect = new Rect(x, y, cellSize, cellSize);
				Rect inner = rect;
				inner.xMin += 2f;
				inner.xMax -= 2f;
				inner.yMin += 2f;
				inner.yMax -= 2f;
				rect.yMax -= 1f; // Button seems to be mis-shaped. It's height is larger than its width by a single pixel.

				if (!isDragging && (mMode == Mode.CompactMode || (ent == null || ent.tex != null)))
					mContent.tooltip = (ent != null) ? ent.prefab.name : "Click to add";
				else mContent.tooltip = "";

				//if (ent == selection)
				{
					GUI.color = normal;
					NGUIEditorTools.DrawTiledTexture(inner, NGUIEditorTools.backdropTexture);
				}

				GUI.color = Color.white;
				GUI.backgroundColor = normal;

				if (GUI.Button(rect, mContent, "Button"))
				{
					if (ent == null || currentEvent.button == 0)
					{
						string path = EditorUtility.OpenFilePanel("Add a prefab", NGUISettings.currentPath, "prefab");

						if (!string.IsNullOrEmpty(path))
						{
							NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
							Item newEnt = CreateItemByPath(path);

							if (newEnt != null)
							{
								mItems.Add(newEnt);
								Save();
							}
						}
					}
					else if (currentEvent.button == 1)
					{
						NGUIContextMenu.AddItem("Delete", false, RemoveItem, index);
						NGUIContextMenu.Show();
					}
				}

				string caption = (ent == null) ? "" : ent.prefab.name.Replace("Control - ", "");

				if (ent != null)
				{
					if (ent.tex != null)
					{
						GUI.DrawTexture(inner, ent.tex);
					}
					else if (mMode != Mode.DetailedMode)
					{
						GUI.Label(inner, caption, mStyle);
						caption = "";
					}
				}
				else GUI.Label(inner, "Add", mStyle);

				if (mMode == Mode.DetailedMode)
				{
					GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
					GUI.contentColor = new Color(1f, 1f, 1f, 0.7f);
					GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), caption, "ProgressBarBack");
					GUI.contentColor = Color.white;
					GUI.backgroundColor = Color.white;
				}

				x += spacingX;

				if (x + spacingX > width)
				{
					y += spacingY;
					x = cellPadding;
				}
			}
			GUILayout.Space(y);
		}
		GUILayout.EndScrollView();

		// Mode
		Mode modeAfter = (Mode)EditorGUILayout.EnumPopup(mMode);

		if (modeAfter != mMode)
		{
			mMode = modeAfter;
			mReset = true;
			NGUISettings.SetEnum("NGUI Prefab Mode", mMode);
		}
	}
Esempio n. 24
0
        void OnGUI()
        {
            Event     currentEvent = Event.current;
            EventType type         = currentEvent.type;

            int x = cellPadding, y = cellPadding;
            int width    = Screen.width - cellPadding;
            int spacingX = cellSize + cellPadding;
            int spacingY = spacingX;

            if (mMode == Mode.DetailedMode)
            {
                spacingY += 32;
            }

            GameObject dragged         = draggedObject;
            bool       isDragging      = (dragged != null);
            int        indexUnderMouse = GetCellUnderMouse(spacingX, spacingY);
            Item       selection       = isDragging ? FindItem(dragged) : null;
            string     searchFilter    = EditorPrefs.GetString("PrefabWin_SearchFilter", null);

            s_pageBarOption = mTab;
            TopButton();
            ToolBar();

            if (mTab != s_pageBarOption)
            {
                Save();
                SaveTextureToPng();
                mTab   = s_pageBarOption;
                mReset = true;
                EditorPrefs.SetInt("PrefabWin Prefab Tab", mTab);
                Load();
            }

            if (mReset && type == EventType.Repaint)
            {
                mReset = false;
                SaveTextureToPng();
                foreach (Item item in mItems)
                {
                    GeneratePreview(item, false);
                }
                RectivateLights();
            }
            bool eligibleToDrag = (currentEvent.mousePosition.y < Screen.height - 40 && currentEvent.mousePosition.y > 110);

            if (type == EventType.MouseDown)
            {
                mMouseIsInside = true;
            }
            else if (type == EventType.MouseDrag)
            {
                mMouseIsInside = true;

                if (indexUnderMouse != -1 && eligibleToDrag)
                {
                    if (draggedObjectIsOurs)
                    {
                        DragAndDrop.StartDrag("Prefab Tool");
                    }
                    currentEvent.Use();
                }
            }
            else if (type == EventType.MouseUp)
            {
                DragAndDrop.PrepareStartDrag();
                mMouseIsInside = false;
                Repaint();
            }
            else if (type == EventType.DragUpdated)
            {
                mMouseIsInside = true;
                UpdateVisual();
                currentEvent.Use();
            }
            else if (type == EventType.DragPerform)
            {
                if (dragged != null)
                {
                    if (selection != null)
                    {
                        DestroyTexture(selection);
                        mItems.Remove(selection);
                    }

                    AddItem(dragged, indexUnderMouse);
                    draggedObject = null;
                }
                mMouseIsInside = false;
                currentEvent.Use();
            }
            else if (type == EventType.DragExited || type == EventType.Ignore)
            {
                mMouseIsInside = false;
            }

            if (!mMouseIsInside)
            {
                selection = null;
                dragged   = null;
            }

            BetterList <int> indices = new BetterList <int>();

            for (int i = 0; i < mItems.size;)
            {
                if (dragged != null && indices.size == indexUnderMouse)
                {
                    indices.Add(-1);
                }

                if (mItems[i] != selection)
                {
                    if (string.IsNullOrEmpty(searchFilter) ||
                        mItems[i].prefab.name.IndexOf(searchFilter, System.StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        indices.Add(i);
                    }
                }
                ++i;
            }

            if (!indices.Contains(-1))
            {
                indices.Add(-1);
            }

            if (eligibleToDrag && type == EventType.MouseDown && indexUnderMouse > -1)
            {
                GUIUtility.keyboardControl = 0;

                if (currentEvent.button == 0 && indexUnderMouse < indices.size)
                {
                    int index = indices[indexUnderMouse];

                    if (index != -1 && index < mItems.size)
                    {
                        selection     = mItems[index];
                        draggedObject = selection.prefab;
                        dragged       = selection.prefab;
                        currentEvent.Use();
                    }
                }
            }

            mPos = EditorGUILayout.BeginScrollView(mPos);
            {
                Color normal = new Color(1f, 1f, 1f, 0.5f);
                for (int i = 0; i < indices.size; ++i)
                {
                    int  index = indices[i];
                    Item ent   = (index != -1) ? mItems[index] : selection;

                    if (ent != null && ent.prefab == null)
                    {
                        mItems.RemoveAt(index);
                        continue;
                    }

                    Rect rect  = new Rect(x, y, cellSize, cellSize);
                    Rect inner = rect;
                    inner.xMin += 2f;
                    inner.xMax -= 2f;
                    inner.yMin += 2f;
                    inner.yMax -= 2f;
                    rect.yMax  -= 1f;

                    if (!isDragging && (mMode == Mode.CompactMode || (ent == null || ent.tex != null)))
                    {
                        mContent.tooltip = (ent != null) ? ent.prefab.name : "Click to add";
                    }
                    else
                    {
                        mContent.tooltip = "";
                    }

                    //if (ent == selection)
                    {
                        GUI.color = normal;
                        U3DExtends.UIEditorHelper.DrawTiledTexture(inner, U3DExtends.UIEditorHelper.backdropTexture);
                    }

                    GUI.color           = Color.white;
                    GUI.backgroundColor = normal;

                    if (GUI.Button(rect, mContent, "Button"))
                    {
                        if (ent == null || currentEvent.button == 0)
                        {
                            string path = EditorUtility.OpenFilePanel("Add a prefab", "", "prefab");

                            if (!string.IsNullOrEmpty(path))
                            {
                                Item newEnt = CreateItemByPath(path);

                                if (newEnt != null)
                                {
                                    mItems.Add(newEnt);
                                    Save();
                                }
                            }
                        }
                        else if (currentEvent.button == 1)
                        {
                            //ContextMenu.AddItem("Update Preview", false, UpdatePreView, index);
                            ContextMenu.AddItemWithArge("Delete", false, RemoveItem, index);
                            ContextMenu.Show();
                        }
                    }

                    string caption = (ent == null) ? "" : ent.prefab.name.Replace("Control - ", "");

                    if (ent != null)
                    {
                        if (ent.tex == null)
                        {
                            //texture may be destroy after exit game
                            GeneratePreview(ent, false);
                        }
                        if (ent.tex != null)
                        {
                            GUI.DrawTexture(inner, ent.tex, ScaleMode.ScaleToFit, false);
                        }
                        else if (mMode != Mode.DetailedMode)
                        {
                            GUI.Label(inner, caption, mStyle);
                            caption = "";
                        }
                    }
                    else
                    {
                        GUI.Label(inner, "Add", mStyle);
                    }

                    if (mMode == Mode.DetailedMode)
                    {
                        GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                        GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                        string guistyle = "flow node 0";
                        if (ent != null && ent.isDirty)
                        {
                            guistyle = "flow node 3";
                        }
                        GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), caption, guistyle);
                        GUI.contentColor    = Color.white;
                        GUI.backgroundColor = Color.white;
                    }

                    x += spacingX;

                    if (x + spacingX > width)
                    {
                        y += spacingY;
                        x  = cellPadding;
                    }
                }
                GUILayout.Space(y + spacingY);
            }
            EditorGUILayout.EndScrollView();
            //if (mTab == 0)
            {
                //EditorGUILayout.BeginHorizontal();
                //bool isCreateBackground = GUILayout.Button("背景");
                //if (isCreateBackground)
                //    EditorApplication.ExecuteMenuItem("UIEditor/创建/Background");

                //bool isCreateDecorate = GUILayout.Button("参考图");
                //if (isCreateDecorate)
                //    EditorApplication.ExecuteMenuItem("UIEditor/创建/Decorate");
                //EditorGUILayout.EndHorizontal();
            }
            //else if (mTab != 0)
            {
                GUILayout.BeginHorizontal();
                {
                    string after = EditorGUILayout.TextField("", searchFilter, "SearchTextField", GUILayout.Width(Screen.width - 20f));

                    if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
                    {
                        after = "";
                        GUIUtility.keyboardControl = 0;
                    }

                    if (searchFilter != after)
                    {
                        EditorPrefs.SetString("PrefabWin_SearchFilter", after);
                        searchFilter = after;
                    }
                }
                GUILayout.EndHorizontal();
            }

            SizePercent = EditorGUILayout.Slider(SizePercent, 0, 10);
        }
Esempio n. 25
0
    /// <summary>
    /// Search the entire project for required assets.
    /// </summary>

    void Search()
    {
        mSearched = true;

        if (mExtensions != null)
        {
            string[]            paths       = AssetDatabase.GetAllAssetPaths();
            bool                isComponent = mType.IsSubclassOf(typeof(Component));
            BetterList <Object> list        = new BetterList <Object>();

            for (int i = 0; i < mObjects.Length; ++i)
            {
                if (mObjects[i] != null)
                {
                    list.Add(mObjects[i]);
                }
            }

            for (int i = 0; i < paths.Length; ++i)
            {
                string path = paths[i];

                bool valid = false;

                for (int b = 0; b < mExtensions.Length; ++b)
                {
                    if (path.EndsWith(mExtensions[b], System.StringComparison.OrdinalIgnoreCase))
                    {
                        valid = true;
                        break;
                    }
                }

                if (!valid)
                {
                    continue;
                }

                EditorUtility.DisplayProgressBar("Loading", "Searching assets, please wait...", (float)i / paths.Length);
                Object obj = AssetDatabase.LoadMainAssetAtPath(path);
                if (obj == null || list.Contains(obj))
                {
                    continue;
                }

                if (!isComponent)
                {
                    System.Type t = obj.GetType();
                    if (t == mType || t.IsSubclassOf(mType))
                    {
                        list.Add(obj);
                    }
                }
                else if (PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab)
                {
                    Object t = (obj as GameObject).GetComponent(mType);
                    if (t != null)
                    {
                        list.Add(t);
                    }
                }
            }
            list.Sort(delegate(Object a, Object b) { return(a.name.CompareTo(b.name)); });
            mObjects = list.ToArray();
        }
        EditorUtility.ClearProgressBar();
    }
Esempio n. 26
0
    /// <summary>
    /// 寻找所有类型的预制体
    /// </summary>
    /// <param name="mType">M type.</param>
    public static Object[] Search(params System.Type[] mType)
    {
        string[] mExtensions = new string[] { ".prefab" };

        string[] paths = AssetDatabase.GetAllAssetPaths();

        //			bool isComponent = mType.IsSubclassOf(typeof(Component));

        BetterList <Object> list = new BetterList <Object>();



        for (int i = 0; i < paths.Length; ++i)
        {
            string path = paths[i];

            bool valid = false;

            for (int b = 0; b < mExtensions.Length; ++b)
            {
                if (path.EndsWith(mExtensions[b], System.StringComparison.OrdinalIgnoreCase))
                {
                    valid = true;
                    break;
                }
            }

            if (!valid)
            {
                continue;
            }

            //				EditorUtility.DisplayProgressBar("资源找寻中", "机器正在使出吃奶的劲搜索预制体,切勿浮躁,耐心等候……", (float)i / paths.Length);
            Object obj = AssetDatabase.LoadMainAssetAtPath(path);
            if (obj == null || list.Contains(obj))
            {
                continue;
            }


            for (int numType = 0; numType < mType.Length; numType++)
            {
                bool isComponent = mType[numType].IsSubclassOf(typeof(Component));
                if (!isComponent)
                {
                    System.Type t = obj.GetType();
                    if (t == mType[numType] || t.IsSubclassOf(mType[numType]) && !list.Contains(obj))
                    {
                        list.Add(obj);
                    }
                }
                else if (PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab)
                {
                    GameObject gameobj = obj as GameObject;
                    Object     t       = gameobj.GetComponent(mType[numType]);
                    if (t != null && !list.Contains(t))
                    {
                        list.Add(t);
                    }


                    Object[] listPre = gameobj.GetComponentsInChildren(mType[numType], true);
                    for (int num = 0; num < listPre.Length; num++)
                    {
                        if (!list.Contains(listPre[num]))
                        {
                            list.Add(listPre[num]);
                        }
                    }
                }
            }
            EditorUtility.DisplayProgressBar("资源找寻中", "机器正在使出吃奶的劲搜索预制体,切勿浮躁,耐心等候……", (float)i / paths.Length);
        }
        //list.Sort(delegate(Object a, Object b) { return a.name.CompareTo(b.name); });
        EditorUtility.ClearProgressBar();
        return(list.ToArray());
    }
Esempio n. 27
0
 public bool isUsingSlot(OutfitSlot outfitSlot)
 {
     return(slots.Contains(outfitSlot));
 }
Esempio n. 28
0
        void OnGUI()
        {
            Event     currentEvent = Event.current;
            EventType type         = currentEvent.type;

            int x = cellPadding, y = cellPadding;
            int width    = Screen.width - cellPadding;
            int spacingX = cellSize + cellPadding;
            int spacingY = spacingX;

            if (mMode == Mode.DetailedMode)
            {
                spacingY += 32;
            }

            GameObject[] draggeds        = draggedObjects;
            bool         isDragging      = (draggeds != null);
            int          indexUnderMouse = GetCellUnderMouse(spacingX, spacingY);

            if (isDragging)
            {
                foreach (var gameObject in draggeds)
                {
                    var result = FindItem(gameObject);

                    if (result != null)
                    {
                        _selections.Add(result);
                    }
                }
            }

            string searchFilter = EditorPrefs.GetString("PrefabWin_SearchFilter", null);

            int newTab = mTab;

            GUILayout.BeginHorizontal();
            if (GUILayout.Toggle(newTab == 0, "通用控件", "ButtonLeft"))
            {
                newTab = 0;
            }
            if (GUILayout.Toggle(newTab == 1, "其它模板", "ButtonRight"))
            {
                newTab = 1;
            }
            GUILayout.EndHorizontal();

            if (mTab != newTab)
            {
                Save();
                mTab   = newTab;
                mReset = true;
                EditorPrefs.SetInt("PrefabWin Prefab Tab", mTab);
                Load();
            }

            if (mReset && type == EventType.Repaint)
            {
                mReset = false;
                foreach (Item item in mItems)
                {
                    GeneratePreview(item, false);
                }
                RectivateLights();
            }

            bool eligibleToDrag = (currentEvent.mousePosition.y < Screen.height - 40);

            if (type == EventType.MouseDown)
            {
                mMouseIsInside = true;
            }
            else if (type == EventType.MouseDrag)
            {
                mMouseIsInside = true;

                if (indexUnderMouse != -1 && eligibleToDrag)
                {
                    if (draggedObjectIsOurs)
                    {
                        DragAndDrop.StartDrag("Prefab Tool");
                    }
                    currentEvent.Use();
                }
            }
            else if (type == EventType.MouseUp)
            {
                DragAndDrop.PrepareStartDrag();
                mMouseIsInside = false;
                Repaint();
            }
            else if (type == EventType.DragUpdated)
            {
                mMouseIsInside = true;
                UpdateVisual();
                currentEvent.Use();
            }
            else if (type == EventType.DragPerform)
            {
                if (draggeds != null)
                {
                    if (_selections != null)
                    {
                        foreach (var selection in _selections)
                        {
                            DestroyTexture(selection);
                            mItems.Remove(selection);
                        }
                    }

                    foreach (var dragged in draggeds)
                    {
                        AddItem(dragged, indexUnderMouse);
                        ++indexUnderMouse;
                    }

                    draggeds = null;
                }
                mMouseIsInside = false;
                currentEvent.Use();
            }
            else if (type == EventType.DragExited || type == EventType.Ignore)
            {
                mMouseIsInside = false;
            }

            if (!mMouseIsInside)
            {
                _selections.Clear();
                draggeds = null;
            }

            BetterList <int> indices = new BetterList <int>();

            for (int i = 0; i < mItems.size;)
            {
                if (draggeds != null && indices.size == indexUnderMouse)
                {
                    indices.Add(-1);
                }

                var has = _selections.Exists(item => item == mItems[i]);

                if (!has)
                {
                    if (string.IsNullOrEmpty(searchFilter) ||
                        mItems[i].prefab.name.IndexOf(searchFilter, System.StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        indices.Add(i);
                    }
                }

                ++i;
            }

            if (!indices.Contains(-1))
            {
                indices.Add(-1);
            }

            if (eligibleToDrag && type == EventType.MouseDown && indexUnderMouse > -1)
            {
                GUIUtility.keyboardControl = 0;

                if (currentEvent.button == 0 && indexUnderMouse < indices.size)
                {
                    int index = indices[indexUnderMouse];

                    if (index != -1 && index < mItems.size)
                    {
                        _selections.Add(mItems[index]);
                        draggedObjects = _selections.Select(item => item.prefab).ToArray();
                        draggeds       = _selections.Select(item => item.prefab).ToArray();
                        currentEvent.Use();
                    }
                }
            }

            mPos = EditorGUILayout.BeginScrollView(mPos);
            {
                Color normal = new Color(1f, 1f, 1f, 0.5f);
                for (int i = 0; i < indices.size; ++i)
                {
                    int  index = indices[i];
                    Item ent   = (index != -1) ? mItems[index] : _selections.Count == 0 ? null : _selections[0];

                    if (ent != null && ent.prefab == null)
                    {
                        mItems.RemoveAt(index);
                        continue;
                    }

                    Rect rect  = new Rect(x, y, cellSize, cellSize);
                    Rect inner = rect;
                    inner.xMin += 2f;
                    inner.xMax -= 2f;
                    inner.yMin += 2f;
                    inner.yMax -= 2f;
                    rect.yMax  -= 1f;

                    if (!isDragging && (mMode == Mode.CompactMode || (ent == null || ent.tex != null)))
                    {
                        mContent.tooltip = (ent != null) ? ent.prefab.name : "Click to add";
                    }
                    else
                    {
                        mContent.tooltip = "";
                    }

                    //if (ent == selection)
                    {
                        GUI.color = normal;
                        U3DExtends.UIEditorHelper.DrawTiledTexture(inner, U3DExtends.UIEditorHelper.backdropTexture);
                    }

                    GUI.color           = Color.white;
                    GUI.backgroundColor = normal;

                    if (GUI.Button(rect, mContent, "Button"))
                    {
                        if (ent == null || currentEvent.button == 0)
                        {
                            string path = EditorUtility.OpenFilePanel("Add a prefab", "", "prefab");

                            if (!string.IsNullOrEmpty(path))
                            {
                                Item newEnt = CreateItemByPath(path);

                                if (newEnt != null)
                                {
                                    mItems.Add(newEnt);
                                    Save();
                                }
                            }
                        }
                        else if (currentEvent.button == 1)
                        {
                            //ContextMenu.AddItem("Update Preview", false, UpdatePreView, index);
                            ContextMenu.AddItemWithArge("Delete", false, RemoveItem, index);
                            ContextMenu.Show();
                        }
                    }

                    string caption = (ent == null) ? "" : ent.prefab.name.Replace("Control - ", "");

                    if (ent != null)
                    {
                        if (ent.tex == null)
                        {
                            //texture may be destroy after exit game
                            GeneratePreview(ent, false);
                        }
                        if (ent.tex != null)
                        {
                            GUI.DrawTexture(inner, ent.tex);
                            var labelPos   = new Rect(inner);
                            var labelStyle = EditorStyles.label;
                            labelPos.height      = labelStyle.lineHeight;
                            labelPos.y           = inner.height - labelPos.height + 5;
                            labelStyle.fontSize  = (int)(_labelDefaultFontSize * SizePercent);
                            labelStyle.alignment = TextAnchor.LowerCenter;
                            {
                                GUI.Label(labelPos, ent.prefab.name, labelStyle);
                            }
                            labelStyle.alignment = TextAnchor.UpperLeft;
                            labelStyle.fontSize  = _labelDefaultFontSize;
                        }
                        else if (mMode != Mode.DetailedMode)
                        {
                            GUI.Label(inner, caption, mStyle);
                            caption = "";
                        }
                    }
                    else
                    {
                        GUI.Label(inner, "Add", mStyle);
                    }

                    if (mMode == Mode.DetailedMode)
                    {
                        GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                        GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                        GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), caption, "ProgressBarBack");
                        GUI.contentColor    = Color.white;
                        GUI.backgroundColor = Color.white;
                    }

                    x += spacingX;

                    if (x + spacingX > width)
                    {
                        y += spacingY;
                        x  = cellPadding;
                    }
                }
                GUILayout.Space(y + spacingY);
            }
            EditorGUILayout.EndScrollView();
            //if (mTab == 0)
            {
                //EditorGUILayout.BeginHorizontal();
                //bool isCreateBackground = GUILayout.Button("背景");
                //if (isCreateBackground)
                //    EditorApplication.ExecuteMenuItem("UIEditor/创建/Background");

                //bool isCreateDecorate = GUILayout.Button("参考图");
                //if (isCreateDecorate)
                //    EditorApplication.ExecuteMenuItem("UIEditor/创建/Decorate");
                //EditorGUILayout.EndHorizontal();
            }
            //else if (mTab != 0)
            {
                GUILayout.BeginHorizontal();
                {
                    string after = EditorGUILayout.TextField("", searchFilter, "SearchTextField", GUILayout.Width(Screen.width - 20f));

                    if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
                    {
                        after = "";
                        GUIUtility.keyboardControl = 0;
                    }

                    if (searchFilter != after)
                    {
                        EditorPrefs.SetString("PrefabWin_SearchFilter", after);
                        searchFilter = after;
                    }
                }
                GUILayout.EndHorizontal();
            }

            SizePercent = EditorGUILayout.Slider(SizePercent, 0, 1);
        }
Esempio n. 29
0
        private void ParseData(string str)
        {
            this.listEmotionData.Clear();
            int length = str.Length;
            int num    = -6;
            BetterList <string> listOfSprites = this.atlas.GetListOfSprites();

            for (int num2 = 0; num2 != length; num2++)
            {
                if (str[num2] == '#' && num2 + 4 < length && str[num2 + 1] == 'e')
                {
                    EmotionData item = default(EmotionData);
                    item.serialNumber = str.Substring(num2 + 2, 3);
                    if (listOfSprites.Contains(item.serialNumber))
                    {
                        if (this.IsShowVIPStr(str, num2))
                        {
                            int num3 = (num != 0) ? (num + 6) : (num + 7);
                            item.strContent    = str.Substring(num3, num2 + 5 - num3).Replace(str.Substring(num2, 5), (num2 != 0) ? "      " : "       ");
                            item.position      = num2;
                            item.row           = 1;
                            item.totalConSpace = item.strContent.Length;
                            item.totalNonSpace = (float)(str.Substring(num3, num2 + 5 - num3).Length - 5) + 1.5f;
                            this.listEmotionData.Add(item);
                            num = num2;
                            Regex regex = new Regex(str.Substring(num2, 5));
                            str    = regex.Replace(str, (num2 != 0) ? "      " : "       ", 1);
                            length = str.Length;
                        }
                    }
                }
            }
            string text = string.Empty;

            if (this.listEmotionData != null && this.listEmotionData.Count != 0)
            {
                if (this.listEmotionData[this.listEmotionData.Count - 1].position == 0)
                {
                    if (str.Length != 7)
                    {
                        text = str.Substring(this.listEmotionData[this.listEmotionData.Count - 1].position + 7);
                    }
                }
                else
                {
                    text = str.Substring(this.listEmotionData[this.listEmotionData.Count - 1].position + 6);
                }
            }
            else
            {
                text = str;
            }
            string text2 = null;

            for (int num4 = 0; num4 != this.listEmotionData.Count; num4++)
            {
                text2 += this.listEmotionData[num4].strContent;
            }
            if (!string.IsNullOrEmpty(text))
            {
                text2 += text;
            }
            this.CalculateLineFeed(text2);
        }
Esempio n. 30
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        Event     currentEvent = Event.current;
        EventType type         = currentEvent.type;

        int x = cellPadding, y = cellPadding;
        int width    = Screen.width - cellPadding;
        int spacingX = cellSize + cellPadding;
        int spacingY = spacingX;

        if (mMode == Mode.DetailedMode)
        {
            spacingY += 32;
        }

        GameObject dragged         = draggedObject;
        bool       isDragging      = (dragged != null);
        int        indexUnderMouse = GetCellUnderMouse(spacingX, spacingY);
        Item       selection       = isDragging ? FindItem(dragged) : null;
        string     searchFilter    = NGUISettings.searchField;

        int newTab = mTab;

        GUILayout.BeginHorizontal();
        if (GUILayout.Toggle(newTab == 0, "1", "ButtonLeft"))
        {
            newTab = 0;
        }
        if (GUILayout.Toggle(newTab == 1, "2", "ButtonMid"))
        {
            newTab = 1;
        }
        if (GUILayout.Toggle(newTab == 2, "3", "ButtonMid"))
        {
            newTab = 2;
        }
        if (GUILayout.Toggle(newTab == 3, "4", "ButtonMid"))
        {
            newTab = 3;
        }
        if (GUILayout.Toggle(newTab == 4, "5", "ButtonRight"))
        {
            newTab = 4;
        }
        GUILayout.EndHorizontal();

        if (mTab != newTab)
        {
            Save();
            mTab   = newTab;
            mReset = true;
            NGUISettings.SetInt("NGUI Prefab Tab", mTab);
            Load();
        }

        if (mReset && type == EventType.Repaint)
        {
            mReset = false;
            foreach (Item item in mItems)
            {
                GeneratePreview(item, null);
            }
            RectivateLights();
        }

        // Search field
        GUILayout.BeginHorizontal();
        {
            string after = EditorGUILayout.TextField("", searchFilter, "SearchTextField", GUILayout.Width(Screen.width - 20f));

            if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
            {
                after = "";
                GUIUtility.keyboardControl = 0;
            }

            if (searchFilter != after)
            {
                NGUISettings.searchField = after;
                searchFilter             = after;
            }
        }
        GUILayout.EndHorizontal();

        bool eligibleToDrag = (currentEvent.mousePosition.y < Screen.height - 40);

        if (type == EventType.MouseDown)
        {
            mMouseIsInside = true;
        }
        else if (type == EventType.MouseDrag)
        {
            mMouseIsInside = true;

            if (indexUnderMouse != -1 && eligibleToDrag)
            {
                // Drag operation begins
                if (draggedObjectIsOurs)
                {
                    DragAndDrop.StartDrag("Prefab Tool");
                }
                currentEvent.Use();
            }
        }
        else if (type == EventType.MouseUp)
        {
            DragAndDrop.PrepareStartDrag();
            mMouseIsInside = false;
            Repaint();
        }
        else if (type == EventType.DragUpdated)
        {
            // Something dragged into the window
            mMouseIsInside = true;
            UpdateVisual();
            currentEvent.Use();
        }
        else if (type == EventType.DragPerform)
        {
            // We've dropped a new object into the window
            if (dragged != null)
            {
                if (selection != null)
                {
                    DestroyTexture(selection);
                    mItems.Remove(selection);
                }

                AddItem(dragged, indexUnderMouse);
                draggedObject = null;
            }
            mMouseIsInside = false;
            currentEvent.Use();
        }
        else if (type == EventType.DragExited || type == EventType.Ignore)
        {
            mMouseIsInside = false;
        }

        // If the mouse is not inside the window, clear the selection and dragged object
        if (!mMouseIsInside)
        {
            selection = null;
            dragged   = null;
        }

        // Create a list of indices, inserting an entry of '-1' underneath the dragged object
        BetterList <int> indices = new BetterList <int>();

        for (int i = 0; i < mItems.size;)
        {
            if (dragged != null && indices.size == indexUnderMouse)
            {
                indices.Add(-1);
            }

            if (mItems[i] != selection)
            {
                if (string.IsNullOrEmpty(searchFilter) ||
                    mItems[i].prefab.name.IndexOf(searchFilter, System.StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    indices.Add(i);
                }
            }
            ++i;
        }

        // There must always be '-1' (Add/Move slot) present
        if (!indices.Contains(-1))
        {
            indices.Add(-1);
        }

        // We want to start dragging something from within the window
        if (eligibleToDrag && type == EventType.MouseDown && indexUnderMouse > -1)
        {
            GUIUtility.keyboardControl = 0;

            if (currentEvent.button == 0 && indexUnderMouse < indices.size)
            {
                int index = indices[indexUnderMouse];

                if (index != -1 && index < mItems.size)
                {
                    selection     = mItems[index];
                    draggedObject = selection.prefab;
                    dragged       = selection.prefab;
                    currentEvent.Use();
                }
            }
        }
        //else if (type == EventType.MouseUp && currentEvent.button == 1 && indexUnderMouse > mItems.size)
        //{
        //    NGUIContextMenu.AddItem("Reset", false, RemoveItem, index);
        //    NGUIContextMenu.Show();
        //}

        // Draw the scroll view with prefabs
        mPos = GUILayout.BeginScrollView(mPos);
        {
            Color normal = new Color(1f, 1f, 1f, 0.5f);

            for (int i = 0; i < indices.size; ++i)
            {
                int  index = indices[i];
                Item ent   = (index != -1) ? mItems[index] : selection;

                if (ent != null && ent.prefab == null)
                {
                    mItems.RemoveAt(index);
                    continue;
                }

                Rect rect  = new Rect(x, y, cellSize, cellSize);
                Rect inner = rect;
                inner.xMin += 2f;
                inner.xMax -= 2f;
                inner.yMin += 2f;
                inner.yMax -= 2f;
                rect.yMax  -= 1f;                // Button seems to be mis-shaped. It's height is larger than its width by a single pixel.

                if (!isDragging && (mMode == Mode.CompactMode || (ent == null || ent.tex != null)))
                {
                    mContent.tooltip = (ent != null) ? ent.prefab.name : "Click to add";
                }
                else
                {
                    mContent.tooltip = "";
                }

                //if (ent == selection)
                {
                    GUI.color = normal;
                    NGUIEditorTools.DrawTiledTexture(inner, NGUIEditorTools.backdropTexture);
                }

                GUI.color           = Color.white;
                GUI.backgroundColor = normal;

                if (GUI.Button(rect, mContent, "Button"))
                {
                    if (ent == null || currentEvent.button == 0)
                    {
                        string path = EditorUtility.OpenFilePanel("Add a prefab", NGUISettings.currentPath, "prefab");

                        if (!string.IsNullOrEmpty(path))
                        {
                            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                            Item newEnt = CreateItemByPath(path);

                            if (newEnt != null)
                            {
                                mItems.Add(newEnt);
                                Save();
                            }
                        }
                    }
                    else if (currentEvent.button == 1)
                    {
                        NGUIContextMenu.AddItem("Delete", false, RemoveItem, index);
                        NGUIContextMenu.Show();
                    }
                }

                string caption = (ent == null) ? "" : ent.prefab.name.Replace("Control - ", "");

                if (ent != null)
                {
                    if (ent.tex != null)
                    {
                        GUI.DrawTexture(inner, ent.tex);
                    }
                    else if (mMode != Mode.DetailedMode)
                    {
                        GUI.Label(inner, caption, mStyle);
                        caption = "";
                    }
                }
                else
                {
                    GUI.Label(inner, "Add", mStyle);
                }

                if (mMode == Mode.DetailedMode)
                {
                    GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                    GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                    GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), caption, "ProgressBarBack");
                    GUI.contentColor    = Color.white;
                    GUI.backgroundColor = Color.white;
                }

                x += spacingX;

                if (x + spacingX > width)
                {
                    y += spacingY;
                    x  = cellPadding;
                }
            }
            GUILayout.Space(y);
        }
        GUILayout.EndScrollView();

        // Mode
        Mode modeAfter = (Mode)EditorGUILayout.EnumPopup(mMode);

        if (modeAfter != mMode)
        {
            mMode  = modeAfter;
            mReset = true;
            NGUISettings.SetEnum("NGUI Prefab Mode", mMode);
        }
    }
Esempio n. 31
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        GUILayout.Space(6f);
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.BeginHorizontal();
        // Key not found in the localization file -- draw it as a text field
        SerializedProperty sp = NGUIEditorTools.DrawProperty("Key", serializedObject, "key");

        string myKey     = sp.stringValue;
        bool   isPresent = (mKeys != null) && mKeys.Contains(myKey);

        GUI.color = isPresent ? Color.green : Color.red;
        GUILayout.BeginVertical(GUILayout.Width(22f));
        GUILayout.Space(2f);
#if UNITY_3_5
        GUILayout.Label(isPresent? "ok" : "!!", GUILayout.Height(20f));
#else
        GUILayout.Label(isPresent? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f));
#endif
        GUILayout.EndVertical();
        GUI.color = Color.white;
        GUILayout.EndHorizontal();

        if (isPresent)
        {
            if (NGUIEditorTools.DrawHeader("Preview"))
            {
                NGUIEditorTools.BeginContents();

                string[] keys;
                string[] values;

                if (Localization.dictionary.TryGetValue("KEY", out keys) && Localization.dictionary.TryGetValue(myKey, out values))
                {
                    for (int i = 0; i < keys.Length; ++i)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(keys[i], GUILayout.Width(70f));

                        if (GUILayout.Button(values[i], "AS TextArea", GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f)))
                        {
                            (target as UILocalize).value = values[i];
                            GUIUtility.hotControl        = 0;
                            GUIUtility.keyboardControl   = 0;
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                else
                {
                    GUILayout.Label("No preview available");
                }

                NGUIEditorTools.EndContents();
            }
        }
        else if (mKeys != null && !string.IsNullOrEmpty(myKey))
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            GUILayout.BeginVertical();
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f);

            int matches = 0;

            for (int i = 0; i < mKeys.size; ++i)
            {
                if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey))
                {
#if UNITY_3_5
                    if (GUILayout.Button(mKeys[i] + " \u25B2"))
#else
                    if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge"))
#endif
                    {
                        sp.stringValue             = mKeys[i];
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }

                    if (++matches == 8)
                    {
                        GUILayout.Label("...and more");
                        break;
                    }
                }
            }
            GUI.backgroundColor = Color.white;
            GUILayout.EndVertical();
            GUILayout.Space(22f);
            GUILayout.EndHorizontal();
        }

        serializedObject.ApplyModifiedProperties();
    }