Esempio n. 1
0
        public AdapterAnalysis(object target)
        {
            if (null != target)
            {
                ComponentAdapter = target as ComponentAdapter;
                SkinnableComponentAdapter = target as SkinnableComponentAdapter;
                SkinnableContainerAdapter = target as SkinnableContainerAdapter;
                GroupAdapter = target as GroupAdapter;

                if (null != GroupAdapter)
                {
                    HasAbsoluteLayout = CheckForAbsoluteLayout(GroupAdapter);
                }    
                
                if (null != ComponentAdapter && null != ComponentAdapter.transform && null != ComponentAdapter.transform.parent)
                {
                    ParentGroupAdapter = ComponentAdapter.transform.parent.GetComponent<GroupAdapter>();
                    HasParent = null != ParentGroupAdapter;
                    if (null != ParentGroupAdapter)
                    {
                        ParentIsStage = ParentGroupAdapter is StageAdapter;
                        //ParentUsesLayoutDescriptor = ParentContainerAdapter.UseLayoutDescriptor;
                        //ParentLayoutDescriptor = ParentContainerAdapter.LayoutDescriptor;
                        ParentLayout = ParentGroupAdapter.Layout;

                        ParentHasAbsoluteLayout = CheckForAbsoluteLayout(ParentGroupAdapter);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Since all of the tree displays use the selection change, I decided to implement it in superclass
        /// </summary>
        internal void ProcessSelectionChange()
        {
            //Debug.Log("ProcessSelectionChange: " + Selection.activeObject);
            if (null == Selection.activeGameObject)
                return;

            GameObject go = Selection.activeGameObject;

            /*if (null == go)
                throw new Exception("Couldn't get the selection");*/

            Adapter = go.GetComponent(typeof(ComponentAdapter)) as ComponentAdapter;
            if (null == Adapter)
            {
                /**
                 * Not a GUI component
                 * S hould do cleanup and handle selection (deselect basically)
                 * */
                GroupAdapter = null;
                //HandleSelectionChange();
                return;
            }
            Target = Adapter;
            GroupAdapter = Target as GroupAdapter;
            
            HandleSelectionChange();
        }
Esempio n. 3
0
        ///<summary>
        ///</summary>
        ///<param name="adapter"></param>
        ///<returns></returns>
        public static List<ChildGroupDescriptor> GetChildGroupsReferences(GroupAdapter adapter)
        {
            Type adapterType = adapter.GetType();
            Type componentType = adapter.ComponentType;
            List<ChildGroupDescriptor> descriptors = new List<ChildGroupDescriptor>();

            foreach (MemberInfo memberInfo in adapterType.GetMembers())
            {
                var attributes = Core.Reflection.CoreReflector.GetMemberAttributes<ChildCollectionAttribute>(memberInfo);

                if (null != attributes && attributes.Count > 0)
                {
                    ChildCollectionAttribute attribute = attributes[0];
                    MemberInfo mi = null;
                    if (!string.IsNullOrEmpty(attribute.TargetContainer)) {
                        MemberInfo[] list = componentType.GetMember(attribute.TargetContainer);
                        if (list.Length > 0)
                            mi = list[0];
                    }
                    
                    ChildGroupDescriptor descriptor = new ChildGroupDescriptor
                    {
                        Attribute = attribute,
                        CollectionMemberInfo = memberInfo,
                        TargetContainerMemberInfo = mi
                    };
                    descriptors.Insert(0, descriptor);
                }
            }

            return descriptors;
        }
Esempio n. 4
0
        public GroupManager(GroupAdapter adapter)
        {
            //Debug.Log("Creating GroupManager");
            _groupAdapter = adapter;
            _groupDescriptors = DesignerReflection.GetChildGroupsReferences(adapter);

            _pack = ChildGroupPack.Read(adapter);
        }
        public static void Write(GroupAdapter parentAdapter, ChildGroupPack pack)
        {
            ChildGroupPack currentGroupPack = ChildGroupPack.Read(parentAdapter);
            Debug.Log(string.Format("ParentAdapter: {0}, {1}", parentAdapter,
                                    parentAdapter.GetInstanceID()));

            for (int i = 0; i < currentGroupPack.Groups.Count; i++)
            {
                var currentGroup = currentGroupPack.Groups[i];
                Debug.Log("newGroup.Adapters: " + currentGroup.Adapters.Count);
                currentGroup.Adapters.Clear();
                //Debug.Log("newGroup.Adapters 2: " + newGroup.Adapters.Count);
                currentGroup.Adapters.AddRange(pack.Groups[i].Adapters);
                Debug.Log("newGroup.Adapters 2: " + currentGroup.Adapters.Count);
            }
        }
Esempio n. 6
0
        private void InitializeHandler(Core.Events.Event e)
        {
            _component.RemoveEventListener(FrameworkEvent.INITIALIZE, InitializeHandler);

            GroupAdapter groupAdapter = this as GroupAdapter;

            if (null != groupAdapter)
            {
                groupAdapter.InstantiateChildren(_assignToDescriptor);
            }
            //else
            //{
            //    // TODO: This is for some future implementation (designer skins etc..)
            //    //Debug.Log("_component: " + _component);
            //    // PREINITIALIZE was needed *because of this *
            //    // but INITIALIZE is the right event, because coded skins are created after PREINITIALIZE!!!
            //    /*SkinnableComponent skinnableComponent = _component as SkinnableComponent;
            //    if (null != skinnableComponent)
            //    {
            //        //Debug.Log("Processing skinnable component", this);

            //        // this is a skinnable component
            //        // look for a skin

            //        var adapter = GuiLookup.FindAdapter(gameObject, "skin");
            //        if (null == adapter || !gameObject.activeInHierarchy || !adapter.enabled)
            //            return;

            //        //Debug.Log("    adapter skin: " + adapter, adapter);

            //        var skin = adapter.Produce(true, true);
            //        if (null != skin)
            //        {
            //            //Debug.Log("        About to attach adapter skin: " + skin, adapter);
            //            try {
            //                skinnableComponent.AttachAdapterSkin(skin);
            //            }
            //            catch (Exception ex)
            //            {
            //                Debug.LogError(ex, adapter);
            //            }
            //        }
            //    }*/
            //}
        }
Esempio n. 7
0
        protected bool CheckSelection(bool mustBeContainer, bool renderMessage = true)
        {
            if (null == Selection.activeTransform)
            {
                if (renderMessage)
                    GUILayout.Label(GuiContentCache.Instance.NoSelectionContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                return false;
            }

            Adapter = GuiLookup.GetAdapter(Selection.activeTransform);
            GroupAdapter = Adapter as GroupAdapter;

            if (null == Adapter)
            {
                if (renderMessage)
                    GUILayout.Label(GuiContentCache.Instance.NotEDrivenComponentContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                return false;
            }

            if (mustBeContainer && null == GroupAdapter)
            {
                if (renderMessage)
                    GUILayout.Label(GuiContentCache.Instance.NotAContainerContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                return false;
            }

            return true;
        }
Esempio n. 8
0
        public static ChildGroupRenderingList BuildContentGroups(GroupAdapter groupAdapter)
        {
            //Debug.Log("BuildContentGroups");
            ChildGroupRenderingList childGroupList = new ChildGroupRenderingList();

            var groupDescriptors = DesignerReflection.GetChildGroupsReferences(groupAdapter);
            bool skipFirst = false;
            if (groupDescriptors.Count > 0)
            {
                skipFirst = groupDescriptors[0].Attribute.ShowHeader;
            }

            foreach (ChildGroupDescriptor descriptor in groupDescriptors)
            {
                var attr = descriptor.Attribute;

                ChildGroup group;

                if (attr.ShowHeader)
                {
                    Texture iconTexture = null;

                    if (!string.IsNullOrEmpty(attr.Icon))
                        iconTexture = (Texture)Resources.Load(attr.Icon);

                    group = new ChildGroup(new GUIContent(attr.Label, iconTexture, attr.Tooltip));
                }
                else
                {
                    group = new ChildGroup();
                }

                List<ComponentAdapter> adapters = Core.Reflection.CoreReflector.GetMemberValue(descriptor.CollectionMemberInfo, groupAdapter) as List<ComponentAdapter>;

                // temp hack
                // ReSharper disable ConvertIfStatementToNullCoalescingExpression
                if (null == adapters)
                // ReSharper restore ConvertIfStatementToNullCoalescingExpression
                {
                    // ReSharper disable AssignNullToNotNullAttribute
                    adapters = new List<ComponentAdapter>(Core.Reflection.CoreReflector.GetMemberValue(descriptor.CollectionMemberInfo, groupAdapter) as ComponentAdapter[]);
                    // ReSharper restore AssignNullToNotNullAttribute
                }

                //Debug.Log("adapters.Count: " + adapters.Count);
                foreach (ComponentAdapter adapter in adapters)
                {
                    //Debug.Log("  -> adapter: " + adapter);
                    if (null != adapter)
                    {
                        var dataObject = new OrderDisplayRow(adapter.ToString(), adapter, new Rect(0, 0, 0, 0))
                        {
                            Color = (adapter is GroupAdapter) ? Dark : Light,
                            IsContainer = adapter is GroupAdapter
                        };

                        if (skipFirst)
                            dataObject.YMin = OrderDisplay.ElementHeight;

                        //Debug.Log("Adding " + dataObject);
                        group.Add(dataObject);
                    }
                }

//                Debug.Log(string.Format(@"***** Group created: 
//{0}
//
//", group));
                childGroupList.AddGroup(group);
            }

            //Debug.Log(childGroupList);

            return childGroupList;
        }
Esempio n. 9
0
 public void Update(GroupAdapter parentAdapter)
 {
     Update(parentAdapter, null);
 }
Esempio n. 10
0
        /// <summary>
        /// Scans the supplied parent adapter
        /// Converts ChildGroupPacks to SaveablePacks and saves them to dictionary
        /// These packs are used later (in "Process" method) to apply the changes after the play mode is stopped
        /// </summary>
        /// <param name="parentAdapter"></param>
        /// <param name="pack"></param>
        public void Update(GroupAdapter parentAdapter, ChildGroupPack pack)
        {
            //Debug.Log("Update: " + parentAdapter);
#if DEBUG
            if (DebugMode)
            {
                //Debug.Log(string.Format("Linking {0} -> {1}", parentAdapter, childAdapter));
                Debug.Log(string.Format("ParentChildLinker: Updating {0}", parentAdapter));
            }
#endif
            //Debug.Log("parentAdapter: " + parentAdapter);
            // 1. we have to monitor parentAdapter for later (if not yet monitored)
            if (Application.isPlaying)
                PersistenceManager.Instance.Watch(parentAdapter);

            // 2. if no pack supplied, read it now
            if (null == pack)
            {
                //Debug.Log("ParentChildLinker: Pack not defined. Reading now.");
                pack = ChildGroupPack.Read(parentAdapter);
            }

            // 3. register adapters for later
            pack.RegisterAdapters();

            // 4. get relation object
            var guidPack = pack.ToSaveablePack();

            // 5. cache it (overwrite existing!)
            _changes[guidPack.ParentInstanceId] = guidPack;
        }
Esempio n. 11
0
 private ChildGroupPack(GroupAdapter parentAdapter)
 {
     _parentAdapter = parentAdapter;
 }
Esempio n. 12
0
        public static ChildGroupPack Read(GroupAdapter groupAdapter)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format(@"Read"));
            }
#endif
            ChildGroupPack childGroupPack = new ChildGroupPack(groupAdapter);

            var groupDescriptors = DesignerReflection.GetChildGroupsReferences(groupAdapter);

            foreach (ChildGroupDescriptor groupDescriptor in groupDescriptors)
            {
                List<ComponentAdapter> adapters = Core.Reflection.CoreReflector.GetMemberValue(groupDescriptor.CollectionMemberInfo, groupAdapter) as List<ComponentAdapter>;

                ChildGroup childGroup = new ChildGroup(adapters)
                {
                    GroupName = groupDescriptor.CollectionMemberInfo.Name
                };
                childGroupPack.Add(childGroup);
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("Read. childGroupPack: " + childGroupPack);
            }
#endif

            return childGroupPack;
        }
Esempio n. 13
0
 public bool CheckForAbsoluteLayout(GroupAdapter groupAdapter)
 {
     //return containerAdapter.UseLayoutDescriptor && containerAdapter.LayoutDescriptor == LayoutDescriptor.Absolute ||
     //                !containerAdapter.UseLayoutDescriptor && containerAdapter.Layout == ContainerAdapter.LayoutEnum.Absolute;
     return groupAdapter.Layout == GroupAdapter.LayoutEnum.Absolute;
 }