Пример #1
0
    public override void BehaviorEnabled()
    {
        SubstanceComponent sComponent = GetComponent <SubstanceComponent>();

        if (calculateVolumeAndMass)
        {
            if (sComponent != null)
            {
                volume = sComponent.substance.voxels.Count;
            }
            if (volume == 0)
            {
                volume = 1;
            }
        }
        Rigidbody rigidBody = GetComponent <Rigidbody>();

        if (rigidBody != null)
        {
            rigidBody.isKinematic = false;
            if (calculateVolumeAndMass)
            {
                rigidBody.mass = volume * density;
            }
            rigidBody.useGravity = gravity;
        }
    }
Пример #2
0
    public override EntityComponent InitEntityGameObject(VoxelArray voxelArray, bool storeComponent = true)
    {
        GameObject substanceObject = new GameObject();

        substanceObject.name               = "Substance";
        substanceObject.transform.parent   = voxelArray.transform;
        substanceObject.transform.position = PositionInEditor();
        foreach (Voxel voxel in voxels)
        {
            if (storeComponent)
            {
                voxel.transform.parent = substanceObject.transform;
            }
            else
            {
                // clone
                Voxel vClone = voxel.Clone();
                vClone.transform.parent   = substanceObject.transform;
                vClone.transform.position = voxel.transform.position;
                vClone.transform.rotation = voxel.transform.rotation;
            }
        }
        SubstanceComponent component = substanceObject.AddComponent <SubstanceComponent>();

        component.entity    = this;
        component.substance = this;
        component.health    = health;
        if (storeComponent)
        {
            this.component = component;
        }
        return(component);
    }
Пример #3
0
    public override void Start()
    {
        SubstanceComponent substanceComponent = GetComponent <SubstanceComponent>();

        if (substanceComponent != null)
        {
            foreach (Voxel voxel in substanceComponent.substance.voxels)
            {
                float top = voxel.GetBounds().max.y - transform.position.y;
                if (top > waterLevel)
                {
                    waterLevel = top;
                }
            }
        }
        base.Start();
    }
Пример #4
0
    public override void Start()
    {
        voxels = new List <Vector3>();
        SubstanceComponent substanceComponent = GetComponent <SubstanceComponent>();

        if (substanceComponent != null)
        {
            foreach (Voxel voxel in substanceComponent.substance.voxels)
            {
                voxels.Add(voxel.GetBounds().center - transform.position);
            }
        }
        else
        {
            voxels.Add(Vector3.zero);
        }
        base.Start();
    }
Пример #5
0
    public override EntityComponent InitEntityGameObject(VoxelArray voxelArray, bool storeComponent = true)
    {
        GameObject substanceObject = new GameObject();

        substanceObject.name               = "Substance";
        substanceObject.transform.parent   = voxelArray.transform;
        substanceObject.transform.position = PositionInEditor();

        var voxelComponents = new HashSet <VoxelComponent>();

        foreach (Voxel v in voxels)
        {
            voxelComponents.Add(v.voxelComponent);
        }
        foreach (VoxelComponent vc in voxelComponents)
        {
            // TODO: need to update this!
            if (storeComponent)
            {
                vc.transform.parent = substanceObject.transform;
            }
            else
            {
                // clone
                VoxelComponent vClone = vc.Clone();
                vClone.transform.parent   = substanceObject.transform;
                vClone.transform.position = vc.transform.position;
                vClone.transform.rotation = vc.transform.rotation;
            }
        }
        SubstanceComponent component = substanceObject.AddComponent <SubstanceComponent>();

        component.entity    = this;
        component.substance = this;
        component.health    = health;
        if (storeComponent)
        {
            this.component = component;
        }
        return(component);
    }