WrapAngle() private method

private WrapAngle ( float angle ) : float
angle float
return float
Esempio n. 1
0
 static public int WrapAngle_s(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         System.Single a1;
         checkType(l, 1, out a1);
         var ret = NGUIMath.WrapAngle(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Esempio n. 2
0
 private void OnWillRenderObject()
 {
     this.UpdateMaterials();
     if (this.mDynamicMat == null || this.mClipCount == 0)
     {
         return;
     }
     if (!this.mLegacyShader)
     {
         UIPanel parentPanel = this.panel;
         int     num         = 0;
         while (parentPanel != null)
         {
             if (parentPanel.hasClipping)
             {
                 float   angle             = 0f;
                 Vector4 drawCallClipRange = parentPanel.drawCallClipRange;
                 if (parentPanel != this.panel)
                 {
                     Vector3 vector = parentPanel.cachedTransform.InverseTransformPoint(this.panel.cachedTransform.position);
                     drawCallClipRange.x -= vector.x;
                     drawCallClipRange.y -= vector.y;
                     Vector3 eulerAngles  = this.panel.cachedTransform.rotation.eulerAngles;
                     Vector3 eulerAngles2 = parentPanel.cachedTransform.rotation.eulerAngles;
                     Vector3 vector2      = eulerAngles2 - eulerAngles;
                     vector2.x = NGUIMath.WrapAngle(vector2.x);
                     vector2.y = NGUIMath.WrapAngle(vector2.y);
                     vector2.z = NGUIMath.WrapAngle(vector2.z);
                     if (Mathf.Abs(vector2.x) > 0.001f || Mathf.Abs(vector2.y) > 0.001f)
                     {
                         Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", this.panel);
                     }
                     angle = vector2.z;
                 }
                 this.SetClipping(num++, drawCallClipRange, parentPanel.clipSoftness, angle);
             }
             parentPanel = parentPanel.parentPanel;
         }
     }
     else
     {
         Vector2 clipSoftness       = this.panel.clipSoftness;
         Vector4 drawCallClipRange2 = this.panel.drawCallClipRange;
         Vector2 mainTextureOffset  = new Vector2(-drawCallClipRange2.x / drawCallClipRange2.z, -drawCallClipRange2.y / drawCallClipRange2.w);
         Vector2 mainTextureScale   = new Vector2(1f / drawCallClipRange2.z, 1f / drawCallClipRange2.w);
         Vector2 v = new Vector2(1000f, 1000f);
         if (clipSoftness.x > 0f)
         {
             v.x = drawCallClipRange2.z / clipSoftness.x;
         }
         if (clipSoftness.y > 0f)
         {
             v.y = drawCallClipRange2.w / clipSoftness.y;
         }
         this.mDynamicMat.mainTextureOffset = mainTextureOffset;
         this.mDynamicMat.mainTextureScale  = mainTextureScale;
         this.mDynamicMat.SetVector("_ClipSharpness", v);
     }
 }
Esempio n. 3
0
    public static Single RotateTowards(Single from, Single to, Single maxAngle)
    {
        Single num = NGUIMath.WrapAngle(to - from);

        if (Mathf.Abs(num) > maxAngle)
        {
            num = maxAngle * Mathf.Sign(num);
        }
        return(from + num);
    }
Esempio n. 4
0
    public static float RotateTowards(float from, float to, float maxAngle)
    {
        float num = NGUIMath.WrapAngle(to - from);

        if (Mathf.Abs(num) > maxAngle)
        {
            num = maxAngle * Mathf.Sign(num);
        }
        return(from + num);
    }
Esempio n. 5
0
    public static float RotateTowards(float from, float to, float maxAngle)
    {
        float single = NGUIMath.WrapAngle(to - from);

        if (Mathf.Abs(single) > maxAngle)
        {
            single = maxAngle * Mathf.Sign(single);
        }
        return(from + single);
    }
Esempio n. 6
0
 static public int WrapAngle_s(IntPtr l)
 {
     try {
         System.Single a1;
         checkType(l, 1, out a1);
         var ret = NGUIMath.WrapAngle(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Esempio n. 7
0
    void DrawServerRotation()
    {
        GUILayout.BeginHorizontal();
        Vector3 visible = (serializedObject.targetObject as Transform).localEulerAngles;

        visible.y = NGUIMath.WrapAngle(visible.y);
        float val = visible.y * Mathf.PI / 18f + Mathf.PI / 2f;//GetDir 方法

        EditorGUILayout.LabelField(">>", GUILayout.Width(20f));
        EditorGUILayout.FloatField("R", val, GUILayout.MinWidth(30));
        EditorGUILayout.LabelField(" ", "", GUILayout.MinWidth(30));
        EditorGUILayout.LabelField(" ", "", GUILayout.MinWidth(30));
        GUILayout.EndHorizontal();
    }
Esempio n. 8
0
 static public int WrapAngle_s(IntPtr l)
 {
     try {
         System.Single a1;
         checkType(l, 1, out a1);
         var ret = NGUIMath.WrapAngle(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 9
0
    /// <summary>
    /// This function is called when it's clear that the object will be rendered.
    /// We want to set the shader used by the material, creating a copy of the material in the process.
    /// We also want to update the material's properties before it's actually used.
    /// </summary>

    void OnWillRenderObject()
    {
        UpdateMaterials();

        if (mDynamicMat == null || mClipCount == 0)
        {
            return;
        }

        if (!mLegacyShader)
        {
            UIPanel currentPanel = panel;

            for (int i = 0; currentPanel != null;)
            {
                if (currentPanel.hasClipping)
                {
                    float   angle = 0f;
                    Vector4 cr    = currentPanel.drawCallClipRange;

                    // Clipping regions past the first one need additional math
                    if (currentPanel != panel)
                    {
                        Vector3 pos = currentPanel.cachedTransform.InverseTransformPoint(panel.cachedTransform.position);
                        cr.x -= pos.x;
                        cr.y -= pos.y;

                        Vector3 v0   = panel.cachedTransform.rotation.eulerAngles;
                        Vector3 v1   = currentPanel.cachedTransform.rotation.eulerAngles;
                        Vector3 diff = v1 - v0;

                        diff.x = NGUIMath.WrapAngle(diff.x);
                        diff.y = NGUIMath.WrapAngle(diff.y);
                        diff.z = NGUIMath.WrapAngle(diff.z);

                        if (Mathf.Abs(diff.x) > 0.001f || Mathf.Abs(diff.y) > 0.001f)
                        {
                            Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", panel);
                        }

                        angle = diff.z;
                    }

                    // Pass the clipping parameters to the shader
                    SetClipping(i++, cr, currentPanel.clipSoftness, angle);
                }
                currentPanel = currentPanel.parentPanel;
            }
        }
        else         // Legacy functionality
        {
            Vector2 soft = panel.clipSoftness;
            Vector4 cr   = panel.drawCallClipRange;
            Vector2 v0   = new Vector2(-cr.x / cr.z, -cr.y / cr.w);
            Vector2 v1   = new Vector2(1f / cr.z, 1f / cr.w);

            Vector2 sharpness = new Vector2(1000.0f, 1000.0f);
            if (soft.x > 0f)
            {
                sharpness.x = cr.z / soft.x;
            }
            if (soft.y > 0f)
            {
                sharpness.y = cr.w / soft.y;
            }

            mDynamicMat.mainTextureOffset = v0;
            mDynamicMat.mainTextureScale  = v1;
            mDynamicMat.SetVector("_ClipSharpness", sharpness);
        }
    }
Esempio n. 10
0
 private void OnWillRenderObject()
 {
     UpdateMaterials();
     if (onRender != null)
     {
         onRender(mDynamicMat ?? mMaterial);
     }
     if (!(mDynamicMat == null) && mClipCount != 0)
     {
         if (mTextureClip)
         {
             Vector4 drawCallClipRange = panel.drawCallClipRange;
             Vector2 clipSoftness      = panel.clipSoftness;
             Vector2 vector            = new Vector2(1000f, 1000f);
             if (clipSoftness.x > 0f)
             {
                 vector.x = drawCallClipRange.z / clipSoftness.x;
             }
             if (clipSoftness.y > 0f)
             {
                 vector.y = drawCallClipRange.w / clipSoftness.y;
             }
             mDynamicMat.SetVector(ClipRange[0], new Vector4((0f - drawCallClipRange.x) / drawCallClipRange.z, (0f - drawCallClipRange.y) / drawCallClipRange.w, 1f / drawCallClipRange.z, 1f / drawCallClipRange.w));
             mDynamicMat.SetTexture("_ClipTex", clipTexture);
         }
         else if (!mLegacyShader)
         {
             UIPanel parentPanel = panel;
             int     num         = 0;
             while (parentPanel != null)
             {
                 if (parentPanel.hasClipping)
                 {
                     float   angle = 0f;
                     Vector4 drawCallClipRange2 = parentPanel.drawCallClipRange;
                     if (parentPanel != panel)
                     {
                         Vector3 vector2 = parentPanel.cachedTransform.InverseTransformPoint(panel.cachedTransform.position);
                         drawCallClipRange2.x -= vector2.x;
                         drawCallClipRange2.y -= vector2.y;
                         Vector3 eulerAngles  = panel.cachedTransform.rotation.eulerAngles;
                         Vector3 eulerAngles2 = parentPanel.cachedTransform.rotation.eulerAngles;
                         Vector3 vector3      = eulerAngles2 - eulerAngles;
                         vector3.x = NGUIMath.WrapAngle(vector3.x);
                         vector3.y = NGUIMath.WrapAngle(vector3.y);
                         vector3.z = NGUIMath.WrapAngle(vector3.z);
                         if (Mathf.Abs(vector3.x) > 0.001f || Mathf.Abs(vector3.y) > 0.001f)
                         {
                             Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", panel);
                         }
                         angle = vector3.z;
                     }
                     SetClipping(num++, drawCallClipRange2, parentPanel.clipSoftness, angle);
                 }
                 parentPanel = parentPanel.parentPanel;
             }
         }
         else
         {
             Vector2 clipSoftness2      = panel.clipSoftness;
             Vector4 drawCallClipRange3 = panel.drawCallClipRange;
             Vector2 mainTextureOffset  = new Vector2((0f - drawCallClipRange3.x) / drawCallClipRange3.z, (0f - drawCallClipRange3.y) / drawCallClipRange3.w);
             Vector2 mainTextureScale   = new Vector2(1f / drawCallClipRange3.z, 1f / drawCallClipRange3.w);
             Vector2 v = new Vector2(1000f, 1000f);
             if (clipSoftness2.x > 0f)
             {
                 v.x = drawCallClipRange3.z / clipSoftness2.x;
             }
             if (clipSoftness2.y > 0f)
             {
                 v.y = drawCallClipRange3.w / clipSoftness2.y;
             }
             mDynamicMat.mainTextureOffset = mainTextureOffset;
             mDynamicMat.mainTextureScale  = mainTextureScale;
             mDynamicMat.SetVector("_ClipSharpness", v);
         }
     }
 }
Esempio n. 11
0
    void DrawRotation(bool isWidget)
    {
        GUILayout.BeginHorizontal();
        {
            bool reset = GUILayout.Button("R", GUILayout.Width(20f));

            Vector3 visible = (serializedObject.targetObject as Transform).localEulerAngles;

            visible.x = NGUIMath.WrapAngle(visible.x);
            visible.y = NGUIMath.WrapAngle(visible.y);
            visible.z = NGUIMath.WrapAngle(visible.z);

            Axes changed = CheckDifference(mRot);
            Axes altered = Axes.None;

            GUILayoutOption opt = GUILayout.MinWidth(30f);

            if (FloatField("X", ref visible.x, (changed & Axes.X) != 0, isWidget, opt))
            {
                altered |= Axes.X;
            }
            if (FloatField("Y", ref visible.y, (changed & Axes.Y) != 0, isWidget, opt))
            {
                altered |= Axes.Y;
            }
            if (FloatField("Z", ref visible.z, (changed & Axes.Z) != 0, false, opt))
            {
                altered |= Axes.Z;
            }

            if (reset)
            {
                mRot.quaternionValue = Quaternion.identity;
            }
            else if (altered != Axes.None)
            {
                NGUIEditorTools.RegisterUndo("Change Rotation", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;
                    Vector3   v = t.localEulerAngles;

                    if ((altered & Axes.X) != 0)
                    {
                        v.x = visible.x;
                    }
                    if ((altered & Axes.Y) != 0)
                    {
                        v.y = visible.y;
                    }
                    if ((altered & Axes.Z) != 0)
                    {
                        v.z = visible.z;
                    }

                    t.localEulerAngles = v;
                }
            }
        }
        GUILayout.EndHorizontal();
    }
Esempio n. 12
0
    void OnWillRenderObject()
    {
        UpdateMaterials();

        if (mBlock != null)
        {
            mRenderer.SetPropertyBlock(mBlock);
        }
        if (onRender != null)
        {
            onRender(mDynamicMat ?? mMaterial);
        }
#if NGUI_BACKUP
        if (mDynamicMat == null || mClipCount == 0)
        {
            return;
        }
#else
        if (mDynamicMat == null || mClipCount == 0 || mDynamicMat.frameCount == Time.frameCount)
        {
            return;
        }
        mDynamicMat.frameCount = Time.frameCount;
#endif

        if (mTextureClip)
        {
            Vector4 cr   = panel.drawCallClipRange;
            Vector2 soft = panel.clipSoftness;

            Vector2 sharpness = new Vector2(1000.0f, 1000.0f);
            if (soft.x > 0f)
            {
                sharpness.x = cr.z / soft.x;
            }
            if (soft.y > 0f)
            {
                sharpness.y = cr.w / soft.y;
            }

            mDynamicMat.SetVector(ClipRange[0], new Vector4(-cr.x / cr.z, -cr.y / cr.w, 1f / cr.z, 1f / cr.w));
            mDynamicMat.SetTexture("_ClipTex", clipTexture);
        }
        else if (!mLegacyShader)
        {
            UIPanel currentPanel = panel;

            for (int i = 0; currentPanel != null;)
            {
                if (currentPanel.hasClipping)
                {
                    float angle = 0f;
                    rootScale = (float)Screen.height / _root.activeHeight;
                    Vector4   cr   = currentPanel.drawCallClipRange * rootScale;
                    Transform node = panel.cachedTransform;

                    // Clipping regions past the first one need additional math
                    if (currentPanel != panel)
                    {
                        Vector3 pos = currentPanel.cachedTransform.InverseTransformPoint(node.position);
                        cr.x -= pos.x * rootScale;
                        cr.y -= pos.y * rootScale;

                        Vector3 v0   = node.rotation.eulerAngles;
                        Vector3 v1   = currentPanel.cachedTransform.rotation.eulerAngles;
                        Vector3 diff = v1 - v0;

                        diff.x = NGUIMath.WrapAngle(diff.x);
                        diff.y = NGUIMath.WrapAngle(diff.y);
                        diff.z = NGUIMath.WrapAngle(diff.z);

                        if (Mathf.Abs(diff.x) > 0.001f || Mathf.Abs(diff.y) > 0.001f)
                        {
                            Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", panel);
                        }

                        angle = diff.z;
                        Vector2 offset = panel.clipOffset;

                        if (angle != 0)
                        {
                            Rotate(ref offset, -angle * Mathf.Deg2Rad);
                        }

                        cr.x -= offset.x * rootScale;
                        cr.y -= offset.y * rootScale;

                        // Pass the clipping parameters to the shader
                        SetClipping(i++, cr, currentPanel.clipSoftness, angle);
                    }
                    else
                    {
                        if (panel.cachedTransform.rotation == Quaternion.identity)
                        {
                            cr.x += node.position.x * (float)Screen.height / 2.0f;
                            cr.y += node.position.y * (float)Screen.height / 2.0f;

                            // Pass the clipping parameters to the shader
                            SetClipping(i++, cr, panel.clipSoftness, 0, 1);
                        }
                        else
                        {
                            Vector3 diff = panel.cachedTransform.eulerAngles;
                            diff.z = NGUIMath.WrapAngle(diff.z);
                            angle  = diff.z;
                            angle *= Mathf.Deg2Rad;
                            Rotate(ref cr, angle);
                            cr.x += node.position.x * (float)Screen.height / 2.0f;
                            cr.y += node.position.y * (float)Screen.height / 2.0f;
                            angle = -angle;

                            // Pass the clipping parameters to the shader
                            SetClipping(i++, cr, panel.clipSoftness, Mathf.Sin(angle), Mathf.Cos(angle));
                        }
                    }
                }
                currentPanel = currentPanel.parentPanel;
            }
        }
        else // Legacy functionality
        {
            Vector2 soft = panel.clipSoftness;
            Vector4 cr   = panel.drawCallClipRange;
            Vector2 v0   = new Vector2(-cr.x / cr.z, -cr.y / cr.w);
            Vector2 v1   = new Vector2(1f / cr.z, 1f / cr.w);

            Vector2 sharpness = new Vector2(1000.0f, 1000.0f);
            if (soft.x > 0f)
            {
                sharpness.x = cr.z / soft.x;
            }
            if (soft.y > 0f)
            {
                sharpness.y = cr.w / soft.y;
            }

            mDynamicMat.mainTextureOffset = v0;
            mDynamicMat.mainTextureScale  = v1;
            mDynamicMat.SetVector("_ClipSharpness", sharpness);
        }
    }
Esempio n. 13
0
 private void OnWillRenderObject()
 {
     this.UpdateMaterials();
     if (this.mDynamicMat == null)
     {
         return;
     }
     if (this.mClipCount == 0)
     {
         if (this.useMerge)
         {
             for (int i = 0; i < 4; i++)
             {
                 this.SetClipping(i, new Vector4(0f, 0f, 10000f, 10000f), new Vector2(0f, 0f), 0f);
             }
         }
         return;
     }
     if (!this.mLegacyShader)
     {
         UIPanel parentPanel = this.panel;
         int     num         = 0;
         while (parentPanel != null)
         {
             if (parentPanel.hasClipping)
             {
                 float   angle             = 0f;
                 Vector4 drawCallClipRange = parentPanel.drawCallClipRange;
                 if (parentPanel != this.panel)
                 {
                     Vector3 vector = parentPanel.cachedTransform.InverseTransformPoint(this.panel.cachedTransform.position);
                     drawCallClipRange.x -= vector.x;
                     drawCallClipRange.y -= vector.y;
                     Vector3 eulerAngles  = this.panel.cachedTransform.rotation.eulerAngles;
                     Vector3 eulerAngles2 = parentPanel.cachedTransform.rotation.eulerAngles;
                     Vector3 vector2      = eulerAngles2 - eulerAngles;
                     vector2.x = NGUIMath.WrapAngle(vector2.x);
                     vector2.y = NGUIMath.WrapAngle(vector2.y);
                     vector2.z = NGUIMath.WrapAngle(vector2.z);
                     angle     = vector2.z;
                 }
                 this.SetClipping(num++, drawCallClipRange, parentPanel.clipSoftness, angle);
             }
             parentPanel = parentPanel.parentPanel;
         }
         if (this.useMerge)
         {
             for (int j = num; j < 4; j++)
             {
                 this.SetClipping(j, new Vector4(0f, 0f, 10000f, 10000f), new Vector2(0f, 0f), 0f);
             }
         }
     }
     else
     {
         Vector2 clipSoftness       = this.panel.clipSoftness;
         Vector4 drawCallClipRange2 = this.panel.drawCallClipRange;
         Vector2 mainTextureOffset  = new Vector2(-drawCallClipRange2.x / drawCallClipRange2.z, -drawCallClipRange2.y / drawCallClipRange2.w);
         Vector2 mainTextureScale   = new Vector2(1f / drawCallClipRange2.z, 1f / drawCallClipRange2.w);
         Vector2 v = new Vector2(1000f, 1000f);
         if (clipSoftness.x > 0f)
         {
             v.x = drawCallClipRange2.z / clipSoftness.x;
         }
         if (clipSoftness.y > 0f)
         {
             v.y = drawCallClipRange2.w / clipSoftness.y;
         }
         this.mDynamicMat.mainTextureOffset = mainTextureOffset;
         this.mDynamicMat.mainTextureScale  = mainTextureScale;
         this.mDynamicMat.SetVector("_ClipSharpness", v);
     }
 }
Esempio n. 14
0
    void OnWillRenderObject()
    {
        UpdateMaterials();

        if (mBlock != null)
        {
            mRenderer.SetPropertyBlock(mBlock);
        }
        if (onRender != null)
        {
            onRender(mDynamicMat ?? mMaterial);
        }
        //if (mDynamicMat == null || mClipCount == 0) return;
        if ((mDynamicMat == null || mClipCount == 0) && panel.clipping != Clipping.AcePolygon)
        {
            return;
        }

        if (mTextureClip)
        {
            Vector4 cr   = panel.drawCallClipRange;
            Vector2 soft = panel.clipSoftness;

            Vector2 sharpness = new Vector2(1000.0f, 1000.0f);
            if (soft.x > 0f)
            {
                sharpness.x = cr.z / soft.x;
            }
            if (soft.y > 0f)
            {
                sharpness.y = cr.w / soft.y;
            }

            mDynamicMat.SetVector(ClipRange[0], new Vector4(-cr.x / cr.z, -cr.y / cr.w, 1f / cr.z, 1f / cr.w));
            mDynamicMat.SetTexture("_ClipTex", clipTexture);
        }
        //----pat------
        else if (mAcePolygonClip)
        {
            if (panel.acePolygon)
            {
                AceVertex[] listVerts = panel.acePolygon.mListVerts;
                if (listVerts.Length > 3)
                {
                    if (listVerts[0] != null && listVerts[1] != null && listVerts[2] != null &&
                        listVerts[3] != null)
                    {
                        Vector3 v0 = panel.transform.InverseTransformPoint(listVerts [0].transform.position);
                        Vector3 v1 = panel.transform.InverseTransformPoint(listVerts [1].transform.position);
                        Vector3 v2 = panel.transform.InverseTransformPoint(listVerts [2].transform.position);
                        Vector3 v3 = panel.transform.InverseTransformPoint(listVerts [3].transform.position);
                        mDynamicMat.SetVector(ClipRange [0],
                                              new Vector4(
                                                  v0.x, v0.y,
                                                  v1.x - v0.x, v1.y - v0.y
                                                  )
                                              );
                        mDynamicMat.SetVector(ClipRange [1],
                                              new Vector4(
                                                  v1.x, v1.y,
                                                  v2.x - v1.x, v2.y - v1.y
                                                  )
                                              );
                        mDynamicMat.SetVector(ClipRange [2],
                                              new Vector4(
                                                  v2.x, v2.y,
                                                  v3.x - v2.x, v3.y - v2.y
                                                  )
                                              );
                        mDynamicMat.SetVector(ClipRange [3],
                                              new Vector4(
                                                  v3.x, v3.y,
                                                  v0.x - v3.x, v0.y - v3.y
                                                  )
                                              );
                    }
                }
            }
        }
        else if (!mLegacyShader)
        {
            UIPanel currentPanel = panel;

            for (int i = 0; currentPanel != null;)
            {
                if (currentPanel.hasClipping)
                {
                    float   angle = 0f;
                    Vector4 cr    = currentPanel.drawCallClipRange;

                    // Clipping regions past the first one need additional math
                    if (currentPanel != panel)
                    {
                        Vector3 pos = currentPanel.cachedTransform.InverseTransformPoint(panel.cachedTransform.position);
                        cr.x -= pos.x;
                        cr.y -= pos.y;

                        Vector3 v0   = panel.cachedTransform.rotation.eulerAngles;
                        Vector3 v1   = currentPanel.cachedTransform.rotation.eulerAngles;
                        Vector3 diff = v1 - v0;

                        diff.x = NGUIMath.WrapAngle(diff.x);
                        diff.y = NGUIMath.WrapAngle(diff.y);
                        diff.z = NGUIMath.WrapAngle(diff.z);

                        if (Mathf.Abs(diff.x) > 0.001f || Mathf.Abs(diff.y) > 0.001f)
                        {
                            Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", panel);
                        }

                        angle = diff.z;
                    }

                    // Pass the clipping parameters to the shader
                    SetClipping(i++, cr, currentPanel.clipSoftness, angle);
                }
                currentPanel = currentPanel.parentPanel;
            }
        }
        else         // Legacy functionality
        {
            Vector2 soft = panel.clipSoftness;
            Vector4 cr   = panel.drawCallClipRange;
            Vector2 v0   = new Vector2(-cr.x / cr.z, -cr.y / cr.w);
            Vector2 v1   = new Vector2(1f / cr.z, 1f / cr.w);

            Vector2 sharpness = new Vector2(1000.0f, 1000.0f);
            if (soft.x > 0f)
            {
                sharpness.x = cr.z / soft.x;
            }
            if (soft.y > 0f)
            {
                sharpness.y = cr.w / soft.y;
            }

            mDynamicMat.mainTextureOffset = v0;
            mDynamicMat.mainTextureScale  = v1;
            mDynamicMat.SetVector("_ClipSharpness", sharpness);
        }
    }
Esempio n. 15
0
 private void OnWillRenderObject()
 {
     //IL_005d: Unknown result type (might be due to invalid IL or missing references)
     //IL_0062: Unknown result type (might be due to invalid IL or missing references)
     //IL_0069: Unknown result type (might be due to invalid IL or missing references)
     //IL_006e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0115: Unknown result type (might be due to invalid IL or missing references)
     //IL_0167: Unknown result type (might be due to invalid IL or missing references)
     //IL_016c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0190: Unknown result type (might be due to invalid IL or missing references)
     //IL_0195: Unknown result type (might be due to invalid IL or missing references)
     //IL_019a: Unknown result type (might be due to invalid IL or missing references)
     //IL_01d1: Unknown result type (might be due to invalid IL or missing references)
     //IL_01d6: Unknown result type (might be due to invalid IL or missing references)
     //IL_01da: Unknown result type (might be due to invalid IL or missing references)
     //IL_01df: Unknown result type (might be due to invalid IL or missing references)
     //IL_01e7: Unknown result type (might be due to invalid IL or missing references)
     //IL_01ec: Unknown result type (might be due to invalid IL or missing references)
     //IL_01f0: Unknown result type (might be due to invalid IL or missing references)
     //IL_01f5: Unknown result type (might be due to invalid IL or missing references)
     //IL_01f7: Unknown result type (might be due to invalid IL or missing references)
     //IL_01f9: Unknown result type (might be due to invalid IL or missing references)
     //IL_01fb: Unknown result type (might be due to invalid IL or missing references)
     //IL_0200: Unknown result type (might be due to invalid IL or missing references)
     //IL_0288: Unknown result type (might be due to invalid IL or missing references)
     //IL_028b: Unknown result type (might be due to invalid IL or missing references)
     //IL_02b5: Unknown result type (might be due to invalid IL or missing references)
     //IL_02ba: Unknown result type (might be due to invalid IL or missing references)
     //IL_02c2: Unknown result type (might be due to invalid IL or missing references)
     //IL_02c7: Unknown result type (might be due to invalid IL or missing references)
     //IL_0376: Unknown result type (might be due to invalid IL or missing references)
     //IL_0383: Unknown result type (might be due to invalid IL or missing references)
     //IL_0395: Unknown result type (might be due to invalid IL or missing references)
     //IL_0397: Unknown result type (might be due to invalid IL or missing references)
     UpdateMaterials();
     if (onRender != null)
     {
         onRender(mDynamicMat ?? mMaterial);
     }
     if (!(mDynamicMat == null) && mClipCount != 0)
     {
         if (mTextureClip)
         {
             Vector4 drawCallClipRange = panel.drawCallClipRange;
             Vector2 clipSoftness      = panel.clipSoftness;
             Vector2 val = default(Vector2);
             val._002Ector(1000f, 1000f);
             if (clipSoftness.x > 0f)
             {
                 val.x = drawCallClipRange.z / clipSoftness.x;
             }
             if (clipSoftness.y > 0f)
             {
                 val.y = drawCallClipRange.w / clipSoftness.y;
             }
             mDynamicMat.SetVector(ClipRange[0], new Vector4((0f - drawCallClipRange.x) / drawCallClipRange.z, (0f - drawCallClipRange.y) / drawCallClipRange.w, 1f / drawCallClipRange.z, 1f / drawCallClipRange.w));
             mDynamicMat.SetTexture("_ClipTex", clipTexture);
         }
         else if (!mLegacyShader)
         {
             UIPanel parentPanel = panel;
             int     num         = 0;
             while (parentPanel != null)
             {
                 if (parentPanel.hasClipping)
                 {
                     float   angle = 0f;
                     Vector4 drawCallClipRange2 = parentPanel.drawCallClipRange;
                     if (parentPanel != panel)
                     {
                         Vector3 val2 = parentPanel.cachedTransform.InverseTransformPoint(panel.cachedTransform.get_position());
                         drawCallClipRange2.x -= val2.x;
                         drawCallClipRange2.y -= val2.y;
                         Quaternion rotation     = panel.cachedTransform.get_rotation();
                         Vector3    eulerAngles  = rotation.get_eulerAngles();
                         Quaternion rotation2    = parentPanel.cachedTransform.get_rotation();
                         Vector3    eulerAngles2 = rotation2.get_eulerAngles();
                         Vector3    val3         = eulerAngles2 - eulerAngles;
                         val3.x = NGUIMath.WrapAngle(val3.x);
                         val3.y = NGUIMath.WrapAngle(val3.y);
                         val3.z = NGUIMath.WrapAngle(val3.z);
                         if (Mathf.Abs(val3.x) > 0.001f || Mathf.Abs(val3.y) > 0.001f)
                         {
                             Debug.LogWarning((object)"Panel can only be clipped properly if X and Y rotation is left at 0", panel);
                         }
                         angle = val3.z;
                     }
                     SetClipping(num++, drawCallClipRange2, parentPanel.clipSoftness, angle);
                 }
                 parentPanel = parentPanel.parentPanel;
             }
         }
         else
         {
             Vector2 clipSoftness2      = panel.clipSoftness;
             Vector4 drawCallClipRange3 = panel.drawCallClipRange;
             Vector2 mainTextureOffset  = default(Vector2);
             mainTextureOffset._002Ector((0f - drawCallClipRange3.x) / drawCallClipRange3.z, (0f - drawCallClipRange3.y) / drawCallClipRange3.w);
             Vector2 mainTextureScale = default(Vector2);
             mainTextureScale._002Ector(1f / drawCallClipRange3.z, 1f / drawCallClipRange3.w);
             Vector2 val4 = default(Vector2);
             val4._002Ector(1000f, 1000f);
             if (clipSoftness2.x > 0f)
             {
                 val4.x = drawCallClipRange3.z / clipSoftness2.x;
             }
             if (clipSoftness2.y > 0f)
             {
                 val4.y = drawCallClipRange3.w / clipSoftness2.y;
             }
             mDynamicMat.set_mainTextureOffset(mainTextureOffset);
             mDynamicMat.set_mainTextureScale(mainTextureScale);
             mDynamicMat.SetVector("_ClipSharpness", Vector4.op_Implicit(val4));
         }
     }
 }
Esempio n. 16
0
 public unsafe static long $Invoke45(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(NGUIMath.WrapAngle(*(float *)args)));
 }
Esempio n. 17
0
    private void UpdateClipping()
    {
        if (ClipArgs.Length == 0)
        {
            ClipRange = new[]
            {
                Shader.PropertyToID("_ClipRange0"),
                Shader.PropertyToID("_ClipRange1"),
                Shader.PropertyToID("_ClipRange2"),
                Shader.PropertyToID("_ClipRange4"),
            };
            ClipArgs = new[]
            {
                Shader.PropertyToID("_ClipArgs0"),
                Shader.PropertyToID("_ClipArgs1"),
                Shader.PropertyToID("_ClipArgs2"),
                Shader.PropertyToID("_ClipArgs3"),
            };
        }
        var     panel        = UiPanel;
        UIPanel currentPanel = panel;

        for (int clipIndex = 0; currentPanel != null;)
        {
            if (currentPanel.hasClipping)
            {
                float   angle        = 0f;
                Vector4 cr           = currentPanel.drawCallClipRange;
                var     worldCorners = currentPanel.worldCorners;
                var     worldCenter  = new Vector3(worldCorners[0].x + worldCorners[2].x, worldCorners[0].y + worldCorners[1].y) * 0.5f;

                worldCenter = currentPanel.root.transform.InverseTransformPoint(worldCenter);
                var h = currentPanel.root.activeHeight;
                var w = (int)(h * Screen.width / Screen.height);

                Vector4 clipSize;
                clipSize.x = worldCenter.x / w;
                clipSize.y = worldCenter.y / h;
                clipSize.z = cr.z / w;
                clipSize.w = cr.w / h;
                clipSize  *= 2;

                //Clipping regions past the first one need additional math
                if (currentPanel != panel)
                {
                    Vector3 pos = currentPanel.cachedTransform.InverseTransformPoint(panel.cachedTransform.position);
                    cr.x -= pos.x;
                    cr.y -= pos.y;

                    Vector3 v0   = panel.cachedTransform.rotation.eulerAngles;
                    Vector3 v1   = currentPanel.cachedTransform.rotation.eulerAngles;
                    Vector3 diff = v1 - v0;

                    diff.x = NGUIMath.WrapAngle(diff.x);
                    diff.y = NGUIMath.WrapAngle(diff.y);
                    diff.z = NGUIMath.WrapAngle(diff.z);

                    if (Mathf.Abs(diff.x) > 0.001f || Math.Abs(diff.y) > 0.001f)
                    {
                        Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", panel);
                    }
                    angle = diff.z;
                }

                //Pass the Clipping parameters to the shader
                for (int i = 0; i < _cachedMaterials.Count; i++)
                {
                    _cachedMaterials[i].SetVector("_ClipSize", clipSize);
                    SetClipping(_cachedMaterials[i], clipIndex, cr, currentPanel.clipSoftness, angle);
                }
                ++clipIndex;
            }
            currentPanel = currentPanel.parentPanel;
        }
    }