Ejemplo n.º 1
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.anim == null)
            {
                this.anim = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            string path = data.GetPath();

            if (data.Inspector.Hierarchy.GetUpdateNotification(path) != NotificationPath.None)
            {
                this.drag.NewValue((UInt32)data.Value);
                this.anim.Start();
            }

            using (this.anim.Restorer(0F, .8F + this.anim.Value, 0F, 1F))
            {
                try
                {
                    EditorGUI.BeginChangeCheck();
                    UInt32 newValue = Convert.ToUInt32(EditorGUI.LongField(r, data.Name, Convert.ToInt64(this.drag.Get((UInt32)data.Value))));
                    if (EditorGUI.EndChangeCheck() == true &&
                        this.AsyncUpdateCommand(data.unityData, path, newValue, typeof(UInt32)) == true)
                    {
                        data.unityData.RecordChange(path, typeof(UInt32), this.drag.Get((UInt32)data.Value), newValue);
                        this.drag.Set(newValue);
                    }

                    this.drag.Draw(r);
                }
                catch (OverflowException)
                {
                }
            }
        }
Ejemplo n.º 2
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.anim == null)
            {
                this.anim = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            string path = data.GetPath();

            if (data.Inspector.Hierarchy.GetUpdateNotification(path) != NotificationPath.None)
            {
                this.drag.NewValue((Single)data.Value);
                this.anim.Start();
            }

            using (this.anim.Restorer(0F, .8F + this.anim.Value, 0F, 1F))
            {
                EditorGUI.BeginChangeCheck();
                Single newValue = EditorGUI.FloatField(r, data.Name, this.drag.Get((Single)data.Value));
                if (EditorGUI.EndChangeCheck() == true &&
                    this.AsyncUpdateCommand(data.unityData, path, newValue, typeof(Single)) == true)
                {
                    data.unityData.RecordChange(path, typeof(Single), this.drag.Get((Single)data.Value), newValue);
                    this.drag.Set(newValue);
                }

                this.drag.Draw(r);
            }
        }
Ejemplo n.º 3
0
        public void     Init(Client client, int parentInstanceID, int instanceID, ClientMethod method)
        {
            this.client           = client;
            this.parentInstanceID = parentInstanceID;
            this.instanceID       = instanceID;
            this.method           = method;

            this.drawers = new ArgumentDrawer[this.method.argumentNames.Length];

            if (MethodArgumentsWindow.types == null)
            {
                MethodArgumentsWindow.types = new DynamicOrderedArray <Type>(Utility.GetAllSubClassesOf(typeof(ArgumentDrawer)));
            }

            for (int i = 0; i < this.method.argumentTypes.Length; i++)
            {
                for (int j = 0; j < MethodArgumentsWindow.types.array.Length; j++)
                {
                    ArgumentDrawerFor[] attribute = MethodArgumentsWindow.types.array[j].GetCustomAttributes(typeof(ArgumentDrawerFor), false) as ArgumentDrawerFor[];

                    if (attribute.Length > 0)
                    {
                        if (attribute[0].type.IsAssignableFrom(this.method.argumentTypes[i]) == true)
                        {
                            this.drawers[i] = Activator.CreateInstance(MethodArgumentsWindow.types.array[j], this.method.argumentNames[i], this.method.argumentTypes[i]) as ArgumentDrawer;
                            this.drawers[i].Load(this.method.name + "." + this.method.argumentNames[i]);
                            MethodArgumentsWindow.types.BringToTop(j);
                            break;
                        }
                    }
                }
            }

            this.invokeFeedbackAnim = new BgColorContentAnimator(this.Repaint, 1F, 0F);
        }
