Example #1
0
        private void btnResetPropertyType_Click(object sender, EventArgs e)
        {
            //-- 找到选中的type
            string selectedTypeName = this.comboBoxType.SelectedItem as string;
            Type   newDistType      = null;

            foreach (Type t in m_distributionClasses)
            {
                if (t.Name == selectedTypeName)
                {
                    newDistType = t;
                    break;
                }
            }
            if (newDistType == null)
            {
                return;
            }

            //-- 创建新对象
            NDistribution newDistObj = Activator.CreateInstance(newDistType) as NDistribution;

            if (newDistObj == null)
            {
                return;
            }

            //-- 把新的Distribution对象设置给特效元素
            NEffectElement sfxElem      = this.groupBoxObject.Tag as NEffectElement;
            string         propertyName = this.groupBoxObject.Text;
            Type           elemType     = sfxElem.GetType();
            PropertyInfo   propertyObj  = elemType.GetProperty(propertyName);

            propertyObj.SetValue(sfxElem, newDistObj, null);

            //-- 更新自己的显示
            this.propertyGridDist.SelectedObject = newDistObj;

            string name      = this.propertyGridDist.Text;
            Type   valueType = newDistObj.GetType();

            //-- 更新编辑网格
            if (valueType == typeof(NexusEngine.NDistributionFloatCurve))
            {
                FloatCurve item = new FloatCurve();
                item.Name = name;
                item.Bind((NexusEngine.NDistributionFloatCurve)newDistObj);
                m_Timeline.AddItem(item);
            }
            else if (valueType == typeof(NexusEngine.NDistributionVector2Curve))
            {
                VectorCurve2 item = new VectorCurve2();
                item.Name = name;
                item.Bind((NexusEngine.NDistributionVector2Curve)newDistObj);
                m_Timeline.AddItem(item);
            }
            else if (valueType == typeof(NexusEngine.NDistributionVector3Curve))
            {
                VectorCurve3 item = new VectorCurve3();
                item.Name = name;
                item.Bind((NexusEngine.NDistributionVector3Curve)newDistObj);
                m_Timeline.AddItem(item);
            }
            else if (valueType == typeof(NexusEngine.NDistributionColorCurve))
            {
                ColorCurve item = new ColorCurve();
                item.Name = name;
                item.Bind((NexusEngine.NDistributionColorCurve)newDistObj);
                m_Timeline.AddItem(item);
            }
            else
            {
                m_Timeline.Clear();
            }
        }
Example #2
0
        void OnElementPropertySelected(object sender, EventArgs e)
        {
            SFXElement senderSFX = sender as SFXElement;
            SelectedGridItemChangedEventArgs se = e as SelectedGridItemChangedEventArgs;
            object value = se.NewSelection.Value;

            if (value == null)
            {
                return;
            }
            string name = se.NewSelection.Label;

            this.propertyGridDist.SelectedObject = value;
            this.propertyGridDist.Text           = name;

            Type valueType = value.GetType();
            Type baseType  = valueType.BaseType;
            bool isDist    = valueType.IsSubclassOf(typeof(NexusEngine.NDistribution));

            if (isDist)
            {
                this.groupBoxObject.Text = se.NewSelection.Label;
                this.groupBoxObject.Tag  = senderSFX.EditElement;
                this.comboBoxType.Items.Clear();
                int sel = 0;
                foreach (Type t in m_distributionClasses)
                {
                    if (t.IsSubclassOf(baseType))
                    {
                        this.comboBoxType.Items.Add(t.Name);
                        if (t.Name == valueType.Name)
                        {
                            sel = this.comboBoxType.Items.Count - 1;
                        }
                    }
                }
                this.comboBoxType.SelectedIndex = sel;
                if (valueType == typeof(NexusEngine.NDistributionFloatCurve))
                {
                    FloatCurve item = new FloatCurve();
                    item.Name = name;
                    item.Bind((NexusEngine.NDistributionFloatCurve)value);
                    m_Timeline.AddItem(item);
                }
                else if (valueType == typeof(NexusEngine.NDistributionVector2Curve))
                {
                    VectorCurve2 item = new VectorCurve2();
                    item.Name = name;
                    item.Bind((NexusEngine.NDistributionVector2Curve)value);
                    m_Timeline.AddItem(item);
                }
                else if (valueType == typeof(NexusEngine.NDistributionVector3Curve))
                {
                    VectorCurve3 item = new VectorCurve3();
                    item.Name = name;
                    item.Bind((NexusEngine.NDistributionVector3Curve)value);
                    m_Timeline.AddItem(item);
                }
                else if (valueType == typeof(NexusEngine.NDistributionColorCurve))
                {
                    ColorCurve item = new ColorCurve();
                    item.Name = name;
                    item.Bind((NexusEngine.NDistributionColorCurve)value);
                    m_Timeline.AddItem(item);
                }
                else
                {
                    m_Timeline.Clear();
                }
            }
            else
            {
                m_Timeline.Clear();
            }

            this.splitContainerH.Panel2.Enabled = isDist;
        }