Esempio n. 1
0
        public Mesh GetSFMesh(string find_name)
        {
            UnityEngine.Object[] objs = SF_Resources.LoadAll(SF_Resources.pMeshes + "sf_meshes.fbx");
            if (objs == null)
            {
                Debug.LogError("sf_meshes.fbx missing");
                return(null);
            }
            if (objs.Length == 0)
            {
                Debug.LogError("sf_meshes.fbx missing sub assets");
                return(null);
            }
            foreach (UnityEngine.Object o in objs)
            {
#if UNITY_2018_2_OR_NEWER
                if (o is GameObject)
                {
                    (o as GameObject).layer = specialLayer;
                }
#endif
                if (o.name == find_name && o.GetType() == typeof(Mesh))
                {
                    return(o as Mesh);
                }
            }
            Debug.LogError("Mesh " + find_name + " could not be found in sf_meshes.fbx");
            return(null);
        }
Esempio n. 2
0
        private static Texture2D LoadTexture(string path, string name)
        {
            //AssetDatabase.LoadAssetAtPath(

            return(SF_Resources.Load <Texture2D>(path + name));

            //return (Texture2D)Resources.Load(path + name, typeof(Texture2D) ); // TODO: This has to change into something that's not using resources
        }
        public void LoadAndInitializeIcons(Type type)
        {
            string nodeNameLower = type.Name.ToLower();


            iconActive = SF_Resources.LoadNodeIcon(nodeNameLower);             // Main icon


            if (iconActive == null)
            {
                //Debug.Log("No icon found for: " + nodeNameLower);
            }
            else
            {
                // See if additional ones exist, if it found the first

                List <Texture2D> iconList = new List <Texture2D>();
                iconList.Add(iconActive);

                Texture2D tmp;
                for (int i = 2; i < 16; i++)                                  // max 16, to prevent while-loop locking
                {
                    tmp = SF_Resources.LoadNodeIcon(nodeNameLower + "_" + i); // Search for more
                    if (tmp == null)
                    {
                        break;
                    }
                    iconList.Add(tmp);
                }

                if (iconList.Count > 1)
                {
                    icons = iconList.ToArray();
                }

                //while( tmp =
            }
        }
 public Mesh GetSFMesh(string find_name)
 {
     UnityEngine.Object[] objs = SF_Resources.LoadAll(SF_Resources.pMeshes + "sf_meshes.fbx");
     if (objs == null)
     {
         Debug.LogError("sf_meshes.fbx missing");
         return(null);
     }
     if (objs.Length == 0)
     {
         Debug.LogError("sf_meshes.fbx missing sub assets");
         return(null);
     }
     foreach (UnityEngine.Object o in objs)
     {
         if (o.name == find_name && o.GetType() == typeof(Mesh))
         {
             return(o as Mesh);
         }
     }
     Debug.LogError("Mesh " + find_name + " could not be found in sf_meshes.fbx");
     return(null);
 }
        public void LoadDataTexture(string path)
        {
            Texture2D nodeIcon = SF_Resources.LoadNodeIcon(path);

            SF_Blit.Render(texture, "ReadPackedData", nodeIcon);
        }
        public SF_EditorNodeData CheckHotkeyInput(bool mouseOverSomeNode)
        {
            bool mouseInNodeView = SF_Editor.instance.nodeView.MouseInsideNodeView(false);


            if (Event.current.type == EventType.Repaint)
            {
                smoothHotkeySelectorIndex = Mathf.Lerp(smoothHotkeySelectorIndex, hotkeySelectorIndex, 0.5f);
            }

            bool useScroll = SF_Settings.quickPickScrollWheel;

            if (holding && Event.current.type == EventType.ScrollWheel && HotkeyFriends.Count > 0 && mouseInNodeView)
            {
                if (useScroll)
                {
                    hotkeySelectorIndex += (int)Mathf.Sign(Event.current.delta.y);
                    hotkeySelectorIndex  = Mathf.Clamp(hotkeySelectorIndex, 0, HotkeyFriends.Count - 1);
                }


                // hotkeySelectorIndex = ( hotkeySelectorIndex + HotkeyFriends.Count ) % HotkeyFriends.Count; // Wrap
                Event.current.Use();
            }

            if (key == KeyCode.None)
            {
                return(null);
            }

            if (Event.current.keyCode == key)
            {
                if (Event.current.type == EventType.KeyDown && !SF_GUI.HoldingControl() && holding == false && mouseInNodeView)
                {
                    hotkeySelectorIndex       = defaultHotkeySelectorIndex;
                    smoothHotkeySelectorIndex = defaultHotkeySelectorIndex;

                    quickpickerStartPosition = Event.current.mousePosition;

                    holding = true;
                }
                if (Event.current.rawType == EventType.KeyUp)
                {
                    holding = false;
                }
            }



            if (holding && !mouseOverSomeNode)
            {
                float width   = 166f; // nodeName.Length*8 + 10;
                Rect  dispPos = new Rect(0, 0, width, 36);

                Vector2 centerPos = useScroll ? Event.current.mousePosition : quickpickerStartPosition;

                dispPos.center = centerPos;
                dispPos.y     -= dispPos.height * 0.3333f;

                //
                //GUI.Box(dispPos, nodeName, GUI.skin.button);
                //



                // Draw hotkey node picker
                //if(Event.current.type == EventType.keyDown){
                //Debug.Log(Event.current.keyCode);
                Rect nRect = dispPos; //new Rect(0,0,128,32);
                nRect.center = centerPos - Vector2.up * nRect.height * 0.3333f;
                //nRect = nRect.MovedRight();
                if (useScroll)
                {
                    nRect.y -= nRect.height * smoothHotkeySelectorIndex;
                }
                else
                {
                    nRect.y -= nRect.height * defaultHotkeySelectorIndex;
                }
                //if(Event.current.keyCode != KeyCode.None){

                Color prevCol = GUI.color;



                int i = 0;
                foreach (SF_EditorNodeData node in HotkeyFriends)
                {
                    //float dist = Mathf.Abs(smoothHotkeySelectorIndex - i);
                    //float alpha = Mathf.Clamp(1f-Mathf.Clamp01(dist*0.25f), 0.2f, 0.8f);


                    float offset = 0f;//(dist*dist)/3f;



                    //if(i == hotkeySelectorIndex){
                    //alpha = 1;
                    //offset -= 8f;
                    //GUI.Box(nRect, node.nodeName, PopupButtonStyle);
                    //}
                    Rect newNRect = nRect;
                    newNRect.x += offset;


                    if (!useScroll && newNRect.Contains(Event.current.mousePosition))
                    {
                        hotkeySelectorIndex = i;
                    }

                    bool selected = (i == hotkeySelectorIndex);

                    if (selected)
                    {
                        GUI.color = new Color(1f, 1f, 1f, 1f);
                    }
                    else
                    {
                        GUI.color = new Color(0.6f, 0.6f, 0.6f, 0.5f);
                    }

                    if (node.isProperty)
                    {
                        GUI.color *= SF_Node.colorExposed;
                    }

                    Texture2D icon = SF_Resources.LoadNodeIcon(node.type.Split('.')[1].ToLower());

                    if (icon != null)
                    {
                        newNRect.width -= newNRect.height;
                    }

                    //if(useScroll){
                    GUI.Box(newNRect, node.nodeName, PopupButtonStyle);
                    //} else {
                    //if(GUI.Button(newNRect, node.nodeName, PopupButtonStyle)){
                    //hotkeySelectorIndex = i;
                    //}
                    //}



                    if (icon != null)
                    {
                        Rect iconRect = newNRect;
                        iconRect       = iconRect.MovedRight();
                        iconRect.width = iconRect.height;
                        GUI.color      = selected ? Color.white : new Color(1f, 1f, 1f, 0.4f);
                        GUI.DrawTexture(iconRect, icon);
                    }



                    nRect = nRect.MovedDown();

                    i++;
                }
                GUI.color = prevCol;



                //}
                if (Event.current.type == EventType.KeyDown /* && Event.current.type == EventType.layout*/ /*&& GUI.GetNameOfFocusedControl() == "defocus"*/)
                {
                    Event.current.Use();
                }
                //}

                //}

                //GUI.Label(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 256,32),"currentindex = " + hotkeySelectorIndex);
            }



            bool clicked = Event.current.type == EventType.MouseDown;

            if (holding && clicked)
            {
                return(HotkeyFriends[hotkeySelectorIndex]);
            }
            else
            {
                return(null);
            }
        }