Пример #1
0
        // ----------------------------------------------------------------------
        /// Determines if the vsObject refers to an element of the given type.
        ///
        /// @param vsObj The object on which the search occurs.
        ///
        public static bool IsLocalType(iCS_EditorObject vsObj)
        {
            // First determine if the type is included inside the GameObject.
            var iStorage = vsObj.IStorage;
            var baseType = CodeGenerationUtility.GetBaseType(iStorage);

            if (vsObj.IsIncludedInType(baseType))
            {
                return(true);
            }
            var typeNode = vsObj.ParentTypeNode;

            if (typeNode == null)
            {
                return(false);
            }
            if (vsObj.Namespace == CodeGenerationUtility.GetNamespace(iStorage))
            {
                return(vsObj.TypeName == typeNode.CodeName);
            }
            return(false);
        }
        // ----------------------------------------------------------------------
        void CanvasMenu(iCS_EditorObject selectedObject, iCS_IStorage iStorage)
        {
            // Don't show any menu if behaviour not visible.
            if (selectedObject.IsIconizedInLayout || selectedObject.IsFoldedInLayout)
            {
                return;
            }

            iCS_MenuContext[] menu = new iCS_MenuContext[3];
            menu[0] = new iCS_MenuContext(VariableCreationStr);
            menu[1] = new iCS_MenuContext(FunctionCreationStr);
            menu[2] = new iCS_MenuContext(NestedTypeCreationStr);
            // Add Unity message handlers
            var baseType = CodeGenerationUtility.GetBaseType(iStorage);

            if (iCS_Types.IsA <MonoBehaviour>(baseType))
            {
                var libraryType   = LibraryController.LibraryDatabase.GetLibraryType(typeof(MonoBehaviour));
                var eventHandlers = libraryType.GetMembers <LibraryEventHandler>();
                int len           = P.length(eventHandlers);
                int idx           = GrowMenuBy(ref menu, len);
                for (int i = 0; i < len; ++i)
                {
                    var    eventHandler  = eventHandlers[i];
                    string nodeName      = eventHandler.nodeName;
                    string displayString = eventHandler.displayString;
                    if (iCS_AllowedChildren.CanAddChildNode(nodeName, VSObjectType.InstanceMessage, selectedObject, iStorage))
                    {
                        menu[idx + i] = new iCS_MenuContext(String.Concat("+ " + AddUnityEventStr, displayString), eventHandler);
                    }
                    else
                    {
                        menu[idx + i] = new iCS_MenuContext(String.Concat("#+ " + AddUnityEventStr, displayString), eventHandler);
                    }
                }
            }
            ShowMenu(menu, selectedObject, iStorage);
        }
Пример #3
0
        // -----------------------------------------------------------------------
        void Toolbar()
        {
            // No toolbar if editor snapshot without background requested.
            if (iCS_DevToolsConfig.IsFrameWithoutBackground)
            {
                return;
            }

            // Build standard toolbar at top of editor window.
            Rect r = iCS_ToolbarUtility.BuildToolbar(position.width, 0f);

            // Insert an initial spacer.
            float spacer = 8f;

            // --------------
            // LEFT TOOLBAR
            // -- Navigation History --
            var   backwardNavigationIcon = iCS_BuiltinTextures.BackwardNavigationHistoryIcon();
            var   forwardNavigationIcon  = iCS_BuiltinTextures.ForwardNavigationHistoryIcon();
            var   hasBackwardHistory     = IStorage.HasBackwardNavigationHistory;
            float width = backwardNavigationIcon.width + spacer;

            if (iCS_ToolbarUtility.Button(ref r, width, hasBackwardHistory, backwardNavigationIcon, 0, 0))
            {
                if (hasBackwardHistory)
                {
                    iCS_UserCommands.ReloadFromBackwardNavigationHistory(IStorage);
                }
            }
            var hasForwardHistory = IStorage.HasForwardNavigationHistory;

            width = forwardNavigationIcon.width + spacer;
            if (iCS_ToolbarUtility.Button(ref r, width, hasForwardHistory, forwardNavigationIcon, 0, 0))
            {
                if (hasForwardHistory)
                {
                    iCS_UserCommands.ReloadFromForwardNavigationHistory(IStorage);
                }
            }

            // -- Generate & Delete C#
            if (iCS_ToolbarUtility.Button(ref r, 100, true, "Generate C#", spacer, 0))
            {
                var codeGenerator = new CodeGenerator();
                codeGenerator.GenerateCodeFor(IStorage);
            }
            if (iCS_ToolbarUtility.Button(ref r, 100, true, "Delete C#", spacer, 0))
            {
                var codeGenerator = new CodeGenerator();
                codeGenerator.DeleteGeneratedFilesFor(IStorage);
            }


            // -- Zoom factor --
            float newScale = iCS_ToolbarUtility.Slider(ref r, kSliderSize, Scale, 2f, 0.15f, spacer, spacer, true);

            iCS_ToolbarUtility.MiniLabel(ref r, "Zoom", 10f, 0, true);
            if (Math3D.IsNotEqual(newScale, Scale))
            {
                Vector2 pivot = ViewportToGraph(ViewportCenter);
                CenterAtWithScale(pivot, newScale);
            }

            // -- Visual Script Settings --
            if (iCS_ToolbarUtility.Button(ref r, 100, true, "Visual Script Settings", 0, spacer, true))
            {
                VisualScriptSettingsEditor.Init(IStorage);
            }

            // -- Show Display Root Node. --
            if (IStorage.DisplayRoot != IStorage.RootObject)
            {
                IStorage.ShowDisplayRootNode = iCS_ToolbarUtility.Toggle(ref r, IStorage.ShowDisplayRootNode, spacer, spacer);
                iCS_ToolbarUtility.MiniLabel(ref r, "Show Root Node", 0, 0);
                iCS_ToolbarUtility.Separator(ref r);
            }

            // --------------
            // CENTER TOOLBAR
            // Show game object name in middle of toolbar.
            var projectName = "";
            var project     = IStorage.Package;

            if (project != null)
            {
                projectName = project.PackageName + " -- ";
            }
            var vsName   = IStorage.TypeName;
            var baseType = CodeGenerationUtility.GetBaseType(IStorage);

            if (baseType != null && baseType != typeof(void))
            {
                vsName += " : " + baseType.Name;
            }
            iCS_ToolbarUtility.CenteredTitle(ref r, projectName + vsName);

            // Trial information.
            ShowTrialInformation(ref r);

            // Show scroll position
            var scrollPositionAsStr        = ScrollPosition.ToString();
            var scrollPositionAsGUIContent = new GUIContent(scrollPositionAsStr);
            var scrollPositionSize         = EditorStyles.label.CalcSize(scrollPositionAsGUIContent);

            r = new Rect(position.width - scrollPositionSize.x, position.height - scrollPositionSize.y,
                         scrollPositionSize.x, scrollPositionSize.y);
            GUI.Label(r, scrollPositionAsGUIContent);
        }