Ejemplo n.º 1
0
    protected override void OnDisable()
    {
        for (int i = 0; i < drawCalls.size; ++i)
        {
            UIDrawCall dc = drawCalls.buffer[i];
            if (dc != null)
            {
                UIDrawCall.Destroy(dc);
            }
        }

        drawCalls.Clear();
        list.Remove(this);

        if (list.size == 0)
        {
            UIDrawCall.ReleaseAll();
        }
        base.OnDisable();
    }
Ejemplo n.º 2
0
	/// <summary>
	/// Destroy all draw calls we've created when this script gets disabled.
	/// </summary>

	protected override void OnDisable ()
	{
		for (int i = 0; i < drawCalls.size; ++i)
		{
			UIDrawCall dc = drawCalls.buffer[i];
			if (dc != null) UIDrawCall.Destroy(dc);
		}
		
		drawCalls.Clear();
		list.Remove(this);

		mAlphaFrameID = -1;
		mMatrixFrame = -1;
		
		if (list.size == 0)
		{
			UIDrawCall.ReleaseAll();
			mUpdateFrame = -1;
		}
		base.OnDisable();
	}
Ejemplo n.º 3
0
        protected void UpdateRevealers(int deltaMS)
        {
            // Add all items scheduled to be added
            if (revealersAdded.size > 0)
            {
                lock (revealersAdded)
                {
                    while (revealersAdded.size > 0)
                    {
                        int index = revealersAdded.size - 1;
                        revealers.Add(revealersAdded.buffer[index]);
                        revealersAdded.RemoveAt(index);
                    }
                }
            }

            // Remove all items scheduled for removal
            if (revealersRemoved.size > 0)
            {
                lock (revealersRemoved)
                {
                    while (revealersRemoved.size > 0)
                    {
                        int index = revealersRemoved.size - 1;
                        revealers.Remove(revealersRemoved.buffer[index]);
                        revealersRemoved.RemoveAt(index);
                    }
                }
            }

            for (int i = revealers.size - 1; i >= 0; i--)
            {
                IMangoFogRevealer revealer = revealers[i];
                revealer.Update(deltaMS);
                if (!revealer.IsValid())
                {
                    revealer.Release();
                }
            }
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Remove the specified widget from the managed list.
    /// </summary>

    public void RemoveWidget(UIWidget w)
    {
        if (w != null)
        {
            // Do we have this node? Mark the widget's material as having been changed
            UINode pc = GetNode(w.cachedTransform);

            if (pc != null)
            {
                // Mark the material as having been changed
                if (pc.visibleFlag == 1 && !mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                    mChangedLastFrame = true;
                }

                // Remove this transform
                RemoveTransform(w.cachedTransform);
            }
            mWidgets.Remove(w);
        }
    }
Ejemplo n.º 5
0
	static void CompareTwoAtlas(){
		GameObject[] gameObjs = Selection.gameObjects;
		UIAtlas oldUIAltas = gameObjs[0].GetComponent<UIAtlas>();
		UIAtlas newUIAltas = gameObjs[1].GetComponent<UIAtlas>();
		
		BetterList<string> oldNames = oldUIAltas.GetListOfSprites();
		BetterList<string> newNames = newUIAltas.GetListOfSprites();
		
		Debug.Log("Old Counts:"+oldNames.ToArray().Length);
		Debug.Log("New Counts:"+newNames.ToArray().Length);
		
		foreach(string name in oldNames){
			newNames.Remove(name);
			Debug.Log("delete:"+name);
		}
		
		foreach(string name in newNames){
			Debug.LogWarning("The New Texture:"+name);
		}
		
		
	}
    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;
            }
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Show the specified window.
    /// </summary>

    static public void Show(UIPanel window)
    {
        if (mActive == window)
        {
            return;
        }

        CreateInstance();

        if (mActive != null)
        {
            if (showSound != null)
            {
                NGUITools.PlaySound(hideSound);
            }
            mFading.Add(mActive);
            mHistory.Add(mActive);
        }

        if (mHistory.Remove(window))
        {
            mFading.Remove(window);
        }
        else if (window != null)
        {
            window.alpha = 0f;
        }

        mActive = window;

        if (mActive != null)
        {
            mActive.alpha = 0f;
            mActive.transform.localScale = Vector3.one * 0.9f;
            mActive.gameObject.SetActive(true);
        }
    }
Ejemplo n.º 8
0
 protected virtual void OnDisable()
 {
     list.Remove(this);
 }
