Example #1
0
    /// <summary>
    /// 获取灯具 DMX 模式
    /// </summary>
    private static void GetDmxModes(GDTF_Data data)
    {
        if (dmxModes == null)
        {
            Debug.Log("Not Found DmxModes Node!");
            return;
        }

        if (dmxModes.HasChildNodes)
        {
            // 获取所有 DMX 模式
            foreach (XmlNode dmxModeNode in dmxModes)
            {
                // 如果当前模式下包含子节点
                if (dmxModeNode.HasChildNodes)
                {
                    XmlNode dmxChannelsNode = FindChildNode(dmxModeNode, "DMXChannels");
                    // 查找 DMXChannels 节点
                    if (dmxChannelsNode != null)
                    {
                        // 创建 DMXModesData 对象
                        GDTF_DmxModesData modeData = new GDTF_DmxModesData()
                        {
                            dmxModeName     = GetNodeAttribute(dmxModeNode, "Name"),
                            dmxModeGeometry = GetNodeAttribute(dmxModeNode, "Geometry")
                        };

                        // 为该模式添加通道信息
                        GetDmxModeChannels(dmxChannelsNode, modeData, data);
                        data.dmxModes.Add(modeData);
                    }
                }
            }
        }
    }
Example #2
0
    public static GDTF_Data GetGdtfData(string xmlPath)
    {
        GDTF_Data data = new GDTF_Data();

        if (xmlPath == null || xmlPath == string.Empty)
        {
            Debug.LogError("Fixture description.xml not found!");
            return(null);
        }

        LoadXmlFile(xmlPath, data);

        return(data);
    }
    /// <summary>
    /// 根据灯具名称开始加载配置信息
    /// </summary>
    public void LoadConfig()
    {
        // 如果 fixtureName 为空 或者 Dictionary 中没有该灯具信息 则跳出函数
        if (gdtfFileName == null || gdtfFileName == string.Empty)
        {
            return;
        }
        if (!GDTF_ResourcesLoader.GetFixtures().ContainsKey(gdtfFileName))
        {
            return;
        }

        // 获取该灯具的所有资源文件信息
        fileInfo = GDTF_ResourcesLoader.GetFileInfo(gdtfFileName);

        // 添加灯具缩略图
        fixtureThumbanil = Resources.Load <Texture2D>(fileInfo.thumbnail.filePath);
        // 添加灯具灯库信息
        descriptionData = GDTF_DescriptionReader.GetGdtfData(fileInfo.description.filePath);

        // 添加灯具基本信息
        model         = descriptionData.fixtureType.ShortName;
        gdtfDataVer   = descriptionData.fixtureType.GDTFDataVersion;
        fixtureType   = descriptionData.fixtureType.FixtureType;
        fixtureTypeID = descriptionData.fixtureType.FixtureTypeID;
        manufacturer  = descriptionData.fixtureType.Manufacturer;

        descriptionData.dmxModes.ForEach(mode => { if (mode.dmxModeName == dmxModeName)
                                                   {
                                                       dmxMode = mode;
                                                   }
                                         });

        if (goboTextures.Count > 0)
        {
            goboTextures.Clear();
        }

        for (int i = 0; i < fileInfo.wheels.Length; i++)
        {
            goboTextures.Add(fileInfo.wheels[i].fileName, Resources.Load <Texture2D>(fileInfo.wheels[i].filePath));
        }
    }
Example #4
0
    /// <summary>
    /// 获取灯具 Wheels 信息
    /// </summary>
    private static void GetWheelsData(GDTF_Data data)
    {
        if (wheelsNode == null)
        {
            Debug.Log("Not Found Wheels Node!");
            return;
        }

        // 如果节点下存在子节点
        if (wheelsNode.HasChildNodes)
        {
            foreach (XmlNode wheelNode in wheelsNode.ChildNodes)
            {
                if (wheelNode.Name != "Wheel")
                {
                    continue;
                }

                if (wheelNode.HasChildNodes)
                {
                    // 创建 GDTF_WheelsData 对象,并设置该组 Wheel 名称
                    GDTF_WheelsData wheelsData = new GDTF_WheelsData()
                    {
                        wheelName = GetNodeAttribute(wheelNode, "Name")
                    };

                    foreach (XmlNode slotNode in wheelNode.ChildNodes)
                    {
                        WheelSlot slotData = new WheelSlot();
                        slotData.name          = GetNodeAttribute(slotNode, "Name");
                        slotData.color         = XmlColorToColor(GetNodeAttribute(slotNode, "Color"));
                        slotData.mediaFileName = GetNodeAttribute(slotNode, "MediaFileName");

                        // 将该条 slot 信息添加
                        wheelsData.slots.Add(slotData);
                    }

                    data.wheels.Add(wheelsData);
                }
            }
        }
    }
