Esempio n. 1
0
 protected void reset(bool fault = false)
 {
     configurator = target as AbstractConfigurator;
     tracker      = new GameObjectsTracker();
     tracker.GO   = configurator.gameObject;
     chosenName   = "";
     if (fault)
     {
         objectMode                  = false;
         showingConfigurations       = true;
         configuringConfiguration    = false;
         chosingNewConfigurationName = false;
     }
     else
     {
         if (!(configuringConfiguration || chosingNewConfigurationName))
         {
             showingConfigurations = true;
         }
         if (!(configuration is null))
         {
             tracker.updateDataStructures(null, configuration);
         }
         if (objectMode && objectToConfigure is null)
         {
             objectMode = false;
         }
     }
 }
        public void SaveConfiguration(GameObjectsTracker tr)
        {
            properties      = new List <string>();
            propertiesNames = new List <string>();
            advancedConf    = new List <SimpleGameObjectsTracker>();
            cleanSpecificDataStructure();
            gO                = tr.GO;
            gOName            = gO.name;
            configurationName = tr.configurationName;
            UnityEngine.Object parent = PrefabUtility.GetCorrespondingObjectFromSource(gO);
            gOType = parent != null?parent.ToString() : "";

            tracker = tr;
            Dictionary <string, FieldOrProperty> gOProperties = tr.ObjectsProperties[gO];
            List <Component> comp = tr.GOComponents[gO];

            foreach (string s in gOProperties.Keys)
            {
                if (tr.ObjectsToggled[gOProperties[s]])
                {
                    //Debug.Log("property " + s + " toggled");
                    if (tracker.IsMappable(gOProperties[s]))
                    {
                        //Debug.Log("adding " + gOProperties[s].Name());
                        properties.Add(s);
                        if (!tracker.IsBaseType(gOProperties[s]))
                        {
                            tracker.basicTypeCollectionsConfigurations[gOProperties[s]].propertyName = s;
                            advancedConf.Add(tracker.basicTypeCollectionsConfigurations[gOProperties[s]]);
                        }
                        else
                        {
                            specificConfiguration(gOProperties[s], s);
                        }
                    }
                    else if (tracker.ObjectDerivedFromFields.ContainsKey(gO))
                    {
                        //Debug.Log("recursing on " + gOProperties[s].Name());
                        recursevelyAdd(gO, gOProperties[s], "");
                    }
                }
            }
            foreach (Component c in comp)
            {
                if (tr.ObjectsToggled[c])
                {
                    //Debug.Log("adding " + c.GetType().ToString());
                    // properties.Add(c.GetType().ToString());
                    Dictionary <string, FieldOrProperty> componentProperties = tr.ObjectsProperties[c];
                    foreach (string s in componentProperties.Keys)
                    {
                        if (tr.ObjectsToggled[componentProperties[s]])
                        {
                            if (tracker.IsMappable(componentProperties[s]))
                            {
                                string adding = c.GetType() + "^" + s;
                                // Debug.Log("adding " + c.GetType().ToString() + "^" + s);
                                properties.Add(adding);
                                if (tracker.IsBaseType(componentProperties[s]))
                                {
                                    specificConfiguration(componentProperties[s], adding);
                                }
                                int startFrom = 0;
                                while (startFrom < adding.Length - 1 && adding.IndexOf("^", startFrom) != -1)
                                {
                                    int currentIndex = adding.IndexOf("^", startFrom);
                                    properties.Add(adding.Substring(0, currentIndex));
                                    startFrom = currentIndex + 1;
                                }
                                properties.Add(adding);
                                if (!tracker.IsBaseType(componentProperties[s]))
                                {
                                    tracker.basicTypeCollectionsConfigurations[componentProperties[s]].propertyName = adding;
                                    advancedConf.Add(tracker.basicTypeCollectionsConfigurations[componentProperties[s]]);
                                }
                            }
                            else if (tracker.ObjectDerivedFromFields.ContainsKey(c))// && !tracker.IsBaseType(componentProperties[s]))
                            {
                                //Debug.Log("recursing on " + c.name);
                                recursevelyAdd(c, componentProperties[s], c.GetType() + "^");
                            }
                        }
                    }
                }
            }
            if (properties.Count == 0)
            {
                throw new Exception("No properties selected, invalid configuration to save.");
            }
            //Debug.Log("success");
        }