Ejemplo n.º 4
0
        protected override void OnEnable()
        {
            base.OnEnable();

            this.animActive   = new BgColorContentAnimator(this.Repaint, 1F, 0F);
            this.animName     = new BgColorContentAnimator(this.Repaint, 1F, 0F);
            this.animIsStatic = new BgColorContentAnimator(this.Repaint, 1F, 0F);
            this.animTag      = new BgColorContentAnimator(this.Repaint, 1F, 0F);
            this.animLayer    = new BgColorContentAnimator(this.Repaint, 1F, 0F);

            this.booleanHandler = TypeHandlersManager.GetTypeHandler <bool>();
            this.stringHandler  = TypeHandlersManager.GetTypeHandler <string>();
            this.intHandler     = TypeHandlersManager.GetTypeHandler <int>();

            this.minSize = new Vector2(275F, this.minSize.y);

            this.bodyRect = new Rect();
            this.viewRect = new Rect();
            this.r        = new Rect();

            this.selectedWindow = 0;

            this.lastMaterialsHash = -1;
        }
Ejemplo n.º 5
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.animX == null)
            {
                this.animX = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
                this.animY = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
                this.animZ = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            Vector3 vector = (Vector3)data.Value;
            float   labelWidth;
            float   controlWidth;

            Utility.CalculSubFieldsWidth(r.width, 60F, 3, out labelWidth, out controlWidth);

            r.width = labelWidth;
            EditorGUI.LabelField(r, data.Name);
            r.x += r.width;

            using (IndentLevelRestorer.Get(0))
                using (LabelWidthRestorer.Get(12F))
                {
                    r.width = controlWidth;

                    string path = data.GetPath();
                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + 'x') != NotificationPath.None)
                    {
                        this.dragX.NewValue(vector.x);
                        this.animX.Start();
                    }

                    using (this.animX.Restorer(0F, .8F + this.animX.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single v = EditorGUI.FloatField(r, "X", this.dragX.Get(vector.x));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + 'x', v, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + 'x', typeof(Single), this.dragX.Get(vector.x), v);
                            this.dragX.Set(v);
                        }

                        this.dragX.Draw(r);

                        r.x += r.width;
                    }

                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + 'y') != NotificationPath.None)
                    {
                        this.dragY.NewValue(vector.y);
                        this.animY.Start();
                    }

                    using (this.animY.Restorer(0F, .8F + this.animY.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single v = EditorGUI.FloatField(r, "Y", this.dragY.Get(vector.y));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + 'y', v, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + 'y', typeof(Single), this.dragY.Get(vector.y), v);
                            this.dragY.Set(v);
                        }

                        this.dragY.Draw(r);

                        r.x += r.width;
                    }

                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + 'z') != NotificationPath.None)
                    {
                        this.dragZ.NewValue(vector.z);
                        this.animZ.Start();
                    }

                    using (this.animZ.Restorer(0F, .8F + this.animZ.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single v = EditorGUI.FloatField(r, "Z", this.dragZ.Get(vector.z));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + 'z', v, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + 'z', typeof(Single), this.dragZ.Get(vector.z), v);
                            this.dragZ.Set(v);
                        }

                        this.dragZ.Draw(r);
                    }
                }
        }
Ejemplo n.º 6
0
        public ClientComponent(ClientGameObject parent, NetComponent component, IUnityData unityData)
        {
            this.parent     = parent;
            this.type       = component.type;
            this.unityData  = unityData;
            this.instanceID = component.instanceID;
            this.togglable  = component.togglable;
            this.deletable  = component.deletable;
            this.name       = component.name;

            ClientComponent.reuseFields.Clear();

            this.enabledFieldIndex = -1;

            for (int i = 0; i < component.fields.Length; i++)
            {
                if (component.fields[i].name.Equals("enabled") == true)
                {
                    this.enabledFieldIndex = i;
                }

                ClientComponent.reuseFields.Add(new ClientField(this, i, component.fields[i], this.unityData));
            }

            this.fields = ClientComponent.reuseFields.ToArray();

            this.methods     = new ClientMethod[component.methods.Length];
            this.methodNames = new string[this.methods.Length];

            for (int i = 0; i < this.methods.Length; i++)
            {
                try
                {
                    this.methods[i] = new ClientMethod(this, component.methods[i]);

                    StringBuilder buffer = Utility.GetBuffer();

                    if (component.methods[i].returnType != null)
                    {
                        buffer.Append(component.methods[i].returnType.Name);
                    }
                    else
                    {
                        buffer.Append(component.methods[i].returnTypeRaw);
                    }
                    buffer.Append('	');
                    buffer.Append(component.methods[i].name);
                    buffer.Append('(');

                    string comma = string.Empty;

                    for (int j = 0; j < component.methods[i].argumentTypes.Length; j++)
                    {
                        buffer.Append(comma);
                        buffer.Append(component.methods[i].argumentTypes[j].Name);

                        comma = ", ";
                    }

                    buffer.Append(')');

                    this.methodNames[i] = Utility.ReturnBuffer(buffer);
                }
                catch (Exception ex)
                {
                    InternalNGDebug.LogException("Method " + i + " " + component.methods[i] + " in Component " + this.name + " (" + this.type + ") failed.", ex);
                }
            }

            this.booleanHandler = TypeHandlersManager.GetTypeHandler <bool>();
            this.animEnable     = new BgColorContentAnimator(null, 1F, 0F);

            if (this.type != null)
            {
                this.icon = AssetPreview.GetMiniTypeThumbnail(this.type);
            }
            if (this.icon == null)
            {
                this.icon = UtilityResources.CSharpIcon;
            }
        }