Ejemplo n.º 9
0
    /// <summary>
    /// Convenience function that figures out the panel's correct change flag by searching the parents.
    /// </summary>

    int GetChangeFlag(UINode start)
    {
        int flag = start.changeFlag;

        if (flag == -1)
        {
            Transform trans = start.trans.parent;
            UINode    sub;

            // Keep going until we find a set flag
            for (;;)
            {
                // Check the parent's flag
#if USE_SIMPLE_DICTIONARY
                if (trans != null && mChildren.TryGetValue(trans, out sub))
                {
#else
                if (trans != null && mChildren.Contains(trans))
                {
                    sub = (UINode)mChildren[trans];
#endif
                    flag  = sub.changeFlag;
                    trans = trans.parent;

                    // If the flag hasn't been set either, add this child to the hierarchy
                    if (flag == -1)
                    {
                        mHierarchy.Add(sub);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            // Update the parent flags
            for (int i = 0, imax = mHierarchy.size; i < imax; ++i)
            {
                UINode pc = mHierarchy.buffer[i];
                pc.changeFlag = flag;
            }
            mHierarchy.Clear();
        }
        return(flag);
    }

    /// <summary>
    /// Run through all managed transforms and see if they've changed.
    /// </summary>

    void UpdateTransforms()
    {
        bool transformsChanged = false;
        bool shouldCull        = false;

#if UNITY_EDITOR
        shouldCull = (clipping != UIDrawCall.Clipping.None) && (!Application.isPlaying || (cullWhileDragging || mUpdateTime > mCullTime));
        if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#else
        shouldCull = (clipping != UIDrawCall.Clipping.None) && (mUpdateTime > mCullTime);
        if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#endif
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode node = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode node = (UINode)mChildren[i];
#endif
                if (node.trans == null)
                {
                    mRemoved.Add(node.trans);
                    continue;
                }

                if (node.HasChanged())
                {
                    node.changeFlag   = 1;
                    transformsChanged = true;
#if UNITY_EDITOR
                    Vector3 s   = node.trans.lossyScale;
                    float   min = Mathf.Abs(Mathf.Min(s.x, s.y));

                    if (min == 0f)
                    {
                        Debug.LogError("Scale of 0 is invalid! Zero cannot be divided by, which causes problems. Use a small value instead, such as 0.01\n" +
                                       node.trans.lossyScale, node.trans);
                    }
#endif
                }
                else
                {
                    node.changeFlag = -1;
                }
            }

            // Clean up the deleted transforms
            for (int i = 0, imax = mRemoved.Count; i < imax; ++i)
            {
                mChildren.Remove(mRemoved[i]);
            }
            mRemoved.Clear();
        }

        // If the children weren't culled but should be, check their visibility
        if (!mCulled && shouldCull)
        {
            mCheckVisibility = true;
        }

        // If something has changed, propagate the changes *down* the tree hierarchy (to children).
        // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>()
        // in the loop above, and mark each one as dirty.

        if (mCheckVisibility || transformsChanged || mRebuildAll)
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode pc = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode pc = (UINode)mChildren[i];
#endif
                if (pc.widget != null)
                {
                    int visibleFlag = 1;

                    // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true')
                    if (shouldCull || transformsChanged)
                    {
                        // If the change flag has not yet been determined...
                        if (pc.changeFlag == -1)
                        {
                            pc.changeFlag = GetChangeFlag(pc);
                        }

                        // Is the widget visible?
                        if (shouldCull)
                        {
                            visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag;
                        }
                    }

                    // If visibility changed, mark the node as changed as well
                    if (pc.visibleFlag != visibleFlag)
                    {
                        pc.changeFlag = 1;
                    }

                    // If the node has changed and the widget is visible (or was visible before)
                    if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0))
                    {
                        // Update the visibility flag
                        pc.visibleFlag = visibleFlag;
                        Material mat = pc.widget.material;

                        // Add this material to the list of changed materials
                        if (!mChanged.Contains(mat))
                        {
                            mChanged.Add(mat);
                        }
                    }
                }
            }
        }
        mCulled          = shouldCull;
        mCheckVisibility = false;
        mWidgetsAdded    = false;
    }

    /// <summary>
    /// Update all widgets and rebuild their geometry if necessary.
    /// </summary>

    void UpdateWidgets()
    {
#if USE_SIMPLE_DICTIONARY
        foreach (KeyValuePair <Transform, UINode> c in mChildren)
        {
            UINode pc = c.Value;
#else
        for (int i = 0, imax = mChildren.Count; i < imax; ++i)
        {
            UINode pc = (UINode)mChildren[i];
#endif
            UIWidget w = pc.widget;

            // If the widget is visible, update it
            if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(this, ref worldToLocal, (pc.changeFlag == 1), generateNormals))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                }
            }
            pc.changeFlag = 0;
        }
    }
#endif

    /// <summary>
    /// Update the clipping rect in the shaders and draw calls' positions.
    /// </summary>

    public void UpdateDrawcalls()
    {
        Vector4 range = Vector4.zero;

        if (mClipping != UIDrawCall.Clipping.None)
        {
            range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f);
        }

        if (range.z == 0f)
        {
            range.z = Screen.width * 0.5f;
        }
        if (range.w == 0f)
        {
            range.w = Screen.height * 0.5f;
        }

        RuntimePlatform platform = Application.platform;

        if (platform == RuntimePlatform.WindowsPlayer ||
            platform == RuntimePlatform.WindowsWebPlayer ||
            platform == RuntimePlatform.WindowsEditor)
        {
            range.x -= 0.5f;
            range.y += 0.5f;
        }

        Transform  t = cachedTransform;
        UIDrawCall dc;
        Transform  dt;

        for (int i = 0, imax = mDrawCalls.size; i < imax; ++i)
        {
            dc              = mDrawCalls.buffer[i];
            dc.clipping     = mClipping;
            dc.clipRange    = range;
            dc.clipSoftness = mClipSoftness;
            dc.depthPass    = depthPass && mClipping == UIDrawCall.Clipping.None;

            // Set the draw call's transform to match the panel's.
            // Note that parenting directly to the panel causes unity to crash as soon as you hit Play.
            dt            = dc.transform;
            dt.position   = t.position;
            dt.rotation   = t.rotation;
            dt.localScale = t.lossyScale;
        }
    }

    /// <summary>
    /// Set the draw call's geometry responsible for the specified material.
    /// </summary>

    void Fill(Material mat)
    {
        int highest = -100;

        // Fill the buffers for the specified material
        for (int i = 0; i < mWidgets.size;)
        {
            UIWidget w = mWidgets.buffer[i];

            if (w == null)
            {
                mWidgets.RemoveAt(i);
                continue;
            }
#if OLD_UNITY
            else if (w.visibleFlag == 1 && w.material == mat)
#else
            else if (w.material == mat && w.isVisible)
#endif
            {
                if (w.panel == this)
                {
                    int depth = w.depth;
                    if (depth > highest)
                    {
                        highest = depth;
                    }
                    if (generateNormals)
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans);
                    }
                    else
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, null, null);
                    }
                }
                else
                {
                    mWidgets.RemoveAt(i);
                    continue;
                }
            }
            ++i;
        }

        if (mVerts.size > 0)
        {
            // Rebuild the draw call's mesh
            UIDrawCall dc = GetDrawCall(mat, true);
            dc.depthPass = depthPass && mClipping == UIDrawCall.Clipping.None;
            dc.depth     = sortByDepth ? highest : 0;
            dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols);
            dc.mainTexture = mat.mainTexture;
        }
        else
        {
            // There is nothing to draw for this material -- eliminate the draw call
            UIDrawCall dc = GetDrawCall(mat, false);

            if (dc != null)
            {
                mDrawCalls.Remove(dc);
                NGUITools.DestroyImmediate(dc.gameObject);
            }
        }

        // Cleanup
        mVerts.Clear();
        mNorms.Clear();
        mTans.Clear();
        mUvs.Clear();
        mCols.Clear();
    }

    /// <summary>
    /// Main update function
    /// </summary>

    void LateUpdate()
    {
        mUpdateTime = Time.realtimeSinceStartup;
        UpdateTransformMatrix();
#if OLD_UNITY
        UpdateTransforms();
#endif
        // Always move widgets to the panel's layer
        if (mLayer != cachedGameObject.layer)
        {
            mLayer = mGo.layer;
            UICamera uic = UICamera.FindCameraForLayer(mLayer);
            mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer);
            SetChildLayer(cachedTransform, mLayer);
            for (int i = 0, imax = drawCalls.size; i < imax; ++i)
            {
                mDrawCalls.buffer[i].gameObject.layer = mLayer;
            }
        }

