示例#1
0
        public override void Init(FObject obj, FEditor owner)
        {
            base.Init(obj, owner);

            Type evtType = obj.GetType();

            object[] customAttributes = evtType.GetCustomAttributes(typeof(FEventAttribute), false);
            if (customAttributes.Length > 0)
            {
                _isSingleFrame = ((FEventAttribute)customAttributes[0]).isSingleFrame;
            }

            if (_isSingleFrame && Evt.FrameRange.Length != 1)
            {
                FrameRange range = Evt.FrameRange;
                range.Length   = 1;
                Evt.FrameRange = range;
            }

            if (_singleFrameStyle == null)
            {
                _singleFrameStyle = FUtility.GetFluxSkin().GetStyle("SingleFrame");
            }

            GUIContent singleWidth = new GUIContent(FUtility.GetFluxTexture("SingleFrame_Active.png"));

            _singleSize = _singleFrameStyle.CalcSize(singleWidth);
        }
示例#2
0
        public T GetEditor <T>(FObject obj) where T : FEditor
        {
            if (_editorHash == null)
            {
                Refresh();
//				editorHash = new Dictionary<int, CEditor>();
//
//				int numEditors = editorHashKeys.Count;
//
//				for( int i = 0; i != numEditors; ++i )
//				{
//					editorHash.Add( editorHashKeys[i], editorHashValues[i] );
//				}
            }

            if (obj == null)
            {
                Debug.Log("obj is null");
            }

            if (_editorHash.ContainsKey(obj.GetInstanceID()))
            {
                //T editor = editorHash[obj.GetInstanceID()];
                //editor.Init( editor
                //				Debug.LogWarning ("Contains key! " + obj.GetInstanceID() + " selected? " + editorHash[obj.GetInstanceID()].IsSelected() + " id " + editorHash[obj.GetInstanceID()].GetInstanceID() );
                return((T)_editorHash[obj.GetInstanceID()]);
            }


            Type[] allTypes = typeof(FEditor).Assembly.GetTypes();

            Type editorType = typeof(T);

            Type bestEditorType = editorType;

            Type objType = obj.GetType();

            Type closestObjType = objType;

            foreach (Type type in allTypes)
            {
                if (!type.IsSubclassOf(editorType))
                {
                    continue;
                }

                object[] attributes = type.GetCustomAttributes(false);

                foreach (object o in attributes)
                {
                    if (!(o is FEditorAttribute))
                    {
                        continue;
                    }

                    FEditorAttribute editorAttribute = (FEditorAttribute)o;
                    if (editorAttribute.type == objType)
                    {
                        bestEditorType = type;
                        break;
                    }

                    if (editorAttribute.type.IsAssignableFrom(objType) && editorAttribute.type.IsSubclassOf(closestObjType))
                    {
                        bestEditorType = type;
                        closestObjType = editorAttribute.type;
                    }
                }
            }
            T editor = (T)Editor.CreateInstance(bestEditorType);

            //			editor.Init( this, obj );

            _editorHash.Add(obj.GetInstanceID(), editor);
            _editorHashKeys.Add(obj.GetInstanceID());
            _editorHashValues.Add(editor);
#if FLUX_DEBUG
            Debug.LogWarning("Creating new.. " + obj.GetInstanceID() + " selected? " + _editorHash[obj.GetInstanceID()].IsSelected() + " id " + _editorHash[obj.GetInstanceID()].GetInstanceID() + " name : " + obj.name);
#endif
            return(editor);
        }
示例#3
0
        public T GetEditor <T>(FObject obj) where T : FEditor
        {
            if (_editorHash == null)
            {
                Refresh();
            }

            if (obj == null)
            {
                Debug.Log("obj is null");
            }

            if (_editorHash.ContainsKey(obj.GetInstanceID()))
            {
                return((T)_editorHash[obj.GetInstanceID()]);
            }


            Type[] allTypes = typeof(FEditor).Assembly.GetTypes();

            Type editorType = typeof(T);

            Type bestEditorType = editorType;

            Type objType = obj.GetType();

            Type closestObjType = objType;

            foreach (Type type in allTypes)
            {
                if (!type.IsSubclassOf(editorType))
                {
                    continue;
                }

                object[] attributes = type.GetCustomAttributes(false);

                foreach (object o in attributes)
                {
                    if (!(o is FEditorAttribute))
                    {
                        continue;
                    }

                    FEditorAttribute editorAttribute = (FEditorAttribute)o;
                    if (editorAttribute.type == objType)
                    {
                        bestEditorType = type;
                        break;
                    }

                    if (editorAttribute.type.IsAssignableFrom(objType) && editorAttribute.type.IsSubclassOf(closestObjType))
                    {
                        bestEditorType = type;
                        closestObjType = editorAttribute.type;
                    }
                }
            }
            T editor = (T)Editor.CreateInstance(bestEditorType);

            _editorHash.Add(obj.GetInstanceID(), editor);
            _editorHashKeys.Add(obj.GetInstanceID());
            _editorHashValues.Add(editor);

            return(editor);
        }