Example #5
0
    /// <summary>
    /// 获取当前 DMX LogicalChannel 下的 ChannelFunction
    /// </summary>
    /// <param name="logicalChannelNode">LogicalChannel 节点</param>
    /// <param name="logicalChannel">DMXChannelData 对象</param>
    /// <param name="data">GDTF_Data 对象</param>
    private static void GetDmxChannelFuctions(XmlNode logicalChannelNode, GDTF_DmxLogicalChannel logicalChannel, GDTF_Data data)
    {
        // 如果 LogicalChannel 节点下存在子节点
        if (logicalChannelNode.HasChildNodes)
        {
            List <XmlNode> channelFunctionNodes = new List <XmlNode>();

            // 获取所有 ChannelFunction 节点
            foreach (XmlNode channelFunctionNode in logicalChannelNode)
            {
                // 只保存 ChannelFunction 节点
                if (channelFunctionNode.Name == "ChannelFunction")
                {
                    channelFunctionNodes.Add(channelFunctionNode);
                }
            }

            for (int i = 0; i < channelFunctionNodes.Count; i++)
            {
                GDTF_DmxChannelFunction channelFunction = new GDTF_DmxChannelFunction();

                int functionDmxFrom = GetDmxValue(GetNodeAttribute(channelFunctionNodes[i], "DMXFrom"));
                int functionDmxTo;

                if (i == channelFunctionNodes.Count - 1)
                {
                    functionDmxTo = (1 << ((int)GetDmxValueResolution(GetNodeAttribute(channelFunctionNodes[i], "DMXFrom")) * 8)) - 1;
                }
                else
                {
                    functionDmxTo = GetDmxValue(GetNodeAttribute(channelFunctionNodes[i + 1], "DMXFrom")) - 1;
                }

                channelFunction.functionName = GetNodeAttribute(channelFunctionNodes[i], "Name");
                string attributeName = GetNodeAttribute(channelFunctionNodes[i], "Attribute");
                if (attributeName != null)
                {
                    channelFunction.attribute = data.attributeDefinitions.attributes[attributeName];
                }
                channelFunction.functionDmxFrom      = functionDmxFrom;
                channelFunction.functionDmxTo        = functionDmxTo;
                channelFunction.functionPhysicalFrom = Convert.ToSingle(GetNodeAttribute(channelFunctionNodes[i], "PhysicalFrom"));
                channelFunction.functionPhysicalTo   = Convert.ToSingle(GetNodeAttribute(channelFunctionNodes[i], "PhysicalTo"));
                channelFunction.wheelName            = GetNodeAttribute(channelFunctionNodes[i], "Wheel");

                // 为该 ChannelFunction 添加 ChannelSet
                GetDmxChannelSets(channelFunctionNodes[i], channelFunction);

                // 为该 Channel 添加 ChannelFunction
                logicalChannel.channelFunctions.Add(channelFunction);
            }
        }
    }
Example #6
0
    /// <summary>
    /// 获取当前模式下 LogicalChannel 信息
    /// </summary>
    /// <param name="dmxChannelNode">DmxChannel 节点</param>
    /// <param name="channel">DMXChannel 对象</param>
    /// <param name="data">GDTF_Data 对象</param>
    private static void GetDmxLogicalChannel(XmlNode dmxChannelNode, GDTF_DmxChannel channel, GDTF_Data data)
    {
        // 如果 DMXChannel 节点下存在 LogicalChannel 节点
        if (dmxChannelNode.HasChildNodes)
        {
            XmlNode logicalChannelNode = dmxChannelNode.FirstChild;
            if (logicalChannelNode != null)
            {
                string attributeName = GetNodeAttribute(logicalChannelNode, "Attribute");

                GDTF_DmxLogicalChannel logicalChannel = new GDTF_DmxLogicalChannel
                {
                    attribute = data.attributeDefinitions.attributes[attributeName]
                };

                GetDmxChannelFuctions(logicalChannelNode, logicalChannel, data);
                channel.logicalChannel = logicalChannel;
            }
        }
    }