#if OLD_UNITY
        UpdateWidgets();
#else
#if UNITY_EDITOR
        bool forceVisible = cullWhileDragging ? false : (clipping == UIDrawCall.Clipping.None) || (Application.isPlaying && mCullTime > mUpdateTime);
#else
        bool forceVisible = cullWhileDragging ? false : (clipping == UIDrawCall.Clipping.None) || (mCullTime > mUpdateTime);
#endif
        // Update all widgets
        for (int i = 0, imax = mWidgets.size; i < imax; ++i)
        {
            UIWidget w = mWidgets[i];

            // If the widget is visible, update it
            if (w.UpdateGeometry(this, forceVisible))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                }
            }
        }
#endif
        // Inform the changed event listeners
        if (mChanged.size != 0 && onChange != null)
        {
            onChange();
        }

        // If the depth has changed, we need to re-sort the widgets
        if (mDepthChanged)
        {
            mDepthChanged = false;
            mWidgets.Sort(UIWidget.CompareFunc);
        }

        // Fill the draw calls for all of the changed materials
        for (int i = 0, imax = mChanged.size; i < imax; ++i)
        {
            Fill(mChanged.buffer[i]);
        }

        // Update the clipping rects
        UpdateDrawcalls();
        mChanged.Clear();
#if OLD_UNITY
        mRebuildAll = false;
#endif
#if UNITY_EDITOR
        mScreenSize = new Vector2(Screen.width, Screen.height);
#endif
    }
Ejemplo n.º 10
0
 void OnDisable()
 {
     list.Remove(this); mPressed = false;
 }
Ejemplo n.º 11
0
    /// <summary>
    /// Cleanup.
    /// </summary>

    void OnDestroy()
    {
        mInactiveList.Remove(this);
        NGUITools.DestroyImmediate(mMesh);
    }
Ejemplo n.º 12
0
 public void Remove(Chuck chuck)
 {
     _chucks.Remove(chuck);
 }
Ejemplo n.º 13
0
    /// <summary>
    /// Cleanup.
    /// </summary>

    void OnDestroy()
    {
        list.Remove(this);
        NGUITools.DestroyImmediate(mMesh);
        NGUITools.DestroyImmediate(mDynamicMat);
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Remove the font texture change listener.
    /// </summary>

    protected override void OnDisable()
    {
        SetActiveFont(null);
        mList.Remove(this);
        base.OnDisable();
    }
Ejemplo n.º 15
0
 public void Remove(Actor actor)
 {
     _actors.Remove(actor);
 }
Ejemplo n.º 16
0
        //绘制预览界面
        public void DrawPreviewEvent()
        {
            Event     currentEvent = Event.current;
            EventType type         = currentEvent.type;

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

            if (m_mode == 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);

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

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

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

                if (indexUnderMouse != -1 && eligibleToDrag)
                {
                    if (draggedObjectIsOurs)
                    {
                        DragAndDrop.StartDrag("Prefab Tool");
                    }
                    currentEvent.Use();
                }
            }
            else if (type == EventType.MouseUp)
            {
                DragAndDrop.PrepareStartDrag();
                m_mouseIsInside = false;
                Repaint();
            }
            else if (type == EventType.DragUpdated)
            {
                m_mouseIsInside = 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;
                }
                m_mouseIsInside = false;
                currentEvent.Use();
            }
            else if (type == EventType.DragExited || type == EventType.Ignore)
            {
                m_mouseIsInside = false;
            }

            if (!m_mouseIsInside)
            {
                _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();
                    }
                }
            }

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

                    if (item != null && item.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 && (m_mode == Mode.CompactMode || (item == null || item.tex != null)))
                    {
                        m_content.tooltip = (item != null) ? item.prefab.name : "Click to add";
                    }
                    else
                    {
                        m_content.tooltip = "";
                    }

                    GUI.color = normal;
                    UIEditorHelper.DrawTiledTexture(inner, UIEditorHelper.backdropTexture);

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

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

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

                                if (newEnt != null)
                                {
                                    mItems.Add(newEnt);
                                    Save();
                                }
                            }
                        }
                        else if (currentEvent.button == 1)
                        {
                            ContextMenu.AddItemWithArge("更新预览", false, delegate {
                                GeneratePreview(item, true);
                            }, index);
                            ContextMenu.AddItemWithArge("删除当前", false, RemoveItem, index);
                            ContextMenu.Show();
                        }
                    }

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

                    if (item != null)
                    {
                        if (item.tex == null)
                        {
                            GeneratePreview(item, false);
                        }
                        if (item.tex != null)
                        {
                            GUI.DrawTexture(inner, item.tex);
                            var labelPos   = new Rect(inner);
                            var labelStyle = EditorStyles.label;
                            labelPos.height      = labelStyle.lineHeight;
                            labelPos.y           = inner.height - labelPos.height + 5;
                            labelStyle.fontSize  = 16;
                            labelStyle.alignment = TextAnchor.LowerCenter;
                            {
                                GUI.color = Color.black;
                                var name = item.prefab.name.Split('(');
                                if (name.Length == 2)
                                {
                                    GUI.Label(rect, name[0] + "\n(" + name[1], labelStyle);
                                }
                                else
                                {
                                    GUI.Label(rect, item.prefab.name, labelStyle);
                                }
                            }
                            labelStyle.alignment = TextAnchor.UpperLeft;
                            labelStyle.fontSize  = m_labelDefaultFontSize;
                        }
                        else if (m_mode != Mode.DetailedMode)
                        {
                            GUI.Label(inner, caption, m_style);
                            caption = "";
                        }
                    }
                    else
                    {
                        GUI.Label(inner, "Add", m_style);
                    }

                    if (m_mode == 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  = m_cellPadding;
                    }
                }
                GUILayout.Space(y + spacingY);
            }
            EditorGUILayout.EndScrollView();

            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, 2);
        }
