public override void OnInspectorGUI()
    {
        //Target
        UModbusTCP oUModbusTCP = (UModbusTCP)target;

        //Setup Styles
        GUIStyle oGUIStyleStatus = new GUIStyle();

        oGUIStyleStatus.fontStyle = FontStyle.Bold;
        oGUIStyleStatus.alignment = TextAnchor.MiddleCenter;

        GUIStyle oGUIStyleStatusResult = new GUIStyle();

        oGUIStyleStatusResult.alignment   = TextAnchor.MiddleCenter;
        oGUIStyleStatusResult.fixedHeight = 40f;

        GUIStyle oGUIStyleStatusResultInfo = new GUIStyle();

        oGUIStyleStatusResultInfo.alignment = TextAnchor.MiddleCenter;

        //Editor
        GUILayout.Space(20);
        GUILayout.BeginHorizontal();
        GUILayout.Label("STATUS", oGUIStyleStatus);
        GUILayout.EndHorizontal();
        GUILayout.Space(10);
        if (oUModbusTCP.connected)
        {
            //Style
            GUIStyle oGUIStyleStatusText = new GUIStyle();
            oGUIStyleStatusText.normal.background = MakeTex(1000, 1, COLOR_CONNECTED);
            //Status text
            GUILayout.BeginHorizontal(oGUIStyleStatusText);
            GUILayout.Label("CONNECTED", oGUIStyleStatusResult);
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("IP: {0}", oUModbusTCP.ip), oGUIStyleStatusResultInfo);
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("PORT: {0}", oUModbusTCP.port), oGUIStyleStatusResultInfo);
            GUILayout.EndHorizontal();
        }
        else
        {
            //Style
            GUIStyle oGUIStyleStatusText = new GUIStyle();
            oGUIStyleStatusText.normal.background = MakeTex(1000, 1, COLOR_NOT_CONNECTED);
            //Status text
            GUILayout.BeginHorizontal(oGUIStyleStatusText);
            GUILayout.Label("NOT CONNECTED", oGUIStyleStatusResult);
            GUILayout.EndHorizontal();
        }
        GUILayout.Space(40);
    }
Esempio n. 2
0
 void Awake()
 {
     if (m_oInstance != null && m_oInstance != this)
     {
         Destroy(GetComponent <UModbusTCP>());
     }
     else
     {
         m_oInstance = this;
     }
 }