Ejemplo n.º 7
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.anim == null)
            {
                this.anim = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            string path = data.GetPath();

            if (data.Inspector.Hierarchy.GetUpdateNotification(path) != NotificationPath.None)
            {
                this.anim.Start();
            }

            EnumInstance enumInstance = data.Value as EnumInstance;

            using (this.anim.Restorer(0F, .8F + this.anim.Value, 0F, 1F))
            {
                EnumData enumData = data.Inspector.Hierarchy.GetEnumData(enumInstance.type);

                if (enumData != null)
                {
                    if (enumInstance.GetFlag() == EnumInstance.IsFlag.Unset)
                    {
                        if (enumData.hasFlagAttribute == true)
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Flag);
                        }
                        else
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Value);
                        }
                    }

                    float width = r.width;

                    r.width = 16F;
                    r.x    += (EditorGUI.indentLevel - 1) * 15F;
                    if (GUI.Button(r, "F", enumInstance.GetFlag() == EnumInstance.IsFlag.Flag ? GUI.skin.button : GUI.skin.textField) == true)
                    {
                        if (enumInstance.GetFlag() == EnumInstance.IsFlag.Value)
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Flag);
                        }
                        else
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Value);
                        }
                    }
                    r.x -= (EditorGUI.indentLevel - 1) * 15F;

                    r.width = width;

                    EditorGUI.BeginChangeCheck();

                    int newValue;

                    if (enumInstance.GetFlag() == EnumInstance.IsFlag.Value)
                    {
                        newValue = EditorGUI.IntPopup(r, data.Name, enumInstance.value, enumData.names, enumData.values);
                    }
                    else
                    {
                        newValue = EditorGUI.MaskField(r, data.Name, enumInstance.value, enumData.names);
                    }

                    if (EditorGUI.EndChangeCheck() == true &&
                        this.AsyncUpdateCommand(data.unityData, path, newValue, typeof(Enum)) == true)
                    {
                        data.unityData.RecordChange(path, typeof(Enum), data.Value, newValue);
                    }
                }
                else
                {
                    EditorGUI.LabelField(r, data.Name, LC.G("NGInspector_NotAvailableYet"));

                    if (data.Inspector.Hierarchy.IsChannelBlocked(enumInstance.type.GetHashCode()) == true)
                    {
                        GUI.Label(r, GeneralStyles.StatusWheel);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.anim == null)
            {
                this.anim = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            ClientClass genericClass = data.Value as ClientClass;

            r.height = Constants.SingleLineHeight;

            if (genericClass.fields == null)
            {
                EditorGUI.LabelField(r, data.Name, "Null");
                return;
            }

            string path = data.GetPath();

            if (data.Inspector.Hierarchy.GetUpdateNotification(path) != NotificationPath.None)
            {
                this.anim.Start();
            }

            using (this.anim.Restorer(0F, .8F + this.anim.Value, 0F, 1F))
            {
                --EditorGUI.indentLevel;
                r.x      += 3F;
                this.fold = EditorGUI.Foldout(r, this.fold, data.Name, true);
                r.x      -= 3F;
                ++EditorGUI.indentLevel;
            }

            if (this.fold == false)
            {
                return;
            }

            r.y += r.height;

            if (this.fieldDrawers == null)
            {
                this.InitDrawers(genericClass);
            }

            using (data.CreateLayerChildScope())
            {
                ++EditorGUI.indentLevel;
                for (int i = 0; i < this.fieldDrawers.Length; i++)
                {
                    r.height = this.fieldDrawers[i].GetHeight(genericClass.fields[i].value);

                    if (r.y + r.height <= data.Inspector.ScrollPosition.y)
                    {
                        r.y += r.height;
                        continue;
                    }

                    this.fieldDrawers[i].Draw(r, data.DrawChild(genericClass.fields[i].name, genericClass.fields[i].value));

                    r.y += r.height;
                    if (r.y - data.Inspector.ScrollPosition.y > data.Inspector.BodyRect.height)
                    {
                        break;
                    }
                }
                --EditorGUI.indentLevel;
            }
        }
Ejemplo n.º 9
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.animCenterX == null)
            {
                this.animCenterX  = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
                this.animCenterY  = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
                this.animCenterZ  = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
                this.animExtentsX = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
                this.animExtentsY = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
                this.animExtentsZ = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            Bounds vector = (Bounds)data.Value;
            float  labelWidth;
            float  controlWidth;

            Utility.CalculSubFieldsWidth(r.width, 44F, 4, out labelWidth, out controlWidth);

            r.width = labelWidth;
            EditorGUI.LabelField(r, data.Name);
            r.x += r.width;

            using (IndentLevelRestorer.Get(0))
                using (LabelWidthRestorer.Get(14F))
                {
                    float x = r.x;
                    r.width  = controlWidth;
                    r.height = Constants.SingleLineHeight;

                    GUI.Label(r, "Center:");
                    r.x += r.width;

                    string path = data.GetPath();
                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'x') != NotificationPath.None)
                    {
                        this.dragCenterX.NewValue(vector.center.x);
                        this.animCenterX.Start();
                    }

                    using (this.animCenterX.Restorer(0F, .8F + this.animCenterX.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single newValue = EditorGUI.FloatField(r, "x", this.dragCenterX.Get(vector.center.x));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'x', newValue, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'x', typeof(Single), this.dragCenterX.Get(vector.center.x), newValue);
                            this.dragCenterX.Set(newValue);
                        }

                        this.dragCenterX.Draw(r);

                        r.x += r.width;
                    }

                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'y') != NotificationPath.None)
                    {
                        this.dragCenterY.NewValue(vector.center.y);
                        this.animCenterY.Start();
                    }

                    using (this.animCenterY.Restorer(0F, .8F + this.animCenterY.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single newValue = EditorGUI.FloatField(r, "Y", this.dragCenterY.Get(vector.center.y));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'y', newValue, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'y', typeof(Single), this.dragCenterY.Get(vector.center.y), newValue);
                            this.dragCenterY.Set(newValue);
                        }

                        this.dragCenterY.Draw(r);

                        r.x += r.width;
                    }

                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'z') != NotificationPath.None)
                    {
                        this.dragCenterZ.NewValue(vector.center.z);
                        this.animCenterZ.Start();
                    }

                    using (this.animCenterZ.Restorer(0F, .8F + this.animCenterZ.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single newValue = EditorGUI.FloatField(r, "Z", this.dragCenterZ.Get(vector.center.z));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'z', newValue, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + "center" + NGServerScene.ValuePathSeparator + 'z', typeof(Single), this.dragCenterZ.Get(vector.center.z), newValue);
                            this.dragCenterZ.Set(newValue);
                        }

                        this.dragCenterZ.Draw(r);

                        r.x += r.width;
                    }

                    r.y += r.height + 2F;
                    r.x  = x;

                    GUI.Label(r, "Extents:");
                    r.x += r.width;

                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'x') != NotificationPath.None)
                    {
                        this.dragExtentsX.NewValue(vector.extents.x);
                        this.animExtentsX.Start();
                    }

                    using (this.animExtentsX.Restorer(0F, .8F + this.animExtentsX.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single newValue = EditorGUI.FloatField(r, "X", this.dragExtentsX.Get(vector.extents.x));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'x', newValue, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'x', typeof(Single), this.dragExtentsX.Get(vector.extents.x), newValue);
                            this.dragExtentsX.Set(newValue);
                        }

                        this.dragExtentsX.Draw(r);

                        r.x += r.width;
                    }

                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'y') != NotificationPath.None)
                    {
                        this.dragExtentsY.NewValue(vector.extents.y);
                        this.animExtentsY.Start();
                    }

                    using (this.animExtentsY.Restorer(0F, .8F + this.animExtentsY.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single newValue = EditorGUI.FloatField(r, "Y", this.dragExtentsY.Get(vector.extents.y));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'y', newValue, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'y', typeof(Single), this.dragExtentsY.Get(vector.extents.y), newValue);
                            this.dragExtentsY.Set(newValue);
                        }

                        this.dragExtentsY.Draw(r);

                        r.x += r.width;
                    }

                    if (data.Inspector.Hierarchy.GetUpdateNotification(path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'z') != NotificationPath.None)
                    {
                        this.dragExtentsZ.NewValue(vector.extents.z);
                        this.animExtentsZ.Start();
                    }

                    using (this.animExtentsZ.Restorer(0F, .8F + this.animExtentsZ.Value, 0F, 1F))
                    {
                        EditorGUI.BeginChangeCheck();
                        Single newValue = EditorGUI.FloatField(r, "Z", this.dragExtentsZ.Get(vector.extents.z));
                        if (EditorGUI.EndChangeCheck() == true &&
                            this.AsyncUpdateCommand(data.unityData, path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'z', newValue, typeof(Single), TypeHandlersManager.GetTypeHandler(typeof(Single))))
                        {
                            data.unityData.RecordChange(path + NGServerScene.ValuePathSeparator + "extents" + NGServerScene.ValuePathSeparator + 'z', typeof(Single), this.dragExtentsZ.Get(vector.extents.z), newValue);
                            this.dragExtentsZ.Set(newValue);
                        }

                        this.dragExtentsZ.Draw(r);

                        r.x += r.width;
                    }
                }
        }