Ejemplo n.º 17
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);
        }
    }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
 public void DestroyArrow(GameObject arrow)
 {
     ArrowsList.Remove(arrow);
     GameObject.Destroy(arrow);
 }
Ejemplo n.º 20
0
    /// <summary>
    /// Convenience function that figures out the panel's correct change flag by searching the parents.
    /// </summary>

    int GetChangeFlag(UINode start)
    {
        int flag = start.changeFlag;

        if (flag == -1)
        {
            Transform trans = start.trans.parent;
            UINode    sub;

            // Keep going until we find a set flag
            for (;;)
            {
                // Check the parent's flag
#if USE_SIMPLE_DICTIONARY
                if (trans != null && mChildren.TryGetValue(trans, out sub))
                {
#else
                if (trans != null && mChildren.Contains(trans))
                {
                    sub = (UINode)mChildren[trans];
#endif
                    flag  = sub.changeFlag;
                    trans = trans.parent;

                    // If the flag hasn't been set either, add this child to the hierarchy
                    if (flag == -1)
                    {
                        mHierarchy.Add(sub);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            // Update the parent flags
            for (int i = 0, imax = mHierarchy.size; i < imax; ++i)
            {
                UINode pc = mHierarchy.buffer[i];
                pc.changeFlag = flag;
            }
            mHierarchy.Clear();
        }
        return(flag);
    }

    /// <summary>
    /// Update the world-to-local transform matrix as well as clipping bounds.
    /// </summary>

    void UpdateTransformMatrix()
    {
        if (mUpdateTime == 0f || mMatrixTime != mUpdateTime)
        {
            mMatrixTime   = mUpdateTime;
            mWorldToLocal = cachedTransform.worldToLocalMatrix;

            if (mClipping != UIDrawCall.Clipping.None)
            {
                Vector2 size = new Vector2(mClipRange.z, mClipRange.w);

                if (size.x == 0f)
                {
                    size.x = (mCam == null) ? Screen.width  : mCam.pixelWidth;
                }
                if (size.y == 0f)
                {
                    size.y = (mCam == null) ? Screen.height : mCam.pixelHeight;
                }

                size *= 0.5f;

                mMin.x = mClipRange.x - size.x;
                mMin.y = mClipRange.y - size.y;
                mMax.x = mClipRange.x + size.x;
                mMax.y = mClipRange.y + size.y;
            }
        }
    }

    /// <summary>
    /// Run through all managed transforms and see if they've changed.
    /// </summary>

    void UpdateTransforms()
    {
        mChangedLastFrame = false;
        bool transformsChanged = false;
        bool shouldCull        = false;

#if UNITY_EDITOR
        shouldCull = (clipping != UIDrawCall.Clipping.None) && (!Application.isPlaying || mUpdateTime > mCullTime);
        if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#else
        shouldCull = (clipping != UIDrawCall.Clipping.None) && (mUpdateTime > mCullTime);
        if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#endif
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode node = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode node = (UINode)mChildren[i];
#endif
                if (node.trans == null)
                {
                    mRemoved.Add(node.trans);
                    continue;
                }

                if (node.HasChanged())
                {
                    node.changeFlag   = 1;
                    transformsChanged = true;
#if UNITY_EDITOR
                    Vector3 s   = node.trans.lossyScale;
                    float   min = Mathf.Abs(Mathf.Min(s.x, s.y));

                    if (min == 0f)
                    {
                        Debug.LogError("Scale of 0 is invalid! Zero cannot be divided by, which causes problems. Use a small value instead, such as 0.01\n" +
                                       node.trans.lossyScale, node.trans);
                    }
#endif
                }
                else
                {
                    node.changeFlag = -1;
                }
            }

            // Clean up the deleted transforms
            for (int i = 0, imax = mRemoved.Count; i < imax; ++i)
            {
                mChildren.Remove(mRemoved[i]);
            }
            mRemoved.Clear();
        }

        // If the children weren't culled but should be, check their visibility
        if (!mCulled && shouldCull)
        {
            mCheckVisibility = true;
        }

        // If something has changed, propagate the changes *down* the tree hierarchy (to children).
        // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>()
        // in the loop above, and mark each one as dirty.

        if (mCheckVisibility || transformsChanged || mRebuildAll)
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode pc = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode pc = (UINode)mChildren[i];
#endif
                if (pc.widget != null)
                {
                    int visibleFlag = 1;

                    // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true')
                    if (shouldCull || transformsChanged)
                    {
                        // If the change flag has not yet been determined...
                        if (pc.changeFlag == -1)
                        {
                            pc.changeFlag = GetChangeFlag(pc);
                        }

                        // Is the widget visible?
                        if (shouldCull)
                        {
                            visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag;
                        }
                    }

                    // If visibility changed, mark the node as changed as well
                    if (pc.visibleFlag != visibleFlag)
                    {
                        pc.changeFlag = 1;
                    }

                    // If the node has changed and the widget is visible (or was visible before)
                    if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0))
                    {
                        // Update the visibility flag
                        pc.visibleFlag = visibleFlag;
                        Material mat = pc.widget.material;

                        // Add this material to the list of changed materials
                        if (!mChanged.Contains(mat))
                        {
                            mChanged.Add(mat);
                            mChangedLastFrame = true;
                        }
                    }
                }
            }
        }
        mCulled          = shouldCull;
        mCheckVisibility = false;
        mWidgetsAdded    = false;
    }

    /// <summary>
    /// Update all widgets and rebuild their geometry if necessary.
    /// </summary>

    void UpdateWidgets()
    {
#if USE_SIMPLE_DICTIONARY
        foreach (KeyValuePair <Transform, UINode> c in mChildren)
        {
            UINode pc = c.Value;
#else
        for (int i = 0, imax = mChildren.Count; i < imax; ++i)
        {
            UINode pc = (UINode)mChildren[i];
#endif
            UIWidget w = pc.widget;

            // If the widget is visible, update it
            if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(ref mWorldToLocal, (pc.changeFlag == 1), generateNormals))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                    mChangedLastFrame = true;
                }
            }
            pc.changeFlag = 0;
        }
    }

    /// <summary>
    /// Update the clipping rect in the shaders and draw calls' positions.
    /// </summary>

    bool nestingClip     = false;
    Vector4 newClipRange = Vector4.zero;
    public void UpdateDrawcalls()
    {
        Vector4 range = Vector4.zero;

        if (mClipping != UIDrawCall.Clipping.None)
        {
            UIDraggablePanel dragPanel = gameObject.GetComponent <UIDraggablePanel>();
            if (dragPanel != null && gameObject.transform.parent != null)
            {
                UIPanel parentPanel = NGUITools.FindInParents <UIPanel>(gameObject.transform.parent.gameObject);
                if (parentPanel != null && parentPanel.transform.parent != null && parentPanel.clipping != UIDrawCall.Clipping.None)
                {
                    Vector3 worldPos = transform.TransformPoint(Vector3.zero);
                    Vector3 localPos = parentPanel.transform.parent.InverseTransformPoint(worldPos);
                    newClipRange = mClipRange;

                    Vector4 parentRect = new Vector4(-localPos.x - parentPanel.clipRange.z / 2
                                                     , -localPos.y - parentPanel.clipRange.w / 2
                                                     , -localPos.x + parentPanel.clipRange.z / 2
                                                     , -localPos.y + parentPanel.clipRange.w / 2);

                    Vector4 selfRect = new Vector4(newClipRange.x - newClipRange.z / 2
                                                   , newClipRange.y - newClipRange.w / 2
                                                   , newClipRange.x + newClipRange.z / 2
                                                   , newClipRange.y + newClipRange.w / 2
                                                   );

                    if (selfRect.x < parentRect.x)
                    {
                        selfRect.x  = parentRect.x;
                        nestingClip = true;
                    }

                    if (selfRect.y < parentRect.y)
                    {
                        selfRect.y  = parentRect.y;
                        nestingClip = true;
                    }

                    if (selfRect.z > parentRect.z)
                    {
                        selfRect.z  = parentRect.z;
                        nestingClip = true;
                    }

                    if (selfRect.w > parentRect.w)
                    {
                        selfRect.w  = parentRect.w;
                        nestingClip = true;
                    }


                    float xLength = selfRect.z - selfRect.x;
                    if (xLength < 0)
                    {
                        xLength = 0.0001f;
                    }

                    float yLength = selfRect.w - selfRect.y;
                    if (yLength < 0)
                    {
                        yLength = 0.0001f;
                    }

                    newClipRange = new Vector4(selfRect.x + xLength / 2
                                               , selfRect.y + yLength / 2
                                               , xLength
                                               , yLength);

                    //if (newClipRange.x < -localPos.x - Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2)
                    //{
                    //    float offset = -localPos.x - Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2;
                    //    newClipRange.x = offset / 2;
                    //    newClipRange.z -= offset;

                    //    nestingClip = true;
                    //}
                    //else if (newClipRange.x > -localPos.x + Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2)
                    //{
                    //    float offset = localPos.x + Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2;
                    //    newClipRange.x -= offset / 2;
                    //    newClipRange.z = offset;

                    //    nestingClip = true;
                    //}
                    //else
                    //{
                    //    nestingClip = false;
                    //}

                    //if (newClipRange.y < -localPos.y)
                    //{
                    //    newClipRange.y = -localPos.y;
                    //    newClipRange.w = parentPanel.clipRange.w;
                    //}
                }
            }

            if (nestingClip)
            {
                range = new Vector4(newClipRange.x, newClipRange.y, newClipRange.z * 0.5f, newClipRange.w * 0.5f);
            }
            else
            {
                range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f);
            }
        }

        if (range.z == 0f)
        {
            range.z = Screen.width * 0.5f;
        }
        if (range.w == 0f)
        {
            range.w = Screen.height * 0.5f;
        }

        RuntimePlatform platform = Application.platform;

        if (platform == RuntimePlatform.WindowsPlayer ||
            platform == RuntimePlatform.WindowsWebPlayer ||
            platform == RuntimePlatform.WindowsEditor)
        {
            range.x -= 0.5f;
            range.y += 0.5f;
        }

        Transform t = cachedTransform;

        for (int i = 0, imax = mDrawCalls.size; i < imax; ++i)
        {
            UIDrawCall dc = mDrawCalls.buffer[i];
            dc.clipping     = mClipping;
            dc.clipRange    = range;
            dc.clipSoftness = mClipSoftness;
            dc.depthPass    = depthPass;

            // Set the draw call's transform to match the panel's.
            // Note that parenting directly to the panel causes unity to crash as soon as you hit Play.
            Transform dt = dc.transform;
            dt.position   = t.position;
            dt.rotation   = t.rotation;
            dt.localScale = t.lossyScale;
        }
    }

    /// <summary>
    /// Set the draw call's geometry responsible for the specified material.
    /// </summary>

    void Fill(Material mat)
    {
        // Cleanup deleted widgets
        for (int i = mWidgets.size; i > 0;)
        {
            if (mWidgets[--i] == null)
            {
                mWidgets.RemoveAt(i);
            }
        }

        // Fill the buffers for the specified material
        for (int i = 0, imax = mWidgets.size; i < imax; ++i)
        {
            UIWidget w = mWidgets.buffer[i];

            if (w.visibleFlag == 1 && w.material == mat)
            {
                UINode node = GetNode(w.cachedTransform);

                if (node != null)
                {
                    if (generateNormals)
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans);
                    }
                    else
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, null, null);
                    }
                }
                else
                {
                    Debug.LogError("No transform found for " + NGUITools.GetHierarchy(w.gameObject), this);
                }
            }
        }

        if (mVerts.size > 0)
        {
            // Rebuild the draw call's mesh
            UIDrawCall dc = GetDrawCall(mat, true);
            dc.depthPass = depthPass;
            dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols);
        }
        else
        {
            // There is nothing to draw for this material -- eliminate the draw call
            UIDrawCall dc = GetDrawCall(mat, false);

            if (dc != null)
            {
                mDrawCalls.Remove(dc);
                NGUITools.DestroyImmediate(dc.gameObject);
            }
        }

        // Cleanup
        mVerts.Clear();
        mNorms.Clear();
        mTans.Clear();
        mUvs.Clear();
        mCols.Clear();
    }
