コード例 #1
0
    public void Init(IMDrawCamera cam)
    {
        //Debug.Log("IMDrawTextMeshComponent.Init");

        m_IMDrawCamera = cam;

        if (m_TextMeshList == null)
        {
            m_TextMeshList = new LinkedList <IMDrawTextMesh>();
        }

        if (m_TextMeshPool == null)
        {
            m_TextMeshPool = new Stack <IMDrawTextMesh>(m_MaxTextMeshes);
        }

        if (m_Font == null)
        {
            m_Font = Resources.GetBuiltinResource <Font>("Arial.ttf");            // If no font is assigned, use the Unity default
        }
        if (m_Font != null)
        {
            Texture tex = m_Font.material.GetTexture(IMDrawSPID._MainTex);

            if (cam.MaterialTextMesh != null)
            {
                cam.MaterialTextMesh.SetTexture(IMDrawSPID._MainTex, tex);
            }
        }
    }
コード例 #2
0
    private void DrawCameraList(IMDrawManager component, bool isPlaying)
    {
        if (!isPlaying)         // Unity isn't running
        {
            return;
        }

        Space();

        List <IMDrawCamera> cameraList = IMDrawCamera.GetCameraList();

        if (cameraList.Count > 0)
        {
            IMDrawCamera child;

            for (int index = 0; index < cameraList.Count; ++index)
            {
                child = cameraList[index];

                if (child == null)
                {
                    continue;
                }

                EditorGUILayout.BeginHorizontal();

                if (isPlaying)
                {
                    // Indicate if this camera is the current target
                    if (child == IMDrawManager.TargetCamera)
                    {
                        GUILayout.Label("►", EditorStyles.whiteLabel, GUILayout.Width(15f));
                    }
                    else
                    {
                        GUILayout.Space(20f);
                    }
                }

                GUILayout.Label(string.Format("Priority:{0}", child.Priority), EditorStyles.whiteLabel, GUILayout.Width(100f));

                GUILayout.Label(child != null ? child.name : "null", EditorStyles.whiteLabel);

                if (IMDrawManager.TargetCamera != child)
                {
                    if (GUILayout.Button("Set as target", GUILayout.Width(90f)))
                    {
                        IMDrawManager.TargetCamera = child;
                    }
                }

                EditorGUILayout.EndHorizontal();
            }
        }
        else
        {
            GUILayout.Label("No active IMDrawCamera components found.", EditorStyles.whiteLabel);
        }
    }
コード例 #3
0
    /// <summary>Flush draw commands on all cameras.</summary>
    public void FlushAll()
    {
        List <IMDrawCamera> cameraList = IMDrawCamera.GetCameraList();

        for (int i = 0; i < cameraList.Count; ++i)
        {
            cameraList[i].FlushImmediate();
        }
    }
コード例 #4
0
    private void DrawArc(IMDrawCamera component)
    {
        s_Matrix.SetTRS(m_Position, m_Rotation, new Vector3(m_Size.y, 1f, m_Size.y));

        s_ArcPropertyBlock.SetColor(IMDrawSPID._Color, m_Color);
        s_ArcPropertyBlock.SetFloat(IMDrawSPID._InnerRadius, m_Size.x / m_Size.y);
        s_ArcPropertyBlock.SetFloat(IMDrawSPID._DirAngle, m_DirAngle);
        s_ArcPropertyBlock.SetFloat(IMDrawSPID._SectorAngle, m_SectorAngle);

        Graphics.DrawMesh(IMDrawManager.Instance.MeshQuad, s_Matrix, component.MaterialMeshArc, component.MeshLayer, component.Camera, 0, s_ArcPropertyBlock);
    }
コード例 #5
0
    void OnGUI()
    {
        if (IMDrawManager.Instance != this)
        {
            return;
        }

        List <IMDrawCamera> cameraList = IMDrawCamera.GetCameraList();

        for (int i = 0; i < cameraList.Count; ++i)
        {
            cameraList[i].GUIDraw();
        }
    }
コード例 #6
0
    public override void Draw(IMDrawCamera component)
    {
        Color previousGUIColor = GUI.color;

        GUI.color = m_Color;

        switch (m_Style)
        {
        case GUIRectangleStyle.FILLED: GUI.DrawTexture(m_Rect, IMDrawManager.WhiteTexture); break;

        case GUIRectangleStyle.BORDER: GUI.Label(m_Rect, GUIContent.none, IMDrawManager.GUIStyleOutlineRect); break;
        }

        GUI.color = previousGUIColor;
    }
コード例 #7
0
    private IMDrawCamera GetCamera(int instanceID)
    {
        if (instanceID != 0)
        {
            List <IMDrawCamera> cameraList = IMDrawCamera.GetCameraList();

            for (int i = 0; i < cameraList.Count; ++i)
            {
                if (instanceID == cameraList[i].GetInstanceID())
                {
                    return(cameraList[i]);
                }
            }
        }

        return(null);
    }
