Exemplo n.º 1
0
        void IPersistantUnityObject.OnSerialize(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("pos", this.transform.position);
            info.AddValue("rot", this.transform.rotation);
            info.AddValue("scale", this.transform.localScale);

            var arr = this.GetComponentsInChildren <IPersistantUnityObject>();

            if (arr.Length > 0)
            {
                var data = new ChildObjectData();
                int cnt  = 0;

                for (int i = 0; i < arr.Length; i++)
                {
                    if (object.ReferenceEquals(this, arr[i]))
                    {
                        continue;
                    }

                    data.Path          = GameObjectUtil.GetPathNameRelativeTo((arr[i] as Component).transform, this.transform);
                    data.ComponentType = arr[i].GetType();
                    data.Pobj          = arr[i];
                    info.AddValue(cnt.ToString(), data, typeof(ChildObjectData));
                    cnt++;
                }
                info.AddValue("count", cnt);
            }
        }
        private void DrawTree(Transform avatar)
        {
            EditorGUILayout.LabelField("Mask Tree", EditorStyles.boldLabel);

            _masks.Clear();
            for (int i = 0; i < _lstDrawer.serializedProperty.arraySize; i++)
            {
                var prop = _lstDrawer.serializedProperty.GetArrayElementAtIndex(i);
                var pathProp = prop.FindPropertyRelative(PROP_ENTRY_PATH);
                var recurseProp = prop.FindPropertyRelative(PROP_ENTRY_RECURSE);

                var t = avatar.Find(pathProp.stringValue);
                if (t != null) _masks[t] = recurseProp.boolValue;
            }

            EditorGUI.BeginChangeCheck();
            this.DrawTreeRecurse(avatar, avatar, false);

            if (EditorGUI.EndChangeCheck())
            {
                _lstDrawer.serializedProperty.arraySize = _masks.Count;
                int i = 0;
                foreach (var entry in _masks)
                {
                    var prop = _lstDrawer.serializedProperty.GetArrayElementAtIndex(i);
                    var pathProp = prop.FindPropertyRelative(PROP_ENTRY_PATH);
                    var recurseProp = prop.FindPropertyRelative(PROP_ENTRY_RECURSE);

                    pathProp.stringValue = GameObjectUtil.GetPathNameRelativeTo(entry.Key, avatar);
                    recurseProp.boolValue = entry.Value;

                    i++;
                }
            }
        }