Ejemplo n.º 21
0
    /// <summary>
    /// 更新战争能见度的迷雾
    /// </summary>

    void UpdateBuffer()
    {
        // 添加计划添加的所有项目
        if (mAdded.size > 0)
        {
            lock (mAdded)
            {
                while (mAdded.size > 0)
                {
                    int index = mAdded.size - 1;
                    mRevealers.Add(mAdded.buffer[index]);
                    mAdded.RemoveAt(index);
                }
            }
        }

        // 移除所有移除的项目
        if (mRemoved.size > 0)
        {
            lock (mRemoved)
            {
                while (mRemoved.size > 0)
                {
                    int index = mRemoved.size - 1;
                    mRevealers.Remove(mRemoved.buffer[index]);
                    mRemoved.RemoveAt(index);
                }
            }
        }

        // 使用纹理混合时间,因此估计这次更新完成的时间
        // 这样做有助于避免混合结果导致的混合结果的可见变化。
        float factor = (textureBlendTime > 0f) ? Mathf.Clamp01(mBlendFactor + mElapsed / textureBlendTime) : 1f;

        // 清除缓冲区的红色通道(用于当前可见性的通道——它将在后面更新)
        for (int i = 0, imax = mBuffer0.Length; i < imax; ++i)
        {
            mBuffer0[i]   = Color32.Lerp(mBuffer0[i], mBuffer1[i], factor);
            mBuffer1[i].r = 0;
        }

        // 用于从世界坐标转换到纹理坐标
        float worldToTex = (float)textureSize / worldSize;

        // 每次更新可见度缓冲,一个探出器
        for (int i = 0; i < mRevealers.size; ++i)
        {
            Revealer rev = mRevealers[i];
            if (!rev.isActive)
            {
                continue;
            }

            if (rev.los == LOSChecks.None)
            {
                RevealUsingRadius(rev, worldToTex);
            }
            else if (rev.los == LOSChecks.OnlyOnce)
            {
                RevealUsingCache(rev, worldToTex);
            }
            else
            {
                RevealUsingLOS(rev, worldToTex);
            }
        }

        // 模糊最终的可见数据
        for (int i = 0; i < blurIterations; ++i)
        {
            BlurVisibility();
        }

        // Reveal the map based on what's currently visible
        RevealMap();
    }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
 public void RemoveOutfit(Outfit outfit)
 {
     outfits.Remove(outfit);
 }