コード例 #8
0
    private void OnBeginFrame()
    {
        ScreenWidth  = Screen.width;
        ScreenHeight = Screen.height;

        float deltaTime = Time.deltaTime;

        List <IMDrawCamera> cameraList = IMDrawCamera.GetCameraList();

        for (int i = 0; i < cameraList.Count; ++i)
        {
            if (cameraList[i] != null)
            {
                cameraList[i].OnBeginFrame(deltaTime);
            }
        }
    }
コード例 #9
0
    /// <summary>Compute the position of the label. Return true if the label should be drawn.</summary>
    public override bool UpdateLayout(IMDrawCamera component)
    {
        if ((m_Flags & IMDrawGUICommandFlag.WORLD_SPACE) != 0)         // Element is positioned in world space
        {
            Vector3 screenPos = component.Camera.WorldToScreenPoint(m_Position);

            if (screenPos.z <= 0f)
            {
                return(false);                // Element is behind the camera, if the element is displayed for just one frame, dispose of this command
            }

            m_Z = component.GetCameraDistSqrd(ref m_Position);

            if (component.GUIApplyDistanceFade(this))             // Apply distance fade to this label - if the label is beyond the max fade range, skip drawing it
            {
                return(false);
            }

            m_Rect.x = screenPos.x + m_OffsetX;
            m_Rect.y = IMDrawManager.Instance.ScreenHeight - screenPos.y + m_OffsetY;
        }
        else         // Element is positioned in screen space
        {
            m_Rect.x = m_Position.x;
            m_Rect.y = m_Position.y;
        }

        //Vector2 size = GUI.skin.label.CalcSize(m_Text);
        Vector2 size = component.FontGUIStyle.CalcSize(m_Text);

        m_Rect.width  = size.x;
        m_Rect.height = size.y;

        m_Rect.x -= (m_Rect.width * m_PivotX);
        m_Rect.y -= (m_Rect.height * m_PivotY);

        return(m_Rect.x > -m_Rect.width && m_Rect.x < IMDrawManager.Instance.ScreenWidth && m_Rect.y > -m_Rect.height && m_Rect.y < IMDrawManager.Instance.ScreenHeight);
    }
コード例 #10
0
    public override void Draw(IMDrawCamera component)
    {
        if (m_Texture == null)
        {
            return;
        }

        Color previousGUIColor = GUI.color;

        GUI.color = m_Color;

        switch (m_Style)
        {
        case GUITextureStyle.NORMAL:
            GUI.DrawTexture(m_Rect, m_Texture, m_ScaleMode, true, m_Aspect);
            break;

        case GUITextureStyle.UV:
            GUI.DrawTextureWithTexCoords(m_Rect, m_Texture, m_TexCoord);
            break;
        }

        GUI.color = previousGUIColor;
    }
コード例 #11
0
    void FixedUpdate()
    {
        if (IMDrawManager.Instance != this)
        {
            return;
        }

        if (s_SortCameraList)
        {
            IMDrawCamera.SortCameraList();
            s_SortCameraList = false;
        }

        //m_InsideFixedUpdate = true;

        // FixedUpdate is called before Update, however it is not guaranteed to be called so instead it will be caught in Update
        if (!m_EnteredNewFrame)
        {
            OnBeginFrame();

            // Notify XDraw component
            m_EnteredNewFrame = true;
        }
    }
コード例 #12
0
    public override void Draw(IMDrawCamera component)
    {
        if (m_Color.a == 0f)         // Skip drawing any labels which are completely transparent
        {
            return;
        }

        GUIStyle guiStyle = component.FontGUIStyle;

        guiStyle.alignment = m_Anchor;
        guiStyle.fontSize  = m_FontSize > 0 ? m_FontSize : component.DefaultLabelFontSize;        // Change font size if custom size has been specified

        if ((m_Flags & IMDrawGUICommandFlag.SHADOWED) != 0)
        {
            s_ShadowColor.a           = m_Color.a;
            guiStyle.normal.textColor = s_ShadowColor;
            GUI.Label(new Rect(m_Rect.x + 2f, m_Rect.y + 2f, m_Rect.width, m_Rect.height), m_Text, guiStyle);
        }

        guiStyle.normal.textColor = m_Color;
        GUI.Label(m_Rect, m_Text, guiStyle);

        guiStyle.fontSize = component.DefaultLabelFontSize;
    }
