Example #1
0
 private void OnEnable()
 {
     instance = this;
     mPos     = serializedObject.FindProperty("m_LocalPosition");
     mRot     = serializedObject.FindProperty("m_LocalRotation");
     mScale   = serializedObject.FindProperty("m_LocalScale");
 }
Example #2
0
		public EntityInspector(Entity entity)
		{
			_entity = entity;
			_transformInspector = new TransformInspector(_entity.Transform);

			for (var i = 0; i < entity.Components.Count; i++)
				_componentInspectors.Add(new ComponentInspector(entity.Components[i]));
		}
    private void OnEnable()
    {
        try
        {
            instance = this;

            if (serializedObject != null)
            {
                _hasObj = true;
                mPos    = serializedObject.FindProperty("m_LocalPosition");
                mRot    = serializedObject.FindProperty("m_LocalRotation");
                mScale  = serializedObject.FindProperty("m_LocalScale");
            }
        }
        catch { }
    }
Example #4
0
    void OnEnable()
    {
        instance = this;

        if (this)
        {
            try
            {
                var so = serializedObject;
                mPos   = so.FindProperty("m_LocalPosition");
                mRot   = so.FindProperty("m_LocalRotation");
                mScale = so.FindProperty("m_LocalScale");
            }
            catch { }
        }
    }
Example #5
0
    private void OnEnable()
    {
        try
        {
            instance = this;

            if (serializedObject != null)
            {
                _hasObj = true;
                mPos    = serializedObject.FindProperty("m_LocalPosition");
                mRot    = serializedObject.FindProperty("m_LocalRotation");
                mScale  = serializedObject.FindProperty("m_LocalScale");
                Vector3 scaleAll_Vec3 = mScale.vector3Value;
                if (scaleAll_Vec3.x == scaleAll_Vec3.y && scaleAll_Vec3.x == scaleAll_Vec3.z)
                {
                    m_Scale = scaleAll_Vec3.x;
                }
            }
        }
        catch { }
    }
Example #6
0
 void OnDestroy()
 {
     instance = null;
 }