Ejemplo n.º 24
0
    /// <summary>
    /// Update the fog of war's visibility.
    /// </summary>

    void UpdateBuffer()
    {
        // Add all items scheduled to be added
        if (mAdded.size > 0)
        {
            lock (mAdded)
            {
                while (mAdded.size > 0)
                {
                    int index = mAdded.size - 1;
                    mRevealers.Add(mAdded.buffer[index]);
                    mAdded.RemoveAt(index);
                }
            }
        }

        // Remove all items scheduled for removal
        if (mRemoved.size > 0)
        {
            lock (mRemoved)
            {
                while (mRemoved.size > 0)
                {
                    int index = mRemoved.size - 1;
                    mRevealers.Remove(mRemoved.buffer[index]);
                    mRemoved.RemoveAt(index);
                }
            }
        }

        // Use the texture blend time, thus estimating the time this update will finish
        // Doing so helps avoid visible changes in blending caused by the blended result being X milliseconds behind.
        float factor = (textureBlendTime > 0f) ? Mathf.Clamp01(mBlendFactor + mElapsed / textureBlendTime) : 1f;

        // Clear the buffer's red channel (channel used for current visibility -- it's updated right after)
        for (int i = 0, imax = mBuffer0.Length; i < imax; ++i)
        {
            mBuffer0[i]   = Color32.Lerp(mBuffer0[i], mBuffer1[i], factor);
            mBuffer1[i].r = 0;
        }

        // For conversion from world coordinates to texture coordinates
        float worldToTex = (float)textureSize / worldSize;

        // Update the visibility buffer, one revealer at a time
        for (int i = 0; i < mRevealers.size; ++i)
        {
            Revealer rev = mRevealers[i];
            if (!rev.mIsActive)
            {
                continue;
            }

            if (rev.mLos == LOSChecks.None)
            {
                RevealUsingRadius(rev, worldToTex);
            }
            else if (rev.mLos == LOSChecks.OnlyOnce)
            {
                RevealUsingCache(rev, worldToTex);
            }
            else
            {
                RevealUsingLOS(rev, worldToTex);
            }
        }

        // Blur the final visibility data
        for (int i = 0; i < blurIterations; ++i)
        {
            BlurVisibility();
        }

        // Reveal the map based on what's currently visible
        RevealMap();
    }