Example #7
0
    /// <summary>
    ///  获取当前模式下 DMX 通道信息
    /// </summary>
    /// <param name="dmxChannelsNode">DMX Channels 节点</param>
    /// <param name="modeData">DMX Mode 对象</param>
    /// <param name="data">GDTF Data 对象</param>
    private static void GetDmxModeChannels(XmlNode dmxChannelsNode, GDTF_DmxModesData modeData, GDTF_Data data)
    {
        // 如果 DMXChannels 节点下存在 DMXChannel
        if (dmxChannelsNode.HasChildNodes)
        {
            foreach (XmlNode dmxChannel in dmxChannelsNode)
            {
                // 如果 DMXChannel 下存在子节点
                if (dmxChannel.HasChildNodes)
                {
                    // 如果当前 DMXChannel 下存在 LogicalChannel 节点
                    XmlNode logicalChannelNode = FindChildNode(dmxChannel, "LogicalChannel");
                    if (logicalChannelNode != null)
                    {
                        // 创建 DMXChannelData 对象
                        GDTF_DmxChannel channel = new GDTF_DmxChannel()
                        {
                            dmxBreak = Convert.ToInt32(GetNodeAttribute(dmxChannel, "DMXBreak")),
                            dmxBit   = GetDmxValueResolution(GetNodeAttribute(dmxChannel, "Default")),
                            deafault = GetDmxValue(GetNodeAttribute(dmxChannel, "Default")),
                            geometry = GetNodeAttribute(dmxChannel, "Geometry"),
                            offset   = XmlSplitToIntArray(GetNodeAttribute(dmxChannel, "Offset"))
                        };

                        // 为该 DMX Mode 添加 DMXChannel
                        modeData.channelsData.Add(channel);
                        GetDmxLogicalChannel(dmxChannel, channel, data);
                    }
                }
            }
        }
    }
Example #8
0
    private static void LoadXmlFile(string filePath, GDTF_Data data)
    {
        if (File.Exists(filePath))
        {
            // 打开 XML 文件并设置根节点
            xmlDoc.Load(filePath);
            rootNode = xmlDoc.SelectSingleNode("GDTF");

            // 获取 GDTF 版本信息
            data.fixtureType.GDTFDataVersion = GetNodeAttribute(rootNode, "DataVersion");

            // 获取 FixtureType 节点
            fixtureTypeNode = rootNode.FirstChild;

            // 获取 FixtureType 节点属性
            data.fixtureType.FixtureType   = GetNodeAttribute(fixtureTypeNode, "Description");
            data.fixtureType.FixtureTypeID = GetNodeAttribute(fixtureTypeNode, "FixtureTypeID");
            data.fixtureType.LongName      = GetNodeAttribute(fixtureTypeNode, "LongName");
            data.fixtureType.Manufacturer  = GetNodeAttribute(fixtureTypeNode, "Manufacturer");
            data.fixtureType.Name          = GetNodeAttribute(fixtureTypeNode, "Name");
            data.fixtureType.RefFT         = GetNodeAttribute(fixtureTypeNode, "RefFT");
            data.fixtureType.ShortName     = GetNodeAttribute(fixtureTypeNode, "ShortName");
            data.fixtureType.Thumbnail     = GetNodeAttribute(fixtureTypeNode, "Thumbnail");

            foreach (XmlNode item in fixtureTypeNode.ChildNodes)
            {
                switch (item.Name)
                {
                case "AttributeDefinitions":
                    attributeDefinitionsNode = item;
                    GetAttributeDefinitions(data);
                    break;

                case "Wheels":
                    wheelsNode = item;
                    GetWheelsData(data);
                    break;

                case "PhysicalDescriptions":
                    physicalDescriptionsNode = item;
                    break;

                case "Models":
                    modelsNode = item;
                    break;

                case "Geometries":
                    geometriesNode = item;
                    break;

                case "DMXModes":
                    dmxModes = item;
                    GetDmxModes(data);
                    break;

                case "Revisions":
                    revisionsNode = item;
                    break;

                case "FTPresets":
                    ftPresetsNode = item;
                    break;

                case "FTMacros":
                    ftMacrosNode = item;
                    break;

                case "Protocols":
                    protocolsNode = item;
                    break;

                default:
                    break;
                }
            }
        }
        else
        {
            Debug.LogError("Xml Unfined!");
        }
    }