コード例 #13
0
    public void Draw(IMDrawCamera component)
    {
        s_MaterialPropertyBlock.SetColor(IMDrawSPID._Color, m_Color);
        //s_MaterialPropertyBlock.SetFloat(IMDrawSPID._ZTest, (float)m_ZTest); // This doesn't work for some reason - probably a Unity bug?
        component.MaterialMesh.SetInt(IMDrawSPID._ZTest, (int)m_ZTest);

        switch (m_Type)
        {
        case IMDrawCommandType.QUAD:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshQuad, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.BOX:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshBox, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.PYRAMID:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshPyramid, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.RHOMBUS:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshRhombus, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.ARC:
        {
            DrawArc(component);
        }
        break;

        case IMDrawCommandType.DISC:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshDisc, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.SPHERE:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshSphere, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CONE:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshCone, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CAPSULE:
        {
            float bodyHeight = m_Size.y - (m_Size.x * 2f);

            if (bodyHeight > 0f)
            {
                s_Matrix.SetTRS(m_Position, m_Rotation, new Vector3(m_Size.x, bodyHeight, m_Size.z));
                Graphics.DrawMesh(IMDrawManager.Instance.MeshCapsuleBody, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
            }

            Vector3 capOffset = ToUpVector(bodyHeight * 0.5f);

            s_Matrix.SetTRS(
                m_Position + capOffset,
                m_Rotation,
                new Vector3(m_Size.x, m_Size.x, m_Size.x));
            Graphics.DrawMesh(IMDrawManager.Instance.MeshCapsuleCap, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);

            s_Matrix.SetTRS(
                m_Position - capOffset,
                m_Rotation * CAPSULE_BOTTOM_CAP_ROTATION,
                new Vector3(m_Size.x, m_Size.x, m_Size.x));

            Graphics.DrawMesh(IMDrawManager.Instance.MeshCapsuleCap, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CYLINDER:
        {
            s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshCylinder, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CUSTOM_MESH:
        {
            if (m_Mesh != null)
            {
                s_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
                Graphics.DrawMesh(m_Mesh, s_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, s_MaterialPropertyBlock);
            }
        }
        break;
        }
    }
コード例 #14
0
 public override void Dispose(IMDrawCamera component)
 {
     m_Texture = null;
     component.Dispose(this);
 }
コード例 #15
0
 public override bool UpdateLayout(IMDrawCamera component)     // This is called on first update to compute position, returns true if the command is visible
 {
     return(m_Rect.x > -m_Rect.width && m_Rect.x < IMDrawManager.Instance.ScreenWidth && m_Rect.y > -m_Rect.height && m_Rect.y < IMDrawManager.Instance.ScreenHeight);
 }
コード例 #16
0
    public void Draw(IMDrawCamera component)
    {
        m_MaterialPropertyBlock.SetColor(SHADER_PROPERTY_ID_COLOR, m_Color);

        switch (m_Type)
        {
        case IMDrawCommandType.QUAD:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshQuad, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.BOX:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshBox, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.PYRAMID:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshPyramid, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.RHOMBUS:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshRhombus, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.DISC:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshDisc, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.SPHERE:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshSphere, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CONE:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshCone, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CAPSULE:
        {
            float bodyHeight = m_Size.y - (m_Size.x * 2f);
            m_Matrix.SetTRS(m_Position, m_Rotation, new Vector3(m_Size.x, bodyHeight, m_Size.z));
            Graphics.DrawMesh(IMDrawManager.Instance.MeshCapsuleBody, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);

            Vector3 capOffset = ToUpVector(bodyHeight * 0.5f);

            m_Matrix.SetTRS(
                m_Position + capOffset,
                m_Rotation,
                new Vector3(m_Size.x, m_Size.x, m_Size.x));
            Graphics.DrawMesh(IMDrawManager.Instance.MeshCapsuleCap, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);

            m_Matrix.SetTRS(
                m_Position - capOffset,
                m_Rotation * CAPSULE_BOTTOM_CAP_ROTATION,
                new Vector3(m_Size.x, m_Size.x, m_Size.x));

            Graphics.DrawMesh(IMDrawManager.Instance.MeshCapsuleCap, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CYLINDER:
        {
            m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
            Graphics.DrawMesh(IMDrawManager.Instance.MeshCylinder, m_Matrix, component.MaterialMesh, component.MeshLayer, component.Camera, 0, m_MaterialPropertyBlock);
        }
        break;

        case IMDrawCommandType.CUSTOM_MESH:
        {
            if (m_Mesh != null)
            {
                m_Matrix.SetTRS(m_Position, m_Rotation, m_Size);
                Graphics.DrawMesh(m_Mesh, m_Matrix, component.MaterialMesh, 0, component.Camera, component.MeshLayer, m_MaterialPropertyBlock);
            }
        }
        break;
        }
    }
コード例 #17
0
    public abstract bool UpdateLayout(IMDrawCamera component);      // This is called on first update to compute position, returns true if the command is visible

    public abstract void Draw(IMDrawCamera component);
コード例 #18
0
 public override void Dispose(IMDrawCamera component)
 {
     component.Dispose(this);
 }
コード例 #19
0
 public abstract bool UpdateLayout(IMDrawCamera component);      // This is called on first update to compute position, returns true if the command is visible
コード例 #20
0
 public abstract void Dispose(IMDrawCamera component);