void scriptitem_Click(object sender, RoutedEventArgs e)
        {
            var menuitem = e.Source as MenuItem;
            EngineManagerViewModel view = (this.DataContext as EngineManagerViewModel);

            e.Handled = true;
            if (view.SelectedGameObjects.Count == 0)
            {
                return;
            }
            string scriptname = menuitem.DataContext as String;

            EditorSubsystemManaged.getInstance().QueueAction(() =>
            {
                foreach (GameObject g in view.SelectedGameObjects)
                {
                    CScript cs     = CastingHelper.CastTo <CScript>(g.RequireComponentByName("CScript"));
                    cs.scriptAsset = AssetManager.getInstance().GetAsset(scriptname);
                }
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    ComponentListViewControl.GetBindingExpression(ListView.ItemsSourceProperty).UpdateTarget();
                }));
            });
        }
Esempio n. 2
0
        private void HackButton_Click(object sender, RoutedEventArgs e)
        {
            int    texindex = TextureIndex.Value.Value;
            string texname  = TextureRoughSettor.Text;

            EditorSubsystemManaged.getInstance().QueueAction(new Action(() => {
                foreach (GameObject g in EngineManagerViewModel.instance.SelectedGameObjects)
                {
                    CMeshRenderer cm = CastingHelper.CastTo <CMeshRenderer>(g.GetComponentByName("CMeshRenderer"));
                    if (cm != null)
                    {
                        Material mat = cm.GetMaterial() as Material;
                        MaterialAttribNodeMap map = mat.mMaterialData.mAttributeMetaLookup;
                        ObservableCollection <MaterialNodeModel> out_nodes = new ObservableCollection <MaterialNodeModel>();
                        MaterialAttribNodeVector nodes = map.Values.ElementAt(1);
                        {
                            MatAttribNode node = nodes[texindex];

                            object castedObj = null;
                            castedObj        = CastingHelper.CastTo <TextureNode>(node);
                            if (castedObj != null)
                            {
                                (castedObj as TextureNode).SetTexture(AssetManager.getInstance().GetAsset(texname));
                            }
                            else
                            {
                                MessageBox.Show("You f****d up the node, this ain't no texture node dummy");
                            }
                        }
                    }
                }
            }));
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is Material))
            {
                return(null);
            }
            if (value == null)
            {
                return(null);
            }
            Material mat = value as Material;
            MaterialAttribNodeMap map = mat.mMaterialData.mAttributeMetaLookup;
            ObservableCollection <MaterialNodeModel> out_nodes = new ObservableCollection <MaterialNodeModel>();
            int texture_node_slot = 0;

            foreach (MaterialAttribNodeVector nodes in map.Values)
            {
                foreach (MatAttribNode node in nodes)
                {
                    MaterialNodeModel model     = new MaterialNodeModel();
                    object            castedObj = null;
                    castedObj = CastingHelper.CastTo <TextureNode>(node);
                    if (castedObj == null)
                    {
                        castedObj = CastingHelper.CastTo <ColorNode>(node);
                        if (castedObj == null)
                        {
                            castedObj = CastingHelper.CastTo <UVTransformNode>(node);
                            if (castedObj == null)
                            {
                                castedObj = CastingHelper.CastTo <ShaderNode>(node);
                                if (castedObj == null)
                                {
                                    throw new InvalidOperationException("Node could not find cast target");
                                }
                            }
                        }
                    }
                    else
                    {
                        //texture node
                        switch (texture_node_slot)
                        {
                        case 0:
                            model.name = "Diffuse";
                            break;

                        case 1:
                            model.name = "Normal";
                            break;

                        case 2:
                            model.name = "Specular";
                            break;

                        case 3:
                            model.name = "Roughness";
                            break;

                        case 4:
                            model.name = "Metallic";
                            break;
                        }
                        texture_node_slot++;
                    }

                    model.node = castedObj;

                    out_nodes.Add(model);
                }
            }
            return(out_nodes);
        }
Esempio n. 4
0
        public object Convert(object ivalue, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (PropertyInfo.nameToTypeLookup == null)
            {
                //first time generate name to type lookups
                PropertyInfo.nameToTypeLookup = new Dictionary <string, Type>();
                var lListOfBs = (from lAssembly in AppDomain.CurrentDomain.GetAssemblies()
                                 from lType in lAssembly.GetTypes()
                                 where typeof(MochaInterface.IMeta).IsAssignableFrom(lType)
                                 select lType).ToArray();
                foreach (Type t in lListOfBs)
                {
                    PropertyInfo.nameToTypeLookup.Add(t.Name, t);
                }
            }

            var retvalue = new ObservableCollection <PropertyInfo>();

            if (ivalue != null)
            {
                object value = ivalue;
                if (parameter as string == "Component")
                {
                    //cast up
                    try
                    {
                        Type t = PropertyInfo.nameToTypeLookup[(ivalue as MochaInterface.IMeta).mytoplevelname()];
                        value = CastingHelper.castTo(ivalue, t);
                    }
                    catch (KeyNotFoundException)
                    {
                        Logger.Log("Component Error: Cannot find Component Type: " + (ivalue as MochaInterface.Component).myType);
                        return(null);
                    }
                    catch (NotSupportedException e)
                    {
                        Logger.Log("Component Error: Error converting: " + e.Message);
                        return(null);
                    }
                    catch (InvalidCastException e)
                    {
                        Logger.Log("Component Error: Error converting: " + e.Message);
                        return(null);
                    }
                }

                //get all properties
                var properties = value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (var propertyInfo in properties)
                {
                    PropertyInfo info;
                    try
                    {
                        object pvalue = propertyInfo.GetValue(value);//?? "Null";
                        info = new PropertyInfo(propertyInfo.Name, propertyInfo.PropertyType, propertyInfo, value);
                    }
                    catch (Exception)
                    {
                        info = new PropertyInfo(propertyInfo.Name, propertyInfo.PropertyType, propertyInfo, value);
                    }
                    if (propertyInfo.GetCustomAttribute(typeof(MochaDoNotShow)) == null)
                    {
                        retvalue.Add(info);
                    }
                }
                return(retvalue);
            }
            return(null);
        }