Example #9
0
    private static void GetAttributeDefinitions(GDTF_Data data)
    {
        // 如果 AttributeDefinitions 节点为空则推出
        if (attributeDefinitionsNode == null)
        {
            Debug.Log("Not Found AttributeDefinitions Node!");
            return;
        }

        // 如果 AttributeDefinitions 节点存在子节点
        if (attributeDefinitionsNode.HasChildNodes)
        {
            // GDTF_Data 对象中保存的信息
            Dictionary <string, GDTF_AttributeDefinitionsData_Attribute>       attributes       = new Dictionary <string, GDTF_AttributeDefinitionsData_Attribute>();
            Dictionary <string, GDTF_AttributeDefinitionsData_ActivationGroup> activationGroups = new Dictionary <string, GDTF_AttributeDefinitionsData_ActivationGroup>();
            Dictionary <string, GDTF_AttributeDefinitionsData_FeatureGroup>    featureGroups    = new Dictionary <string, GDTF_AttributeDefinitionsData_FeatureGroup>();

            // 查找 Group 节点
            foreach (XmlNode groupsNode in attributeDefinitionsNode)
            {
                // 添加激活组相关信息
                if (groupsNode.Name == "ActivationGroups" && groupsNode.HasChildNodes)
                {
                    GetActivationGroups(groupsNode, activationGroups);
                }

                // 添加功能组相关信息
                if (groupsNode.Name == "FeatureGroups" && groupsNode.HasChildNodes)
                {
                    GetFeatureGroups(groupsNode, featureGroups);
                }
            }

            // 查找 Attributes 节点
            foreach (XmlNode attributesNode in attributeDefinitionsNode)
            {
                // 如果存在 Attributes 节点,并且该节点存在子节点
                if (attributesNode.Name == "Attributes" && attributesNode.HasChildNodes)
                {
                    // 遍历 Attributes 节点下的 Attribute 节点
                    foreach (XmlNode attributeNode in attributesNode)
                    {
                        // Attribute 中所绑定的 ActivationGroup 名称、Feature 名称、Color 名称
                        string activationGroupName = GetNodeAttribute(attributeNode, "ActivationGroup");
                        string featureName         = GetNodeAttribute(attributeNode, "Feature");
                        string colorName           = GetNodeAttribute(attributeNode, "Color");

                        // 如果存在 ActivationGroup
                        if (activationGroupName != null)
                        {
                            // 生成 Attribute 对象并绑定到 ActivationGroup 中
                            GDTF_AttributeDefinitionsData_Attribute attribute = GenerateAttribute(attributes, attributeNode);
                            if (attribute != null)
                            {
                                activationGroups[activationGroupName].attributes.Add(attribute);
                            }
                        }

                        // 如果存在 Feature
                        if (featureName != null)
                        {
                            // 生成 Attribute 对象并绑定到对应的 Feature 中
                            GDTF_AttributeDefinitionsData_Attribute attribute = GenerateAttribute(attributes, attributeNode);
                            if (attribute != null)
                            {
                                string[] featurePath = featureName.Split('.');

                                featureGroups[featurePath[0]].features[featurePath[1]].attributes.Add(attribute);
                            }
                        }
                    }
                }
            }

            data.attributeDefinitions.activationGroups = activationGroups;
            data.attributeDefinitions.featureGroups    = featureGroups;
            data.attributeDefinitions.attributes       = attributes;
        }
    }