예제 #1
0
        public static void      Draw(Rect r, NGRemoteHierarchyWindow hierarchy, int instanceID)
        {
            ClientMaterial material = hierarchy.GetMaterial(instanceID);

            r.height = 1F;
            r.y     += 1F;
            EditorGUI.DrawRect(r, Color.black);
            r.y     -= 1F;
            r.height = ClientMaterial.MaterialTitleHeight;

            r.y += ClientComponent.Spacing;

            if (Event.current.type == EventType.Repaint)
            {
                r.height += r.height;
                EditorGUI.DrawRect(r, NGRemoteInspectorWindow.MaterialHeaderBackgroundColor);
                r.height = ClientMaterial.MaterialTitleHeight;
            }

            if (material != null)
            {
                string[] shaderNames;
                int[]    shaderInstanceIDs;
                float    width = r.width;
                Utility.content.text = LC.G("Change");
                float changeWidth = GUI.skin.button.CalcSize(Utility.content).x;

                hierarchy.GetResources(typeof(Shader), out shaderNames, out shaderInstanceIDs);

                Utility.content.text  = "Material";
                Utility.content.image = UtilityResources.MaterialIcon;
                material.open         = EditorGUI.Foldout(r, material.open, Utility.content, true);
                Utility.content.image = null;

                r.xMin += 85F;
                GUI.Label(r, material.name, GeneralStyles.ComponentName);
                r.xMin -= 85F;
                r.y    += r.height;

                ++EditorGUI.indentLevel;

                r.height = ClientMaterial.ShaderTitleHeight;

                if (shaderNames != null)
                {
                    if (material.selectedShader == -1)
                    {
                        for (int j = 0; j < shaderNames.Length; j++)
                        {
                            if (shaderNames[j].Equals(material.shader) == true)
                            {
                                material.originalShader = j;
                                material.selectedShader = j;
                                break;
                            }
                        }
                    }

                    r.width -= changeWidth;
                    r.xMin  += 11F;
                    using (LabelWidthRestorer.Get(75F))
                        material.selectedShader = EditorGUI.Popup(r, "Shader", material.selectedShader, shaderNames);
                    r.xMin -= 11F;

                    float w = r.width;
                    r.width = 16F;
                    r.x    += 13F;
                    GUI.DrawTexture(r, UtilityResources.ShaderIcon);
                    r.width = w;
                    r.x    += r.width - 13F;

                    r.width = changeWidth;
                    EditorGUI.BeginDisabledGroup(material.originalShader == material.selectedShader);
                    if (GUI.Button(r, LC.G("Change")) == true)
                    {
                        hierarchy.AddPacket(new ClientChangeMaterialShaderPacket(instanceID, shaderInstanceIDs[material.selectedShader]), p =>
                        {
                            if (p.CheckPacketStatus() == true)
                            {
                                material.Reset((p as ServerSendMaterialDataPacket).netMaterial);
                            }
                        });
                    }
                    EditorGUI.EndDisabledGroup();

                    r.x     = 0F;
                    r.width = width;
                }
                else
                {
                    EditorGUI.LabelField(r, "Shader", LC.G("NGInspector_NotAvailableYet"));

                    if (hierarchy.IsChannelBlocked(typeof(Shader).GetHashCode()) == true)
                    {
                        GUILayout.Label(GeneralStyles.StatusWheel, GUILayoutOptionPool.Width(20F));
                    }
                }

                r.y += r.height;

                r.height = 1F;
                r.y     += 1F;
                EditorGUI.DrawRect(r, Color.gray);
                r.y += 1F;

                if (material.properties == null)
                {
                    r.y     += ClientMaterial.ShaderPropertiesNotAvailableMargin;
                    r.height = ClientMaterial.ShaderPropertiesNotAvailableHeight;
                    r.xMin  += 5F;
                    r.xMax  -= 5F;
                    EditorGUI.HelpBox(r, "Shader properties are not available. (NG Server Scene requires to scan & save shaders!)", MessageType.Info);
                    --EditorGUI.indentLevel;
                    return;
                }

                if (material.open == false)
                {
                    --EditorGUI.indentLevel;
                    return;
                }

                r.height = Constants.SingleLineHeight;

                for (int j = 0; j < material.properties.Length; j++)
                {
                    NetMaterialProperty properties = material.properties[j];

                    if (properties.hidden == true)
                    {
                        continue;
                    }

                    if (properties.type == NGShader.ShaderPropertyType.Color)
                    {
                        EditorGUI.BeginChangeCheck();
                        Color newValue = EditorGUI.ColorField(r, properties.displayName, properties.colorValue);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            hierarchy.AddPacket(new ClientUpdateMaterialPropertyPacket(instanceID, properties.name, ClientMaterial.colorHandler.Serialize(newValue)), p =>
                            {
                                if (p.CheckPacketStatus() == true)
                                {
                                    ByteBuffer buffer = Utility.GetBBuffer((p as ServerUpdateMaterialPropertyPacket).rawValue);

                                    properties.colorValue = (Color)ClientMaterial.colorHandler.Deserialize(buffer, typeof(Color));
                                    Utility.RestoreBBuffer(buffer);
                                }
                            });
                        }
                    }
                    else if (properties.type == NGShader.ShaderPropertyType.Float)
                    {
                        EditorGUI.BeginChangeCheck();
                        float newValue = EditorGUI.FloatField(r, properties.displayName, properties.floatValue);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            hierarchy.AddPacket(new ClientUpdateMaterialPropertyPacket(instanceID, properties.name, ClientMaterial.floatHandler.Serialize(newValue)), p =>
                            {
                                if (p.CheckPacketStatus() == true)
                                {
                                    ByteBuffer buffer = Utility.GetBBuffer((p as ServerUpdateMaterialPropertyPacket).rawValue);

                                    properties.floatValue = (float)ClientMaterial.floatHandler.Deserialize(buffer, typeof(float));
                                    Utility.RestoreBBuffer(buffer);
                                }
                            });
                        }
                    }
                    else if (properties.type == NGShader.ShaderPropertyType.Range)
                    {
                        EditorGUI.BeginChangeCheck();
                        float newValue = EditorGUI.Slider(r, properties.displayName, properties.floatValue, properties.rangeMin, properties.rangeMax);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            hierarchy.AddPacket(new ClientUpdateMaterialPropertyPacket(instanceID, properties.name, ClientMaterial.floatHandler.Serialize(newValue)), p =>
                            {
                                if (p.CheckPacketStatus() == true)
                                {
                                    ByteBuffer buffer = Utility.GetBBuffer((p as ServerUpdateMaterialPropertyPacket).rawValue);

                                    properties.floatValue = (float)ClientMaterial.floatHandler.Deserialize(buffer, typeof(float));
                                    Utility.RestoreBBuffer(buffer);
                                }
                            });
                        }
                    }
                    else if (properties.type == NGShader.ShaderPropertyType.TexEnv)
                    {
                        UnityObject unityObject = properties.textureValue;
                        int         controlID   = GUIUtility.GetControlID("NGObjectFieldHash".GetHashCode(), FocusType.Keyboard, r);
                        float       x           = r.x;

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

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

                            hierarchy.AddPacket(new ClientUpdateMaterialPropertyPacket(instanceID, properties.name, TypeHandlersManager.GetTypeHandler <UnityObject>().Serialize(nullObject.type, nullObject)), p =>
                            {
                                if (p.CheckPacketStatus() == true)
                                {
                                    ByteBuffer buffer          = Utility.GetBBuffer((p as ServerUpdateMaterialPropertyPacket).rawValue);
                                    UnityObject newUnityObject = (UnityObject)TypeHandlersManager.GetTypeHandler <UnityObject>().Deserialize(buffer, typeof(UnityObject));

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

                            Event.current.Use();
                        }

                        if (Event.current.type == EventType.MouseDown &&
                            r.Contains(Event.current.mousePosition) == true)
                        {
                            hierarchy.PickupResource(typeof(Texture), instanceID + '.' + properties.name, ClientMaterial.UpdateMaterialTexture, p =>
                            {
                                if (p.CheckPacketStatus() == true)
                                {
                                    ByteBuffer buffer          = Utility.GetBBuffer((p as ServerUpdateMaterialPropertyPacket).rawValue);
                                    UnityObject newUnityObject = (UnityObject)TypeHandlersManager.GetTypeHandler <UnityObject>().Deserialize(buffer, typeof(UnityObject));

                                    properties.textureValue.Assign(newUnityObject.type, newUnityObject.gameObjectInstanceID, newUnityObject.instanceID, newUnityObject.name);
                                    Utility.RestoreBBuffer(buffer);
                                }
                            },
                                                     unityObject.instanceID);
                            Event.current.Use();
                        }

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

                        Utility.content.text = properties.displayName;

                        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 (Event.current.type == EventType.Repaint)
                        {
                            GeneralStyles.UnityObjectPicker.Draw(prefixRect, Utility.content, controlID);
                        }

                        ++EditorGUI.indentLevel;
                        r.x     = 0F;
                        r.width = width;

                        r.y += r.height + ClientComponent.Spacing;
                        EditorGUI.BeginChangeCheck();
                        Vector2 newValue = EditorGUI.Vector2Field(r, "Tiling", properties.textureScale);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            hierarchy.AddPacket(new ClientUpdateMaterialVector2Packet(instanceID, properties.name, newValue, MaterialVector2Type.Scale), p =>
                            {
                                if (p.CheckPacketStatus() == true)
                                {
                                    properties.textureScale = (p as ServerUpdateMaterialVector2Packet).value;
                                }
                            });
                        }

                        r.y += r.height + ClientComponent.Spacing;
                        EditorGUI.BeginChangeCheck();
                        newValue = EditorGUI.Vector2Field(r, "Offset", properties.textureOffset);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            hierarchy.AddPacket(new ClientUpdateMaterialVector2Packet(instanceID, properties.name, newValue, MaterialVector2Type.Offset), p =>
                            {
                                if (p.CheckPacketStatus() == true)
                                {
                                    properties.textureOffset = (p as ServerUpdateMaterialVector2Packet).value;
                                }
                            });
                        }
                        --EditorGUI.indentLevel;

                        r.x     = 0F;
                        r.width = width;
                    }
                    else if (properties.type == NGShader.ShaderPropertyType.Vector)
                    {
                        ClientMaterial.DrawVector4(r, hierarchy, instanceID, properties);
                    }

                    r.y += r.height + ClientComponent.Spacing;
                }

                --EditorGUI.indentLevel;
            }
            else
            {
                if (hierarchy.IsChannelBlocked(instanceID) == true)
                {
                    GUI.Label(r, GeneralStyles.StatusWheel);
                }

                r.xMin  += 16F;
                r.height = ClientMaterial.MaterialTitleHeight;

                Utility.content.text  = "Material";
                Utility.content.image = UtilityResources.MaterialIcon;
                EditorGUI.LabelField(r, Utility.content, new GUIContent(LC.G("NGInspector_NotAvailableYet")));
                Utility.content.image = null;
                r.y += r.height;

                r.height = ClientMaterial.ShaderTitleHeight;
                r.xMin  += 16F;
                EditorGUI.LabelField(r, "Shader", LC.G("NGInspector_NotAvailableYet"));
                r.xMin -= 16F;

                r.width = 16F;
                GUI.DrawTexture(r, UtilityResources.ShaderIcon);
            }
        }
예제 #2
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);
                }
            }
        }