Пример #1
0
        public static void      Init(NGRemoteHierarchyWindow hierarchy, Type type, string valuePath, Func <string, byte[], Packet> packetGenerator, Action <ResponsePacket> onPacketComplete, int initialInstanceID)
        {
            ResourcesPickerWindow picker = EditorWindow.GetWindow <ResourcesPickerWindow>(true, "Select " + type.Name);

            picker.hierarchy = hierarchy;
            picker.hierarchy.ResourcesUpdated += picker.RefreshResources;
            picker.type               = type;
            picker.valuePath          = valuePath;
            picker.packetGenerator    = packetGenerator;
            picker.onPacketComplete   = onPacketComplete;
            picker.searchString       = string.Empty;
            picker.selectedInstanceID = 0;
            picker.filteredResources.Clear();
            picker.filteredResourceIDs.Clear();
            picker.initialInstanceID  = initialInstanceID;
            picker.selectedInstanceID = initialInstanceID;
            picker.typeHandler        = TypeHandlersManager.GetTypeHandler(type);
            picker.SetTab(0);
            picker.tabs.Clear();

            foreach (Type t in Utility.EachNGTSubClassesOf(typeof(TabModule), (Type t) =>
            {
                TabModuleForTypeAttribute[]     attributes = t.GetCustomAttributes(typeof(TabModuleForTypeAttribute), false) as TabModuleForTypeAttribute[];

                return(attributes.Length > 0 && type.IsAssignableFrom(attributes[0].type));
            }))
            {
                picker.tabs.Add(Activator.CreateInstance(t, new object[] { picker }) as TabModule);
            }
        }
Пример #2
0
        /// <summary>
        /// <para>Create a drawer from the given <paramref name="typeHandler"/>.</para>
        /// <para>Returns the default drawer if <paramref name="typeHandler"/> is null.</para>
        /// <para>Returns the array drawer if <paramref name="typeHandler"/> is an array.</para>
        /// <para>Returns the class drawer if <paramref name="typeHandler"/> is a class not inheriting from <see cref="UnityEngine.Object"/>.</para>
        /// </summary>
        /// <param name="typeHandler"></param>
        /// <param name="type">Only use for ArrayDrawer purpose.</param>
        /// <returns>Always return an instance of TypeHandlerDrawer.</returns>
        public static TypeHandlerDrawer CreateTypeHandlerDrawer(TypeHandler typeHandler, Type type)
        {
            if (typeHandler != null)
            {
                Type          typeHandlerType;
                TypeSignature typeSignature;

                try
                {
                    typeSignature = TypeHandlersManager.GetTypeSignature(type);

                    if (TypeHandlerDrawersManager.typeHandlerDrawers == null)
                    {
                        TypeHandlerDrawersManager.typeHandlerDrawers = new Dictionary <Type, Type>();

                        foreach (Type t in Utility.EachNGTSubClassesOf(typeof(TypeHandlerDrawer)))
                        {
                            TypeHandlerDrawerForAttribute[] typeHandlerAttributes = t.GetCustomAttributes(typeof(TypeHandlerDrawerForAttribute), false) as TypeHandlerDrawerForAttribute[];

                            if (typeHandlerAttributes.Length >= 1)
                            {
                                TypeHandlerDrawersManager.typeHandlerDrawers.Add(typeHandlerAttributes[0].type, t);
                            }
                        }
                    }

                    if (TypeHandlerDrawersManager.typeHandlerDrawers.TryGetValue(typeHandler.GetType(), out typeHandlerType) == true)
                    {
                        return(Activator.CreateInstance(typeHandlerType, typeHandler) as TypeHandlerDrawer);
                    }

                    if ((typeSignature & TypeSignature.Array) != 0)
                    {
                        return(Activator.CreateInstance(typeof(ArrayDrawer), typeHandler, type) as TypeHandlerDrawer);
                    }

                    if (typeSignature == TypeSignature.Class)
                    {
                        return(Activator.CreateInstance(typeof(ClassDrawer), typeHandler) as TypeHandlerDrawer);
                    }

                    throw new Exception("TypeHandler " + typeHandler + " is not known.");
                }
                catch (Exception ex)
                {
                    InternalNGDebug.LogException("TypeHandler=" + typeHandler + Environment.NewLine + "Type=" + type, ex);
                }
            }

            if (TypeHandlerDrawersManager.defaultDrawer == null)
            {
                TypeHandlerDrawersManager.defaultDrawer = Activator.CreateInstance <UnsupportedTypeDrawer>();
            }
            return(TypeHandlerDrawersManager.defaultDrawer);
        }