Ejemplo n.º 10
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            string      path        = data.GetPath();
            UnityObject unityObject = data.Value as UnityObject;
            int         controlID   = GUIUtility.GetControlID("NGObjectFieldHash".GetHashCode(), FocusType.Keyboard, r);

            if (Event.current.type == EventType.KeyDown &&
                Event.current.keyCode == KeyCode.Delete &&
                GUIUtility.keyboardControl == controlID)
            {
                UnityObject nullObject = new UnityObject(unityObject.type, 0);

                data.unityData.RecordChange(path, unityObject.type, unityObject, nullObject);
                data.unityData.AddPacket(new ClientUpdateFieldValuePacket(path, this.typeHandler.Serialize(nullObject.type, nullObject), this.typeHandler), p =>
                {
                    if (p.CheckPacketStatus() == true)
                    {
                        ByteBuffer buffer    = Utility.GetBBuffer((p as ServerUpdateFieldValuePacket).rawValue);
                        UnityObject newValue = this.typeHandler.Deserialize(Utility.GetBBuffer((p as ServerUpdateFieldValuePacket).rawValue), unityObject.type) as UnityObject;

                        unityObject.Assign(newValue.type, newValue.gameObjectInstanceID, newValue.instanceID, newValue.name);
                        Utility.RestoreBBuffer(buffer);
                    }
                });

                Event.current.Use();
            }

            if (r.Contains(Event.current.mousePosition) == true)
            {
                if (Event.current.type == EventType.MouseDown)
                {
                    if (Event.current.button == 1 && unityObject.instanceID != 0)
                    {
                        UnityObjectDrawer.unityData          = data.unityData;
                        UnityObjectDrawer.currentUnityObject = unityObject;

                        GenericMenu menu = new GenericMenu();

                        menu.AddItem(new GUIContent("Import asset"), false, this.ImportAsset);

                        menu.ShowAsContext();
                    }
                    else
                    {
                        UnityObjectDrawer.dragOriginPosition = Event.current.mousePosition;

                        // Initialize drag data.
                        DragAndDrop.PrepareStartDrag();

                        DragAndDrop.objectReferences = new Object[0];
                        DragAndDrop.SetGenericData("r", unityObject);
                    }
                }
                else if (Event.current.type == EventType.MouseDrag && (UnityObjectDrawer.dragOriginPosition - Event.current.mousePosition).sqrMagnitude >= Constants.MinStartDragDistance)
                {
                    DragAndDrop.StartDrag("Dragging Game Object");
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.DragUpdated)
                {
                    UnityObject dragItem = DragAndDrop.GetGenericData("r") as UnityObject;

                    if (dragItem != null && dragItem.instanceID != unityObject.instanceID &&
                        (dragItem.type == null || unityObject.type == null || unityObject.type.IsAssignableFrom(dragItem.type) == true))
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }

                    Event.current.Use();
                }
                else if (Event.current.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    UnityObject dragItem = DragAndDrop.GetGenericData("r") as UnityObject;

                    data.unityData.RecordChange(path, unityObject.type, unityObject, dragItem);
                    data.unityData.AddPacket(new ClientUpdateFieldValuePacket(path, this.typeHandler.Serialize(dragItem.type, dragItem), this.typeHandler), p =>
                    {
                        if (p.CheckPacketStatus() == true)
                        {
                            ByteBuffer buffer    = Utility.GetBBuffer((p as ServerUpdateFieldValuePacket).rawValue);
                            UnityObject newValue = this.typeHandler.Deserialize(Utility.GetBBuffer((p as ServerUpdateFieldValuePacket).rawValue), unityObject.type) as UnityObject;

                            unityObject.Assign(newValue.type, newValue.gameObjectInstanceID, newValue.instanceID, newValue.name);
                            Utility.RestoreBBuffer(buffer);
                        }
                    });
                }
                else if (Event.current.type == EventType.Repaint &&
                         DragAndDrop.visualMode == DragAndDropVisualMode.Move)
                {
                    Rect r2 = r;

                    r2.width += r2.x;
                    r2.x      = 0F;

                    EditorGUI.DrawRect(r2, Color.yellow);
                }
            }

            float x     = r.x;
            float width = r.width;

            r.width = UnityObjectDrawer.PickerButtonWidth;
            r.x     = width - UnityObjectDrawer.PickerButtonWidth;

            if (Event.current.type == EventType.MouseDown &&
                r.Contains(Event.current.mousePosition) == true)
            {
                UnityObjectDrawer.unityData          = data.unityData;
                UnityObjectDrawer.currentUnityObject = unityObject;
                data.Inspector.Hierarchy.PickupResource(unityObject.type, path, UnityObjectDrawer.CreatePacket, UnityObjectDrawer.OnFieldUpdated, unityObject.instanceID);
                Event.current.Use();
            }

            r.width = width;
            r.x     = x;

            if (this.anim == null)
            {
                this.anim = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            if (data.Inspector.Hierarchy.GetUpdateNotification(path) != NotificationPath.None)
            {
                this.anim.Start();
            }

            using (this.anim.Restorer(0F, .8F + this.anim.Value, 0F, 1F))
            {
                Utility.content.text = data.Name;

                Rect prefixRect = EditorGUI.PrefixLabel(r, Utility.content);

                if (unityObject.instanceID != 0)
                {
                    Utility.content.text = unityObject.name + " (" + unityObject.type.Name + ")";
                }
                else
                {
                    Utility.content.text = "None (" + unityObject.type.Name + ")";
                }

                if (GUI.Button(prefixRect, GUIContent.none, GUI.skin.label) == true)
                {
                    GUIUtility.keyboardControl = controlID;

                    if (unityObject.instanceID != 0 &&
                        typeof(Object).IsAssignableFrom(unityObject.type) == true)
                    {
                        if (this.lastClick + Constants.DoubleClickTime < Time.realtimeSinceStartup)
                        {
                            data.Inspector.Hierarchy.PingObject(unityObject.gameObjectInstanceID);
                        }
                        else
                        {
                            data.Inspector.Hierarchy.SelectGameObject(unityObject.gameObjectInstanceID);
                        }

                        this.lastClick = Time.realtimeSinceStartup;
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    GeneralStyles.UnityObjectPicker.Draw(prefixRect, Utility.content, controlID);
                }
            }
        }
Ejemplo n.º 11
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.anim == null)
            {
                this.anim = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            string    path  = data.GetPath();
            ArrayData array = data.Value as ArrayData;

            if (array.array == null)
            {
                --EditorGUI.indentLevel;
                r.height  = Constants.SingleLineHeight;
                r.x      += 3F;
                this.fold = EditorGUI.Foldout(r, this.fold, data.Name + (array.isNull == true ? " (Null)" : " (Unloaded)"), true);
                r.x      -= 3F;
                ++EditorGUI.indentLevel;

                if (this.fold == false)
                {
                    return;
                }

                r.y += r.height;
                if (array.isNull == true)
                {
                    ++EditorGUI.indentLevel;
                    EditorGUI.BeginChangeCheck();
                    int forceSize = EditorGUI.DelayedIntField(r, "Size", 0);
                    if (EditorGUI.EndChangeCheck() == true &&
                        this.AsyncUpdateCommand(data.unityData, path, forceSize, typeof(int), TypeHandlersManager.GetTypeHandler(typeof(int))))
                    {
                        data.unityData.RecordChange(path, typeof(int), 0, forceSize);
                    }
                    --EditorGUI.indentLevel;
                }
                else
                {
                    GUI.Label(r, "Array was not loaded because it has more than " + ArrayData.BigArrayThreshold + " elements.");
                    r.y += r.height;

                    if (GUI.Button(r, "Load") == true)
                    {
                        data.Inspector.Hierarchy.LoadBigArray(path);
                    }
                }

                return;
            }

            r.height = Constants.SingleLineHeight;

            if (data.Inspector.Hierarchy.GetUpdateNotification(path) != NotificationPath.None)
            {
                this.anim.Start();
            }

            using (this.anim.Restorer(0F, .8F + this.anim.Value, 0F, 1F))
            {
                --EditorGUI.indentLevel;
                r.x      += 3F;
                this.fold = EditorGUI.Foldout(r, this.fold, data.Name + " [" + array.array.Length.ToCachedString() + "]", true);
                r.x      -= 3F;
                ++EditorGUI.indentLevel;
            }

            if (this.fold == false)
            {
                return;
            }

            r.y += r.height;

            ++EditorGUI.indentLevel;
            EditorGUI.BeginChangeCheck();
            int newSize = EditorGUI.DelayedIntField(r, "Size", array.array.Length);

            if (EditorGUI.EndChangeCheck() == true &&
                this.AsyncUpdateCommand(data.unityData, path, newSize, typeof(int), TypeHandlersManager.GetTypeHandler(typeof(int))))
            {
                data.unityData.RecordChange(path, typeof(int), array.array.Length, newSize);
            }

            r.y += r.height;

            using (data.CreateLayerChildScope())
            {
                int i = 0;

                foreach (object item in array.array)
                {
                    // Add new drawer for new element.
                    if (this.subDrawers.Count <= i)
                    {
                        this.subDrawers.Add(TypeHandlerDrawersManager.CreateTypeHandlerDrawer(this.subHandler, this.subType));
                    }

                    float height = this.subDrawers[i].GetHeight(item);

                    if (r.y + height <= data.Inspector.ScrollPosition.y)
                    {
                        r.y += height;
                        ++i;
                        continue;
                    }

                    if (item != null)
                    {
                        this.subDrawers[i].Draw(r, data.DrawChild(i.ToCachedString(), "Element " + i, item));
                    }
                    else
                    {
                        EditorGUI.LabelField(r, i.ToCachedString(), "Null");
                    }

                    r.y += height;
                    if (r.y - data.Inspector.ScrollPosition.y > data.Inspector.BodyRect.height)
                    {
                        // Override i to prevent removing unwanted subDrawers.
                        i = int.MaxValue;
                        break;
                    }

                    ++i;
                }

                // Drawer are linked to their item, therefore they must be removed as their item is removed.
                if (i < this.subDrawers.Count)
                {
                    this.subDrawers.RemoveRange(i, this.subDrawers.Count - i);
                }
            }

            --EditorGUI.indentLevel;
        }