Ejemplo n.º 25
0
    /// <summary>
    /// Convenience function that figures out the panel's correct change flag by searching the parents.
    /// </summary>

    int GetChangeFlag(UINode start)
    {
        int flag = start.changeFlag;

        if (flag == -1)
        {
            Transform trans = start.trans.parent;
            UINode    sub;

            // Keep going until we find a set flag
            for (;;)
            {
                // Check the parent's flag
#if UNITY_FLASH
                if (trans != null && mChildren.TryGetValue(trans, out sub))
                {
#else
                if (trans != null && mChildren.Contains(trans))
                {
                    sub = (UINode)mChildren[trans];
#endif
                    flag  = sub.changeFlag;
                    trans = trans.parent;

                    // If the flag hasn't been set either, add this child to the hierarchy
                    if (flag == -1)
                    {
                        mHierarchy.Add(sub);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            // Update the parent flags
            for (int i = 0, imax = mHierarchy.size; i < imax; ++i)
            {
                UINode pc = mHierarchy.buffer[i];
                pc.changeFlag = flag;
            }
            mHierarchy.Clear();
        }
        return(flag);
    }

    /// <summary>
    /// Update the world-to-local transform matrix as well as clipping bounds.
    /// </summary>

    void UpdateTransformMatrix()
    {
        float time = Time.realtimeSinceStartup;

        if (time == 0f || mMatrixTime != time)
        {
            mMatrixTime   = time;
            mWorldToLocal = cachedTransform.worldToLocalMatrix;

            if (mClipping != UIDrawCall.Clipping.None)
            {
                Vector2 size = new Vector2(mClipRange.z, mClipRange.w);

                if (size.x == 0f)
                {
                    size.x = mScreenSize.x;
                }
                if (size.y == 0f)
                {
                    size.y = mScreenSize.y;
                }

                size *= 0.5f;

                mMin.x = mClipRange.x - size.x;
                mMin.y = mClipRange.y - size.y;
                mMax.x = mClipRange.x + size.x;
                mMax.y = mClipRange.y + size.y;
            }
        }
    }

    /// <summary>
    /// Run through all managed transforms and see if they've changed.
    /// </summary>

    void UpdateTransforms()
    {
        mChangedLastFrame = false;
        bool transformsChanged = false;

#if UNITY_EDITOR
        bool shouldCull = !Application.isPlaying || Time.realtimeSinceStartup > mCullTime;
        if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#else
        bool shouldCull = Time.realtimeSinceStartup > mCullTime;
        if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#endif
        {
#if UNITY_FLASH
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode node = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode node = (UINode)mChildren[i];
#endif
                if (node.trans == null)
                {
                    mRemoved.Add(node.trans);
                    continue;
                }

                if (node.HasChanged())
                {
                    node.changeFlag   = 1;
                    transformsChanged = true;
                }
                else
                {
                    node.changeFlag = -1;
                }
            }

            // Clean up the deleted transforms
            for (int i = 0, imax = mRemoved.Count; i < imax; ++i)
            {
                mChildren.Remove(mRemoved[i]);
            }
            mRemoved.Clear();
        }

        // If the children weren't culled but should be, check their visibility
        if (!mCulled && shouldCull)
        {
            mCheckVisibility = true;
        }

        // If something has changed, propagate the changes *down* the tree hierarchy (to children).
        // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>()
        // in the loop above, and mark each one as dirty.

        if (mCheckVisibility || transformsChanged || mRebuildAll)
        {
#if UNITY_FLASH
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode pc = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode pc = (UINode)mChildren[i];
#endif
                if (pc.widget != null)
                {
                    int visibleFlag = 1;

                    // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true')
                    if (shouldCull || transformsChanged)
                    {
                        // If the change flag has not yet been determined...
                        if (pc.changeFlag == -1)
                        {
                            pc.changeFlag = GetChangeFlag(pc);
                        }

                        // Is the widget visible?
                        if (shouldCull)
                        {
                            visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag;
                        }
                    }

                    // If visibility changed, mark the node as changed as well
                    if (pc.visibleFlag != visibleFlag)
                    {
                        pc.changeFlag = 1;
                    }

                    // If the node has changed and the widget is visible (or was visible before)
                    if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0))
                    {
                        // Update the visibility flag
                        pc.visibleFlag = visibleFlag;
                        Material mat = pc.widget.material;

                        // Add this material to the list of changed materials
                        if (!mChanged.Contains(mat))
                        {
                            mChanged.Add(mat);
                            mChangedLastFrame = true;
                        }
                    }
                }
            }
        }
        mCulled          = shouldCull;
        mCheckVisibility = false;
        mWidgetsAdded    = false;
    }

    /// <summary>
    /// Update all widgets and rebuild their geometry if necessary.
    /// </summary>

    void UpdateWidgets()
    {
#if UNITY_FLASH
        foreach (KeyValuePair <Transform, UINode> c in mChildren)
        {
            UINode pc = c.Value;
#else
        for (int i = 0, imax = mChildren.Count; i < imax; ++i)
        {
            UINode pc = (UINode)mChildren[i];
#endif
            UIWidget w = pc.widget;

            // If the widget is visible, update it
            if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(ref mWorldToLocal, (pc.changeFlag == 1), generateNormals))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                    mChangedLastFrame = true;
                }
            }
            pc.changeFlag = 0;
        }
    }

    /// <summary>
    /// Update the clipping rect in the shaders and draw calls' positions.
    /// </summary>

    public void UpdateDrawcalls()
    {
        Vector4 range = Vector4.zero;

        if (mClipping != UIDrawCall.Clipping.None)
        {
            range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f);
        }

        if (range.z == 0f)
        {
            range.z = mScreenSize.x * 0.5f;
        }
        if (range.w == 0f)
        {
            range.w = mScreenSize.y * 0.5f;
        }

        RuntimePlatform platform = Application.platform;

        if (platform == RuntimePlatform.WindowsPlayer ||
            platform == RuntimePlatform.WindowsWebPlayer ||
            platform == RuntimePlatform.WindowsEditor)
        {
            range.x -= 0.5f;
            range.y += 0.5f;
        }

        Transform t = cachedTransform;

        for (int i = 0, imax = mDrawCalls.size; i < imax; ++i)
        {
            UIDrawCall dc = mDrawCalls.buffer[i];
            dc.clipping     = mClipping;
            dc.clipRange    = range;
            dc.clipSoftness = mClipSoftness;
            dc.depthPass    = depthPass;

            // Set the draw call's transform to match the panel's.
            // Note that parenting directly to the panel causes unity to crash as soon as you hit Play.
            Transform dt = dc.transform;
            dt.position   = t.position;
            dt.rotation   = t.rotation;
            dt.localScale = t.lossyScale;
        }
    }

    /// <summary>
    /// Set the draw call's geometry responsible for the specified material.
    /// </summary>

    void Fill(Material mat)
    {
        // Cleanup deleted widgets
        for (int i = mWidgets.size; i > 0;)
        {
            if (mWidgets[--i] == null)
            {
                mWidgets.RemoveAt(i);
            }
        }

        // Fill the buffers for the specified material
        for (int i = 0, imax = mWidgets.size; i < imax; ++i)
        {
            UIWidget w = mWidgets.buffer[i];

            if (w.visibleFlag == 1 && w.material == mat)
            {
                UINode node = GetNode(w.cachedTransform);

                if (node != null)
                {
                    if (generateNormals)
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans);
                    }
                    else
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, null, null);
                    }
                }
                else
                {
                    Debug.LogError("No transform found for " + NGUITools.GetHierarchy(w.gameObject), this);
                }
            }
        }

        if (mVerts.size > 0)
        {
            // Rebuild the draw call's mesh
            UIDrawCall dc = GetDrawCall(mat, true);
            dc.depthPass = depthPass;
            dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols);
        }
        else
        {
            // There is nothing to draw for this material -- eliminate the draw call
            UIDrawCall dc = GetDrawCall(mat, false);

            if (dc != null)
            {
                mDrawCalls.Remove(dc);
                NGUITools.DestroyImmediate(dc.gameObject);
            }
        }

        // Cleanup
        mVerts.Clear();
        mNorms.Clear();
        mTans.Clear();
        mUvs.Clear();
        mCols.Clear();
    }

    /// <summary>
    /// Main update function
    /// </summary>

    void LateUpdate()
    {
        UpdateTransformMatrix();
        UpdateTransforms();

        // Always move widgets to the panel's layer
        if (mLayer != gameObject.layer)
        {
            mLayer = gameObject.layer;
            UICamera uic = UICamera.FindCameraForLayer(mLayer);
            mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer);
            SetChildLayer(cachedTransform, mLayer);
            for (int i = 0, imax = drawCalls.size; i < imax; ++i)
            {
                mDrawCalls.buffer[i].gameObject.layer = mLayer;
            }
        }

        UpdateWidgets();

        // If the depth has changed, we need to re-sort the widgets
        if (mDepthChanged)
        {
            mDepthChanged = false;
            mWidgets.Sort(UIWidget.CompareFunc);
        }

        // Fill the draw calls for all of the changed materials
        for (int i = 0, imax = mChanged.size; i < imax; ++i)
        {
            Fill(mChanged.buffer[i]);
        }

        // Update the clipping rects
        UpdateDrawcalls();
        mChanged.Clear();
        mRebuildAll = false;

