Exemple #1
0
 void ResetReference()
 {
     m_SceneGuid = m_GameObjectGuid = null;
     m_SerializedComponentType = new SerializedType(null);
     m_ComponentIndex          = 0;
     m_AssetObject             = null;
     m_ReferencedObject        = null;
     m_Prefab = null;
 }
Exemple #2
0
        /// <summary>
        /// Resets/updates this reference to a new object.
        /// </summary>
        /// <param name="newObject"></param>
        public void Update(Object newObject)
        {
            ResetInitialization();
            ResetReference();
            if (newObject == null)
            {
                SaveProperties();
                return;
            }

            SceneObjectGuid guidComponent;

            GameObject go;

            if (newObject is Component)
            {
                Component component = newObject as Component;
                go                        = component.gameObject;
                guidComponent             = go.GetComponent <SceneObjectGuid>();
                m_SerializedComponentType = new SerializedType(component.GetType());
                m_ComponentIndex          = Array.IndexOf(go.GetComponents(component.GetType()), component);
            }
            else if (newObject is GameObject)
            {
                go = newObject as GameObject;
                if (PrefabUtility.IsPartOfPrefabAsset(go))
                {
                    m_Prefab = go;
                    SaveProperties();
                    return;
                }
                guidComponent = go.GetComponent <SceneObjectGuid>();
            }
            else
            {
                m_ReferencedObject = m_AssetObject = newObject;
                SaveProperties();
                return;
            }

            if (guidComponent == null)
            {
                guidComponent = go.AddComponent <SceneObjectGuid>();
                Undo.RegisterCreatedObjectUndo(guidComponent, "Created GUID component");
            }

            m_GameObjectGuid = guidComponent.Id;
            m_SceneGuid      = GetSceneId(go);
            if (string.IsNullOrEmpty(m_SceneGuid))
            {
                Debug.LogError("The scene needs to be saved");
                return;
            }

            SaveProperties();
        }
Exemple #3
0
        /// <summary>
        /// Constructs from a SerializedProperty.
        /// </summary>
        /// <param name="property"></param>
        public SceneObjectReference(SerializedProperty property)
        {
            m_SceneGuidProperty               = property.FindPropertyRelative("m_SceneGuid");
            m_GameObjectGuidProperty          = property.FindPropertyRelative("m_GameObjectGuid");
            m_SerializedComponentTypeProperty = property.FindPropertyRelative("m_SerializedComponentType.m_TypeName");
            m_ComponentIndexProperty          = property.FindPropertyRelative("m_ComponentIndex");
            m_AssetObjectProperty             = property.FindPropertyRelative("m_AssetObject");
            m_PrefabProperty = property.FindPropertyRelative("m_Prefab");

            m_SceneGuid               = m_SceneGuidProperty.stringValue;
            m_GameObjectGuid          = m_GameObjectGuidProperty.stringValue;
            m_SerializedComponentType = new SerializedType(Type.GetType(m_SerializedComponentTypeProperty.stringValue));
            m_ComponentIndex          = m_ComponentIndexProperty.intValue;
            m_AssetObject             = m_AssetObjectProperty.objectReferenceValue;
            m_Prefab = m_PrefabProperty.objectReferenceValue as GameObject;

            Init();
        }
 public EditorWindowType(SerializedType editorWindowType)
 {
     Type = editorWindowType;
 }
Exemple #5
0
 /// <summary>
 /// Constructs with type and criterion.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="criterion"></param>
 public TypedCriterion(SerializedType type, Criterion criterion)
 {
     Type      = type;
     Criterion = criterion;
 }
Exemple #6
0
 /// <summary>
 /// Constructs from a SerializedType.
 /// </summary>
 /// <param name="serializedType"></param>
 public TypeAndFutureReference(SerializedType serializedType)
 {
     this.SerializedType = serializedType;
 }