Пример #3
0
        private static void     OnFieldUpdated(ResponsePacket p)
        {
            if (p.CheckPacketStatus() == true)
            {
                ByteBuffer  buffer      = Utility.GetBBuffer((p as ServerUpdateFieldValuePacket).rawValue);
                UnityObject unityObject = (UnityObject)TypeHandlersManager.GetTypeHandler <UnityObject>().Deserialize(buffer, typeof(UnityObject));

                UnityObjectDrawer.currentUnityObject.Assign(unityObject.type, unityObject.gameObjectInstanceID, unityObject.instanceID, unityObject.name);
                Utility.RestoreBBuffer(buffer);
            }
        }
Пример #4
0
        public void     Append(ByteBuffer buffer)
        {
            TypeHandler typeHandler = TypeHandlersManager.GetTypeHandler(this.type);

            if (typeHandler == null)
            {
                throw new NotImplementedException("TypeHandler for \"" + this.type + "\" was not found.");
            }
            else
            {
                typeHandler.Serialize(buffer, this.type, this.value);
            }
        }
Пример #5
0
        public ClientField(ClientComponent behaviour, int fieldIndex, NetField netField, IUnityData unityData)
        {
            this.unityData       = unityData;
            this.parentBehaviour = behaviour;

            this.fieldIndex = fieldIndex;

            this.fieldType     = netField.fieldType ?? TypeHandlersManager.GetClientType(netField.handler != null ? netField.handler.type : null, netField.typeSignature);
            this.name          = netField.name;
            this.isPublic      = netField.isPublic;
            this.typeSignature = netField.typeSignature;
            this.value         = netField.value;

            this.drawer     = TypeHandlerDrawersManager.CreateTypeHandlerDrawer(netField.handler, this.fieldType);
            this.dataDrawer = new DataDrawer(this.unityData);
        }
Пример #6
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;
        }
Пример #7
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);
                    }
                }
        }
Пример #8
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;
            }
        }
Пример #9
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);
            }
        }
Пример #10
0
 static ClientMaterial()
 {
     ClientMaterial.floatHandler   = TypeHandlersManager.GetTypeHandler <float>();
     ClientMaterial.colorHandler   = TypeHandlersManager.GetTypeHandler <Color>();
     ClientMaterial.vector4Handler = TypeHandlersManager.GetTypeHandler <Vector4>();
 }
Пример #11
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;
                    }
                }
        }
Пример #12
0
 private static Packet   CreatePacket(string valuePath, byte[] rawValue)
 {
     unityData.RecordChange(valuePath, typeof(UnityObject), UnityObjectDrawer.currentUnityObject, rawValue);
     return(new ClientUpdateFieldValuePacket(valuePath, rawValue, TypeHandlersManager.GetTypeHandler <UnityObject>()));
 }
Пример #13
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;
        }
Пример #14
0
 public ArrayDrawer(TypeHandler typeHandler, Type type) : base(typeHandler)
 {
     this.subType    = Utility.GetArraySubType(type);
     this.subHandler = TypeHandlersManager.GetTypeHandler(this.subType);
     this.subDrawers = new List <TypeHandlerDrawer>();
 }