Example #7
0
 private void OnDestroy()
 {
     instance = null;
     _hasObj  = false;
 }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (s_Contents == null)
        {
            s_Contents = new Contents();
        }

        serializedObject.Update();
        Event e = Event.current;

        if (e != null)
        {
            if (image)//Auto set Image's native size if Image.sprite is not null
            {
                if (e.type == EventType.DragPerform || e.type == EventType.MouseDown)
                {
                    autoSetNativeSize = !image.sprite;
                }

                if (autoSetNativeSize && image.sprite && image.type == Image.Type.Simple)
                {
                    autoSetNativeSize = false;
                    RectTransform tf = target as RectTransform;
                    float         x  = image.sprite.rect.width / image.pixelsPerUnit;
                    float         y  = image.sprite.rect.height / image.pixelsPerUnit;
                    tf.anchorMax = tf.anchorMin;
                    tf.sizeDelta = new Vector2(x, y);
                }
            }

            //Keyboard control move by pixel style like Photoshop's move tool
            if (e.type == EventType.KeyDown && e.control)
            {
                int nUnit = e.shift ? 10 : 1;
                switch (e.keyCode)
                {
                case KeyCode.UpArrow:
                    Undo.RecordObjects(targets, "UpArrow");
                    MoveTargetAnchoredPosition(Vector2.up * nUnit);
                    e.Use();
                    break;

                case KeyCode.DownArrow:
                    Undo.RecordObjects(targets, "DownArrow");
                    MoveTargetAnchoredPosition(Vector2.down * nUnit);
                    e.Use();
                    break;

                case KeyCode.LeftArrow:
                    Undo.RecordObjects(targets, "LeftArrow");
                    MoveTargetAnchoredPosition(Vector2.left * nUnit);
                    e.Use();
                    break;

                case KeyCode.RightArrow:
                    Undo.RecordObjects(targets, "RightArrow");
                    MoveTargetAnchoredPosition(Vector2.right * nUnit);
                    e.Use();
                    break;
                }
            }
        }

        const float fButtonWidth = 21;

        if (stylePivotSetup == null)
        {
            stylePivotSetup = new GUIStyle("PreButton")
            {
                normal     = new GUIStyle("CN Box").normal,
                active     = new GUIStyle("AppToolbar").normal,
                overflow   = new RectOffset(),
                padding    = new RectOffset(0, 0, -1, 0),
                fixedWidth = 19
            };

            styleMove = new GUIStyle(stylePivotSetup)
            {
                padding = new RectOffset(0, 0, -2, 0)
            };
        }

        GUILayout.BeginHorizontal();
        {
            GUILayout.BeginVertical();
            {
                #region Tools
                GUILayout.BeginHorizontal();
                {
                    EditorGUIUtility.labelWidth = 64;
                    float newScale = EditorGUILayout.FloatField(s_Contents.scaleContent, scaleAll);
                    if (!Mathf.Approximately(scaleAll, newScale))
                    {
                        scaleAll = newScale;
                        spLocalScale.vector3Value = Vector3.one * scaleAll;
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button(s_Contents.anchoredPosition0Content, strButtonLeft, GUILayout.Width(fButtonWidth)))
                    {
                        foreach (Object item in targets)
                        {
                            RectTransform rtf = item as RectTransform;
                            rtf.LocalPositionIdentity();
                        }
                    }

                    if (GUILayout.Button(s_Contents.deltaSize0Content, strButtonMid, GUILayout.Width(fButtonWidth)))
                    {
                        spSizeDelta.vector2Value = Vector2.zero;
                    }

                    if (GUILayout.Button(s_Contents.rotation0Content, strButtonMid, GUILayout.Width(fButtonWidth)))
                    {
                        spLocalRotation.quaternionValue = Quaternion.identity;
                    }

                    if (GUILayout.Button(s_Contents.scale0Content, strButtonRight, GUILayout.Width(fButtonWidth)))
                    {
                        spLocalScale.vector3Value = Vector3.one;
                        scaleAll = spLocalScale.FindPropertyRelative("x").floatValue;
                    }

                    if (GUILayout.Button(s_Contents.roundContent))
                    {
                        Vector2 v2 = spAnchoredPosition.vector2Value;
                        spAnchoredPosition.vector2Value = new Vector2(Mathf.Round(v2.x), Mathf.Round(v2.y));
                        v2 = spSizeDelta.vector2Value;
                        spSizeDelta.vector2Value = new Vector2(Mathf.Round(v2.x), Mathf.Round(v2.y));
                    }
                }
                GUILayout.EndHorizontal();
                #endregion

                #region Copy Paste
                GUILayout.BeginHorizontal();
                Color c = GUI.color;
                GUI.color = new Color(1f, 1f, 0.5f, 1f);
                if (GUILayout.Button(s_Contents.copyContent, strButtonLeft, GUILayout.Width(fButtonWidth)))
                {
                    ComponentUtility.CopyComponent(target as RectTransform);
                }

                GUI.color = new Color(1f, 0.5f, 0.5f, 1f);
                if (GUILayout.Button(s_Contents.pasteContent, strButtonMid, GUILayout.Width(fButtonWidth)))
                {
                    foreach (Object item in targets)
                    {
                        ComponentUtility.PasteComponentValues(item as RectTransform);
                    }
                }

                GUI.color = c;
                if (GUILayout.Button(s_Contents.fillParentContent, strButtonMid, GUILayout.Width(fButtonWidth)))
                {
                    Undo.RecordObjects(targets, "F");
                    foreach (Object item in targets)
                    {
                        RectTransform rtf = item as RectTransform;
                        rtf.anchorMax = Vector2.one;
                        rtf.anchorMin = Vector2.zero;
                        rtf.offsetMax = Vector2.zero;
                        rtf.offsetMin = Vector2.zero;
                    }
                }

                if (GUILayout.Button(s_Contents.normalSizeDeltaContent, strButtonRight, GUILayout.Width(fButtonWidth)))
                {
                    Undo.RecordObjects(targets, "N");
                    foreach (Object item in targets)
                    {
                        RectTransform rtf  = item as RectTransform;
                        Rect          rect = rtf.rect;
                        rtf.anchorMax = new Vector2(0.5f, 0.5f);
                        rtf.anchorMin = new Vector2(0.5f, 0.5f);
                        rtf.sizeDelta = rect.size;
                    }
                }

                GUILayout.Label(s_Contents.readmeContent);
                GUILayout.EndHorizontal();
                #endregion
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            {
                #region Pivot
                GUILayout.Label("Pivot", "ProfilerPaneSubLabel"); //┌─┐
                GUILayout.BeginHorizontal();                      //│┼│
                {
                    //└─┘
                    if (GUILayout.Button("◤", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(0, 1);
                    }

                    if (GUILayout.Button("", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(0.5f, 1);
                    }

                    if (GUILayout.Button("◥", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(1, 1);
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(0, 0.5f);
                    }

                    if (GUILayout.Button("+", styleMove))
                    {
                        spPivot.vector2Value = new Vector2(0.5f, 0.5f);
                    }

                    if (GUILayout.Button("", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(1, 0.5f);
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("◣", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(0, 0);
                    }

                    if (GUILayout.Button("", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(0.5f, 0);
                    }

                    if (GUILayout.Button("◢", stylePivotSetup))
                    {
                        spPivot.vector2Value = new Vector2(1, 0);
                    }
                }

                GUILayout.EndHorizontal();
            }
            #endregion

            GUILayout.EndVertical();
        }
        GUILayout.EndHorizontal();

        TransformInspector.DrawBottomPanel(targets);
        serializedObject.ApplyModifiedProperties();
    }
    void OnEnable()
    {
        instance = this;

        mPos = serializedObject.FindProperty("m_LocalPosition");
        mRot = serializedObject.FindProperty("m_LocalRotation");
        mScale = serializedObject.FindProperty("m_LocalScale");
    }
 void OnDestroy()
 {
     instance = null;
 }