Exemple #1
0
        /// <summary>
        /// Gets path of bullet storm folder.
        /// </summary>
        /// <returns></returns>
        public static string GetBasePath()
        {
            if (!(_basePath is null) && _basePath.StartsWith("Assets/"))
            {
                return(_basePath);
            }

            var assets = AssetDatabase.FindAssets("BulletStorm t:asmdef");

            Assert.IsNotNull(assets);

            var selected = assets.ToList().ConvertAll(AssetDatabase.GUIDToAssetPath)
                           .Where(path => path.EndsWith("/BulletStorm.asmdef")).ToList();

            if (selected.Count == 1)
            {
                _basePath = selected[0].Substring(0, selected[0].LastIndexOf('/'));
                return(_basePath);
            }

            BulletStormLogger.LogError("Can't locate bullet storm assembly, find " + (selected.Count > 0
                ? selected.Count + " items:\n" + selected.Aggregate((current, next) => current + "\n" + next)
                : "0 item."));
            _basePath = "Assets/BulletStorm";
            return(_basePath);
        }
Exemple #2
0
        public void Build()
        {
            var port = GetInputPort(nameof(shape));

            if (!port.IsConnected)
            {
                BulletStormLogger.LogWarning("The output node has no input value, check if you forget to connect it.");
                return;
            }

            if (!(port.Connection.node is ShapeNode lastNode) || !lastNode)
            {
                BulletStormLogger.LogError($"Unknown output type {port.Connection.node.GetType().FullName}, expected {typeof(ShapeNode).FullName}");
                return;
            }

            lastNode.RecursiveGenerate();
            if (!(graph is ShapeGraph shapeGraph) || !shapeGraph)
            {
                BulletStormLogger.LogError($"Unknown graph type {graph.GetType().FullName}, this node is output node for {typeof(ShapeAsset).FullName}");
                return;
            }

            shapeGraph.shape = lastNode.GetShape();
        }
Exemple #3
0
        /// <summary>
        /// Compile the storm.
        /// </summary>
        /// <returns>True if successes.</returns>
        public bool Compile()
        {
            var scopes = new Stack <int>();

            try
            {
                var index = 0;
                foreach (var stormEvent in events)
                {
                    stormEvent.Compile(this, scopes, index++);
                }

                if (scopes.Count == 0)
                {
                    Compiled = true;
                }
                else
                {
                    BulletStormLogger.LogError(""); // TODO: Write error info.
                    Compiled = false;
                }
            }
            catch (StormCompileException e)
            {
                BulletStormLogger.LogException(e);
                Compiled = false;
            }

            return(Compiled);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="shapeNode"></param>
        /// <param name="inputPortName"></param>
        /// <returns>Default if failed.</returns>
        public static ShapeNode GetInputShapeNode(this ShapeNode shapeNode, string inputPortName)
        {
            var port = shapeNode.GetInputPort(inputPortName);

            if (port is null)
            {
                BulletStormLogger.LogError($"Node {shapeNode}: port 'inputShape' not found.");
                return(default);
Exemple #5
0
 private bool CheckBullet()
 {
     if (bullet)
     {
         return(true);
     }
     BulletStormLogger.LogError($"{this}: Bullet is empty!");
     return(false);
 }
Exemple #6
0
 public void Build()
 {
     if (CheckOutputNode())
     {
         outputNode.Build();
     }
     else
     {
         BulletStormLogger.LogError("Output node not found.");
     }
 }
Exemple #7
0
        /// <summary>
        /// Creates an asset of given shape.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="assetPath"></param>
        public static void CreateAsset(Shape shape, string assetPath)
        {
#if UNITY_EDITOR
            var shapeAsset = CreateInstance <ShapeAsset>();
            shapeAsset.shape = shape;
            AssetDatabase.CreateAsset(shapeAsset, assetPath);
#else
            BulletStormLogger.LogError("Can't create asset in game.");
            return;
#endif
        }
Exemple #8
0
        public override void OnCreate()
        {
            base.OnCreate();

            quaternion = target as Quaternion;
            if (quaternion is null || !quaternion)
            {
                BulletStormLogger.LogError("Failed to initiate editor.");
                return;
            }

            value     = quaternion.GetOutputPort(nameof(value));
            type      = serializedObject.FindProperty(nameof(type));
            setUpward = serializedObject.FindProperty(nameof(setUpward));
            vector0   = serializedObject.FindProperty(nameof(vector0));
            vector1   = serializedObject.FindProperty(nameof(vector1));
        }
Exemple #9
0
        public override void OnDropObjects(Object[] objects)
        {
            var  pos    = window.WindowToGridPosition(Event.current.mousePosition) - new Vector2(15, 15);
            var  cnt    = 0;
            var  offset = new Vector2(10, 10);
            var  add    = false;
            Node node   = null;

            foreach (var @object in objects)
            {
                switch (@object)
                {
                case ShapeAsset asset:
                {
                    node = CreateNode(typeof(ShapeReference), pos + offset * cnt++);
                    window.SelectNode(node, add);
                    add = true;
                    if (node is ShapeReference shapeReference)
                    {
                        shapeReference.shapeAsset = asset;
                    }
                    else
                    {
                        BulletStormLogger.LogError("An unexpected errored occured when creating node.");
                    }
                    break;
                }

                default:
                    BulletStormLogger.Log($"{@object} can't drop into shape graph");
                    break;
                }

                Util.System.SendMessage(node, "OnValidate");
            }
        }