#if UNITY_EDITOR
        mScreenSize = new Vector2(Screen.width, Screen.height);

        UIRoot root = NGUITools.FindInParents <UIRoot>(gameObject);
        if (root != null)
        {
            mScreenSize *= root.GetPixelSizeAdjustment(Screen.height);
        }
#endif
    }
Ejemplo n.º 26
0
 public void Remove(GameObject child)
 {
     mChildren.Remove(child.transform);
     GameObject.Destroy(child);
     ResetChildPositions();
 }
Ejemplo n.º 27
0
    /// <summary>
    /// Clear references.
    /// </summary>

    protected virtual void OnDisable()
    {
        list.Remove(this);
        RemoveFromPanel();
    }
Ejemplo n.º 28
0
    /// <summary>
    /// Update the fog of war's visibility.
    /// </summary>

    void UpdateBuffer()
    {
        // Add all items scheduled to be added
        if (mAdded.size > 0)
        {
            lock (mAdded)
            {
                while (mAdded.size > 0)
                {
                    int index = mAdded.size - 1;
                    mRevealers.Add(mAdded.buffer[index]);
                    mAdded.RemoveAt(index);
                }
            }
        }

        // Remove all items scheduled for removal
        if (mRemoved.size > 0)
        {
            lock (mRemoved)
            {
                while (mRemoved.size > 0)
                {
                    int index = mRemoved.size - 1;
                    mRevealers.Remove(mRemoved.buffer[index]);
                    mRemoved.RemoveAt(index);
                }
            }
        }

        // Use the texture blend time, thus estimating the time this update will finish
        // Doing so helps avoid visible changes in blending caused by the blended result being X milliseconds behind.
        //使用纹理混合时间,从而估计此更新将完成的时间
        //这样做有助于避免由于混合结果落后X毫秒而导致混合中的可见变化。
        float factor = (textureBlendTime > 0f) ? Mathf.Clamp01(mBlendFactor + mElapsed / textureBlendTime) : 1f;

        //// Clear the buffer's red channel (channel used for current visibility -- it's updated right after)
        ////清除缓冲区的红色通道(用于当前可见性的通道-此通道将在之后立即更新)
        for (int i = 0, imax = mBuffer0.Length; i < imax; ++i)
        {
            mBuffer0[i]   = Color32.Lerp(mBuffer0[i], mBuffer1[i], factor);
            mBuffer1[i].r = 0;
        }

        // For conversion from world coordinates to texture coordinates
        //用于从世界坐标转换为纹理坐标
        float worldToTex = (float)textureSize / worldSize;

        // Update the visibility buffer, one revealer at a time
        //更新可见性缓冲区,一次显示一个
        for (int i = 0; i < mRevealers.size; ++i)
        {
            IFOWRevealer rev = mRevealers[i];
            if (rev.IsValid())
            {
                RevealUsingRadius(rev, worldToTex);
            }
        }

        // Blur the final visibility data
        for (int i = 0; i < blurIterations; ++i)
        {
            BlurVisibility();
        }

        // Reveal the map based on what's currently visible
        RevealMap();

        // Merge two buffer to one
        MergeBuffer();
    }
Ejemplo n.º 29
0
 void OnDisable()
 {
     list.Remove(this);
 }
Ejemplo n.º 30
0
 void OnDisable()
 {
     checkBoxContainer.Remove(this);
 }